Index: libdwarf/_libdwarf.h =================================================================== --- libdwarf/_libdwarf.h +++ libdwarf/_libdwarf.h @@ -49,7 +49,7 @@ struct _libdwarf_globals { Dwarf_Handler errhand; Dwarf_Ptr errarg; - int applyrela; + int applyreloc; }; extern struct _libdwarf_globals _libdwarf; Index: libdwarf/dwarf_reloc.c =================================================================== --- libdwarf/dwarf_reloc.c +++ libdwarf/dwarf_reloc.c @@ -33,8 +33,8 @@ { int oldapply; - oldapply = _libdwarf.applyrela; - _libdwarf.applyrela = apply; + oldapply = _libdwarf.applyreloc; + _libdwarf.applyreloc = apply; return (oldapply); } Index: libdwarf/dwarf_set_reloc_application.3 =================================================================== --- libdwarf/dwarf_set_reloc_application.3 +++ libdwarf/dwarf_set_reloc_application.3 @@ -47,6 +47,8 @@ If the argument .Ar apply holds a non-zero value, the library will process all the relevant +.Dq ".rel" +and .Dq ".rela" relocation sections and will apply the relocation records found to their corresponding DWARF sections. Index: libdwarf/libdwarf.c =================================================================== --- libdwarf/libdwarf.c +++ libdwarf/libdwarf.c @@ -31,5 +31,5 @@ struct _libdwarf_globals _libdwarf = { .errhand = NULL, .errarg = NULL, - .applyrela = 1 + .applyreloc = 1 }; Index: libdwarf/libdwarf_elf_init.c =================================================================== --- libdwarf/libdwarf_elf_init.c +++ libdwarf/libdwarf_elf_init.c @@ -50,7 +50,37 @@ }; static void -_dwarf_elf_apply_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data, +_dwarf_elf_apply_rel_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data, + Elf_Data *symtab_data, int endian) +{ + Dwarf_Unsigned type; + GElf_Rel rel; + GElf_Sym sym; + size_t symndx; + uint64_t offset; + int size, j; + + j = 0; + while (gelf_getrel(rel_data, j++, &rel) != NULL) { + symndx = GELF_R_SYM(rel.r_info); + type = GELF_R_TYPE(rel.r_info); + + if (gelf_getsym(symtab_data, symndx, &sym) == NULL) + continue; + + offset = rel.r_offset; + size = _dwarf_get_reloc_size(dbg, type); + + if (endian == ELFDATA2MSB) + _dwarf_write_msb(buf, &offset, sym.st_value, size); + else + _dwarf_write_lsb(buf, &offset, sym.st_value, size); + } +} + + +static void +_dwarf_elf_apply_rela_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data, Elf_Data *symtab_data, int endian) { Dwarf_Unsigned type; @@ -106,7 +136,8 @@ return (DW_DLE_ELF); } - if (sh.sh_type != SHT_RELA || sh.sh_size == 0) + if ((sh.sh_type != SHT_REL && sh.sh_type != SHT_RELA) || + sh.sh_size == 0) continue; if (sh.sh_info == shndx && sh.sh_link == symtab) { @@ -127,8 +158,12 @@ } memcpy(ed->ed_alloc, ed->ed_data->d_buf, ed->ed_data->d_size); - _dwarf_elf_apply_reloc(dbg, ed->ed_alloc, rel, - symtab_data, eh.e_ident[EI_DATA]); + if (sh.sh_type == SHT_REL) + _dwarf_elf_apply_rel_reloc(dbg, ed->ed_alloc, + rel, symtab_data, eh.e_ident[EI_DATA]); + else + _dwarf_elf_apply_rela_reloc(dbg, ed->ed_alloc, + rel, symtab_data, eh.e_ident[EI_DATA]); return (DW_DLE_NONE); } @@ -284,7 +319,7 @@ } } - if (_libdwarf.applyrela) { + if (_libdwarf.applyreloc) { if (_dwarf_elf_relocate(dbg, elf, &e->eo_data[j], elf_ndxscn(scn), symtab_ndx, symtab_data, error) != DW_DLE_NONE)