ld --as-needed sometimes fails with internal error. I've succeeded to construct a small testcase described below. $ cat sample.cc extern void foo(void); void my() { foo(); } $ g++ -Wl,--no-as-needed -shared -Wall -fPIC sample.cc -lsupc++; echo rc=$? rc=0 $ g++ -Wl,--as-needed -shared -Wall -fPIC sample.cc -lsupc++; echo rc=$? /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 /usr/bin/ld: BFD 2.16.91.0.6 20060212 internal error, aborting at elflink.c line 6453 in elf_link_output_extsym /usr/bin/ld: Please report this bug. collect2: ld returned 1 exit status rc=1
The test fails exactly the same way on FC-devel too (binutils-2.16.91.0.6-4, gcc-c++-4.1.0-3).
Even more simple test causes ld to crash in BFD: $ g++ -shared -Wl,--as-needed -Wl,--whole-archive `gcc -print-file-name=libsupc++.a` -Wl,--no-whole-archive collect2: ld terminated with signal 11 [Segmentation fault] /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2317 /usr/bin/ld: BFD 2.16.91.0.6 20060212 assertion fail elflink.c:2318 [last two lines repeated 149 times] $ gdb ld-debug [...] (gdb) r --as-needed --eh-frame-hdr -m elf_i386 -shared --whole-archive `gcc -print-file-name=libsupc++.a` --no-whole-archive `gcc -print-file-name=libstdc++.so` [...] Program received signal SIGSEGV, Segmentation fault. 0x00142c09 in bfd_putl32 (data=64168, p=0x0) at libbfd.c:706 706 addr[0] = data & 0xff; (gdb) bt #0 0x00142c09 in bfd_putl32 (data=64168, p=0x0) at libbfd.c:706 #1 0x001611b3 in bfd_elf32_swap_reloc_out (abfd=0x80aac28, src=0xbfffe1a0, d=0x0) at elfcode.h:408 #2 0x0015d7e4 in elf_i386_relocate_section (output_bfd=0x80aac28, info=0x80a0d20, input_bfd=0x81049f0, input_section=0x8163e0c, contents=0x8317828 "\b", relocs=0x81767cc, local_syms=0x81c1298, local_sections=0x831edf8) at elf32-i386.c:2666 #3 0x0018061b in elf_link_input_bfd (finfo=0xbfffe460, input_bfd=0x81049f0) at elflink.c:7142 #4 0x001828fb in bfd_elf_final_link (abfd=0x80aac28, info=0x80a0d20) at elflink.c:8212 #5 0x08060a50 in ldwrite () at ldwrite.c:557 #6 0x0805e0b1 in main (argc=10, argv=0xbfffe594) at .././ld/ldmain.c:468
*** Bug 2469 has been marked as a duplicate of this bug. ***
http://sources.redhat.com/ml/binutils-cvs/2006-03/msg00079.html http://sources.redhat.com/ml/binutils-cvs/2006-03/msg00087.html