Bug 212456 - --as-needed problem with undefined non-weak symbols in libraries
--as-needed problem with undefined non-weak symbols in libraries
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: binutils (Show other bugs)
5
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-10-26 16:37 EDT by Ville Skyttä
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

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


Attachments (Terms of Use)

  None (edit)
Description Ville Skyttä 2006-10-26 16:37:44 EDT
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 03:08:12 EDT
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.