1 .\" %%%LICENSE_START(PUBLIC_DOMAIN)
2 .\" This is in the public domain
5 .TH LD.SO 8 2016-10-08 "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:
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 strings in an rpath specification (DT_RPATH or DT_RUNPATH); those strings are substituted as follows
99 .IR $ORIGIN " (or equivalently " ${ORIGIN} )
101 the directory containing the program or shared object.
102 Thus, an application located in
104 could be compiled with
106 gcc \-Wl,\-rpath,\(aq$ORIGIN/../lib\(aq
108 so that it finds an associated shared object in
112 is located in the directory hierarchy.
113 This facilitates the creation of "turn-key" applications that
114 do not need to be installed into special directories,
115 but can instead be unpacked into any directory
116 and still find their own shared objects.
118 .IR $LIB " (or equivalently " ${LIB} )
123 depending on the architecture
124 (e.g., on x86-64, it expands to
127 on x86-32, it expands to
130 .IR $PLATFORM " (or equivalently " ${PLATFORM} )
131 This expands to a string corresponding to the processor type
132 of the host system (e.g., "x86_64").
133 On some architectures, the Linux kernel doesn't provide a platform
134 string to the dynamic linker.
135 The value of this string is taken from the
137 value in the auxiliary vector (see
139 .\" To get an idea of the places that $PLATFORM would match,
140 .\" look at the output of the following:
143 .\" LD_LIBRARY_PATH=/tmp/d strace -e open /bin/date 2>&1 | grep /tmp/d
145 .\" ld.so lets names be abbreviated, so $O will work for $ORIGIN;
150 List all dependencies and how they are resolved.
153 Verify that program is dynamically linked and this dynamic linker can handle
158 .IR /etc/ld.so.cache .
160 .BI \-\-library\-path " path"
165 environment variable setting (see below).
171 are interpreted as for the
173 environment variable.
175 .BI \-\-inhibit\-rpath " list"
176 Ignore RPATH and RUNPATH information in object names in
178 This option is ignored when running in secure-execution mode (see below).
180 .BI \-\-audit " list"
185 Various environment variables influence the operation of the dynamic linker.
187 .SS Secure-execution mode
188 For security reasons,
189 the effects of some environment variables are voided or modified if
190 the dynamic linker determines that the binary should be
191 run in secure-execution mode.
192 This determination is made by checking whether the
194 entry in the auxiliary vector (see
197 This entry may have a nonzero value for various reasons, including:
199 The process's real and effective user IDs differ,
200 or the real and effective group IDs differ.
201 This typically occurs as a result of executing
202 a set-user-ID or set-group-ID program.
204 A process with a non-root user ID executed a binary that
205 conferred permitted or effective capabilities.
207 A nonzero value may have been set by a Linux Security Module.
209 .SS Environment variables
210 Among the more important environment variables are the following:
212 .BR LD_ASSUME_KERNEL " (since glibc 2.2.3)"
213 Each shared object can inform the dynamic linker of the minimum kernel ABI
214 version that it requires.
215 (This requirement is encoded in an ELF note section that is viewable via
218 .BR NT_GNU_ABI_TAG .)
220 the dynamic linker determines the ABI version of the running kernel and
221 will reject loading shared objects that specify minimum ABI versions
222 that exceed that ABI version.
226 cause the dynamic linker to assume that it is running on a system with
227 a different kernel ABI version.
228 For example, the following command line causes the
229 dynamic linker to assume it is running on Linux 2.2.5 when loading
230 the shared objects required by
235 $ \fBLD_ASSUME_KERNEL=2.2.5 ./myprog\fP
239 On systems that provide multiple versions of a shared object
240 (in different directories in the search path) that have
241 different minimum kernel ABI version requirements,
243 can be used to select the version of the object that is used
244 (dependent on the directory search order).
245 Historically, the most common use of the
247 feature was to manually select the older
248 LinuxThreads POSIX threads implementation on systems that provided both
249 LinuxThreads and NPTL
250 (which latter was typically the default on such systems);
254 .BR LD_BIND_NOW " (since glibc 2.1.1)"
255 If set to a nonempty string,
256 causes the dynamic linker to resolve all symbols
257 at program startup instead of deferring function call resolution to the point
258 when they are first referenced.
259 This is useful when using a debugger.
262 A list of directories in which to search for
263 ELF libraries at execution-time.
264 The items in the list are separated by either colons or semicolons.
267 environment variable.
268 This variable is ignored in secure-execution mode.
270 Within the pathnames specified in
271 .BR LD_LIBRARY_PATH ,
272 the dynamic linker expands the strings
277 (or the versions using curly braces around the names)
278 as described above in
279 .IR "Rpath token expansion" .
281 the following would cause a library to be searched for in either the
285 subdirectory below the directory containing the program to be executed:
287 $ \fBLD_LIBRARY_PATH='$ORIGIN/$LIB' prog\fP
289 (Note the use of single quotes, which prevent expansion of
296 A list of additional, user-specified, ELF shared
297 objects to be loaded before all others.
298 The items of the list can be separated by spaces or colons.
299 This can be used to selectively override functions in other shared objects.
300 The objects are searched for using the rules given under DESCRIPTION.
301 In secure-execution mode,
302 preload pathnames containing slashes are ignored,
303 and only shared objects in the standard search directories that
304 have the set-user-ID mode bit enabled are loaded.
306 Within the pathnames specified in
308 the dynamic linker understands the strings
313 (or the versions using curly braces around the names)
314 as described above in
315 .IR "Rpath token expansion" .
316 .\" Tested with the following:
318 .\" LD_PRELOAD='$LIB/libmod.so' LD_LIBRARY_PATH=. ./prog
320 .\" which will reload the libmod.so in 'lib' or 'lib64', using it
321 .\" in preference to the version in '.'.
323 .BR LD_TRACE_LOADED_OBJECTS
324 If set (to any value), causes the program to list its dynamic
325 dependencies, as if run by
327 instead of running normally.
329 Then there are lots of more or less obscure variables,
330 many obsolete or only for internal use.
332 .BR LD_AUDIT " (since glibc 2.4)"
333 A colon-separated list of user-specified, ELF shared objects
334 to be loaded before all others in a separate linker namespace
335 (i.e., one that does not intrude upon the normal symbol bindings that
336 would occur in the process).
337 These objects can be used to audit the operation of the dynamic linker.
339 is ignored in secure-execution mode.
341 The dynamic linker will notify the audit
342 shared objects at so-called auditing checkpoints\(emfor example,
343 loading a new shared object, resolving a symbol,
344 or calling a symbol from another shared object\(emby
345 calling an appropriate function within the audit shared object.
348 The auditing interface is largely compatible with that provided on Solaris,
350 .IR "Linker and Libraries Guide" ,
352 .IR "Runtime Linker Auditing Interface" .
354 .BR LD_BIND_NOT " (since glibc 2.1.95)"
355 If this environment variable is set to a nonempty string,
356 do not update the GOT (global offset table) and PLT (procedure linkage table)
357 after resolving a function symbol.
358 By combining the use of this variable with
364 one can observe all run-time function bindings.
366 .BR LD_DEBUG " (since glibc 2.1)"
367 Output verbose debugging information about the dynamic linker.
370 print all debugging information,
371 Setting this variable to
373 does not run the specified program,
374 and displays a help message about which categories can be specified in this
375 environment variable.
380 Display information about which definition each symbol is bound to.
383 Display progress for input file.
386 Display library search paths.
389 Display relocation processing.
392 Display scope information.
395 Display relocation statistics.
398 Display search paths for each symbol look-up.
401 Determine unused DSOs.
404 Display version dependencies.
409 can specify multiple categories, separated by colons, commas,
410 or (if the value is quoted) spaces.
414 is ignored in secure-execution mode, unless the file
416 exists (the content of the file is irrelevant).
418 .BR LD_DEBUG_OUTPUT " (since glibc 2.1)"
421 output should be written.
422 The default is standard error.
424 is ignored in secure-execution mode.
426 .BR LD_DYNAMIC_WEAK " (since glibc 2.1.91)"
427 If this environment variable is defined (with any value),
428 allow weak symbols to be overridden (reverting to old glibc behavior).
429 .\" See weak handling
430 .\" https://www.sourceware.org/ml/libc-hacker/2000-06/msg00029.html
431 .\" To: GNU libc hacker <libc-hacker at sourceware dot cygnus dot com>
432 .\" Subject: weak handling
433 .\" From: Ulrich Drepper <drepper at redhat dot com>
434 .\" Date: 07 Jun 2000 20:08:12 -0700
435 .\" Reply-To: drepper at cygnus dot com (Ulrich Drepper)
438 is ignored in secure-execution mode.
440 .BR LD_HWCAP_MASK " (since glibc 2.1)"
441 Mask for hardware capabilities.
443 .BR LD_ORIGIN_PATH " (since glibc 2.1)"
444 Path where the binary is found.
447 is ignored in secure-execution mode.
448 .\" Used only if $ORIGIN can't be determined by normal means
449 .\" (from the origin path saved at load time, or from /proc/self/exe)?
451 .BR LD_POINTER_GUARD " (glibc from 2.4 to 2.22)"
452 Set to 0 to disable pointer guarding.
453 Any other value enables pointer guarding, which is also the default.
454 Pointer guarding is a security mechanism whereby some pointers to code
455 stored in writable program memory (return addresses saved by
457 or function pointers used by various glibc internals) are mangled
458 semi-randomly to make it more difficult for an attacker to hijack
459 the pointers for use in the event of a buffer overrun or
460 stack-smashing attack.
462 .\" commit a014cecd82b71b70a6a843e250e06b541ad524f7
464 can no longer be used to disable pointer guarding,
465 which is now always enabled.
467 .BR LD_PROFILE " (since glibc 2.1)"
468 The name of a (single) shared object to be profiled,
469 specified either as a pathname or a soname.
470 Profiling output is appended to the file whose name is:
471 "\fI$LD_PROFILE_OUTPUT\fP/\fI$LD_PROFILE\fP.profile".
473 .BR LD_PROFILE_OUTPUT " (since glibc 2.1)"
476 output should be written.
477 If this variable is not defined, or is defined as an empty string,
481 is ignored in secure-execution mode; instead
485 .BR LD_SHOW_AUXV " (since glibc 2.1)"
486 If this environment variable is defined (with any value),
487 show the auxiliary array passed up from the kernel (see also
491 is ignored in secure-execution mode.
493 .BR LD_TRACE_PRELINKING " (since glibc 2.4)"
494 If this environment variable is defined (with any value),
495 trace prelinking of the object whose name is assigned to
496 this environment variable.
499 to get a list of the objects that might be traced.)
500 If the object name is not recognized,
501 .\" (This is what seems to happen, from experimenting)
502 then all prelinking activity is traced.
504 .BR LD_USE_LOAD_BIAS " (since glibc 2.3.3)"
505 .\" http://sources.redhat.com/ml/libc-hacker/2003-11/msg00127.html
506 .\" Subject: [PATCH] Support LD_USE_LOAD_BIAS
508 By default (i.e., if this variable is not defined),
509 executables and prelinked
510 shared objects will honor base addresses of their dependent shared objects
511 and (nonprelinked) position-independent executables (PIEs)
512 and other shared objects will not honor them.
515 is defined with the value 1, both executables and PIEs
516 will honor the base addresses.
519 is defined with the value 0,
520 neither executables nor PIEs will honor the base addresses.
521 This variable is ignored in secure-execution mode.
523 .BR LD_VERBOSE " (since glibc 2.1)"
524 If set to a nonempty string,
525 output symbol versioning information about the
527 .B LD_TRACE_LOADED_OBJECTS
528 environment variable has been set.
530 .BR LD_WARN " (since glibc 2.1.3)
531 If set to a nonempty string, warn about unresolved symbols.
533 .BR LD_PREFER_MAP_32BIT_EXEC " (x86-64 only; since glibc 2.23)"
534 According to the Intel Silvermont software optimization guide, for 64-bit
535 applications, branch prediction performance can be negatively impacted
536 when the target of a branch is more than 4GB away from the branch.
537 If this environment variable is set (to any value),
539 will first try to map executable pages using the
542 flag, and fall back to mapping without that flag if that attempt fails.
543 NB: MAP_32BIT will map to the low 2GB (not 4GB) of the address space.
546 reduces the address range available for address space layout
547 randomization (ASLR),
548 .B LD_PREFER_MAP_32BIT_EXEC
549 is always disabled in secure-execution mode.
554 a.out dynamic linker/loader
556 .IR /lib/ld\-linux.so. { 1 , 2 }
557 ELF dynamic linker/loader
560 File containing a compiled list of directories in which to search for
561 shared objects and an ordered list of candidate shared objects.
563 .I /etc/ld.so.preload
564 File containing a whitespace-separated list of ELF shared objects to
565 be loaded before the program.
571 .SS Hardware capabilities
572 Some shared objects are compiled using hardware-specific instructions which do
573 not exist on every CPU.
574 Such objects should be installed in directories whose names define the
575 required hardware capabilities, such as
577 The dynamic linker checks these directories against the hardware of the
578 machine and selects the most suitable version of a given shared object.
579 Hardware capability directories can be cascaded to combine CPU features.
580 The list of supported hardware capability names depends on the CPU.
581 The following names are currently recognized:
584 ev4, ev5, ev56, ev6, ev67
587 loongson2e, loongson2f, octeon, octeon2
590 4xxmac, altivec, arch_2_05, arch_2_06, booke, cellbe, dfp, efpdouble, efpsingle,
591 fpu, ic_snoop, mmu, notb, pa6t, power4, power5, power5+, power6x, ppc32, ppc601,
592 ppc64, smt, spe, ucache, vsx
595 flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2
598 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle,
599 z900, z990, z9-109, z10, zarch
602 acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx,
603 mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm
611 .BR capabilities (7),
616 .\" ld.so: David Engel, Eric Youngdale, Peter MacDonald, Hongjiu Lu, Linus
617 .\" Torvalds, Lars Wirzenius and Mitch D'Souza
618 .\" ld-linux.so: Roland McGrath, Ulrich Drepper and others.
620 .\" In the above, (libc5) stands for David Engel's ld.so/ld-linux.so.