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 2021-03-22 "GNU" "Linux Programmer's Manual"
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\-tunables " (since 2.33)"
242 Print the names and values of all tunables,
243 along with the minimum and maximum allowed values.
245 .BR \-\-preload " \fIlist\fP (since glibc 2.30)"
246 Preload the objects specified in
250 are delimited by colons or spaces.
251 The objects are preloaded as explained in the description of the
253 environment variable below.
259 option provides a way to perform preloading for a single executable
260 without affecting preloading performed in any child process that executes
264 Verify that program is dynamically linked and this dynamic linker can handle
267 Various environment variables influence the operation of the dynamic linker.
269 .SS Secure-execution mode
270 For security reasons,
271 if the dynamic linker determines that a binary should be
272 run in secure-execution mode,
273 the effects of some environment variables are voided or modified,
274 and furthermore those environment variables are stripped from the environment,
275 so that the program does not even see the definitions.
276 Some of these environment variables affect the operation of
277 the dynamic linker itself, and are described below.
278 Other environment variables treated in this way include:
287 .BR RESOLV_HOST_CONF ,
293 A binary is executed in secure-execution mode if the
295 entry in the auxiliary vector (see
298 This entry may have a nonzero value for various reasons, including:
300 The process's real and effective user IDs differ,
301 or the real and effective group IDs differ.
302 This typically occurs as a result of executing
303 a set-user-ID or set-group-ID program.
305 A process with a non-root user ID executed a binary that
306 conferred capabilities to the process.
308 A nonzero value may have been set by a Linux Security Module.
310 .SS Environment variables
311 Among the more important environment variables are the following:
313 .BR LD_ASSUME_KERNEL " (since glibc 2.2.3)"
314 Each shared object can inform the dynamic linker of the minimum kernel ABI
315 version that it requires.
316 (This requirement is encoded in an ELF note section that is viewable via
319 .BR NT_GNU_ABI_TAG .)
321 the dynamic linker determines the ABI version of the running kernel and
322 will reject loading shared objects that specify minimum ABI versions
323 that exceed that ABI version.
327 cause the dynamic linker to assume that it is running on a system with
328 a different kernel ABI version.
329 For example, the following command line causes the
330 dynamic linker to assume it is running on Linux 2.2.5 when loading
331 the shared objects required by
336 $ \fBLD_ASSUME_KERNEL=2.2.5 ./myprog\fP
340 On systems that provide multiple versions of a shared object
341 (in different directories in the search path) that have
342 different minimum kernel ABI version requirements,
344 can be used to select the version of the object that is used
345 (dependent on the directory search order).
347 Historically, the most common use of the
349 feature was to manually select the older
350 LinuxThreads POSIX threads implementation on systems that provided both
351 LinuxThreads and NPTL
352 (which latter was typically the default on such systems);
356 .BR LD_BIND_NOW " (since glibc 2.1.1)"
357 If set to a nonempty string,
358 causes the dynamic linker to resolve all symbols
359 at program startup instead of deferring function call resolution to the point
360 when they are first referenced.
361 This is useful when using a debugger.
364 A list of directories in which to search for
365 ELF libraries at execution time.
366 The items in the list are separated by either colons or semicolons,
367 and there is no support for escaping either separator.
368 A zero-length directory name indicates the current working directory.
370 This variable is ignored in secure-execution mode.
372 Within the pathnames specified in
373 .BR LD_LIBRARY_PATH ,
374 the dynamic linker expands the tokens
379 (or the versions using curly braces around the names)
380 as described above in
381 .IR "Dynamic string tokens" .
383 the following would cause a library to be searched for in either the
387 subdirectory below the directory containing the program to be executed:
391 $ \fBLD_LIBRARY_PATH=\(aq$ORIGIN/$LIB\(aq prog\fP
395 (Note the use of single quotes, which prevent expansion of
402 A list of additional, user-specified, ELF shared
403 objects to be loaded before all others.
404 This feature can be used to selectively override functions
405 in other shared objects.
407 The items of the list can be separated by spaces or colons,
408 and there is no support for escaping either separator.
409 The objects are searched for using the rules given under DESCRIPTION.
410 Objects are searched for and added to the link map in the left-to-right
411 order specified in the list.
413 In secure-execution mode,
414 preload pathnames containing slashes are ignored.
415 Furthermore, shared objects are preloaded only
416 from the standard search directories and only
417 if they have set-user-ID mode bit enabled (which is not typical).
419 Within the names specified in the
421 list, the dynamic linker understands the tokens
426 (or the versions using curly braces around the names)
427 as described above in
428 .IR "Dynamic string tokens" .
429 (See also the discussion of quoting under the description of
430 .BR LD_LIBRARY_PATH .)
431 .\" Tested with the following:
433 .\" LD_PRELOAD='$LIB/libmod.so' LD_LIBRARY_PATH=. ./prog
435 .\" which will preload the libmod.so in 'lib' or 'lib64', using it
436 .\" in preference to the version in '.'.
438 There are various methods of specifying libraries to be preloaded,
439 and these are handled in the following order:
444 environment variable.
448 command-line option when invoking the dynamic linker directly.
451 .I /etc/ld.so.preload
452 file (described below).
455 .BR LD_TRACE_LOADED_OBJECTS
456 If set (to any value), causes the program to list its dynamic
457 dependencies, as if run by
459 instead of running normally.
461 Then there are lots of more or less obscure variables,
462 many obsolete or only for internal use.
464 .BR LD_AUDIT " (since glibc 2.4)"
465 A list of user-specified, ELF shared objects
466 to be loaded before all others in a separate linker namespace
467 (i.e., one that does not intrude upon the normal symbol bindings that
468 would occur in the process)
469 These objects can be used to audit the operation of the dynamic linker.
470 The items in the list are colon-separated,
471 and there is no support for escaping the separator.
474 is ignored in secure-execution mode.
476 The dynamic linker will notify the audit
477 shared objects at so-called auditing checkpoints\(emfor example,
478 loading a new shared object, resolving a symbol,
479 or calling a symbol from another shared object\(emby
480 calling an appropriate function within the audit shared object.
483 The auditing interface is largely compatible with that provided on Solaris,
485 .IR "Linker and Libraries Guide" ,
487 .IR "Runtime Linker Auditing Interface" .
489 Within the names specified in the
491 list, the dynamic linker understands the tokens
496 (or the versions using curly braces around the names)
497 as described above in
498 .IR "Dynamic string tokens" .
499 (See also the discussion of quoting under the description of
500 .BR LD_LIBRARY_PATH .)
503 .\" commit 8e9f92e9d5d7737afdacf79b76d98c4c42980508
504 in secure-execution mode,
505 names in the audit list that contain slashes are ignored,
506 and only shared objects in the standard search directories that
507 have the set-user-ID mode bit enabled are loaded.
509 .BR LD_BIND_NOT " (since glibc 2.1.95)"
510 If this environment variable is set to a nonempty string,
511 do not update the GOT (global offset table) and PLT (procedure linkage table)
512 after resolving a function symbol.
513 By combining the use of this variable with
519 one can observe all run-time function bindings.
521 .BR LD_DEBUG " (since glibc 2.1)"
522 Output verbose debugging information about operation of the dynamic linker.
523 The content of this variable is one of more of the following categories,
524 separated by colons, commas, or (if the value is quoted) spaces:
530 in the value of this variable does not run the specified program,
531 and displays a help message about which categories can be specified in this
532 environment variable.
535 Print all debugging information (except
542 Display information about which definition each symbol is bound to.
545 Display progress for input file.
548 Display library search paths.
551 Display relocation processing.
554 Display scope information.
557 Display relocation statistics.
560 Display search paths for each symbol look-up.
563 Determine unused DSOs.
566 Display version dependencies.
571 is ignored in secure-execution mode, unless the file
573 exists (the content of the file is irrelevant).
575 .BR LD_DEBUG_OUTPUT " (since glibc 2.1)"
578 output is written to standard error.
581 is defined, then output is written to the pathname specified by its value,
582 with the suffix "." (dot) followed by the process ID appended to the pathname.
585 is ignored in secure-execution mode.
587 .BR LD_DYNAMIC_WEAK " (since glibc 2.1.91)"
588 By default, when searching shared libraries to resolve a symbol reference,
589 the dynamic linker will resolve to the first definition it finds.
591 Old glibc versions (before 2.2), provided a different behavior:
592 if the linker found a symbol that was weak,
593 it would remember that symbol and
594 keep searching in the remaining shared libraries.
595 If it subsequently found a strong definition of the same symbol,
596 then it would instead use that definition.
597 (If no further symbol was found,
598 then the dynamic linker would use the weak symbol that it initially found.)
600 The old glibc behavior was nonstandard.
601 (Standard practice is that the distinction between
602 weak and strong symbols should have effect only at static link time.)
604 .\" More precisely 2.1.92
605 .\" See weak handling
606 .\" https://www.sourceware.org/ml/libc-hacker/2000-06/msg00029.html
607 .\" To: GNU libc hacker <libc-hacker at sourceware dot cygnus dot com>
608 .\" Subject: weak handling
609 .\" From: Ulrich Drepper <drepper at redhat dot com>
610 .\" Date: 07 Jun 2000 20:08:12 -0700
611 .\" Reply-To: drepper at cygnus dot com (Ulrich Drepper)
612 the dynamic linker was modified to provide the current behavior
613 (which was the behavior that was provided by most other implementations
618 environment variable (with any value) provides
619 the old (nonstandard) glibc behavior,
620 whereby a weak symbol in one shared library may be overridden by
621 a strong symbol subsequently discovered in another shared library.
622 (Note that even when this variable is set,
623 a strong symbol in a shared library will not override
624 a weak definition of the same symbol in the main program.)
628 is ignored in secure-execution mode.
630 .BR LD_HWCAP_MASK " (since glibc 2.1)"
631 Mask for hardware capabilities.
633 .BR LD_ORIGIN_PATH " (since glibc 2.1)"
634 Path where the binary is found.
635 .\" Used only if $ORIGIN can't be determined by normal means
636 .\" (from the origin path saved at load time, or from /proc/self/exe)?
640 is ignored in secure-execution mode.
642 .BR LD_POINTER_GUARD " (glibc from 2.4 to 2.22)"
643 Set to 0 to disable pointer guarding.
644 Any other value enables pointer guarding, which is also the default.
645 Pointer guarding is a security mechanism whereby some pointers to code
646 stored in writable program memory (return addresses saved by
648 or function pointers used by various glibc internals) are mangled
649 semi-randomly to make it more difficult for an attacker to hijack
650 the pointers for use in the event of a buffer overrun or
651 stack-smashing attack.
653 .\" commit a014cecd82b71b70a6a843e250e06b541ad524f7
655 can no longer be used to disable pointer guarding,
656 which is now always enabled.
658 .BR LD_PROFILE " (since glibc 2.1)"
659 The name of a (single) shared object to be profiled,
660 specified either as a pathname or a soname.
661 Profiling output is appended to the file whose name is:
662 "\fI$LD_PROFILE_OUTPUT\fP/\fI$LD_PROFILE\fP.profile".
666 is ignored in secure-execution mode.
668 .BR LD_PROFILE_OUTPUT " (since glibc 2.1)"
671 output should be written.
672 If this variable is not defined, or is defined as an empty string,
677 is ignored in secure-execution mode; instead
680 (This detail is relevant only before glibc 2.2.5,
681 since in later glibc versions,
683 is also ignored in secure-execution mode.)
685 .BR LD_SHOW_AUXV " (since glibc 2.1)"
686 If this environment variable is defined (with any value),
687 show the auxiliary array passed up from the kernel (see also
692 is ignored in secure-execution mode.
694 .BR LD_TRACE_PRELINKING " (since glibc 2.4)"
695 If this environment variable is defined,
696 trace prelinking of the object whose name is assigned to
697 this environment variable.
700 to get a list of the objects that might be traced.)
701 If the object name is not recognized,
702 .\" (This is what seems to happen, from experimenting)
703 then all prelinking activity is traced.
705 .BR LD_USE_LOAD_BIAS " (since glibc 2.3.3)"
706 .\" http://sources.redhat.com/ml/libc-hacker/2003-11/msg00127.html
707 .\" Subject: [PATCH] Support LD_USE_LOAD_BIAS
709 By default (i.e., if this variable is not defined),
710 executables and prelinked
711 shared objects will honor base addresses of their dependent shared objects
712 and (nonprelinked) position-independent executables (PIEs)
713 and other shared objects will not honor them.
716 is defined with the value 1, both executables and PIEs
717 will honor the base addresses.
720 is defined with the value 0,
721 neither executables nor PIEs will honor the base addresses.
723 Since glibc 2.3.3, this variable is ignored in secure-execution mode.
725 .BR LD_VERBOSE " (since glibc 2.1)"
726 If set to a nonempty string,
727 output symbol versioning information about the
729 .B LD_TRACE_LOADED_OBJECTS
730 environment variable has been set.
732 .BR LD_WARN " (since glibc 2.1.3)"
733 If set to a nonempty string, warn about unresolved symbols.
735 .BR LD_PREFER_MAP_32BIT_EXEC " (x86-64 only; since glibc 2.23)"
736 According to the Intel Silvermont software optimization guide, for 64-bit
737 applications, branch prediction performance can be negatively impacted
738 when the target of a branch is more than 4\ GB away from the branch.
739 If this environment variable is set (to any value),
741 will first try to map executable pages using the
744 flag, and fall back to mapping without that flag if that attempt fails.
745 NB: MAP_32BIT will map to the low 2\ GB (not 4\ GB) of the address space.
749 reduces the address range available for address space layout
750 randomization (ASLR),
751 .B LD_PREFER_MAP_32BIT_EXEC
752 is always disabled in secure-execution mode.
756 a.out dynamic linker/loader
758 .IR /lib/ld\-linux.so. { 1 , 2 }
759 ELF dynamic linker/loader
762 File containing a compiled list of directories in which to search for
763 shared objects and an ordered list of candidate shared objects.
767 .I /etc/ld.so.preload
768 File containing a whitespace-separated list of ELF shared objects to
769 be loaded before the program.
770 See the discussion of
776 .I /etc/ld.so.preload
777 are employed, the libraries specified by
780 .I /etc/ld.so.preload
781 has a system-wide effect,
782 causing the specified libraries to be preloaded for
783 all programs that are executed on the system.
784 (This is usually undesirable,
785 and is typically employed only as an emergency remedy, for example,
786 as a temporary workaround to a library misconfiguration issue.)
791 .SS Hardware capabilities
792 Some shared objects are compiled using hardware-specific instructions which do
793 not exist on every CPU.
794 Such objects should be installed in directories whose names define the
795 required hardware capabilities, such as
797 The dynamic linker checks these directories against the hardware of the
798 machine and selects the most suitable version of a given shared object.
799 Hardware capability directories can be cascaded to combine CPU features.
800 The list of supported hardware capability names depends on the CPU.
801 The following names are currently recognized:
802 .\" Presumably, this info comes from sysdeps/i386/dl-procinfo.c and
806 ev4, ev5, ev56, ev6, ev67
809 loongson2e, loongson2f, octeon, octeon2
812 4xxmac, altivec, arch_2_05, arch_2_06, booke, cellbe, dfp, efpdouble, efpsingle,
813 fpu, ic_snoop, mmu, notb, pa6t, power4, power5, power5+, power6x, ppc32, ppc601,
814 ppc64, smt, spe, ucache, vsx
817 flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2
820 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle,
821 z900, z990, z9-109, z10, zarch
824 acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx,
825 mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm
834 .BR capabilities (7),
839 .\" ld.so: David Engel, Eric Youngdale, Peter MacDonald, Hongjiu Lu, Linus
840 .\" Torvalds, Lars Wirzenius and Mitch D'Souza
841 .\" ld\-linux.so: Roland McGrath, Ulrich Drepper and others.
843 .\" In the above, (libc5) stands for David Engel's ld.so/ld\-linux.so.