pro_reloc_symbolic.c [plain text]
#include "config.h"
#include "libdwarfdefs.h"
#include <stdio.h>
#include <string.h>
#include "pro_incl.h"
#include "pro_section.h"
#include "pro_reloc.h"
#include "pro_reloc_symbolic.h"
int
_dwarf_pro_reloc_name_symbolic(Dwarf_P_Debug dbg, int base_sec_index, Dwarf_Unsigned offset,
Dwarf_Unsigned symidx,
enum Dwarf_Rel_Type type,
int reltarget_length)
{
void *relrec_to_fill;
int res;
struct Dwarf_Relocation_Data_s *slotp;
res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index,
&relrec_to_fill);
if (res != DW_DLV_OK)
return res;
slotp = (struct Dwarf_Relocation_Data_s *) relrec_to_fill;
slotp->drd_type = type;
slotp->drd_length = reltarget_length;
slotp->drd_offset = offset;
slotp->drd_symbol_index = symidx;
return DW_DLV_OK;
}
int
_dwarf_pro_reloc_length_symbolic(Dwarf_P_Debug dbg, int base_sec_index, Dwarf_Unsigned offset,
Dwarf_Unsigned start_symidx,
Dwarf_Unsigned end_symidx,
enum Dwarf_Rel_Type type,
int reltarget_length)
{
void *relrec_to_fill;
int res;
struct Dwarf_Relocation_Data_s *slotp1;
struct Dwarf_Relocation_Data_s *slotp2;
res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index,
&relrec_to_fill);
if (res != DW_DLV_OK)
return res;
slotp1 = (struct Dwarf_Relocation_Data_s *) relrec_to_fill;
res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index,
&relrec_to_fill);
if (res != DW_DLV_OK)
return res;
slotp2 = (struct Dwarf_Relocation_Data_s *) relrec_to_fill;
slotp1->drd_type = type;
slotp1->drd_length = reltarget_length;
slotp1->drd_offset = offset;
slotp1->drd_symbol_index = start_symidx;
slotp2->drd_type = dwarf_drt_second_of_length_pair;
slotp2->drd_length = reltarget_length;
slotp2->drd_offset = offset;
slotp2->drd_symbol_index = end_symidx;
return DW_DLV_OK;
}
static void
_dwarf_reset_reloc_sect_info(struct Dwarf_P_Per_Reloc_Sect_s *pblk,
unsigned long ct)
{
pblk->pr_reloc_total_count = 0;
pblk->pr_first_block = 0;
pblk->pr_last_block = 0;
pblk->pr_block_count = 0;
pblk->pr_slots_per_block_to_alloc = ct;
}
int
_dwarf_symbolic_relocs_to_disk(Dwarf_P_Debug dbg,
Dwarf_Signed * new_sec_count)
{
Dwarf_Small *data;
int sec_index;
int res;
unsigned long i;
Dwarf_Error error;
Dwarf_Signed sec_count = 0;
Dwarf_P_Per_Reloc_Sect p_reloc = &dbg->de_reloc_sect[0];
for (i = 0; i < NUM_DEBUG_SECTIONS; ++i, ++p_reloc) {
unsigned long ct = p_reloc->pr_reloc_total_count;
struct Dwarf_P_Relocation_Block_s *p_blk;
struct Dwarf_P_Relocation_Block_s *p_blk_last;
int err;
if (ct == 0) {
continue;
}
++sec_count;
sec_index = p_reloc->pr_sect_num_of_reloc_sect;
if (sec_index == 0) {
int rel_section_index;
int int_name;
Dwarf_Unsigned name_idx;
if (dbg->de_func_b) {
rel_section_index =
dbg->de_func_b(_dwarf_rel_section_names[i],
dbg->de_relocation_record_size,
SHT_REL,
0,
SHN_UNDEF,
dbg->de_elf_sects[i],
&name_idx, &err);
} else {
rel_section_index =
dbg->de_func(_dwarf_rel_section_names[i],
dbg->de_relocation_record_size,
SHT_REL,
0,
SHN_UNDEF,
dbg->de_elf_sects[i], &int_name, &err);
name_idx = int_name;
}
if (rel_section_index == -1) {
{
_dwarf_p_error(dbg, &error, DW_DLE_ELF_SECT_ERR);
return (DW_DLV_ERROR);
}
}
p_reloc->pr_sect_num_of_reloc_sect = rel_section_index;
sec_index = rel_section_index;
}
p_blk = p_reloc->pr_first_block;
if (p_reloc->pr_block_count > 1) {
struct Dwarf_P_Relocation_Block_s *new_blk;
_dwarf_reset_reloc_sect_info(p_reloc, ct);
res = _dwarf_pro_pre_alloc_n_reloc_slots(dbg, (int) i, ct);
if (res != DW_DLV_OK) {
return res;
}
new_blk = p_reloc->pr_first_block;
data = (Dwarf_Small *) new_blk->rb_data;
do {
unsigned long len =
p_blk->rb_where_to_add_next - p_blk->rb_data;
memcpy(data, p_blk->rb_data, len);
data += len;
p_blk_last = p_blk;
p_blk = p_blk->rb_next;
_dwarf_p_dealloc(dbg, (Dwarf_Small *) p_blk_last);
} while (p_blk);
new_blk->rb_next_slot_to_use = ct;
new_blk->rb_where_to_add_next = (char *) data;
p_reloc->pr_reloc_total_count = ct;
}
}
*new_sec_count = 0;
return DW_DLV_OK;
}