]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
backends: Use elf_getshdrstrndx to find .odp section in ppc64_init
authorMark Wielaard <mark@klomp.org>
Sat, 4 Aug 2018 20:32:56 +0000 (22:32 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 13 Sep 2018 12:30:30 +0000 (14:30 +0200)
The .odp section is found by name. But ppc64_init used the e_shstrndx
Ehdr field for that. This is wrong if the file contains more than
SHN_LORESERVE sections. Use elf_getshdrstrndx instead to find the
shstrtab section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
backends/ChangeLog
backends/ppc64_init.c

index ada349fe5db8e99de3227df78617bfd591b1faef..fdff30219491c1bda2666d103085428340b007ee 100644 (file)
@@ -1,3 +1,7 @@
+2018-09-12  Mark Wielaard  <mark@klomp.org>
+
+       * ppc64_init.c (ppc64_init): Use elf_getshdrstrndx.
+
 2018-09-12  Mark Wielaard  <mark@klomp.org>
 
        * aarch64_symbol.c (aarch64_check_special_symbol): Drop ehdr argument,
index e5670338ce4ac3e101447b6f7624daefb629bc94..3db5e7666ff9045baf1c230a39257f7056c9da54 100644 (file)
@@ -80,7 +80,9 @@ ppc64_init (Elf *elf __attribute__ ((unused)),
   if (elf != NULL)
     {
       GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (elf, &ehdr_mem);
-      if (ehdr != NULL && ehdr->e_type != ET_REL)
+      size_t shstrndx;
+      if (ehdr != NULL && ehdr->e_type != ET_REL
+         && elf_getshdrstrndx (elf, &shstrndx) == 0)
        {
          /* We could also try through DT_PPC64_OPD and DT_PPC64_OPDSZ. */
          GElf_Shdr opd_shdr_mem, *opd_shdr;
@@ -93,7 +95,7 @@ ppc64_init (Elf *elf __attribute__ ((unused)),
                  && opd_shdr->sh_type == SHT_PROGBITS
                  && opd_shdr->sh_size > 0)
                {
-                 const char *name = elf_strptr (elf, ehdr->e_shstrndx,
+                 const char *name = elf_strptr (elf, shstrndx,
                                                 opd_shdr->sh_name);
                  if (name != NULL && strcmp (name, ".opd") == 0)
                    {