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 .BI \-\-glibc-hwcaps-mask " list"
212 only search built-in subdirectories if in
215 .BI \-\-glibc-hwcaps-prepend " list"
216 Search glibc-hwcaps subdirectories in
219 .B \-\-inhibit\-cache
221 .IR /etc/ld.so.cache .
223 .BI \-\-library\-path " path"
228 environment variable setting (see below).
234 are interpreted as for the
236 environment variable.
238 .BI \-\-inhibit\-rpath " list"
239 Ignore RPATH and RUNPATH information in object names in
241 This option is ignored when running in secure-execution mode (see below).
244 are delimited by colons or spaces.
247 List all dependencies and how they are resolved.
249 .BR \-\-list\-diagnostics " (since glibc 2.33)"
250 Print system diagnostic information in a machine-readable format,
251 such as some internal loader variables,
255 and the environment variables.
256 On some architectures,
257 the command might print additional information
258 (like the cpu features used in GNU indirect function selection on x86).
259 .BR \-\-list\-tunables " (since glibc 2.33)"
260 Print the names and values of all tunables,
261 along with the minimum and maximum allowed values.
263 .BR \-\-preload " \fIlist\fP (since glibc 2.30)"
264 Preload the objects specified in
268 are delimited by colons or spaces.
269 The objects are preloaded as explained in the description of the
271 environment variable below.
277 option provides a way to perform preloading for a single executable
278 without affecting preloading performed in any child process that executes
282 Verify that program is dynamically linked and this dynamic linker can handle
285 Various environment variables influence the operation of the dynamic linker.
287 .SS Secure-execution mode
288 For security reasons,
289 if the dynamic linker determines that a binary should be
290 run in secure-execution mode,
291 the effects of some environment variables are voided or modified,
292 and furthermore those environment variables are stripped from the environment,
293 so that the program does not even see the definitions.
294 Some of these environment variables affect the operation of
295 the dynamic linker itself, and are described below.
296 Other environment variables treated in this way include:
303 .BR LD_DEBUG_OUTPUT ,
304 .BR LD_DYNAMIC_WEAK ,
306 .BR LD_LIBRARY_PATH ,
316 .BR RESOLV_HOST_CONF ,
322 A binary is executed in secure-execution mode if the
324 entry in the auxiliary vector (see
327 This entry may have a nonzero value for various reasons, including:
329 The process's real and effective user IDs differ,
330 or the real and effective group IDs differ.
331 This typically occurs as a result of executing
332 a set-user-ID or set-group-ID program.
334 A process with a non-root user ID executed a binary that
335 conferred capabilities to the process.
337 A nonzero value may have been set by a Linux Security Module.
339 .SS Environment variables
340 Among the more important environment variables are the following:
342 .BR LD_ASSUME_KERNEL " (from glibc 2.2.3 to glibc 2.36)"
343 Each shared object can inform the dynamic linker of the minimum kernel ABI
344 version that it requires.
345 (This requirement is encoded in an ELF note section that is viewable via
348 .BR NT_GNU_ABI_TAG .)
350 the dynamic linker determines the ABI version of the running kernel and
351 will reject loading shared objects that specify minimum ABI versions
352 that exceed that ABI version.
356 cause the dynamic linker to assume that it is running on a system with
357 a different kernel ABI version.
358 For example, the following command line causes the
359 dynamic linker to assume it is running on Linux 2.2.5 when loading
360 the shared objects required by
365 $ \fBLD_ASSUME_KERNEL=2.2.5 ./myprog\fP
369 On systems that provide multiple versions of a shared object
370 (in different directories in the search path) that have
371 different minimum kernel ABI version requirements,
373 can be used to select the version of the object that is used
374 (dependent on the directory search order).
376 Historically, the most common use of the
378 feature was to manually select the older
379 LinuxThreads POSIX threads implementation on systems that provided both
380 LinuxThreads and NPTL
381 (which latter was typically the default on such systems);
385 .BR LD_BIND_NOW " (since glibc 2.1.1)"
386 If set to a nonempty string,
387 causes the dynamic linker to resolve all symbols
388 at program startup instead of deferring function call resolution to the point
389 when they are first referenced.
390 This is useful when using a debugger.
393 A list of directories in which to search for
394 ELF libraries at execution time.
395 The items in the list are separated by either colons or semicolons,
396 and there is no support for escaping either separator.
397 A zero-length directory name indicates the current working directory.
399 This variable is ignored in secure-execution mode.
401 Within the pathnames specified in
402 .BR LD_LIBRARY_PATH ,
403 the dynamic linker expands the tokens
408 (or the versions using curly braces around the names)
409 as described above in
410 .IR "Dynamic string tokens" .
412 the following would cause a library to be searched for in either the
416 subdirectory below the directory containing the program to be executed:
420 $ \fBLD_LIBRARY_PATH=\[aq]$ORIGIN/$LIB\[aq] prog\fP
424 (Note the use of single quotes, which prevent expansion of
431 A list of additional, user-specified, ELF shared
432 objects to be loaded before all others.
433 This feature can be used to selectively override functions
434 in other shared objects.
436 The items of the list can be separated by spaces or colons,
437 and there is no support for escaping either separator.
438 The objects are searched for using the rules given under DESCRIPTION.
439 Objects are searched for and added to the link map in the left-to-right
440 order specified in the list.
442 In secure-execution mode,
443 preload pathnames containing slashes are ignored.
444 Furthermore, shared objects are preloaded only
445 from the standard search directories and only
446 if they have set-user-ID mode bit enabled (which is not typical).
448 Within the names specified in the
450 list, the dynamic linker understands the tokens
455 (or the versions using curly braces around the names)
456 as described above in
457 .IR "Dynamic string tokens" .
458 (See also the discussion of quoting under the description of
459 .BR LD_LIBRARY_PATH .)
460 .\" Tested with the following:
462 .\" LD_PRELOAD='$LIB/libmod.so' LD_LIBRARY_PATH=. ./prog
464 .\" which will preload the libmod.so in 'lib' or 'lib64', using it
465 .\" in preference to the version in '.'.
467 There are various methods of specifying libraries to be preloaded,
468 and these are handled in the following order:
473 environment variable.
477 command-line option when invoking the dynamic linker directly.
480 .I /etc/ld.so.preload
481 file (described below).
484 .B LD_TRACE_LOADED_OBJECTS
485 If set (to any value), causes the program to list its dynamic
486 dependencies, as if run by
488 instead of running normally.
490 Then there are lots of more or less obscure variables,
491 many obsolete or only for internal use.
493 .BR LD_AUDIT " (since glibc 2.4)"
494 A list of user-specified, ELF shared objects
495 to be loaded before all others in a separate linker namespace
496 (i.e., one that does not intrude upon the normal symbol bindings that
497 would occur in the process)
498 These objects can be used to audit the operation of the dynamic linker.
499 The items in the list are colon-separated,
500 and there is no support for escaping the separator.
503 is ignored in secure-execution mode.
505 The dynamic linker will notify the audit
506 shared objects at so-called auditing checkpoints\[em]for example,
507 loading a new shared object, resolving a symbol,
508 or calling a symbol from another shared object\[em]by
509 calling an appropriate function within the audit shared object.
512 The auditing interface is largely compatible with that provided on Solaris,
514 .IR "Linker and Libraries Guide" ,
516 .IR "Runtime Linker Auditing Interface" .
518 Within the names specified in the
520 list, the dynamic linker understands the tokens
525 (or the versions using curly braces around the names)
526 as described above in
527 .IR "Dynamic string tokens" .
528 (See also the discussion of quoting under the description of
529 .BR LD_LIBRARY_PATH .)
532 .\" commit 8e9f92e9d5d7737afdacf79b76d98c4c42980508
533 in secure-execution mode,
534 names in the audit list that contain slashes are ignored,
535 and only shared objects in the standard search directories that
536 have the set-user-ID mode bit enabled are loaded.
538 .BR LD_BIND_NOT " (since glibc 2.1.95)"
539 If this environment variable is set to a nonempty string,
540 do not update the GOT (global offset table) and PLT (procedure linkage table)
541 after resolving a function symbol.
542 By combining the use of this variable with
548 one can observe all run-time function bindings.
550 .BR LD_DEBUG " (since glibc 2.1)"
551 Output verbose debugging information about operation of the dynamic linker.
552 The content of this variable is one of more of the following categories,
553 separated by colons, commas, or (if the value is quoted) spaces:
559 in the value of this variable does not run the specified program,
560 and displays a help message about which categories can be specified in this
561 environment variable.
564 Print all debugging information (except
571 Display information about which definition each symbol is bound to.
574 Display progress for input file.
577 Display library search paths.
580 Display relocation processing.
583 Display scope information.
586 Display relocation statistics.
589 Display search paths for each symbol look-up.
592 Determine unused DSOs.
595 Display version dependencies.
600 is ignored in secure-execution mode, unless the file
602 exists (the content of the file is irrelevant).
604 .BR LD_DEBUG_OUTPUT " (since glibc 2.1)"
607 output is written to standard error.
610 is defined, then output is written to the pathname specified by its value,
611 with the suffix "." (dot) followed by the process ID appended to the pathname.
614 is ignored in secure-execution mode.
616 .BR LD_DYNAMIC_WEAK " (since glibc 2.1.91)"
617 By default, when searching shared libraries to resolve a symbol reference,
618 the dynamic linker will resolve to the first definition it finds.
620 Old glibc versions (before glibc 2.2), provided a different behavior:
621 if the linker found a symbol that was weak,
622 it would remember that symbol and
623 keep searching in the remaining shared libraries.
624 If it subsequently found a strong definition of the same symbol,
625 then it would instead use that definition.
626 (If no further symbol was found,
627 then the dynamic linker would use the weak symbol that it initially found.)
629 The old glibc behavior was nonstandard.
630 (Standard practice is that the distinction between
631 weak and strong symbols should have effect only at static link time.)
633 .\" More precisely 2.1.92
634 .\" See weak handling
635 .\" https://www.sourceware.org/ml/libc-hacker/2000-06/msg00029.html
636 .\" To: GNU libc hacker <libc-hacker at sourceware dot cygnus dot com>
637 .\" Subject: weak handling
638 .\" From: Ulrich Drepper <drepper at redhat dot com>
639 .\" Date: 07 Jun 2000 20:08:12 -0700
640 .\" Reply-To: drepper at cygnus dot com (Ulrich Drepper)
641 the dynamic linker was modified to provide the current behavior
642 (which was the behavior that was provided by most other implementations
647 environment variable (with any value) provides
648 the old (nonstandard) glibc behavior,
649 whereby a weak symbol in one shared library may be overridden by
650 a strong symbol subsequently discovered in another shared library.
651 (Note that even when this variable is set,
652 a strong symbol in a shared library will not override
653 a weak definition of the same symbol in the main program.)
657 is ignored in secure-execution mode.
659 .BR LD_HWCAP_MASK " (from glibc 2.1 to glibc 2.38)"
660 Mask for hardware capabilities.
662 the option might be ignored
663 if glibc does not support tunables.
665 .BR LD_ORIGIN_PATH " (since glibc 2.1)"
666 Path where the binary is found.
667 .\" Used only if $ORIGIN can't be determined by normal means
668 .\" (from the origin path saved at load time, or from /proc/self/exe)?
672 is ignored in secure-execution mode.
674 .BR LD_POINTER_GUARD " (from glibc 2.4 to glibc 2.22)"
675 Set to 0 to disable pointer guarding.
676 Any other value enables pointer guarding, which is also the default.
677 Pointer guarding is a security mechanism whereby some pointers to code
678 stored in writable program memory (return addresses saved by
680 or function pointers used by various glibc internals) are mangled
681 semi-randomly to make it more difficult for an attacker to hijack
682 the pointers for use in the event of a buffer overrun or
683 stack-smashing attack.
685 .\" commit a014cecd82b71b70a6a843e250e06b541ad524f7
687 can no longer be used to disable pointer guarding,
688 which is now always enabled.
690 .BR LD_PROFILE " (since glibc 2.1)"
691 The name of a (single) shared object to be profiled,
692 specified either as a pathname or a soname.
693 Profiling output is appended to the file whose name is:
694 .RI \%$LD_PROFILE_OUTPUT /\: $LD_PROFILE .profile .
698 uses a different default path in secure-execution mode.
700 .BR LD_PROFILE_OUTPUT " (since glibc 2.1)"
703 output should be written.
704 If this variable is not defined, or is defined as an empty string,
709 is ignored in secure-execution mode; instead
713 .BR LD_SHOW_AUXV " (since glibc 2.1)"
714 If this environment variable is defined (with any value),
715 show the auxiliary array passed up from the kernel (see also
720 is ignored in secure-execution mode.
722 .BR LD_TRACE_PRELINKING " (from glibc 2.4 to glibc 2.35)"
723 If this environment variable is defined,
724 trace prelinking of the object whose name is assigned to
725 this environment variable.
728 to get a list of the objects that might be traced.)
729 If the object name is not recognized,
730 .\" (This is what seems to happen, from experimenting)
731 then all prelinking activity is traced.
733 .BR LD_USE_LOAD_BIAS " (from glibc 2.3.3 to glibc 2.35)"
734 .\" http://sources.redhat.com/ml/libc-hacker/2003-11/msg00127.html
735 .\" Subject: [PATCH] Support LD_USE_LOAD_BIAS
737 By default (i.e., if this variable is not defined),
738 executables and prelinked
739 shared objects will honor base addresses of their dependent shared objects
740 and (nonprelinked) position-independent executables (PIEs)
741 and other shared objects will not honor them.
744 is defined with the value 1, both executables and PIEs
745 will honor the base addresses.
748 is defined with the value 0,
749 neither executables nor PIEs will honor the base addresses.
751 Since glibc 2.3.3, this variable is ignored in secure-execution mode.
753 .BR LD_VERBOSE " (since glibc 2.1)"
754 If set to a nonempty string,
755 output symbol versioning information about the
757 .B LD_TRACE_LOADED_OBJECTS
758 environment variable has been set.
760 .BR LD_WARN " (since glibc 2.1.3)"
761 If set to a nonempty string, warn about unresolved symbols.
763 .BR LD_PREFER_MAP_32BIT_EXEC " (x86-64 only; since glibc 2.23)"
764 According to the Intel Silvermont software optimization guide, for 64-bit
765 applications, branch prediction performance can be negatively impacted
766 when the target of a branch is more than 4\ GB away from the branch.
767 If this environment variable is set (to any value),
769 will first try to map executable pages using the
772 flag, and fall back to mapping without that flag if that attempt fails.
773 NB: MAP_32BIT will map to the low 2\ GB (not 4\ GB) of the address space.
777 reduces the address range available for address space layout
778 randomization (ASLR),
779 .B LD_PREFER_MAP_32BIT_EXEC
780 is always disabled in secure-execution mode.
784 a.out dynamic linker/loader
786 .IR /lib/ld\-linux.so. { 1 , 2 }
787 ELF dynamic linker/loader
790 File containing a compiled list of directories in which to search for
791 shared objects and an ordered list of candidate shared objects.
795 .I /etc/ld.so.preload
796 File containing a whitespace-separated list of ELF shared objects to
797 be loaded before the program.
798 See the discussion of
804 .I /etc/ld.so.preload
805 are employed, the libraries specified by
808 .I /etc/ld.so.preload
809 has a system-wide effect,
810 causing the specified libraries to be preloaded for
811 all programs that are executed on the system.
812 (This is usually undesirable,
813 and is typically employed only as an emergency remedy, for example,
814 as a temporary workaround to a library misconfiguration issue.)
819 .SS Legacy Hardware capabilities (from glibc 2.5 to glibc 2.37)
820 Some shared objects are compiled using hardware-specific instructions which do
821 not exist on every CPU.
822 Such objects should be installed in directories whose names define the
823 required hardware capabilities, such as
825 The dynamic linker checks these directories against the hardware of the
826 machine and selects the most suitable version of a given shared object.
827 Hardware capability directories can be cascaded to combine CPU features.
828 The list of supported hardware capability names depends on the CPU.
829 The following names are currently recognized:
830 .\" Presumably, this info comes from sysdeps/i386/dl-procinfo.c and
834 ev4, ev5, ev56, ev6, ev67
837 loongson2e, loongson2f, octeon, octeon2
840 4xxmac, altivec, arch_2_05, arch_2_06, booke, cellbe, dfp, efpdouble, efpsingle,
841 fpu, ic_snoop, mmu, notb, pa6t, power4, power5, power5+, power6x, ppc32, ppc601,
842 ppc64, smt, spe, ucache, vsx
845 flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2
848 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle,
849 z900, z990, z9-109, z10, zarch
852 acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx,
853 mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm
855 The legacy hardware capabilities support has the drawback that
856 each new feature added grows the search path exponentially,
857 because it has to be added to
858 every combination of the other existing features.
860 For instance, on x86 32-bit,
861 if the hardware supports
865 the resulting search path will be
866 .BR i686/sse2:i686:sse2:. .
869 will set the search path to
870 .BR newcap/i686/sse2:newcap/i686:newcap/sse2:newcap:i686/sse2:i686:sse2: .
872 .SS glibc Hardware capabilities (from glibc 2.33)
874 .\" The initial discussion on various pitfalls of the old scheme is
875 .\" <https://sourceware.org/pipermail/libc-alpha/2020-May/113757.html>
876 .\" and the patchset that proposes the glibc-hwcap support is
877 .\" <https://sourceware.org/pipermail/libc-alpha/2020-June/115250.html>
878 glibc 2.33 added a new hardware capability scheme,
879 where under each CPU architecture,
880 certain levels can be defined,
881 grouping support for certain features or special instructions.
882 Each architecture level has
883 a fixed set of paths that it adds to the dynamic linker search list,
884 depending on the hardware of the machine.
885 Since each new architecture level is
886 not combined with previously existing ones,
887 the new scheme does not have the drawback of
888 growing the dynamic linker search list uncontrollably.
890 For instance, on x86 64-bit,
891 if the hardware supports
893 (for instance Intel Haswell or AMD Excavator),
894 the resulting search path will be
895 .BR glibc-hwcaps/x86-64-v3:glibc-hwcaps/x86-64-v2:.
896 .\" The x86_64 architectures levels are defined the official ABI:
897 .\" <https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/low-level-sys-info.tex>
898 .\" The PowerPC and s390x are glibc defined ones based on chip
899 .\" support (which maps to ISA levels).
900 The following paths are currently supported, in priority order.
902 .B PowerPC (64-bit little-endian only)
905 .B s390 (64-bit only)
909 x86-64-v4, x86-64-v3, x86-64-v2
911 glibc 2.37 removed support for the legacy hardware capabilities.
921 .BR capabilities (7),
926 .\" ld.so: David Engel, Eric Youngdale, Peter MacDonald, Hongjiu Lu, Linus
927 .\" Torvalds, Lars Wirzenius and Mitch D'Souza
928 .\" ld\-linux.so: Roland McGrath, Ulrich Drepper and others.
930 .\" In the above, (libc5) stands for David Engel's ld.so/ld\-linux.so.