Linux "ld.so" Command Line Options and Examples
dynamic linker/loader

The programs ld.so and ld-linux.so* find and load the shared objects (shared libraries) needed by a program, prepare the program to run, and then run it.


Usage:

The dynamic linker can be run either indirectly by running some dynamically linked program or shared object (in which case no com‐
mand-line options to the dynamic linker can be passed and, in the ELF case, the dynamic linker which is stored in the .interp section
of the program is executed) or directly by running:






Command Line Options:

--list
List all dependencies and how they are resolved.
ld.so --list ...
--verify
Verify that program is dynamically linked and this dynamic linker can handle it.
ld.so --verify ...
--inhibit-cache
Do not use /etc/ld.so.cache.
ld.so --inhibit-cache ...
--library-path
Use path instead of LD_LIBRARY_PATH environment variable setting (see below). The names ORIGIN, LIB, and PLATFORM are inter‐preted as for the LD_LIBRARY_PATH environment variable.
ld.so --library-path ...
--inhibit-rpath
Ignore RPATH and RUNPATH information in object names in list. This option is ignored when running in secure-execution mode(see below).
ld.so --inhibit-rpath ...
--audit
Use objects named in list as auditors.ENVIRONMENTVarious environment variables influence the operation of the dynamic linker.Secure-execution modeFor security reasons, the effects of some environment variables are voided or modified if the dynamic linker determines that thebinary should be run in secure-execution mode. (For details, see the discussion of individual environment variables below.) Abinary is executed in secure-execution mode if the AT_SECURE entry in the auxiliary vector (see getauxval(3)) has a nonzero value.This entry may have a nonzero value for various reasons, including:* The process's real and effective user IDs differ, or the real and effective group IDs differ. This typically occurs as a resultof executing a set-user-ID or set-group-ID program.* A process with a non-root user ID executed a binary that conferred capabilities to the process.* A nonzero value may have been set by a Linux Security Module.Environment variablesAmong the more important environment variables are the following:LD_ASSUME_KERNEL (since glibc 2.2.3)Each shared object can inform the dynamic linker of the minimum kernel ABI version that it requires. (This requirement isencoded in an ELF note section that is viewable via readelf -n as a section labeled NT_GNU_ABI_TAG.) At run time, the dynamiclinker determines the ABI version of the running kernel and will reject loading shared objects that specify minimum ABI ver‐sions that exceed that ABI version.LD_ASSUME_KERNEL can be used to cause the dynamic linker to assume that it is running on a system with a different kernel ABIversion. For example, the following command line causes the dynamic linker to assume it is running on Linux 2.2.5 when load‐ing the shared objects required by myprog:$ LD_ASSUME_KERNEL=2.2.5 ./myprogOn systems that provide multiple versions of a shared object (in different directories in the search path) that have differentminimum kernel ABI version requirements, LD_ASSUME_KERNEL can be used to select the version of the object that is used (depen‐dent on the directory search order).Historically, the most common use of the LD_ASSUME_KERNEL feature was to manually select the older LinuxThreads POSIX threadsimplementation on systems that provided both LinuxThreads and NPTL (which latter was typically the default on such systems);see pthreads(7).LD_BIND_NOW (since glibc 2.1.1)If set to a nonempty string, causes the dynamic linker to resolve all symbols at program startup instead of deferring functioncall resolution to the point when they are first referenced. This is useful when using a debugger.LD_LIBRARY_PATHA list of directories in which to search for ELF libraries at execution time. The items in the list are separated by eithercolons or semicolons. Similar to the PATH environment variable.This variable is ignored in secure-execution mode.Within the pathnames specified in LD_LIBRARY_PATH, the dynamic linker expands the tokens $ORIGIN, $LIB, and $PLATFORM (or theversions using curly braces around the names) as described above in Rpath token expansion. Thus, for example, the followingwould cause a library to be searched for in either the lib or lib64 subdirectory below the directory containing the program tobe executed:$ LD_LIBRARY_PATH='$ORIGIN/$LIB' prog(Note the use of single quotes, which prevent expansion of $ORIGIN and $LIB as shell variables!)LD_PRELOADA list of additional, user-specified, ELF shared objects to be loaded before all others. The items of the list can be sepa‐rated by spaces or colons. This can be used to selectively override functions in other shared objects. The objects aresearched for using the rules given under DESCRIPTION.In secure-execution mode, preload pathnames containing slashes are ignored. Furthermore, shared objects are preloaded onlyfrom the standard search directories and only if they have set-user-ID mode bit enabled (which is not typical).Within the names specified in the LD_PRELOAD list, the dynamic linker understands the tokens $ORIGIN, $LIB, and $PLATFORM (orthe versions using curly braces around the names) as described above in Rpath token expansion. (See also the discussion ofquoting under the description of LD_LIBRARY_PATH.)LD_TRACE_LOADED_OBJECTSIf set (to any value), causes the program to list its dynamic 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.LD_AUDIT (since glibc 2.4)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 objects can be usedto audit the operation of the dynamic linker.LD_AUDIT is ignored in secure-execution mode.The dynamic linker will notify the audit shared objects at so-called auditing checkpoints—for example, loading a new sharedobject, resolving a symbol, or calling a symbol from another shared object—by calling an appropriate function within the auditshared object. 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.Within the names specified in the LD_AUDIT list, the dynamic linker understands the tokens $ORIGIN, $LIB, and $PLATFORM (orthe versions using curly braces around the names) as described above in Rpath token expansion. (See also the discussion ofquoting under the description of LD_LIBRARY_PATH.)Since glibc 2.13, in secure-execution mode, names in the audit list that contain slashes are ignored, and only shared objectsin the standard search directories that have the set-user-ID mode bit enabled are loaded.LD_BIND_NOT (since glibc 2.1.95)If this environment variable is set to a nonempty string, do not update the GOT (global offset table) and PLT (procedure link‐age table) after resolving a function symbol. By combining the use of this variable with LD_DEBUG (with the categories bind‐ings and symbols), one can observe all run-time function bindings.LD_DEBUG (since glibc 2.1)Output verbose debugging information about operation of the dynamic linker. The content of this variable is one of more ofthe following categories, separated by colons, commas, or (if the value is quoted) spaces:help Specifying help in the value of this variable does not run the specified program, and displays a help messageabout which categories can be specified in this environment variable.all Print all debugging information (except statistics and unused; see below).bindings Display information about which definition each symbol is bound to.files Display progress for input file.libs Display library search paths.reloc Display relocation processing.scopes Display scope information.statistics Display relocation statistics.symbols Display search paths for each symbol look-up.unused Determine unused DSOs.versions Display version dependencies.Since glibc 2.3.4, LD_DEBUG is ignored in secure-execution mode, unless the file /etc/suid-debug exists (the content of thefile is irrelevant).LD_DEBUG_OUTPUT (since glibc 2.1)By default, LD_DEBUG output is written to standard error. If LD_DEBUG_OUTPUT is defined, then output is written to the path‐name specified by its value, with the suffix "." (dot) followed by the process ID appended to the pathname.LD_DEBUG_OUTPUT is ignored in secure-execution mode.LD_DYNAMIC_WEAK (since glibc 2.1.91)By default, when searching shared libraries to resolve a symbol reference, the dynamic linker will resolve to the first defi‐nition it finds.Old glibc versions (before 2.2), provided a different behavior: if the linker found a symbol that was weak, it would rememberthat symbol and keep searching in the remaining shared libraries. If it subsequently found a strong definition of the samesymbol, then it would instead use that definition. (If no further symbol was found, then the dynamic linker would use theweak symbol that it initially found.)The old glibc behavior was nonstandard. (Standard practice is that the distinction between weak and strong symbols shouldhave effect only at static link time.) In glibc 2.2, the dynamic linker was modified to provide the current behavior (whichwas the behavior that was provided by most other implementations at that time).Defining the LD_DYNAMIC_WEAK environment variable (with any value) provides the old (nonstandard) glibc behavior, whereby aweak symbol in one shared library may be overridden by a strong symbol subsequently discovered in another shared library.(Note that even when this variable is set, a strong symbol in a shared library will not override a weak definition of the samesymbol in the main program.)Since glibc 2.3.4, LD_DYNAMIC_WEAK is ignored in secure-execution mode.LD_HWCAP_MASK (since glibc 2.1)Mask for hardware capabilities.LD_ORIGIN_PATH (since glibc 2.1)Path where the binary is found.Since glibc 2.4, LD_ORIGIN_PATH is ignored in secure-execution mode.LD_POINTER_GUARD (glibc from 2.4 to 2.22)Set to 0 to disable pointer guarding. Any other value enables pointer guarding, which is also the default. Pointer guardingis 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 tohijack the pointers for use in the event of a buffer overrun or stack-smashing attack. Since glibc 2.23, LD_POINTER_GUARD canno longer be used to disable pointer guarding, which is now always enabled.LD_PROFILE (since glibc 2.1)The name of a (single) shared object to be profiled, specified either as a pathname or a soname. Profiling output is appendedto the file whose name is: "$LD_PROFILE_OUTPUT/$LD_PROFILE.profile".Since glibc 2.2.5, LD_PROFILE is ignored in secure-execution mode.LD_PROFILE_OUTPUT (since glibc 2.1)Directory where LD_PROFILE output should be written. If this variable is not defined, or is defined as an empty string, thenthe default is /var/tmp.LD_PROFILE_OUTPUT is ignored in secure-execution mode; instead /var/profile is always used. (This detail is relevant onlybefore glibc 2.2.5, since in later glibc versions, LD_PROFILE is also ignored in secure-execution mode.)LD_SHOW_AUXV (since glibc 2.1)If this environment variable is defined (with any value), show the auxiliary array passed up from the kernel (see also getaux‐val(3)).Since glibc 2.3.4, LD_SHOW_AUXV is ignored in secure-execution mode.LD_TRACE_PRELINKING (since glibc 2.4)If this environment variable is defined, trace prelinking of the object whose name is assigned to this environment variable.(Use ldd(1) to get a list of the objects that might be traced.) If the object name is not recognized, then all prelinkingactivity is traced.LD_USE_LOAD_BIAS (since glibc 2.3.3)By default (i.e., if this variable is not defined), executables and prelinked shared objects will honor base addresses oftheir dependent shared objects and (nonprelinked) position-independent executables (PIEs) and other shared objects will nothonor them. If LD_USE_LOAD_BIAS is defined with the value 1, both executables and PIEs will honor the base addresses. IfLD_USE_LOAD_BIAS is defined with the value 0, neither executables nor PIEs will honor the base addresses.Since glibc 2.3.3, this variable is ignored in secure-execution mode.LD_VERBOSE (since glibc 2.1)If set to a nonempty string, output symbol versioning information about the program if the LD_TRACE_LOADED_OBJECTS environmentvariable has been set.LD_WARN (since glibc 2.1.3)If set to a nonempty string, warn about unresolved symbols.LD_PREFER_MAP_32BIT_EXEC (x86-64 only; since glibc 2.23)According to the Intel Silvermont software optimization guide, for 64-bit applications, branch prediction performance can benegatively impacted when the target of a branch is more than 4 GB away from the branch. If this environment variable is set(to any value), the dynamic linker will first try to map executable pages using the mmap(2) MAP_32BIT flag, and fall back tomapping without that flag if that attempt fails. NB: MAP_32BIT will map to the low 2 GB (not 4 GB) of the address space.Because MAP_32BIT reduces the address range available for address space layout randomization (ASLR), LD_PREFER_MAP_32BIT_EXECis always disabled in secure-execution mode.FILES/lib/ld.soa.out dynamic linker/loader/lib/ld-linux.so.{1,2}ELF dynamic linker/loader/etc/ld.so.cacheFile containing a compiled list of directories in which to search for shared objects and an ordered list of candidate sharedobjects. See ldconfig(8)./etc/ld.so.preloadFile containing a whitespace-separated list of ELF shared objects to be loaded before the program. See the discussion ofLD_PRELOAD above. If both LD_PRELOAD and /etc/ld.so.preload are employed, the libraries specified by LD_PRELOAD are preloadedfirst. /etc/ld.so.preload has a system-wide effect, causing the specified libraries to be preloaded for all programs that areexecuted on the system. (This is usually undesirable, and is typically employed only as an emergency remedy, for example, asa temporary workaround to a library misconfiguration issue.)lib*.so*shared objectsNOTESHardware capabilitiesSome shared objects are compiled using hardware-specific instructions which do not exist on every CPU. Such objects should beinstalled in directories whose names define the required hardware capabilities, such as /usr/lib/sse2/. The dynamic linker checksthese directories against the hardware of the machine and selects the most suitable version of a given shared object. Hardware capa‐bility directories can be cascaded to combine CPU features. The list of supported hardware capability names depends on the CPU. Thefollowing names are currently recognized:Alpha ev4, ev5, ev56, ev6, ev67MIPS loongson2e, loongson2f, octeon, octeon2PowerPC4xxmac, 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, vsxSPARC flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2s390 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle, z900, z990, z9-109, z10, zarchx86 (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
ld.so --audit ...