diff options
author | emaste <emaste@FreeBSD.org> | 2016-03-11 16:24:39 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2016-03-11 16:24:39 +0000 |
commit | e24ba1eb53e66c865d0afc65bbb8e0cb0a424272 (patch) | |
tree | 7d5c5de6c37775ecf94afd847caa354427a7b7e0 /contrib/elftoolchain/libdwarf | |
parent | 986728b2546cacf72ad5eceebc3c9b7e118561c4 (diff) | |
download | FreeBSD-src-e24ba1eb53e66c865d0afc65bbb8e0cb0a424272.zip FreeBSD-src-e24ba1eb53e66c865d0afc65bbb8e0cb0a424272.tar.gz |
libdwarf: fix SHT_REL relocation processing
Relocation of type SHT_REL must use the current value as addend.
PR: 204084
Obtained from: NetBSD libdwarf_elf_init.c v1.4
Diffstat (limited to 'contrib/elftoolchain/libdwarf')
-rw-r--r-- | contrib/elftoolchain/libdwarf/libdwarf_elf_init.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c b/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c index af2d370..5ab6ffc 100644 --- a/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c +++ b/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c @@ -51,7 +51,8 @@ static const char *debug_name[] = { static void _dwarf_elf_write_reloc(Dwarf_Debug dbg, Elf_Data *symtab_data, int endian, - void *buf, uint64_t offset, GElf_Xword r_info, GElf_Sxword r_addend) + void *buf, uint64_t offset, GElf_Xword r_info, GElf_Sxword r_addend, + int is_rel) { GElf_Sym sym; int size; @@ -60,6 +61,14 @@ _dwarf_elf_write_reloc(Dwarf_Debug dbg, Elf_Data *symtab_data, int endian, return; if ((size = _dwarf_get_reloc_size(dbg, GELF_R_TYPE(r_info))) == 0) return; /* Unknown or non-absolute relocation. */ + if (is_rel) { + uint64_t roffset = offset; + + if (endian == ELFDATA2MSB) + r_addend = _dwarf_read_msb(buf, &roffset, size); + else + r_addend = _dwarf_read_lsb(buf, &roffset, size); + } if (endian == ELFDATA2MSB) _dwarf_write_msb(buf, &offset, sym.st_value + r_addend, size); else @@ -76,7 +85,7 @@ _dwarf_elf_apply_rel_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data, j = 0; while (gelf_getrel(rel_data, j++, &rel) != NULL) _dwarf_elf_write_reloc(dbg, symtab_data, endian, buf, - rel.r_offset, rel.r_info, 0); + rel.r_offset, rel.r_info, 0, 1); } static void @@ -89,7 +98,7 @@ _dwarf_elf_apply_rela_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data, j = 0; while (gelf_getrela(rel_data, j++, &rela) != NULL) _dwarf_elf_write_reloc(dbg, symtab_data, endian, buf, - rela.r_offset, rela.r_info, rela.r_addend); + rela.r_offset, rela.r_info, rela.r_addend, 0); } static int |