Bug 9727 - "ld -r --gc-sections --entry" doesn't work with COMDAT group
Summary: "ld -r --gc-sections --entry" doesn't work with COMDAT group
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-11 18:29 UTC by Michael Bruck
Modified: 2009-01-15 09:11 UTC (History)
4 users (show)

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


Attachments
Compiled object file (556 bytes, application/octet-stream)
2009-01-12 15:37 UTC, Michael Bruck
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Bruck 2009-01-11 18:29:49 UTC
$ cat test.c

struct A
{
    virtual void aaa()
    {
    }
};

void foo()
{
    A myA;
}

$ arm-elf-g++ -O6 test.c -c -o test.o
$ arm-elf-ld -r --gc-sections --entry _Z3foov test.o -o test.o2

with GDB:

Program received signal SIGSEGV, Segmentation fault.
0x0042a5d4 in bfd_elf_set_group_contents (abfd=0x23fd98, sec=0x14a1658,
    failedptrarg=0x108fe34) at ../../../sources/binutils-2.19/bfd/elf.c:2760
2760            idx = elf_section_data (s)->this_idx;


---

The error disappears if the object was not compiled with -O6.
Comment 1 Nick Clifton 2009-01-12 13:59:47 UTC
Hi Michael,

  I could not reproduce this problem using the current mainline sources (for
both gcc and the binutils).  Please could you try using them yourself and see if
you can make the bug occur.  (Or else prove that it has already been fixed).  If
it does occur, please could you upload the test.o object file to this PR so that
I can investigate further.

Cheers
  Nick
Comment 2 Michael Bruck 2009-01-12 15:37:05 UTC
Created attachment 3658 [details]
Compiled object file

This is the object file compiled with g++ 4.3.2
Comment 3 Michael Bruck 2009-01-12 15:56:20 UTC
(In reply to comment #1)

I stumbled upon this with an binutils-2.19.51 (fetched on 2008-12-13). I went 
back to 2.19 only for verification purposes.

I attached a an object file, please let me know if you can verify it with that.

Michael
Comment 4 H.J. Lu 2009-01-13 22:06:28 UTC
I saw it on Linux/x86:

[hjl@gnu-6 9727]$ cat x.s
	.section	.text.foo,"axG",@progbits,foo,comdat
	.globl foo
	.type	foo,@function
foo:
	.byte 0
	.section	.text.bar,"axG",@progbits,bar,comdat
	.globl bar
	.type	bar,@function
bar:
	.byte 0
[hjl@gnu-6 9727]$ gcc -c x.s
[hjl@gnu-6 9727]$ ld -r --gc-sections --entry foo x.o
Segmentation fault
[hjl@gnu-6 9727]$ 
Comment 5 H.J. Lu 2009-01-13 22:39:10 UTC
We should check section groups to properly support ld -r --gc-sections:

1. If all sections in a section group are removed, we should also
remove the group section.
2. If any sections in a section group is kept, we should keep all
sections in the section group.
Comment 6 H.J. Lu 2009-01-14 18:07:55 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2009-01/msg00196.html
Comment 7 Sourceware Commits 2009-01-14 21:53:02 UTC
Subject: Bug 9727

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2009-01-14 21:52:49

Modified files:
	bfd            : ChangeLog elflink.c 
	ld/testsuite   : ChangeLog 
Added files:
	ld/testsuite/ld-elf: group8.s group8a.d group8b.d group9.s 
	                     group9a.d group9b.d 

Log message:
	bfd/
	
	2009-01-14  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/9727
	* elflink.c (elf_gc_sweep): Exclude the group section if the
	first member of the section group is excluded.
	
	ld/testsuite/
	
	2009-01-14  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/9727
	* ld-elf/group8.s: New.
	* ld-elf/group8a.d: Likewise.
	* ld-elf/group8b.d: Likewise.
	* ld-elf/group9.s: Likewise.
	* ld-elf/group9a.d: Likewise.
	* ld-elf/group9b.d: Likewise.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4419&r2=1.4420
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.324&r2=1.325
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1007&r2=1.1008
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/group8.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/group8a.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/group8b.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/group9.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/group9a.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/group9b.d.diff?cvsroot=src&r1=NONE&r2=1.1

Comment 8 H.J. Lu 2009-01-14 21:56:59 UTC
Fixed.
Comment 9 Michael Bruck 2009-01-15 09:11:37 UTC
(In reply to comment #8)
> Fixed.

Works for me

Thanks