1 .\" %%%LICENSE_START(PUBLIC_DOMAIN)
2 .\" This is in the public domain
5 .\" Copyright (C) 2007-9, 2013, 2016 Michael Kerrisk <mtk.manpages@gmail.com>
7 .TH ld.so 8 (date) "Linux man-pages (unreleased)"
9 ld.so, ld\-linux.so \- dynamic linker/loader
11 The dynamic linker can be run either indirectly by running some
12 dynamically linked program or shared object
13 (in which case no command-line options
14 to the dynamic linker can be passed and, in the ELF case, the dynamic linker
15 which is stored in the
17 section of the program is executed) or directly by running:
19 .I /lib/ld\-linux.so.*
20 [OPTIONS] [PROGRAM [ARGUMENTS]]
26 find and load the shared objects (shared libraries) needed by a program,
27 prepare the program to run, and then run it.
29 Linux binaries require dynamic linking (linking at run time)
38 handles a.out binaries, a binary format used long ago.
41 (\fI/lib/ld\-linux.so.1\fP for libc5, \fI/lib/ld\-linux.so.2\fP for glibc2)
42 handles binaries that are in the more modern ELF format.
43 Both programs have the same behavior, and use the same
44 support files and programs
48 .IR /etc/ld.so.conf ).
50 When resolving shared object dependencies,
51 the dynamic linker first inspects each dependency
52 string to see if it contains a slash (this can occur if
53 a shared object pathname containing slashes was specified at link time).
54 If a slash is found, then the dependency string is interpreted as
55 a (relative or absolute) pathname,
56 and the shared object is loaded using that pathname.
58 If a shared object dependency does not contain a slash,
59 then it is searched for in the following order:
61 Using the directories specified in the
62 DT_RPATH dynamic section attribute
63 of the binary if present and DT_RUNPATH attribute does not exist.
64 Use of DT_RPATH is deprecated.
66 Using the environment variable
68 unless the executable is being run in secure-execution mode (see below),
69 in which case this variable is ignored.
71 Using the directories specified in the
72 DT_RUNPATH dynamic section attribute
73 of the binary if present.
74 Such directories are searched only to
75 find those objects required by DT_NEEDED (direct dependencies) entries
76 and do not apply to those objects' children,
77 which must themselves have their own DT_RUNPATH entries.
78 This is unlike DT_RPATH, which is applied
79 to searches for all children in the dependency tree.
82 .IR /etc/ld.so.cache ,
83 which contains a compiled list of candidate shared objects previously found
84 in the augmented library path.
85 If, however, the binary was linked with the
87 linker option, shared objects in the default paths are skipped.
88 Shared objects installed in hardware capability directories (see below)
89 are preferred to other shared objects.
95 (On some 64-bit architectures, the default paths for 64-bit shared objects are
99 If the binary was linked with the
101 linker option, this step is skipped.
103 .SS Dynamic string tokens
104 In several places, the dynamic linker expands dynamic string tokens:
106 In the environment variables
107 .BR LD_LIBRARY_PATH ,
112 inside the values of the dynamic section tags
121 in the arguments to the
125 .BR \-\-library\-path ,
130 in the filename arguments to the
136 The substituted tokens are as follows:
138 .IR $ORIGIN " (or equivalently " ${ORIGIN} )
140 the directory containing the program or shared object.
141 Thus, an application located in
143 could be compiled with
147 gcc \-Wl,\-rpath,\[aq]$ORIGIN/../lib\[aq]
151 so that it finds an associated shared object in
155 is located in the directory hierarchy.
156 This facilitates the creation of "turn-key" applications that
157 do not need to be installed into special directories,
158 but can instead be unpacked into any directory
159 and still find their own shared objects.
161 .IR $LIB " (or equivalently " ${LIB} )
166 depending on the architecture
167 (e.g., on x86-64, it expands to
170 on x86-32, it expands to
173 .IR $PLATFORM " (or equivalently " ${PLATFORM} )
174 This expands to a string corresponding to the processor type
175 of the host system (e.g., "x86_64").
176 On some architectures, the Linux kernel doesn't provide a platform
177 string to the dynamic linker.
178 The value of this string is taken from the
180 value in the auxiliary vector (see
182 .\" To get an idea of the places that $PLATFORM would match,
183 .\" look at the output of the following:
186 .\" LD_LIBRARY_PATH=/tmp/d strace -e open /bin/date 2>&1 | grep /tmp/d
188 .\" ld.so lets names be abbreviated, so $O will work for $ORIGIN;
191 Note that the dynamic string tokens have to be quoted properly when
193 to prevent their expansion as shell or environment variables.
196 .BR \-\-argv0 " \fIstring\fP (since glibc 2.33)"
201 before running the program.
203 .BI \-\-audit " list"
209 are delimited by colons.
211 .B \-\-inhibit\-cache
213 .IR /etc/ld.so.cache .
215 .BI \-\-library\-path " path"
220 environment variable setting (see below).
226 are interpreted as for the
228 environment variable.
230 .BI \-\-inhibit\-rpath " list"
231 Ignore RPATH and RUNPATH information in object names in
233 This option is ignored when running in secure-execution mode (see below).
236 are delimited by colons or spaces.
239 List all dependencies and how they are resolved.
241 .BR \-\-list\-diagnostics " (since glibc 2.33)"
242 Print system diagnostic information in a machine-readable format,
243 such as some internal loader variables,
247 and the environment variables.
248 On some architectures,
249 the command might print additional information
250 (like the cpu features used in GNU indirect function selection on x86).
251 .BR \-\-list\-tunables " (since glibc 2.33)"
252 Print the names and values of all tunables,
253 along with the minimum and maximum allowed values.
255 .BR \-\-preload " \fIlist\fP (since glibc 2.30)"
256 Preload the objects specified in
260 are delimited by colons or spaces.
261 The objects are preloaded as explained in the description of the
263 environment variable below.
269 option provides a way to perform preloading for a single executable
270 without affecting preloading performed in any child process that executes
274 Verify that program is dynamically linked and this dynamic linker can handle
277 Various environment variables influence the operation of the dynamic linker.
279 .SS Secure-execution mode
280 For security reasons,
281 if the dynamic linker determines that a binary should be
282 run in secure-execution mode,
283 the effects of some environment variables are voided or modified,
284 and furthermore those environment variables are stripped from the environment,
285 so that the program does not even see the definitions.
286 Some of these environment variables affect the operation of
287 the dynamic linker itself, and are described below.
288 Other environment variables treated in this way include:
295 .BR LD_DEBUG_OUTPUT ,
296 .BR LD_DYNAMIC_WEAK ,
298 .BR LD_LIBRARY_PATH ,
308 .BR RESOLV_HOST_CONF ,
314 A binary is executed in secure-execution mode if the
316 entry in the auxiliary vector (see
319 This entry may have a nonzero value for various reasons, including:
321 The process's real and effective user IDs differ,
322 or the real and effective group IDs differ.
323 This typically occurs as a result of executing
324 a set-user-ID or set-group-ID program.
326 A process with a non-root user ID executed a binary that
327 conferred capabilities to the process.
329 A nonzero value may have been set by a Linux Security Module.
331 .SS Environment variables
332 Among the more important environment variables are the following:
334 .BR LD_ASSUME_KERNEL " (from glibc 2.2.3 to glibc 2.36)"
335 Each shared object can inform the dynamic linker of the minimum kernel ABI
336 version that it requires.
337 (This requirement is encoded in an ELF note section that is viewable via
340 .BR NT_GNU_ABI_TAG .)
342 the dynamic linker determines the ABI version of the running kernel and
343 will reject loading shared objects that specify minimum ABI versions
344 that exceed that ABI version.
348 cause the dynamic linker to assume that it is running on a system with
349 a different kernel ABI version.
350 For example, the following command line causes the
351 dynamic linker to assume it is running on Linux 2.2.5 when loading
352 the shared objects required by
357 $ \fBLD_ASSUME_KERNEL=2.2.5 ./myprog\fP
361 On systems that provide multiple versions of a shared object
362 (in different directories in the search path) that have
363 different minimum kernel ABI version requirements,
365 can be used to select the version of the object that is used
366 (dependent on the directory search order).
368 Historically, the most common use of the
370 feature was to manually select the older
371 LinuxThreads POSIX threads implementation on systems that provided both
372 LinuxThreads and NPTL
373 (which latter was typically the default on such systems);
377 .BR LD_BIND_NOW " (since glibc 2.1.1)"
378 If set to a nonempty string,
379 causes the dynamic linker to resolve all symbols
380 at program startup instead of deferring function call resolution to the point
381 when they are first referenced.
382 This is useful when using a debugger.
385 A list of directories in which to search for
386 ELF libraries at execution time.
387 The items in the list are separated by either colons or semicolons,
388 and there is no support for escaping either separator.
389 A zero-length directory name indicates the current working directory.
391 This variable is ignored in secure-execution mode.
393 Within the pathnames specified in
394 .BR LD_LIBRARY_PATH ,
395 the dynamic linker expands the tokens
400 (or the versions using curly braces around the names)
401 as described above in
402 .IR "Dynamic string tokens" .
404 the following would cause a library to be searched for in either the
408 subdirectory below the directory containing the program to be executed:
412 $ \fBLD_LIBRARY_PATH=\[aq]$ORIGIN/$LIB\[aq] prog\fP
416 (Note the use of single quotes, which prevent expansion of
423 A list of additional, user-specified, ELF shared
424 objects to be loaded before all others.
425 This feature can be used to selectively override functions
426 in other shared objects.
428 The items of the list can be separated by spaces or colons,
429 and there is no support for escaping either separator.
430 The objects are searched for using the rules given under DESCRIPTION.
431 Objects are searched for and added to the link map in the left-to-right
432 order specified in the list.
434 In secure-execution mode,
435 preload pathnames containing slashes are ignored.
436 Furthermore, shared objects are preloaded only
437 from the standard search directories and only
438 if they have set-user-ID mode bit enabled (which is not typical).
440 Within the names specified in the
442 list, the dynamic linker understands the tokens
447 (or the versions using curly braces around the names)
448 as described above in
449 .IR "Dynamic string tokens" .
450 (See also the discussion of quoting under the description of
451 .BR LD_LIBRARY_PATH .)
452 .\" Tested with the following:
454 .\" LD_PRELOAD='$LIB/libmod.so' LD_LIBRARY_PATH=. ./prog
456 .\" which will preload the libmod.so in 'lib' or 'lib64', using it
457 .\" in preference to the version in '.'.
459 There are various methods of specifying libraries to be preloaded,
460 and these are handled in the following order:
465 environment variable.
469 command-line option when invoking the dynamic linker directly.
472 .I /etc/ld.so.preload
473 file (described below).
476 .B LD_TRACE_LOADED_OBJECTS
477 If set (to any value), causes the program to list its dynamic
478 dependencies, as if run by
480 instead of running normally.
482 Then there are lots of more or less obscure variables,
483 many obsolete or only for internal use.
485 .BR LD_AUDIT " (since glibc 2.4)"
486 A list of user-specified, ELF shared objects
487 to be loaded before all others in a separate linker namespace
488 (i.e., one that does not intrude upon the normal symbol bindings that
489 would occur in the process)
490 These objects can be used to audit the operation of the dynamic linker.
491 The items in the list are colon-separated,
492 and there is no support for escaping the separator.
495 is ignored in secure-execution mode.
497 The dynamic linker will notify the audit
498 shared objects at so-called auditing checkpoints\[em]for example,
499 loading a new shared object, resolving a symbol,
500 or calling a symbol from another shared object\[em]by
501 calling an appropriate function within the audit shared object.
504 The auditing interface is largely compatible with that provided on Solaris,
506 .IR "Linker and Libraries Guide" ,
508 .IR "Runtime Linker Auditing Interface" .
510 Within the names specified in the
512 list, the dynamic linker understands the tokens
517 (or the versions using curly braces around the names)
518 as described above in
519 .IR "Dynamic string tokens" .
520 (See also the discussion of quoting under the description of
521 .BR LD_LIBRARY_PATH .)
524 .\" commit 8e9f92e9d5d7737afdacf79b76d98c4c42980508
525 in secure-execution mode,
526 names in the audit list that contain slashes are ignored,
527 and only shared objects in the standard search directories that
528 have the set-user-ID mode bit enabled are loaded.
530 .BR LD_BIND_NOT " (since glibc 2.1.95)"
531 If this environment variable is set to a nonempty string,
532 do not update the GOT (global offset table) and PLT (procedure linkage table)
533 after resolving a function symbol.
534 By combining the use of this variable with
540 one can observe all run-time function bindings.
542 .BR LD_DEBUG " (since glibc 2.1)"
543 Output verbose debugging information about operation of the dynamic linker.
544 The content of this variable is one of more of the following categories,
545 separated by colons, commas, or (if the value is quoted) spaces:
551 in the value of this variable does not run the specified program,
552 and displays a help message about which categories can be specified in this
553 environment variable.
556 Print all debugging information (except
563 Display information about which definition each symbol is bound to.
566 Display progress for input file.
569 Display library search paths.
572 Display relocation processing.
575 Display scope information.
578 Display relocation statistics.
581 Display search paths for each symbol look-up.
584 Determine unused DSOs.
587 Display version dependencies.
592 is ignored in secure-execution mode, unless the file
594 exists (the content of the file is irrelevant).
596 .BR LD_DEBUG_OUTPUT " (since glibc 2.1)"
599 output is written to standard error.
602 is defined, then output is written to the pathname specified by its value,
603 with the suffix "." (dot) followed by the process ID appended to the pathname.
606 is ignored in secure-execution mode.
608 .BR LD_DYNAMIC_WEAK " (since glibc 2.1.91)"
609 By default, when searching shared libraries to resolve a symbol reference,
610 the dynamic linker will resolve to the first definition it finds.
612 Old glibc versions (before glibc 2.2), provided a different behavior:
613 if the linker found a symbol that was weak,
614 it would remember that symbol and
615 keep searching in the remaining shared libraries.
616 If it subsequently found a strong definition of the same symbol,
617 then it would instead use that definition.
618 (If no further symbol was found,
619 then the dynamic linker would use the weak symbol that it initially found.)
621 The old glibc behavior was nonstandard.
622 (Standard practice is that the distinction between
623 weak and strong symbols should have effect only at static link time.)
625 .\" More precisely 2.1.92
626 .\" See weak handling
627 .\" https://www.sourceware.org/ml/libc-hacker/2000-06/msg00029.html
628 .\" To: GNU libc hacker <libc-hacker at sourceware dot cygnus dot com>
629 .\" Subject: weak handling
630 .\" From: Ulrich Drepper <drepper at redhat dot com>
631 .\" Date: 07 Jun 2000 20:08:12 -0700
632 .\" Reply-To: drepper at cygnus dot com (Ulrich Drepper)
633 the dynamic linker was modified to provide the current behavior
634 (which was the behavior that was provided by most other implementations
639 environment variable (with any value) provides
640 the old (nonstandard) glibc behavior,
641 whereby a weak symbol in one shared library may be overridden by
642 a strong symbol subsequently discovered in another shared library.
643 (Note that even when this variable is set,
644 a strong symbol in a shared library will not override
645 a weak definition of the same symbol in the main program.)
649 is ignored in secure-execution mode.
651 .BR LD_HWCAP_MASK " (from glibc 2.1 to glibc 2.38)"
652 Mask for hardware capabilities.
654 the option might be ignored
655 if glibc does not support tunables.
657 .BR LD_ORIGIN_PATH " (since glibc 2.1)"
658 Path where the binary is found.
659 .\" Used only if $ORIGIN can't be determined by normal means
660 .\" (from the origin path saved at load time, or from /proc/self/exe)?
664 is ignored in secure-execution mode.
666 .BR LD_POINTER_GUARD " (from glibc 2.4 to glibc 2.22)"
667 Set to 0 to disable pointer guarding.
668 Any other value enables pointer guarding, which is also the default.
669 Pointer guarding is a security mechanism whereby some pointers to code
670 stored in writable program memory (return addresses saved by
672 or function pointers used by various glibc internals) are mangled
673 semi-randomly to make it more difficult for an attacker to hijack
674 the pointers for use in the event of a buffer overrun or
675 stack-smashing attack.
677 .\" commit a014cecd82b71b70a6a843e250e06b541ad524f7
679 can no longer be used to disable pointer guarding,
680 which is now always enabled.
682 .BR LD_PROFILE " (since glibc 2.1)"
683 The name of a (single) shared object to be profiled,
684 specified either as a pathname or a soname.
685 Profiling output is appended to the file whose name is:
686 .RI \%$LD_PROFILE_OUTPUT /\: $LD_PROFILE .profile .
690 uses a different default path in secure-execution mode.
692 .BR LD_PROFILE_OUTPUT " (since glibc 2.1)"
695 output should be written.
696 If this variable is not defined, or is defined as an empty string,
701 is ignored in secure-execution mode; instead
705 .BR LD_SHOW_AUXV " (since glibc 2.1)"
706 If this environment variable is defined (with any value),
707 show the auxiliary array passed up from the kernel (see also
712 is ignored in secure-execution mode.
714 .BR LD_TRACE_PRELINKING " (from glibc 2.4 to glibc 2.35)"
715 If this environment variable is defined,
716 trace prelinking of the object whose name is assigned to
717 this environment variable.
720 to get a list of the objects that might be traced.)
721 If the object name is not recognized,
722 .\" (This is what seems to happen, from experimenting)
723 then all prelinking activity is traced.
725 .BR LD_USE_LOAD_BIAS " (from glibc 2.3.3 to glibc 2.35)"
726 .\" http://sources.redhat.com/ml/libc-hacker/2003-11/msg00127.html
727 .\" Subject: [PATCH] Support LD_USE_LOAD_BIAS
729 By default (i.e., if this variable is not defined),
730 executables and prelinked
731 shared objects will honor base addresses of their dependent shared objects
732 and (nonprelinked) position-independent executables (PIEs)
733 and other shared objects will not honor them.
736 is defined with the value 1, both executables and PIEs
737 will honor the base addresses.
740 is defined with the value 0,
741 neither executables nor PIEs will honor the base addresses.
743 Since glibc 2.3.3, this variable is ignored in secure-execution mode.
745 .BR LD_VERBOSE " (since glibc 2.1)"
746 If set to a nonempty string,
747 output symbol versioning information about the
749 .B LD_TRACE_LOADED_OBJECTS
750 environment variable has been set.
752 .BR LD_WARN " (since glibc 2.1.3)"
753 If set to a nonempty string, warn about unresolved symbols.
755 .BR LD_PREFER_MAP_32BIT_EXEC " (x86-64 only; since glibc 2.23)"
756 According to the Intel Silvermont software optimization guide, for 64-bit
757 applications, branch prediction performance can be negatively impacted
758 when the target of a branch is more than 4\ GB away from the branch.
759 If this environment variable is set (to any value),
761 will first try to map executable pages using the
764 flag, and fall back to mapping without that flag if that attempt fails.
765 NB: MAP_32BIT will map to the low 2\ GB (not 4\ GB) of the address space.
769 reduces the address range available for address space layout
770 randomization (ASLR),
771 .B LD_PREFER_MAP_32BIT_EXEC
772 is always disabled in secure-execution mode.
776 a.out dynamic linker/loader
778 .IR /lib/ld\-linux.so. { 1 , 2 }
779 ELF dynamic linker/loader
782 File containing a compiled list of directories in which to search for
783 shared objects and an ordered list of candidate shared objects.
787 .I /etc/ld.so.preload
788 File containing a whitespace-separated list of ELF shared objects to
789 be loaded before the program.
790 See the discussion of
796 .I /etc/ld.so.preload
797 are employed, the libraries specified by
800 .I /etc/ld.so.preload
801 has a system-wide effect,
802 causing the specified libraries to be preloaded for
803 all programs that are executed on the system.
804 (This is usually undesirable,
805 and is typically employed only as an emergency remedy, for example,
806 as a temporary workaround to a library misconfiguration issue.)
811 .SS Hardware capabilities
812 Some shared objects are compiled using hardware-specific instructions which do
813 not exist on every CPU.
814 Such objects should be installed in directories whose names define the
815 required hardware capabilities, such as
817 The dynamic linker checks these directories against the hardware of the
818 machine and selects the most suitable version of a given shared object.
819 Hardware capability directories can be cascaded to combine CPU features.
820 The list of supported hardware capability names depends on the CPU.
821 The following names are currently recognized:
822 .\" Presumably, this info comes from sysdeps/i386/dl-procinfo.c and
826 ev4, ev5, ev56, ev6, ev67
829 loongson2e, loongson2f, octeon, octeon2
832 4xxmac, altivec, arch_2_05, arch_2_06, booke, cellbe, dfp, efpdouble, efpsingle,
833 fpu, ic_snoop, mmu, notb, pa6t, power4, power5, power5+, power6x, ppc32, ppc601,
834 ppc64, smt, spe, ucache, vsx
837 flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2
840 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle,
841 z900, z990, z9-109, z10, zarch
844 acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx,
845 mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm
854 .BR capabilities (7),
859 .\" ld.so: David Engel, Eric Youngdale, Peter MacDonald, Hongjiu Lu, Linus
860 .\" Torvalds, Lars Wirzenius and Mitch D'Souza
861 .\" ld\-linux.so: Roland McGrath, Ulrich Drepper and others.
863 .\" In the above, (libc5) stands for David Engel's ld.so/ld\-linux.so.