]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elfcmp: Get, check and shdrstrndx for section names.
authorMark Wielaard <mark@klomp.org>
Thu, 13 Sep 2018 11:52:46 +0000 (13:52 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 13 Sep 2018 12:30:30 +0000 (14:30 +0200)
elfcmp would use the Ehdr e_shstrndx field to find the shdr string
index table. Use elf_getshdrstrndx instead to be able to handle ELF
files with more than SHN_LORESERVE sections.

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

index 7d046ec3382985e1a724984db1e2f560062bb02c..79da69b01f4d0a6e93aaf08a8370cbce6b0115b9 100644 (file)
@@ -1,3 +1,7 @@
+2018-09-13  Mark Wielaard  <mark@klomp.org>
+
+       * elfcmp.c (main): Get, check and shdrstrndx for section names.
+
 2018-09-12  Mark Wielaard  <mark@klomp.org>
 
        * elfcmp.c (main): Call ebl_section_strip_p without ehdr.
index b68df688527408a8c21da40c1c430967906a3b06..d5dc1ff2b932e6c48547392d499ef72f140d0fc2 100644 (file)
@@ -235,6 +235,22 @@ main (int argc, char *argv[])
       DIFFERENCE;
     }
 
+  size_t shstrndx1;
+  size_t shstrndx2;
+  if (elf_getshdrstrndx (elf1, &shstrndx1) != 0)
+    error (2, 0, gettext ("cannot get hdrstrndx of '%s': %s"),
+          fname1, elf_errmsg (-1));
+  if (elf_getshdrstrndx (elf2, &shstrndx2) != 0)
+    error (2, 0, gettext ("cannot get hdrstrndx of '%s': %s"),
+          fname2, elf_errmsg (-1));
+  if (shstrndx1 != shstrndx2)
+    {
+      if (! quiet)
+       error (0, 0, gettext ("%s %s diff: shdr string index"),
+              fname1, fname2);
+      DIFFERENCE;
+    }
+
   /* Iterate over all sections.  We expect the sections in the two
      files to match exactly.  */
   Elf_Scn *scn1 = NULL;
@@ -251,7 +267,7 @@ main (int argc, char *argv[])
          scn1 = elf_nextscn (elf1, scn1);
          shdr1 = gelf_getshdr (scn1, &shdr1_mem);
          if (shdr1 != NULL)
-           sname1 = elf_strptr (elf1, ehdr1->e_shstrndx, shdr1->sh_name);
+           sname1 = elf_strptr (elf1, shstrndx1, shdr1->sh_name);
        }
       while (scn1 != NULL
             && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
@@ -264,7 +280,7 @@ main (int argc, char *argv[])
          scn2 = elf_nextscn (elf2, scn2);
          shdr2 = gelf_getshdr (scn2, &shdr2_mem);
          if (shdr2 != NULL)
-           sname2 = elf_strptr (elf2, ehdr2->e_shstrndx, shdr2->sh_name);
+           sname2 = elf_strptr (elf2, shstrndx2, shdr2->sh_name);
        }
       while (scn2 != NULL
             && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));