Bug 22836 - "-r -s" doesn't work with -g3 using GCC 7
Summary: "-r -s" doesn't work with -g3 using GCC 7
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.31
: P2 normal
Target Milestone: 2.31
Assignee: Alan Modra
URL:
Keywords:
: 22981 (view as bug list)
Depends on: 12181
Blocks:
  Show dependency treegraph
 
Reported: 2018-02-12 13:47 UTC by H.J. Lu
Modified: 2018-03-31 12:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2018-02-12 13:47:40 UTC
[hjl@gnu-4 tmp]$ cat x.c
void
foo ()
{
}
[hjl@gnu-4 tmp]$ gcc -c -g3 x.c
[hjl@gnu-4 tmp]$ ld.bfd -r -s x.o
ld.bfd: BFD (Linux/GNU Binutils) 2.30.51.0.1.20180210 assertion fail /net/gnu-bdx-1/export/linux/src/binutils/binutils/bfd/elf.c:3565
ld.bfd: BFD (Linux/GNU Binutils) 2.30.51.0.1.20180210 assertion fail /net/gnu-bdx-1/export/linux/src/binutils/binutils/bfd/elf.c:3565

Gold gives reason, but still fails:

[hjl@gnu-4 tmp]$ ld.gold -r -s x.o
ld.gold: error: x.o: section group retained but group element discarded
ld.gold: error: x.o: section group retained but group element discarded
ld.gold: error: x.o: section group retained but group element discarded
ld.gold: error: x.o: section group retained but group element discarded
[hjl@gnu-4 tmp]$
Comment 1 H.J. Lu 2018-02-12 14:08:00 UTC
"strip -g" works correctly.
Comment 2 Sourceware Commits 2018-02-13 12:27:47 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6e5e9d58c1eeef5677c90886578a895cb8c164c5

commit 6e5e9d58c1eeef5677c90886578a895cb8c164c5
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Feb 13 14:09:48 2018 +1030

    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.
Comment 3 Alan Modra 2018-02-13 12:31:23 UTC
Fixed.
Comment 4 Sourceware Commits 2018-02-14 01:33:00 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=60f763ee16fca2cd1ec9fa6960f765de9b26ef70

commit 60f763ee16fca2cd1ec9fa6960f765de9b26ef70
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Feb 14 11:38:03 2018 +1030

    PR22836 testcases
    
    	PR 22836
    	* testsuite/ld-elf/pr22836-1.s: New file.
    	* testsuite/ld-elf/pr22836-1a.d: Likewise.
    	* testsuite/ld-elf/pr22836-1b.d: Likewise.
Comment 5 H.J. Lu 2018-02-18 17:14:19 UTC
It doesn't work for x86_64-solaris2 target:

./ld-new: tmpdir/dump: could not find output section .group for input section .group
./ld-new: final link failed: Nonrepresentable section on output
failed with: <./ld-new: tmpdir/dump: could not find output section .group for input section .group
./ld-new: final link failed: Nonrepresentable section on output>, no expected output
./ld-new: tmpdir/dump: could not find output section .group for input section .group
./ld-new: final link failed: Nonrepresentable section on output
FAIL: ld-elf/pr22836-1a
Comment 6 H.J. Lu 2018-02-18 17:24:55 UTC
This is caused by

      if (!sy 
          || (sy != symbol_lastP
              && (sy->sy_next == NULL 
                  || sy->sy_next->sy_previous != sy)))
        {
          /* Create the symbol now.  */
          sy = symbol_new (group_name, now_seg, (valueT) 0, frag_now);
#ifdef TE_SOLARIS
          /* Before Solaris 11 build 154, Sun ld rejects local group
             signature symbols, so make them weak hidden instead.  */
          symbol_get_bfdsym (sy)->flags |= BSF_WEAK;
          S_SET_OTHER (sy, STV_HIDDEN);
#else
          symbol_get_obj (sy)->local = 1; 
#endif
          symbol_table_insert (sy);

in obj-elf.c.
Comment 7 H.J. Lu 2018-02-18 18:05:11 UTC
It is an assembler bug.
Comment 8 H.J. Lu 2018-02-18 18:12:37 UTC
(In reply to H.J. Lu from comment #7)
> It is an assembler bug.

This is caused by the fix for PR gas/12181.
Comment 9 H.J. Lu 2018-03-19 12:51:44 UTC
*** Bug 22981 has been marked as a duplicate of this bug. ***
Comment 10 Richard Biener 2018-03-19 13:12:40 UTC
Can this be backported?
Comment 11 Sourceware Commits 2018-03-19 15:10:11 UTC
The binutils-2_30-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d957f81cb38d7e82ae546cd03265ee3087ba8a85

commit d957f81cb38d7e82ae546cd03265ee3087ba8a85
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Feb 13 14:09:48 2018 +1030

    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.
    
    (cherry picked from commit 6e5e9d58c1eeef5677c90886578a895cb8c164c5)
Comment 12 Sourceware Commits 2018-03-19 15:10:17 UTC
The binutils-2_30-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cd2de6083def3536d4f247bb4b251a99b770351a

commit cd2de6083def3536d4f247bb4b251a99b770351a
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Feb 14 11:38:03 2018 +1030

    PR22836 testcases
    
    	PR 22836
    	* testsuite/ld-elf/pr22836-1.s: New file.
    	* testsuite/ld-elf/pr22836-1a.d: Likewise.
    	* testsuite/ld-elf/pr22836-1b.d: Likewise.
    
    (cherry picked from commit 60f763ee16fca2cd1ec9fa6960f765de9b26ef70)