]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
unstrip: Handle SHT_GROUP sections in ET_REL files.
authorMark Wielaard <mark@klomp.org>
Sat, 21 Jul 2018 21:40:11 +0000 (23:40 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 27 Jul 2018 12:09:21 +0000 (14:09 +0200)
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 <mark@klomp.org>
src/ChangeLog
src/unstrip.c
tests/ChangeLog
tests/Makefile.am
tests/run-annobingroup.sh [new file with mode: 0755]
tests/testfile-annobingroup.o.bz2 [new file with mode: 0644]

index 39214c39ae42a05f49347c182da00c94594ceb7a..791b627b3dd12d373ce990902c590f89ecba3036 100644 (file)
@@ -1,3 +1,7 @@
+2018-07-21  Mark Wielaard  <mark@klomp.org>
+
+       * unstrip.c (adjust_all_relocs): Skip SHT_GROUP sections.
+
 2018-07-21  Mark Wielaard  <mark@klomp.org>
 
        * elfcompress.c (get_sections): New function.
index 057efef30660d300349da0fb7940dd70685ee09b..cb1f7dc0b698ee0c68f79db3f187dc0717cff712 100644 (file)
@@ -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);
       }
 }
index 70cc9b6adf06670623f12d55f77c84650c3dc3f9..45844b141cb293b27988db098ee36e7ed169d58b 100644 (file)
@@ -1,3 +1,11 @@
+2018-07-21  Mark Wielaard  <mark@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  <schwab@suse.de>
 
        * Makefile.am (TESTS): Add run-strip-test12.sh.
index e04bd7d3c3b8badaa0d06324ce6c21a17be345d8..b7a0e17365fb7449833c0f81fda565e7f65b87a7 100644 (file)
@@ -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 (executable)
index 0000000..5f08b35
--- /dev/null
@@ -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 mode 100644 (file)
index 0000000..b1ca7ea
Binary files /dev/null and b/tests/testfile-annobingroup.o.bz2 differ