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. --- bfd/elflink.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'bfd/elflink.c') diff --git a/bfd/elflink.c b/bfd/elflink.c index d1eb820..6eb47ee 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -11618,6 +11618,13 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) else o->flags |= SEC_EXCLUDE; } + else if ((o->flags & SEC_GROUP) != 0 && o->size == 0) + { + /* Remove empty group section from linker output. */ + o->flags |= SEC_EXCLUDE; + bfd_section_list_remove (abfd, o); + abfd->section_count--; + } } /* Count up the number of relocations we will output for each output -- cgit v1.1