Bug 212456 - --as-needed problem with undefined non-weak symbols in libraries
Summary: --as-needed problem with undefined non-weak symbols in libraries
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils   
(Show other bugs)
Version: 5
Hardware: All Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2006-10-26 20:37 UTC by Ville Skyttä
Modified: 2007-11-30 22:11 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-10-27 07:08:12 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Ville Skyttä 2006-10-26 20:37:44 UTC
FC5, binutils-

As discussed in 
FC5's ld --as-needed doesn't seem to handle undefined non-weak references in 
dependent libs, while it reportedly does in RHEL4.

Example (as noted in the ML discussion, don't pay attention to the fact that 
libgtk should probably not have those undefined in the first place but should 
link with libgdk - this is just for demonstration purposes):

extern void gtk_main();
int main() {

$ gcc -Wl,--as-needed  foo.c `pkg-config --libs gtk+`
$ ./a.out
./a.out: symbol lookup error: /usr/lib64/libgtk-1.2.so.0: undefined symbol: 

Shouldn't the linker find out that linking with libgdk is actually needed in 
this case and not cause --as-needed to drop it?

Comment 1 Jakub Jelinek 2006-10-27 07:08:12 UTC
That's the intended and documented behavior, info ld says:
     This option affects ELF DT_NEEDED tags for dynamic libraries
     mentioned on the command line after the `--as-needed' option.
     Normally, the linker will add a DT_NEEDED tag for each dynamic
     library mentioned on the command line, regardless of whether the
     library is actually needed.  `--as-needed' causes DT_NEEDED tags
     to only be emitted for libraries that satisfy some symbol
     reference from regular objects which is undefined at the point
     that the library was linked.  `--no-as-needed' restores the
     default behaviour.
The only difference between FC5 and FC6 binutils in this area is that FC6
binutils issues an error in this case at link time, but FC5 does not and you
only see the failure at runtime.
On FC6:
echo 'void foo (void) { bar (); }' | gcc -shared -O2 -o liba.so -xc - -fpic
echo 'void bar (void) { }' | gcc -shared -O2 -o libb.so -xc - -fpic
echo 'int main (void) { foo (); }' | gcc -O2 -o c -xc - -Wl,-rpath,.,--as-needed
-L. -la -lb
[ -x c ] && ./c

./liba.so: undefined reference to `bar'
collect2: ld returned 1 exit status

on FC5:
./c: symbol lookup error: ./liba.so: undefined symbol: bar

Note You need to log in before you can comment on or make changes to this bug.