This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ld and GNU/Linux ld.so disagree on dependent library search order (?)


Ian Lance Taylor <ian@airs.com> writes:
> ld and ld.so should use the same search path for shared libraries.
> Anything else is a bug.  It sounds like you have found a bug, or else
> the ld.so behaviour has changed.

Certainly both seem to be behaving as they are documented to; it's
just that they are documented as behaving differently.

At the bottom of this email is a sequence of commands that illustrates
the problem on my Fedora core 3 x86_64 box.  It relies on the implicit
dependency of libgnome-2 on libxml2.  It needs to be run as root,
because it adjusts (and then resets) ld.so.conf.

Here's the most interesting part of the output.  At this point,
libxml2 has been copied into /usr/lib/test, and /usr/lib/test is the
first entry in /etc/ld.so.conf. 

1 sh-3.00#  gcc -Xlinker -verbose foo.c -o foo -lgnome-2 2>&1 | grep libxml2
2 libxml2.so.2 needed by /usr/lib64/libgnomevfs-2.so.0
3 found libxml2.so.2 at /usr/lib64/libxml2.so.2  
4 sh-3.00#  ldd foo | grep libxml2
5         libxml2.so.2 => /usr/lib/test/libxml2.so.2 (0x00002aaaac16b000)
6 sh-3.00#  LD_DEBUG=libs ./foo 2>&1 | grep libxml2
7      24661:     find library=libxml2.so.2 [0]; searching
8      24661:       trying file=/usr/lib/test/libxml2.so.2
9      24661:     calling init: /usr/lib/test/libxml2.so.2
10     24661:     calling fini: /usr/lib/test/libxml2.so.2 [0]

Note that at line 3, the linker reports finding libxml2 at
/usr/lib64/libxml2, while at line 5, ldd finds it in /usr/lib/test/ As
another check, lines 8-10 show that ld.so also finds it in
/usr/lib/test  

As I said, this is consistent with the way both ld and ld.so are
documented, but very, very annoying.  My opinion is that ld is doing
the wrong thing here: it should favor paths in /etc/ld.so.conf ahead
of hard-coded system paths.

Should I report this as a bug?

Thanks for your time,
Jeremy



------------------------------------------------------------
 mkdir -p /usr/lib/test
 echo '/usr/lib/test' | cat - /etc/ld.so.conf > /etc/ld.so.conf.new
 mv /etc/ld.so.conf /etc/ld.so.conf.old
 mv /etc/ld.so.conf.new /etc/ld.so.conf
 cd /usr/lib/test
 cp -s /usr/lib64/libxml2.* .
 ldconfig
 cd /tmp
 echo 'int main(int argc, char **argv) { return 0;}' > foo.c
 gcc -Xlinker -verbose foo.c -o foo -lgnome-2 2>&1 | grep libxml2
 ldd foo | grep libxml2
 LD_DEBUG=libs ./foo 2>&1 | grep libxml2
 gcc -Xlinker -rpath-link /usr/lib/test -Xlinker -verbose foo.c -o foo -lgnome-2 2>&1 | grep libxml2
 ldd foo | grep libxml2
 mv /etc/ld.so.conf.old /etc/ld.so.conf
 rm -r /usr/lib/test
 ldconfig


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]