SHT_GROUP sections are put in both the stripped and debug file. Handle correcting the symbol table/name entry of the group only once.
The testfile was generated with the gcc annobin plugin. Signed-off-by: Mark Wielaard <m...@klomp.org> --- src/ChangeLog | 4 +++ src/unstrip.c | 6 +++- tests/ChangeLog | 8 +++++ tests/Makefile.am | 3 +- tests/run-annobingroup.sh | 68 ++++++++++++++++++++++++++++++++++++++ tests/testfile-annobingroup.o.bz2 | Bin 0 -> 1266 bytes 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100755 tests/run-annobingroup.sh create mode 100644 tests/testfile-annobingroup.o.bz2 diff --git a/src/ChangeLog b/src/ChangeLog index e0f1b51..37e7b62 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2018-07-21 Mark Wielaard <m...@klomp.org> + + * unstrip.c (adjust_all_relocs): Skip SHT_GROUP sections. + 2018-07-04 Mark Wielaard <m...@klomp.org> * readelf.c (print_debug_addr_section): Rename index var to uidx. diff --git a/src/unstrip.c b/src/unstrip.c index 057efef..cb1f7dc 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -563,7 +563,11 @@ adjust_all_relocs (Elf *elf, Elf_Scn *symtab, const GElf_Shdr *symshdr, GElf_Shdr shdr_mem; GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); ELF_CHECK (shdr != NULL, _("cannot get section header: %s")); - if (shdr->sh_type != SHT_NOBITS && shdr->sh_link == new_sh_link) + /* Don't redo SHT_GROUP, groups are in both the stripped and debug, + it will already have been done by adjust_relocs for the + stripped_symtab. */ + if (shdr->sh_type != SHT_NOBITS && shdr->sh_type != SHT_GROUP + && shdr->sh_link == new_sh_link) adjust_relocs (scn, scn, shdr, map, symshdr); } } diff --git a/tests/ChangeLog b/tests/ChangeLog index 70cc9b6..45844b1 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +2018-07-21 Mark Wielaard <m...@klomp.org> + + * run-annobingroup.sh: New test. + * testfile-annobingroup.o.bz2: New test file. + * Makefile.am (TESTS): Add run-annobingroup.sh. + (EXTRA_DIST): Add run-annobingroup.sh and + testfile-annobingroup.o.bz2. + 2018-07-19 Andreas Schwab <sch...@suse.de> * Makefile.am (TESTS): Add run-strip-test12.sh. diff --git a/tests/Makefile.am b/tests/Makefile.am index e04bd7d..b7a0e17 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -87,7 +87,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-strip-test6.sh run-strip-test7.sh run-strip-test8.sh \ run-strip-test9.sh run-strip-test10.sh run-strip-test11.sh \ run-strip-test12.sh \ - run-strip-nothing.sh run-strip-g.sh \ + run-strip-nothing.sh run-strip-g.sh run-annobingroup.sh \ run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \ run-strip-nobitsalign.sh run-strip-remove-keep.sh \ run-unstrip-test.sh run-unstrip-test2.sh run-unstrip-test3.sh \ @@ -194,6 +194,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-strip-test9.sh run-strip-test10.sh run-strip-test11.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 \ 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 new file mode 100755 index 0000000..5f08b35 --- /dev/null +++ b/tests/run-annobingroup.sh @@ -0,0 +1,68 @@ +#! /bin/sh +# Copyright (C) 2018 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# Testfile generated by annobin, creates group. +# strip and unstrip it. Check group symbol/name is correct. + +# echo "int __attribute__((cold)) foo (void) { return 42; }" \ +# > testfile-annobingroup.c +# gcc -g -O2 -fplugin=annobin -c testfile-annobingroup.c +testfiles testfile-annobingroup.o + +tempfiles merged.elf stripped.elf debugfile.elf remerged.elf + +testrun_compare ${abs_top_builddir}/src/readelf -g testfile-annobingroup.o << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +EOF + +testrun ${abs_top_builddir}/src/strip -o stripped.elf -f debugfile.elf testfile-annobingroup.o + +testrun_compare ${abs_top_builddir}/src/readelf -g stripped.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +EOF + +testrun_compare ${abs_top_builddir}/src/readelf -g debugfile.elf << EOF + +Section group [ 1] '.group' with signature '.text.unlikely.group' contains 3 entries: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +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: + [ 7] .gnu.build.attributes..text.unlikely + [ 8] .rela.gnu.build.attributes..text.unlikely + [ 9] .text.unlikely +EOF + +testrun ${abs_top_builddir}/src/elfcmp testfile-annobingroup.o remerged.elf + +exit 0 diff --git a/tests/testfile-annobingroup.o.bz2 b/tests/testfile-annobingroup.o.bz2 new file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