summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-09-13 13:52:46 +0200
committerMark Wielaard <mark@klomp.org>2018-09-13 14:30:30 +0200
commitbe4ea50a689dcfdb46079f8f5ce616107a77cdc4 (patch)
treec23a5a055da87f7024d26d7755f9ba6a69aceaae
parent68e8b84743bdb389776e3aa2bae27aba7f435fdb (diff)
elfcmp: Get, check and shdrstrndx for section names.
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>
-rw-r--r--src/ChangeLog4
-rw-r--r--src/elfcmp.c20
2 files changed, 22 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 7d046ec3..79da69b0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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.
diff --git a/src/elfcmp.c b/src/elfcmp.c
index b68df688..d5dc1ff2 100644
--- a/src/elfcmp.c
+++ b/src/elfcmp.c
@@ -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));