libebl: Use elf_getshdrstrndx in ebl_section_strip_p.
authorMark Wielaard <mark@klomp.org>
Wed, 1 Aug 2018 14:51:03 +0000 (16:51 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 13 Sep 2018 12:30:30 +0000 (14:30 +0200)
The ebl_section_strip_p function used the Ehdr e_shstrndx field
to get at the name of the (debug) sections. This is not correct
if there are more than SHN_LORESERVE sections. Use elf_getshdrstrndx
to get at the shstrtab section. And drop the Ehdr argument that isn't
necessary anymore.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libebl/ChangeLog
libebl/eblsectionstripp.c
libebl/libebl.h
src/ChangeLog
src/elfcmp.c
src/strip.c

index 574aae6..d36a268 100644 (file)
@@ -1,5 +1,11 @@
 2018-09-12  Mark Wielaard  <mark@klomp.org>
 
+       * eblsectionstripp.c (ebl_section_strip_p): Drop ehdr argument.
+       Use elf_getshdrstrndx.
+       * libebl.h (ebl_section_strip_p): Drop ehdr argument.
+
+2018-09-12  Mark Wielaard  <mark@klomp.org>
+
        * ebl-hooks.h (check_special_symbol): Drop ehdr argument.
        * ebl_check_special_symbol.c (ebl_check_special_symbol): Likewise.
        * eblopenbackend.c (default_check_special_symbol): Likewise.
index c6cda63..a5624ff 100644 (file)
@@ -35,7 +35,7 @@
 
 
 bool
-ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr, const GElf_Shdr *shdr,
+ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
                     const char *name, bool remove_comment,
                     bool only_remove_debug)
 {
@@ -53,7 +53,10 @@ ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr, const GElf_Shdr *shdr,
          GElf_Shdr *shdr_l = gelf_getshdr (scn_l, &shdr_mem_l);
          if (shdr_l != NULL)
            {
-             const char *s_l = elf_strptr (ebl->elf, ehdr->e_shstrndx,
+             size_t shstrndx;
+             if (elf_getshdrstrndx (ebl->elf, &shstrndx) != 0)
+               return false;
+             const char *s_l = elf_strptr (ebl->elf, shstrndx,
                                            shdr_l->sh_name);
              if (s_l != NULL && ebl_debugscn_p (ebl, s_l))
                return true;
index 0e1f41b..5abc02d 100644 (file)
@@ -205,7 +205,7 @@ extern bool ebl_none_reloc_p (Ebl *ebl, int reloc);
 extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
 
 /* Check whether section should be stripped.  */
-extern bool ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr,
+extern bool ebl_section_strip_p (Ebl *ebl,
                                 const GElf_Shdr *shdr, const char *name,
                                 bool remove_comment, bool only_remove_debug);
 
index a118519..7d046ec 100644 (file)
@@ -1,5 +1,10 @@
 2018-09-12  Mark Wielaard  <mark@klomp.org>
 
+       * elfcmp.c (main): Call ebl_section_strip_p without ehdr.
+       * strip.c (handle_elf): Likewise.
+
+2018-09-12  Mark Wielaard  <mark@klomp.org>
+
        * elflint.c (check_symtab): Call ebl_check_special_symbol without
        ehdr.
 
index b40df8b..b68df68 100644 (file)
@@ -254,7 +254,7 @@ main (int argc, char *argv[])
            sname1 = elf_strptr (elf1, ehdr1->e_shstrndx, shdr1->sh_name);
        }
       while (scn1 != NULL
-            && ebl_section_strip_p (ebl1, ehdr1, shdr1, sname1, true, false));
+            && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
 
       GElf_Shdr shdr2_mem;
       GElf_Shdr *shdr2;
@@ -267,7 +267,7 @@ main (int argc, char *argv[])
            sname2 = elf_strptr (elf2, ehdr2->e_shstrndx, shdr2->sh_name);
        }
       while (scn2 != NULL
-            && ebl_section_strip_p (ebl2, ehdr2, shdr2, sname2, true, false));
+            && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));
 
       if (scn1 == NULL || scn2 == NULL)
        break;
index 1367de7..dc71236 100644 (file)
@@ -817,7 +817,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
     /* Check whether the section can be removed.  Since we will create
        a new .shstrtab assume it will be removed too.  */
     if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
-       : (ebl_section_strip_p (ebl, ehdr, &shdr_info[cnt].shdr,
+       : (ebl_section_strip_p (ebl, &shdr_info[cnt].shdr,
                                shdr_info[cnt].name, remove_comment,
                                remove_debug)
           || cnt == ehdr->e_shstrndx
@@ -978,7 +978,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
                           original table in the debug file.  Unless
                           it is a redundant data marker to a debug
                           (data only) section.  */
-                       if (! (ebl_section_strip_p (ebl, ehdr,
+                       if (! (ebl_section_strip_p (ebl,
                                                    &shdr_info[scnidx].shdr,
                                                    shdr_info[scnidx].name,
                                                    remove_comment,