Bug 212456 - --as-needed problem with undefined non-weak symbols in libraries
Summary: --as-needed problem with undefined non-weak symbols in libraries
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: 5
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
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:
Clone Of:
Environment:
Last Closed: 2006-10-27 07:08:12 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

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

As discussed in 
https://www.redhat.com/archives/fedora-devel-list/2006-October/msg00724.html, 
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):

foo.c:
extern void gtk_main();
int main() {
    gtk_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: 
gdk_root_window

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:
`--as-needed'
`--no-as-needed'
     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

shows:
./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.