]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Don't trash destshdr for STT_SECTION in handle_relocs_rel[a].
authorMark Wielaard <mjw@redhat.com>
Fri, 28 Nov 2014 21:22:16 +0000 (22:22 +0100)
committerMark Wielaard <mjw@redhat.com>
Thu, 4 Dec 2014 13:42:54 +0000 (14:42 +0100)
We might need the original destshdr for handling other relocations.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/readelf.c

index a6d18b5c09085bab0e9d7c5bb61140ac9a1ea49f..d3828d9cbafef50a51e884d400049efb3eb2f033 100644 (file)
@@ -1,3 +1,10 @@
+2014-11-28  Mark Wielaard  <mjw@redhat.com>
+
+       * readelf.c (handle_relocs_rel): Don't reuse destshdr to store
+       section header of a relocation against a STT_SECTION symbol. Use
+       a new local variable secshdr.
+       (handle_relocs_rela): Likewise.
+
 2014-11-26  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (print_debug_aranges_section): Cast Dwarf_Word length
index cd15e4c0a0e2bf1accee6cad4c5dd9bdcbb1dc5d..69ae5d0d0455b73945a169e64b8a18660879ba80 100644 (file)
@@ -1894,12 +1894,15 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
                    elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
          else
            {
-             destshdr = gelf_getshdr (elf_getscn (ebl->elf,
-                                                  sym->st_shndx == SHN_XINDEX
-                                                  ? xndx : sym->st_shndx),
-                                      &destshdr_mem);
-
-             if (unlikely (destshdr == NULL))
+             /* This is a relocation against a STT_SECTION symbol.  */
+             GElf_Shdr secshdr_mem;
+             GElf_Shdr *secshdr;
+             secshdr = gelf_getshdr (elf_getscn (ebl->elf,
+                                                 sym->st_shndx == SHN_XINDEX
+                                                 ? xndx : sym->st_shndx),
+                                     &secshdr_mem);
+
+             if (unlikely (secshdr == NULL))
                printf ("  %#0*" PRIx64 "  %-20s <%s %ld>\n",
                        class == ELFCLASS32 ? 10 : 18, rel->r_offset,
                        ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
@@ -1921,7 +1924,7 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
                                               buf, sizeof (buf)) + 2
                        : gettext ("<INVALID RELOC>"),
                        class == ELFCLASS32 ? 10 : 18, sym->st_value,
-                       elf_strptr (ebl->elf, shstrndx, destshdr->sh_name));
+                       elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
            }
        }
     }
@@ -2085,12 +2088,15 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
                    elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name));
          else
            {
-             destshdr = gelf_getshdr (elf_getscn (ebl->elf,
-                                                  sym->st_shndx == SHN_XINDEX
-                                                  ? xndx : sym->st_shndx),
-                                      &destshdr_mem);
-
-             if (unlikely (destshdr == NULL))
+             /* This is a relocation against a STT_SECTION symbol.  */
+             GElf_Shdr secshdr_mem;
+             GElf_Shdr *secshdr;
+             secshdr = gelf_getshdr (elf_getscn (ebl->elf,
+                                                 sym->st_shndx == SHN_XINDEX
+                                                 ? xndx : sym->st_shndx),
+                                     &secshdr_mem);
+
+             if (unlikely (secshdr == NULL))
                printf ("  %#0*" PRIx64 "  %-15s <%s %ld>\n",
                        class == ELFCLASS32 ? 10 : 18, rel->r_offset,
                        ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info))
@@ -2114,7 +2120,7 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
                        : gettext ("<INVALID RELOC>"),
                        class == ELFCLASS32 ? 10 : 18, sym->st_value,
                        rel->r_addend,
-                       elf_strptr (ebl->elf, shstrndx, destshdr->sh_name));
+                       elf_strptr (ebl->elf, shstrndx, secshdr->sh_name));
            }
        }
     }