From: Mark Wielaard Date: Tue, 24 Jul 2018 21:34:19 +0000 (+0200) Subject: unstrip: Also check sh_size in compare_unalloc_sections. X-Git-Tag: elfutils-0.174~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9718c94bbce0dabe0ce048efa3a2a6d1ea08bce5;p=thirdparty%2Felfutils.git unstrip: Also check sh_size in compare_unalloc_sections. compare_unalloc_sections only checked sh_flags and the section names. This would cause stripped/debug section mismatches when there were multiple sections with the same name and flags. Fix this by also checking the size of the section matches. Add a testcase that has two ".group" sections created on i386 with the gcc annobin plugin. Signed-off-by: Mark Wielaard --- diff --git a/src/ChangeLog b/src/ChangeLog index 791b627b3..a01bd756e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2018-07-24 Mark Wielaard + + * unstrip.c (compare_unalloc_sections): Also compare sh_size. + 2018-07-21 Mark Wielaard * unstrip.c (adjust_all_relocs): Skip SHT_GROUP sections. diff --git a/src/unstrip.c b/src/unstrip.c index cb1f7dc0b..ec46c9522 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -709,6 +709,12 @@ compare_unalloc_sections (const GElf_Shdr *shdr1, const GElf_Shdr *shdr2, if (shdr1->sh_flags > shdr2->sh_flags) return 1; + /* Sizes should be the same. */ + if (shdr1->sh_size < shdr2->sh_size) + return -1; + if (shdr1->sh_size > shdr2->sh_size) + return 1; + /* Sort by name as last resort. */ return strcmp (name1, name2); } diff --git a/tests/ChangeLog b/tests/ChangeLog index 45844b141..2a20ffa51 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2018-07-24 Mark Wielaard + + * run-annobingroup.sh: Add testfile-annobingroup-i386.o tests. + * testfile-annobingroup-i386.o.bz2: New test file. + * Makefile.am (EXTRA_DIST): Add testfile-annobingroup-i386.o.bz2. + 2018-07-21 Mark Wielaard * run-annobingroup.sh: New test. diff --git a/tests/Makefile.am b/tests/Makefile.am index b7a0e1736..294608348 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -195,6 +195,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-strip-test12.sh \ run-strip-nothing.sh run-strip-remove-keep.sh run-strip-g.sh \ run-annobingroup.sh testfile-annobingroup.o.bz2 \ + testfile-annobingroup-i386.o.bz2 \ run-strip-strmerge.sh run-strip-nobitsalign.sh \ testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \ run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \ diff --git a/tests/run-annobingroup.sh b/tests/run-annobingroup.sh index 5f08b35fa..700df3210 100755 --- a/tests/run-annobingroup.sh +++ b/tests/run-annobingroup.sh @@ -65,4 +65,59 @@ EOF testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup.o remerged.elf +# echo "void * __attribute__((cold)) foo (void) { return foo; }" +# > testfile-annobingroup-i386.c +# gcc -fpic -g -O2 -fplugin=annobin -c testfile-annobingroup-i386.c +testfiles testfile-annobingroup-i386.o + +testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup-i386.o << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup-i386.o + +testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun ${abs_top_builddir}/src/unstrip -o remerged.elf stripped.elf debugfile.elf + +testrun_compare ${abs_top_builddir}/src/readelf -g remerged.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 8] .gnu.build.attributes..text.unlikely + [ 9] .rel.gnu.build.attributes..text.unlikely + [10] .text.unlikely + +COMDAT section group [ 2] '.group' with signature '__x86.get_pc_thunk.ax' contains 1 entry: + [13] .text.__x86.get_pc_thunk.ax +EOF + +testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup-i386.o remerged.elf + exit 0 diff --git a/tests/testfile-annobingroup-i386.o.bz2 b/tests/testfile-annobingroup-i386.o.bz2 new file mode 100644 index 000000000..798eefda9 Binary files /dev/null and b/tests/testfile-annobingroup-i386.o.bz2 differ