Author: emaste
Date: Fri Mar 11 16:24:39 2016
New Revision: 296663
URL: https://svnweb.freebsd.org/changeset/base/296663

Log:
  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

Modified:
  head/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c

Modified: head/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c
==============================================================================
--- head/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c      Fri Mar 11 
16:03:47 2016        (r296662)
+++ head/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c      Fri Mar 11 
16:24:39 2016        (r296663)
@@ -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, 
                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 d
        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 
        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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to