From 6e5e9d58c1eeef5677c90886578a895cb8c164c5 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 13 Feb 2018 14:09:48 +1030 Subject: PR22836, "-r -s" doesn't work with -g3 using GCC 7 This fixes the case where all of a group is removed with ld -r, the situation in the PR, and failures where part of a group is removed that contain relocs. bfd/ PR 22836 * elf.c (_bfd_elf_fixup_group_sections): Account for removed relocation sections. If size reduces to just the flag word, remove that too and mark with SEC_EXCLUDE. * elflink.c (bfd_elf_final_link): Strip empty group sections. binutils/ * testsuite/binutils-all/group-7.s, * testsuite/binutils-all/group-7a.d, * testsuite/binutils-all/group-7b.d, * testsuite/binutils-all/group-7c.d: New tests. * testsuite/binutils-all/objcopy.exp: Run them. ld/ * testsuite/ld-elf/pr22836-2.d, * testsuite/ld-elf/pr22836-2.s: New test. --- binutils/ChangeLog | 9 +++++++++ binutils/testsuite/binutils-all/group-7.s | 6 ++++++ binutils/testsuite/binutils-all/group-7a.d | 16 ++++++++++++++++ binutils/testsuite/binutils-all/group-7b.d | 19 +++++++++++++++++++ binutils/testsuite/binutils-all/group-7c.d | 8 ++++++++ binutils/testsuite/binutils-all/objcopy.exp | 3 +++ 6 files changed, 61 insertions(+) create mode 100644 binutils/testsuite/binutils-all/group-7.s create mode 100644 binutils/testsuite/binutils-all/group-7a.d create mode 100644 binutils/testsuite/binutils-all/group-7b.d create mode 100644 binutils/testsuite/binutils-all/group-7c.d (limited to 'binutils') diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 5fe9d97..19b9507 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,12 @@ +2018-02-13 Alan Modra + + PR 22836 + * testsuite/binutils-all/group-7.s, + * testsuite/binutils-all/group-7a.d, + * testsuite/binutils-all/group-7b.d, + * testsuite/binutils-all/group-7c.d: New tests. + * testsuite/binutils-all/objcopy.exp: Run them. + 2018-02-08 Nick Clifton PR 22802 diff --git a/binutils/testsuite/binutils-all/group-7.s b/binutils/testsuite/binutils-all/group-7.s new file mode 100644 index 0000000..5028afc --- /dev/null +++ b/binutils/testsuite/binutils-all/group-7.s @@ -0,0 +1,6 @@ + .section .data.foo,"awG",%progbits,foo,comdat +here: + .dc.a here + + .section .data2.foo,"awG",%progbits,foo,comdat + .dc.a 0 diff --git a/binutils/testsuite/binutils-all/group-7a.d b/binutils/testsuite/binutils-all/group-7a.d new file mode 100644 index 0000000..fa8db60 --- /dev/null +++ b/binutils/testsuite/binutils-all/group-7a.d @@ -0,0 +1,16 @@ +#name: copy removing reloc group member +#source: group-7.s +#PROG: objcopy +#DUMPPROG: readelf +#objcopy: --remove-section .data.foo +#readelf: -Sg --wide + +#... + \[[ 0-9]+\] \.group[ \t]+GROUP[ \t]+.* +#... + \[[ 0-9]+\] \.data2\.foo[ \t]+PROGBITS[ \t0-9a-f]+WAG.* +#... +COMDAT group section \[[ 0-9]+\] `\.group' \[foo\] contains 1 section.* + \[Index\] Name + \[[ 0-9]+\] \.data2\.foo +#pass diff --git a/binutils/testsuite/binutils-all/group-7b.d b/binutils/testsuite/binutils-all/group-7b.d new file mode 100644 index 0000000..b674545 --- /dev/null +++ b/binutils/testsuite/binutils-all/group-7b.d @@ -0,0 +1,19 @@ +#name: copy removing non-reloc group member +#source: group-7.s +#PROG: objcopy +#DUMPPROG: readelf +#objcopy: --remove-section .data2.foo +#readelf: -Sg --wide + +#... + \[[ 0-9]+\] \.group[ \t]+GROUP[ \t]+.* +#... + \[[ 0-9]+\] \.data\.foo[ \t]+PROGBITS[ \t0-9a-f]+WAG.* +#... + \[[ 0-9]+\] \.rela?\.data\.foo[ \t]+RELA?[ \t0-9a-f]+IG.* +#... +COMDAT group section \[[ 0-9]+\] `\.group' \[foo\] contains 2 sections: + \[Index\] Name + \[[ 0-9]+\] \.data\.foo + \[[ 0-9]+\] \.rela?\.data\.foo +#pass diff --git a/binutils/testsuite/binutils-all/group-7c.d b/binutils/testsuite/binutils-all/group-7c.d new file mode 100644 index 0000000..83e9115 --- /dev/null +++ b/binutils/testsuite/binutils-all/group-7c.d @@ -0,0 +1,8 @@ +#name: copy removing reloc and non-reloc group member +#source: group-7.s +#PROG: objcopy +#DUMPPROG: readelf +#objcopy: -R .data.foo -R .data2.foo +#readelf: -g --wide + +There are no section groups in this file\. diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index 377f88c..f4a7692 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -1051,6 +1051,9 @@ if [is_elf_format] { objcopy_test_readelf "GNU_MBIND section" mbind1.s run_dump_test "group-5" run_dump_test "group-6" + run_dump_test "group-7a" + run_dump_test "group-7b" + run_dump_test "group-7c" run_dump_test "copy-1" run_dump_test "note-1" if [is_elf64 tmpdir/bintest.o] { -- cgit v1.1