From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30708 invoked by alias); 24 Jul 2018 22:15:38 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 30574 invoked by uid 89); 24 Jul 2018 22:15:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.0 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=D*h, OA, oa, o6 X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Jul 2018 22:15:22 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 51EC63000B2D; Wed, 25 Jul 2018 00:15:13 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 0D07940011A3; Wed, 25 Jul 2018 00:15:13 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] unstrip: Also check sh_size in compare_unalloc_sections. Date: Tue, 24 Jul 2018 22:15:00 -0000 Message-Id: <1532470505-20077-1-git-send-email-mark@klomp.org> X-Mailer: git-send-email 1.8.3.1 X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q3/txt/msg00047.txt.bz2 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 --- src/ChangeLog | 4 +++ src/unstrip.c | 6 ++++ tests/ChangeLog | 6 ++++ tests/Makefile.am | 1 + tests/run-annobingroup.sh | 55 +++++++++++++++++++++++++++++++++ tests/testfile-annobingroup-i386.o.bz2 | Bin 0 -> 1387 bytes 6 files changed, 72 insertions(+) create mode 100644 tests/testfile-annobingroup-i386.o.bz2 diff --git a/src/ChangeLog b/src/ChangeLog index 37e7b62..eee144d 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 cb1f7dc..ec46c95 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 45844b1..2a20ffa 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 b7a0e17..2946083 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 5f08b35..700df32 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 0000000000000000000000000000000000000000..798eefda9c6018d7a2a7e46bfd9f850c67b1dcb6 GIT binary patch literal 1387 zcmV-x1(fJ1*F%6dU4glGwgG{ngoGzNeG!Z82<13)wY27mwn00AOI(I8XBJx@(Eo|-)( zdY**Lh&1%jOqu`;X^;~}5w$j^nlMjMr(SVv{ zz$Qij00J;g7zjax#L0k|6B9<5i~th=jWRS~CYdk^k$?aIj1xuzB5YZ0SR6-J2e|lS ze7Q}**D~xW626;O=qy~jtAhs;zn)_zR}G0+IbCpLRaHeGRH0i%6K7*eX^uIutRqjS z#$1=_vG6$fdbKxkZ0yTiXVVQ9!U0dA?cZ)QGvS$z!;(O0i>)3dUwj3jrVIHo+u} zw;sNJ9STj-q}Fredl(T_>4>lpEm^1*6TewR6CJm@F!8vIlF=|j*Zb|-xuK@n1YS;1 zdOC>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