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]

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


We were bitten today by how GNU ld searches for dependent shared
libraries, and I was wondering if anyone could explain why it is done
the way it is.

The thing that got us is that when ld is looking up dependent
libraries, it will search a variety of locations, with the final two
sets being first, the system directories /lib and /usr/lib; and second
and finally, in directories listed in /etc/ld.so.conf [1]

To me, it seems backward for ld to first look in the system
directoreies, and only then look in custom-specified directories.  Why
is it done this way?

The way we got bit is that on GNU/Linux (Fedora), ld.so will look for
shared libraries in a variety of places, with the final two places
searched being, first, entries cached in /etc/ld.so.cache; and second
(and finally), /lib and then /usr/lib.  [2]

Because ld and ld.so disagree, we were forced to use -rpath-link just
to get ld to use the same lookup strategy at link-time as ld.so will
use at runtime --- and until we figured out the conflicting
search-path problem, we were having a really hard time understanding
why our links were failling.

Are we missing something that would simplify headache this away?

Many thanks,
Jeremy


------------------------------------------------------------
[1]:  From the GNU ld info page documentation on -rpath-link:

       7. The default directories, normally `/lib' and `/usr/lib'.

       8. For a native linker on an ELF system, if the file
          `/etc/ld.so.conf' exists, the list of directories found in
          that file.

------------------------------------------------------------
[2]:  From the GNU/Linux man page on ld.so (Fedora):

       o      From  the  cache file /etc/ld.so.cache which contains a compiled
              list of candidate libraries previously found  in  the  augmented
              library  path.  If, however, the binary was linked with -z node-
              flib linker option, libraries in the default library  paths  are
              skipped.

       o      In  the default path /lib, and then /usr/lib.  If the binary was
              linked with -z nodeflib linker option, this step is skipped.


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