1 .\" %%%LICENSE_START(PUBLIC_DOMAIN)
2 .\" This is in the public domain
5 .TH LD.SO 8 2017-05-03 "GNU" "Linux Programmer's Manual"
7 ld.so, ld\-linux.so \- dynamic linker/loader
9 The dynamic linker can be run either indirectly by running some
10 dynamically linked program or shared object
11 (in which case no command-line options
12 to the dynamic linker can be passed and, in the ELF case, the dynamic linker
13 which is stored in the
15 section of the program is executed) or directly by running:
17 .I /lib/ld\-linux.so.*
18 [OPTIONS] [PROGRAM [ARGUMENTS]]
24 find and load the shared objects (shared libraries) needed by a program,
25 prepare the program to run, and then run it.
27 Linux binaries require dynamic linking (linking at run time)
36 handles a.out binaries, a format used long ago;
38 (\fI/lib/ld\-linux.so.1\fP for libc5, \fI/lib/ld\-linux.so.2\fP for glibc2)
40 which everybody has been using for years now.
41 Otherwise, both have the same behavior, and use the same
42 support files and programs
48 When resolving shared object dependencies,
49 the dynamic linker first inspects each dependency
50 string to see if it contains a slash (this can occur if
51 a shared object pathname containing slashes was specified at link time).
52 If a slash is found, then the dependency string is interpreted as
53 a (relative or absolute) pathname,
54 and the shared object is loaded using that pathname.
56 If a shared object dependency does not contain a slash,
57 then it is searched for in the following order:
59 Using the directories specified in the
60 DT_RPATH dynamic section attribute
61 of the binary if present and DT_RUNPATH attribute does not exist.
62 Use of DT_RPATH is deprecated.
64 Using the environment variable
66 (unless the executable is being run in secure-execution mode; see below).
67 in which case it is ignored.
69 Using the directories specified in the
70 DT_RUNPATH dynamic section attribute
71 of the binary if present.
74 .IR /etc/ld.so.cache ,
75 which contains a compiled list of candidate shared objects previously found
76 in the augmented library path.
77 If, however, the binary was linked with the
79 linker option, shared objects in the default paths are skipped.
80 Shared objects installed in hardware capability directories (see below)
81 are preferred to other shared objects.
87 (On some 64-bit architectures, the default paths for 64-bit shared objects are
91 If the binary was linked with the
93 linker option, this step is skipped.
94 .SS Rpath token expansion
97 understands certain token strings in an rpath specification
98 (DT_RPATH or DT_RUNPATH).
99 Those strings are substituted as follows:
101 .IR $ORIGIN " (or equivalently " ${ORIGIN} )
103 the directory containing the program or shared object.
104 Thus, an application located in
106 could be compiled with
108 gcc \-Wl,\-rpath,\(aq$ORIGIN/../lib\(aq
110 so that it finds an associated shared object in
114 is located in the directory hierarchy.
115 This facilitates the creation of "turn-key" applications that
116 do not need to be installed into special directories,
117 but can instead be unpacked into any directory
118 and still find their own shared objects.
120 .IR $LIB " (or equivalently " ${LIB} )
125 depending on the architecture
126 (e.g., on x86-64, it expands to
129 on x86-32, it expands to
132 .IR $PLATFORM " (or equivalently " ${PLATFORM} )
133 This expands to a string corresponding to the processor type
134 of the host system (e.g., "x86_64").
135 On some architectures, the Linux kernel doesn't provide a platform
136 string to the dynamic linker.
137 The value of this string is taken from the
139 value in the auxiliary vector (see
141 .\" To get an idea of the places that $PLATFORM would match,
142 .\" look at the output of the following:
145 .\" LD_LIBRARY_PATH=/tmp/d strace -e open /bin/date 2>&1 | grep /tmp/d
147 .\" ld.so lets names be abbreviated, so $O will work for $ORIGIN;
152 List all dependencies and how they are resolved.
155 Verify that program is dynamically linked and this dynamic linker can handle
158 .B \-\-inhibit\-cache
160 .IR /etc/ld.so.cache .
162 .BI \-\-library\-path " path"
167 environment variable setting (see below).
173 are interpreted as for the
175 environment variable.
177 .BI \-\-inhibit\-rpath " list"
178 Ignore RPATH and RUNPATH information in object names in
180 This option is ignored when running in secure-execution mode (see below).
182 .BI \-\-audit " list"
187 Various environment variables influence the operation of the dynamic linker.
189 .SS Secure-execution mode
190 For security reasons,
191 the effects of some environment variables are voided or modified if
192 the dynamic linker determines that the binary should be
193 run in secure-execution mode.
194 (For details, see the discussion of individual environment variables below.)
195 A binary is executed in secure-execution mode if the
197 entry in the auxiliary vector (see
200 This entry may have a nonzero value for various reasons, including:
202 The process's real and effective user IDs differ,
203 or the real and effective group IDs differ.
204 This typically occurs as a result of executing
205 a set-user-ID or set-group-ID program.
207 A process with a non-root user ID executed a binary that
208 conferred permitted or effective capabilities.
210 A nonzero value may have been set by a Linux Security Module.
212 .SS Environment variables
213 Among the more important environment variables are the following:
215 .BR LD_ASSUME_KERNEL " (since glibc 2.2.3)"
216 Each shared object can inform the dynamic linker of the minimum kernel ABI
217 version that it requires.
218 (This requirement is encoded in an ELF note section that is viewable via
221 .BR NT_GNU_ABI_TAG .)
223 the dynamic linker determines the ABI version of the running kernel and
224 will reject loading shared objects that specify minimum ABI versions
225 that exceed that ABI version.
229 cause the dynamic linker to assume that it is running on a system with
230 a different kernel ABI version.
231 For example, the following command line causes the
232 dynamic linker to assume it is running on Linux 2.2.5 when loading
233 the shared objects required by
238 $ \fBLD_ASSUME_KERNEL=2.2.5 ./myprog\fP
242 On systems that provide multiple versions of a shared object
243 (in different directories in the search path) that have
244 different minimum kernel ABI version requirements,
246 can be used to select the version of the object that is used
247 (dependent on the directory search order).
249 Historically, the most common use of the
251 feature was to manually select the older
252 LinuxThreads POSIX threads implementation on systems that provided both
253 LinuxThreads and NPTL
254 (which latter was typically the default on such systems);
258 .BR LD_BIND_NOW " (since glibc 2.1.1)"
259 If set to a nonempty string,
260 causes the dynamic linker to resolve all symbols
261 at program startup instead of deferring function call resolution to the point
262 when they are first referenced.
263 This is useful when using a debugger.
266 A list of directories in which to search for
267 ELF libraries at execution-time.
268 The items in the list are separated by either colons or semicolons.
271 environment variable.
273 This variable is ignored in secure-execution mode.
275 Within the pathnames specified in
276 .BR LD_LIBRARY_PATH ,
277 the dynamic linker expands the tokens
282 (or the versions using curly braces around the names)
283 as described above in
284 .IR "Rpath token expansion" .
286 the following would cause a library to be searched for in either the
290 subdirectory below the directory containing the program to be executed:
292 $ \fBLD_LIBRARY_PATH='$ORIGIN/$LIB' prog\fP
294 (Note the use of single quotes, which prevent expansion of
301 A list of additional, user-specified, ELF shared
302 objects to be loaded before all others.
303 The items of the list can be separated by spaces or colons.
304 This can be used to selectively override functions in other shared objects.
305 The objects are searched for using the rules given under DESCRIPTION.
307 In secure-execution mode,
308 preload pathnames containing slashes are ignored.
309 Furthermore, shared objects are preloaded only
310 from the standard search directories and only
311 if they have set-user-ID mode bit enabled (which is not typical).
313 Within the names specified in the
315 list, the dynamic linker understands the tokens
320 (or the versions using curly braces around the names)
321 as described above in
322 .IR "Rpath token expansion" .
323 (See also the discussion of quoting under the description of
324 .BR LD_LIBRARY_PATH .)
325 .\" Tested with the following:
327 .\" LD_PRELOAD='$LIB/libmod.so' LD_LIBRARY_PATH=. ./prog
329 .\" which will preload the libmod.so in 'lib' or 'lib64', using it
330 .\" in preference to the version in '.'.
332 .BR LD_TRACE_LOADED_OBJECTS
333 If set (to any value), causes the program to list its dynamic
334 dependencies, as if run by
336 instead of running normally.
338 Then there are lots of more or less obscure variables,
339 many obsolete or only for internal use.
341 .BR LD_AUDIT " (since glibc 2.4)"
342 A colon-separated list of user-specified, ELF shared objects
343 to be loaded before all others in a separate linker namespace
344 (i.e., one that does not intrude upon the normal symbol bindings that
345 would occur in the process).
346 These objects can be used to audit the operation of the dynamic linker.
349 is ignored in secure-execution mode.
351 The dynamic linker will notify the audit
352 shared objects at so-called auditing checkpoints\(emfor example,
353 loading a new shared object, resolving a symbol,
354 or calling a symbol from another shared object\(emby
355 calling an appropriate function within the audit shared object.
358 The auditing interface is largely compatible with that provided on Solaris,
360 .IR "Linker and Libraries Guide" ,
362 .IR "Runtime Linker Auditing Interface" .
364 Within the names specified in the
366 list, the dynamic linker understands the tokens
371 (or the versions using curly braces around the names)
372 as described above in
373 .IR "Rpath token expansion" .
374 (See also the discussion of quoting under the description of
375 .BR LD_LIBRARY_PATH .)
378 .\" commit 8e9f92e9d5d7737afdacf79b76d98c4c42980508
379 in secure-execution mode,
380 names in the audit list that contain slashes are ignored,
381 and only shared objects in the standard search directories that
382 have the set-user-ID mode bit enabled are loaded.
384 .BR LD_BIND_NOT " (since glibc 2.1.95)"
385 If this environment variable is set to a nonempty string,
386 do not update the GOT (global offset table) and PLT (procedure linkage table)
387 after resolving a function symbol.
388 By combining the use of this variable with
394 one can observe all run-time function bindings.
396 .BR LD_DEBUG " (since glibc 2.1)"
397 Output verbose debugging information about operation of the dynamic linker.
398 The content of this variable is one of more of the following categories,
399 separated by colons, commas, or (if the value is quoted) spaces:
405 in the value of this variable does not run the specified program,
406 and displays a help message about which categories can be specified in this
407 environment variable.
410 Print all debugging information (except
417 Display information about which definition each symbol is bound to.
420 Display progress for input file.
423 Display library search paths.
426 Display relocation processing.
429 Display scope information.
432 Display relocation statistics.
435 Display search paths for each symbol look-up.
438 Determine unused DSOs.
441 Display version dependencies.
446 is ignored in secure-execution mode, unless the file
448 exists (the content of the file is irrelevant).
450 .BR LD_DEBUG_OUTPUT " (since glibc 2.1)"
453 output is written to standard error.
456 is defined, then output is written to the pathname specified by its value,
457 with the suffix "." (dot) followed by the process ID appended to the pathname.
460 is ignored in secure-execution mode.
462 .BR LD_DYNAMIC_WEAK " (since glibc 2.1.91)"
463 By default, when searching shared libraries to resolve a symbol reference,
464 the dynamic linker will resolve to the first definition it finds.
466 Old glibc versions (before 2.2), provided a different behavior:
467 if the linker found a symbol that was weak,
468 it would remember that symbol and
469 keep searching in the remaining shared libraries.
470 If it subsequently found a strong definition of the same symbol,
471 then it would instead use that definition.
472 (If no further symbol was found,
473 then the dynamic linker would use the weak symbol that it initially found.)
475 The old glibc behavior was nonstandard.
476 (Standard practice is that the distinction between
477 weak and strong symbols should have effect only at static link time.)
479 .\" More precisely 2.1.92
480 .\" See weak handling
481 .\" https://www.sourceware.org/ml/libc-hacker/2000-06/msg00029.html
482 .\" To: GNU libc hacker <libc-hacker at sourceware dot cygnus dot com>
483 .\" Subject: weak handling
484 .\" From: Ulrich Drepper <drepper at redhat dot com>
485 .\" Date: 07 Jun 2000 20:08:12 -0700
486 .\" Reply-To: drepper at cygnus dot com (Ulrich Drepper)
487 the dynamic linker was modified to provide the current behavior
488 (which was the behavior that was provided by most other implementations
493 environment variable (with any value) provides
494 the old (nonstandard) glibc behavior,
495 whereby a weak symbol in one shared library may be overridden by
496 a strong symbol subsequently discovered in another shared library.
497 (Note that even when this variable is set,
498 a strong symbol in a shared library will not override
499 a weak definition of the same symbol in the main program.)
503 is ignored in secure-execution mode.
505 .BR LD_HWCAP_MASK " (since glibc 2.1)"
506 Mask for hardware capabilities.
508 .BR LD_ORIGIN_PATH " (since glibc 2.1)"
509 Path where the binary is found.
510 .\" Used only if $ORIGIN can't be determined by normal means
511 .\" (from the origin path saved at load time, or from /proc/self/exe)?
515 is ignored in secure-execution mode.
517 .BR LD_POINTER_GUARD " (glibc from 2.4 to 2.22)"
518 Set to 0 to disable pointer guarding.
519 Any other value enables pointer guarding, which is also the default.
520 Pointer guarding is a security mechanism whereby some pointers to code
521 stored in writable program memory (return addresses saved by
523 or function pointers used by various glibc internals) are mangled
524 semi-randomly to make it more difficult for an attacker to hijack
525 the pointers for use in the event of a buffer overrun or
526 stack-smashing attack.
528 .\" commit a014cecd82b71b70a6a843e250e06b541ad524f7
530 can no longer be used to disable pointer guarding,
531 which is now always enabled.
533 .BR LD_PROFILE " (since glibc 2.1)"
534 The name of a (single) shared object to be profiled,
535 specified either as a pathname or a soname.
536 Profiling output is appended to the file whose name is:
537 "\fI$LD_PROFILE_OUTPUT\fP/\fI$LD_PROFILE\fP.profile".
541 is ignored in secure-execution mode.
543 .BR LD_PROFILE_OUTPUT " (since glibc 2.1)"
546 output should be written.
547 If this variable is not defined, or is defined as an empty string,
552 is ignored in secure-execution mode; instead
555 (This detail is relevant only before glibc 2.2.5,
556 since in later glibc versions,
558 is also ignored in secure-execution mode.)
560 .BR LD_SHOW_AUXV " (since glibc 2.1)"
561 If this environment variable is defined (with any value),
562 show the auxiliary array passed up from the kernel (see also
567 is ignored in secure-execution mode.
569 .BR LD_TRACE_PRELINKING " (since glibc 2.4)"
570 If this environment variable is defined,
571 trace prelinking of the object whose name is assigned to
572 this environment variable.
575 to get a list of the objects that might be traced.)
576 If the object name is not recognized,
577 .\" (This is what seems to happen, from experimenting)
578 then all prelinking activity is traced.
580 .BR LD_USE_LOAD_BIAS " (since glibc 2.3.3)"
581 .\" http://sources.redhat.com/ml/libc-hacker/2003-11/msg00127.html
582 .\" Subject: [PATCH] Support LD_USE_LOAD_BIAS
584 By default (i.e., if this variable is not defined),
585 executables and prelinked
586 shared objects will honor base addresses of their dependent shared objects
587 and (nonprelinked) position-independent executables (PIEs)
588 and other shared objects will not honor them.
591 is defined with the value 1, both executables and PIEs
592 will honor the base addresses.
595 is defined with the value 0,
596 neither executables nor PIEs will honor the base addresses.
598 Since glibc 2.3.3, this variable is ignored in secure-execution mode.
600 .BR LD_VERBOSE " (since glibc 2.1)"
601 If set to a nonempty string,
602 output symbol versioning information about the
604 .B LD_TRACE_LOADED_OBJECTS
605 environment variable has been set.
607 .BR LD_WARN " (since glibc 2.1.3)
608 If set to a nonempty string, warn about unresolved symbols.
610 .BR LD_PREFER_MAP_32BIT_EXEC " (x86-64 only; since glibc 2.23)"
611 According to the Intel Silvermont software optimization guide, for 64-bit
612 applications, branch prediction performance can be negatively impacted
613 when the target of a branch is more than 4GB away from the branch.
614 If this environment variable is set (to any value),
616 will first try to map executable pages using the
619 flag, and fall back to mapping without that flag if that attempt fails.
620 NB: MAP_32BIT will map to the low 2GB (not 4GB) of the address space.
624 reduces the address range available for address space layout
625 randomization (ASLR),
626 .B LD_PREFER_MAP_32BIT_EXEC
627 is always disabled in secure-execution mode.
632 a.out dynamic linker/loader
634 .IR /lib/ld\-linux.so. { 1 , 2 }
635 ELF dynamic linker/loader
638 File containing a compiled list of directories in which to search for
639 shared objects and an ordered list of candidate shared objects.
643 .I /etc/ld.so.preload
644 File containing a whitespace-separated list of ELF shared objects to
645 be loaded before the program.
646 See the discussion of
652 .I /etc/ld.so.preload
653 are employed, the libraries specified by
656 .I /etc/ld.so.preload
657 has a system-wide effect,
658 causing the specified libraries to be preloaded for
659 all programs that are executed on the system.
660 (This is usually undesirable,
661 and is typically employed only as an emergency remedy, for example,
662 as a temporary workaround to a library misconfiguration issue.)
668 .SS Hardware capabilities
669 Some shared objects are compiled using hardware-specific instructions which do
670 not exist on every CPU.
671 Such objects should be installed in directories whose names define the
672 required hardware capabilities, such as
674 The dynamic linker checks these directories against the hardware of the
675 machine and selects the most suitable version of a given shared object.
676 Hardware capability directories can be cascaded to combine CPU features.
677 The list of supported hardware capability names depends on the CPU.
678 The following names are currently recognized:
681 ev4, ev5, ev56, ev6, ev67
684 loongson2e, loongson2f, octeon, octeon2
687 4xxmac, altivec, arch_2_05, arch_2_06, booke, cellbe, dfp, efpdouble, efpsingle,
688 fpu, ic_snoop, mmu, notb, pa6t, power4, power5, power5+, power6x, ppc32, ppc601,
689 ppc64, smt, spe, ucache, vsx
692 flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2
695 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle,
696 z900, z990, z9-109, z10, zarch
699 acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx,
700 mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm
709 .BR capabilities (7),
714 .\" ld.so: David Engel, Eric Youngdale, Peter MacDonald, Hongjiu Lu, Linus
715 .\" Torvalds, Lars Wirzenius and Mitch D'Souza
716 .\" ld\-linux.so: Roland McGrath, Ulrich Drepper and others.
718 .\" In the above, (libc5) stands for David Engel's ld.so/ld\-linux.so.