Bug 10875 - links against libraries I never have specified
Summary: links against libraries I never have specified
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-31 15:40 UTC by robert.wohlrab
Modified: 2009-11-07 00:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description robert.wohlrab 2009-10-31 15:40:55 UTC
I tested different packages in debian and noticed that gold always links
against some libraries which aren't used and I never specified. I also tested
to use --as-needed and it didn't change that weird behavior. This doesn't
happen with the old binutils linker

Example output from zlib:

dpkg-shlibdeps: warning: dependency on libgcc_s.so.1 could be avoided if
"debian/zlib1g/usr/lib/libz.so.1.2.3.3" were not 
uselessly linked against it (they use none of its symbols).                     
dpkg-shlibdeps: warning: dependency on ld-linux-x86-64.so.2 could be avoided if
"debian/zlib1g/usr/lib/libz.so.1.2.3.3" were 
not uselessly linked against it (they use none of its symbols).              
dpkg-shlibdeps: warning: dependency on libgcc_s.so.1 could be avoided if
"debian/zlib-bin/usr/bin/miniunzip debian/zlib-
bin/usr/bin/minizip" were not uselessly linked against it (they use none of its
symbols).                                                                                                                                                                                                   
dpkg-shlibdeps: warning: dependency on ld-linux-x86-64.so.2 could be avoided if
"debian/zlib-bin/usr/bin/miniunzip 
debian/zlib-bin/usr/bin/minizip" were not uselessly linked against it (they use
none of its symbols).                                                                                                                                                                                            
dpkg-shlibdeps: warning: dependency on libgcc_s.so.1 could be avoided if
"debian/zlib1g-udeb/usr/lib/libz.so.1.2.3.3" were 
not uselessly linked against it (they use none of its symbols).                
dpkg-shlibdeps: warning: dependency on libgcc_s.so.1 could be avoided if
"debian/lib32z1/usr/lib32/libz.so.1.2.3.3" were not 
uselessly linked against it (they use none of its symbols).                  
dpkg-shlibdeps: warning: dependency on ld-linux.so.2 could be avoided if
"debian/lib32z1/usr/lib32/libz.so.1.2.3.3" were not 
uselessly linked against it (they use none of its symbols).             

I had also a different package which also linked against libICE without any
visible reason, but cannot find it again at the moment

Downstream bug is http://bugs.debian.org/553436
Comment 1 robert.wohlrab 2009-10-31 22:10:18 UTC
It seems to be that it is partly related to the problem that --as-needed
doesn't remove files which aren't really needed by the executable. So a simple

echo "int main() {return 0;}" > testme.c
gcc -Wl,--as-needed testme.c -o testme -lglib-2.0

will link against glib-2.0 even if it is not used. So

readelf -d testme|grep -e '(NEEDED)' -e 'glib-2.0'

will not be an empty string.

But this doesn't explain libgcc_s.so.1 and ld-linux-x86-64.so.2
Comment 2 Ian Lance Taylor 2009-11-07 00:12:17 UTC
Thanks for the bug report.  I fixed --as-needed, and this problem should now be 
fixed.

libgcc_s.so.1 is used with --as-needed by the gcc driver.

ld-linux-x86-64.so.2 is used with --as-needed by /usr/lib/libc.so.