ld --as-needed assertion fail, BFD internal error and crash

Dmitry V. Levin ldv@altlinux.org
Sat Mar 18 23:10:00 GMT 2006


On Fri, Mar 17, 2006 at 01:34:40PM +1030, Alan Modra wrote:
> 	* elflink.c (elf_link_add_object_symbols): Save and restore
> 	warning sym's linked sym.

I tried binutils with this patch applied to build 5300+ packages.
No assertion fails, no internal errors, no segfaults anymore.  Nice.

There is a change in behaviour, though.  Here is a small testcase:

$ cat libfoo1.c 
int foo1(void) { return 0; }
$ cat libfoo2.c
extern int foo1(void);
int foo2(void) { return foo1(); }
$ cat foo3.c 
extern int foo2(void);
int main(void) { return foo2(); }
$ gcc -Wl,--as-needed -Wall -fpic -shared libfoo1.c -o libfoo1.so
$ gcc -Wl,--as-needed -Wall -fpic -shared libfoo2.c -o libfoo2.so -L. -lfoo1
$ gcc -Wl,--as-needed -Wall foo3.c -o foo3 -L. -lfoo2
/usr/bin/ld: warning: libfoo1.so, needed by ./libfoo2.so, not found (try using -rpath or -rpath-link)
./libfoo2.so: undefined reference to `foo1'
collect2: ld returned 1 exit status
$ gcc -Wl,--as-needed -Wall foo3.c -o foo3 -L. -lfoo2 -Wl,-rpath-link,.

All above is clear and expected.  Following command changed behaviour:
$ gcc -Wl,--as-needed -Wall foo3.c -o foo3 -L. -lfoo2 -lfoo1

Without --as-needed fixes it produced a warning
/usr/bin/ld: warning: libfoo1.so, needed by ./libfoo2.so, not found (try using -rpath or -rpath-link)
but linked executable.

With --as-needed fixes it fails:
/usr/bin/ld: warning: libfoo1.so, needed by ./libfoo2.so, not found (try using -rpath or -rpath-link)
./libfoo2.so: undefined reference to `foo1'
collect2: ld returned 1 exit status


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20060318/09358f6e/attachment.sig>


More information about the Binutils mailing list