Manual Reference Pages  - LD.SO (8)

NAME - dynamic linker/loader


Command Line Options
Rpath Token Expansion
Hardware Capabilities
See Also

DESCRIPTION loads the shared libraries needed by a program, prepares the program to run, and then runs it. Unless explicitly specified via the -static option to ld during compilation, all Linux programs are incomplete and require further linking at run time.

The necessary shared libraries needed by the program are searched for in the following order
o Using the environment variable LD_LIBRARY_PATH (LD_AOUT_LIBRARY_PATH for a.out programs). Except if the executable is a setuid/setgid binary, in which case it is ignored.
o From the cache file /etc/ which contains a compiled list of candidate libraries previously found in the augmented library path. Libraries installed in hardware capabilities directories (see below) are prefered to other libraries.
o In the default path /lib, and then /usr/lib.


--list List all dependencies and how they are resolved.
  Verify that program is dynamically linked and this dynamic linker can handle it.
--library-path PATH
  Override LD_LIBRARY_PATH environment variable setting (see below).
--ignore-rpath LIST
  Ignore RPATH and RUNPATH information in object names in LIST. This option has been supported by glibc2 for about one hour. Then it was renamed into:
--inhibit-rpath LIST


There are four important environment variables.
  If set to a nonempty string, causes the dynamic linker to resolve all symbols at program startup instead of deferring function call resolution to the point when they are first referenced. This is useful when using a debugger.
  A colon-separated list of directories in which to search for ELF libraries at execution-time. Similar to the PATH environment variable.
  A whitespace-separated list of additional, user-specified, ELF shared libraries to be loaded before all others. This can be used to selectively override functions in other shared libraries. For setuid/setgid ELF binaries, only libraries in the standard search directories that are also setgid will be loaded.
  If set to a nonempty string, causes the program to list its dynamic library dependencies, as if run by ldd(1), instead of running normally.
Then there are lots of more or less obscure variables, many obsolete or only for internal use.
  A colon-separated list of directories in which to search for a.out libraries at execution-time. Similar to the PATH environment variable.
  The name of an additional, user-specified, a.out shared library to be loaded after all others. This can be used to selectively override functions in other shared libraries.
  Every DSO (Dynamic Shared Object, aka shared library) can tell the dynamic linker in glibc which minimum OS ABI version is needed. The information about the minimum OS ABI version is encoded in a ELF note section usually named .note.ABI-tag. This is used to determine which library to load when multiple version of the same library is installed on the system. The LD_ASSUME_KERNEL environment variable overrides the kernel version used by the dynamic linker to determine which library to load.
  A colon-separated list of user-specified, ELF shared objects to be loaded before all others in a separate linker namespace (i.e., one that does not intrude upon the normal symbol bindings that would occur in the process). These libraries can be used to audit the operation of the dynamic linker. LD_AUDIT is ignored for set-user-ID/set-group-ID binaries.

The dynamic linker will notify the audit libraries at so-called auditing checkpoints—for example, loading a new library, resolving a symbol, or calling a symbol from another shared object—by calling an appropriate function within the audit library. For details, see rtld-audit(7). The auditing interface is largely compatible with that provided on Solaris, as described in its Linker and Libraries Guide, in the chapter Runtime Linker Auditing Interface.

  Do not update the GOT (global offset table) and PLT (procedure linkage table) after resolving a symbol.
  Output verbose debugging information about the dynamic linker. If set to ‘all’ prints all debugging information it has, if set to ‘help’ prints a help message about which categories can be specified in this environment variable.
  File where LD_DEBUG output should be fed into, default is standard output. LD_DEBUG_OUTPUT is ignored for setuid/setgid binaries.
  Allow weak symbols to be overridden (reverting to old glibc behavior). For security reasons, since glibc 2.3.4, LD_DYNAMIC_WEAK is ignored for set-user-ID/set-group-ID binaries.
  Mask for hardware capabilities.
  Don’t ignore the directory in the names of a.out libraries to be loaded. Use of this option is strongly discouraged.
  Suppress warnings about a.out libraries with incompatible minor version numbers.
  Path where the binary is found (for non-set-user-ID programs). For security reasons, since glibc 2.4, LD_ORIGIN_PATH is ignored for set-user-ID/set-group-ID binaries.
  Set to 0 to disable pointer guarding. Any other value enables pointer guarding, which is also the default. Pointer guarding is a security mechanism whereby some pointers to code stored in writable program memory (return addresses saved by setjmp(3) or function pointers used by various glibc internals) are mangled semi-randomly to make it more difficult for an attacker to hijack the pointers for use in the event of a buffer overrun or stack-smashing attack.
  Shared object to be profiled.
LD_PROFILE_OUTPUT File where LD_PROFILE output should be written. If this variable is not defined, or is defined as an empty string, then the default is /var/tmp. LD_PROFILE_OUTPUT is ignored for set-user-ID and set-group-ID programs, which always use /var/profile.
  Show auxiliary array passed up from the kernel. For security reasons, since glibc 2.3.5, LD_SHOW_AUXV is ignored for set-user-ID/set-group-ID binaries.
  By default (i.e., if this variable is not defined) executables and prelinked shared objects will honor base addresses of their dependent libraries and (nonprelinked) position-independent executables (PIEs) and other shared objects will not honor them. If LD_USE_LOAD_BIAS is defined wit the value, both executables and PIEs will honor the base addresses. If LD_USE_LOAD_BIAS is defined with the value 0, neither executables nor PIEs will honor the base addresses. This variable is ignored by set-user-ID and set-group-ID programs.
  If set to non-empty string, output symbol versioning information about the program if querying information about the program (ie. either LD_TRACE_LOADED_OBJECTS has been set, or --list or --verify options have been given to the dynamic linker).
  If set to non-empty string, warn about unresolved symbols.


The runtime linker provides a number of tokens that can be used in an rpath specification (DT_RPATH or DT_RUNPATH).
$ORIGIN understands the string $ORIGIN (or equivalently ${ORIGIN}) in an rpath specification to mean the directory containing the application executable. Thus, an application located in somedir/app could be compiled with gcc -Wl,-rpath,’$ORIGIN/../lib’ so that it finds an associated shared library in somedir/lib no matter where somedir is located in the directory hierarchy.
  The string $PLATFORM (or equivalently ${PLATFORM}) in an rpath specifcation expands to the processor type of the current machine. Please note that on some architectures the Linux kernel doesn’t provide a platform string to the dynamic linker.
$LIB The string $LIB (or equivalently ${LIB}) in an rpath corresponds to the system libraries directory, which is /lib for the native architecture on FHS compliant GNU/Linux systems.


Libraries might be compiled using hardware-specific instructions which do not exist on all CPU. Such libraries should be installed in directories whose name defines the hardware capabilities such as /usr/lib/sse2/. The dynamic linker checks these directories against the hardware of the machine and selects the best suitable version of a given library. Hardware capabilities directories could be cascaded to combine CPU features. Hardware capabilities depends on the CPU. The following names are currently recognized:
Alpha ev4, ev5, ev56, ev6, ev67
MIPS loongson2e, loongson2f, octeon, octeon2
  4xxmac, altivec, arch_2_05, arch_2_06, booke, cellbe, dfp, efpdouble, efpsingle, fpu, ic_snoop, mmu, notb, pa6t, power4, power5, power5+, power6x, ppc32, ppc601, ppc64, smt, spe, ucache, vsx
SPARC flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2
s390 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle, z900, z990, z9-109, z10, zarch
x86 (32-bit only)
  acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx, mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm


/lib/ a.out dynamic linker/loader
/lib/* ELF dynamic linker/loader
/etc/ File containing a compiled list of directories in which to search for libraries and an ordered list of candidate libraries.
/etc/ File containing a whitespace separated list of ELF shared libraries to be loaded before the program. libraries and an ordered list of candidate libraries.
/etc/ When this file is present the dynamic linker will load the non-optimized version of a library, even if the CPU supports the optimized version.
lib*.so* shared libraries


ldd(1), ldconfig(8).


Currently has no means of unloading and searching for compatible or newer version of libraries. functionality is only available for executables compiled using libc version 4.4.3 or greater.


David Engel, Eric Youngdale, Peter MacDonald, Hongjiu Lu, Linus Torvalds, Lars Wirzenius and Mitch D’Souza (not necessarily in that order).

LD.SO (8) 26 May 2007
blog comments powered by Disqus