On 09/06/2011, at 5:31 AM, Till Oliver Knoll wrote:

Yeah, I just checked the ld man pages. For the sake of completeness:

"The linker uses the following search paths to locate required shared
libraries:

  1.  Any directories specified by -rpath-link options.

  2.  Any directories specified by -rpath options.  [...]

  3.  On an ELF system, for native linkers, if the -rpath and
      -rpath-link options were not used, search
      the contents of the environment variable "LD_RUN_PATH".

  4.  On SunOS, if the -rpath option was not used, search any
      directories specified using -L options.

  5.  For a native linker, the search the contents of the environment
      variable "LD_LIBRARY_PATH".

  6.  For a native ELF linker, the directories in "DT_RUNPATH" or
      "DT_RPATH" of a shared library are searched for shared libraries
      needed by it. The "DT_RPATH" entries are ignored if "DT_RUNPATH"
      entries exist.

  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.
"

So RPATH is evaluated before LD_LIBRARY_PATH, and the newer RUNPATH is
evaluated after LD_LIBRARY_PATH (and disables the RPATH entry, if present).

Ah, but ld is not ld.so or ld-linux.so! The ordering you list above applies 
when you are *creating* your binaries, but the ordering used when *running* 
your binaries is a bit different. Here's the runtime ordering as specified in 
the ld.so (or ld-linux.so) man page:

       The shared libraries needed by the program are searched for in the 
following order:

       o  (ELF  only)  Using the directories specified in the DT_RPATH dynamic 
section attribute of the binary if present
          and DT_RUNPATH attribute does not exist.  Use of DT_RPATH is 
deprecated.

       o  Using the environment variable LD_LIBRARY_PATH.  Except if the 
executable is a set-user-ID/set-group-ID binary,
          in which case it is ignored.

       o  (ELF  only)  Using  the  directories  specified  in  the  DT_RUNPATH 
dynamic section attribute of the binary if
          present.

       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 the -z nodeflib 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 the -z nodeflib linker option, this
          step is skipped.


I'm sure there are (hopefully good!) reasons why ld and ld.so/ld-linux.so use 
different search orders, but it sure does add to the confusion. The above list 
is also immediately followed by a description of the $ORIGIN feature.

--
Dr Craig Scott
Computational Software Engineering Team Leader, CSIRO (CMIS)
Melbourne, Australia



_______________________________________________
Qt5-feedback mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback

Reply via email to