Bug 2434 - ld --as-needed causes either crash or BFD internal error
Summary: ld --as-needed causes either crash or BFD internal error
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.16
: P2 critical
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
: 2469 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-08 22:24 UTC by Dmitry V. Levin
Modified: 2006-03-19 01:51 UTC (History)
2 users (show)

See Also:
Host: i586-alt-linux-gnu
Target: i586-alt-linux-gnu
Build: i586-alt-linux-gnu
Last reconfirmed: 2006-03-16 07:09:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry V. Levin 2006-03-08 22:24:16 UTC
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
Comment 1 Dmitry V. Levin 2006-03-10 23:39:15 UTC
The test fails exactly the same way on FC-devel too (binutils-2.16.91.0.6-4,
gcc-c++-4.1.0-3).
Comment 2 Dmitry V. Levin 2006-03-13 23:44:42 UTC
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
Comment 3 Alan Modra 2006-03-19 01:49:13 UTC
*** Bug 2469 has been marked as a duplicate of this bug. ***