$ 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.
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
Created attachment 3658 [details] Compiled object file This is the object file compiled with g++ 4.3.2
(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
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]$
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.
A patch is posted at http://sourceware.org/ml/binutils/2009-01/msg00196.html
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
Fixed.
(In reply to comment #8) > Fixed. Works for me Thanks