]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man8/ld.so.8
ld.so.8: Mention quoting when using "Rpath tokens" in LD_AUDIT and LD_PRELOAD
[thirdparty/man-pages.git] / man8 / ld.so.8
1 .\" %%%LICENSE_START(PUBLIC_DOMAIN)
2 .\" This is in the public domain
3 .\" %%%LICENSE_END
4 .\"
5 .TH LD.SO 8 2017-03-13 "GNU" "Linux Programmer's Manual"
6 .SH NAME
7 ld.so, ld-linux.so \- dynamic linker/loader
8 .SH SYNOPSIS
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
14 .B .interp
15 section of the program is executed) or directly by running:
16 .P
17 .I /lib/ld-linux.so.*
18 [OPTIONS] [PROGRAM [ARGUMENTS]]
19 .SH DESCRIPTION
20 The programs
21 .B ld.so
22 and
23 .B ld-linux.so*
24 find and load the shared objects (shared libraries) needed by a program,
25 prepare the program to run, and then run it.
26 .LP
27 Linux binaries require dynamic linking (linking at run time)
28 unless the
29 .B \-static
30 option was given to
31 .BR ld (1)
32 during compilation.
33 .LP
34 The program
35 .B ld.so
36 handles a.out binaries, a format used long ago;
37 .B ld-linux.so*
38 (\fI/lib/ld-linux.so.1\fP for libc5, \fI/lib/ld-linux.so.2\fP for glibc2)
39 handles ELF,
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
43 .BR ldd (1),
44 .BR ldconfig (8),
45 and
46 .IR /etc/ld.so.conf .
47 .LP
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.
55 .LP
56 If a shared object dependency does not contain a slash,
57 then it is searched for in the following order:
58 .IP o 3
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.
63 .IP o
64 Using the environment variable
65 .BR LD_LIBRARY_PATH
66 (unless the executable is being run in secure-execution mode; see below).
67 in which case it is ignored.
68 .IP o
69 Using the directories specified in the
70 DT_RUNPATH dynamic section attribute
71 of the binary if present.
72 .IP o
73 From the cache file
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
78 .B \-z nodeflib
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.
82 .IP o
83 In the default path
84 .IR /lib ,
85 and then
86 .IR /usr/lib .
87 (On some 64-bit architectures, the default paths for 64-bit shared objects are
88 .IR /lib64 ,
89 and then
90 .IR /usr/lib64 .)
91 If the binary was linked with the
92 .B \-z nodeflib
93 linker option, this step is skipped.
94 .SS Rpath token expansion
95 .PP
96 .B ld.so
97 understands certain token strings in an rpath specification
98 (DT_RPATH or DT_RUNPATH).
99 Those strings are substituted as follows:
100 .TP
101 .IR $ORIGIN " (or equivalently " ${ORIGIN} )
102 This expands to
103 the directory containing the program or shared object.
104 Thus, an application located in
105 .I somedir/app
106 could be compiled with
107
108 gcc \-Wl,\-rpath,\(aq$ORIGIN/../lib\(aq
109
110 so that it finds an associated shared object in
111 .I somedir/lib
112 no matter where
113 .I somedir
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.
119 .TP
120 .IR $LIB " (or equivalently " ${LIB} )
121 This expands to
122 .I lib
123 or
124 .I lib64
125 depending on the architecture
126 (e.g., on x86-64, it expands to
127 .IR lib64
128 and
129 on x86-32, it expands to
130 .IR lib ).
131 .TP
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
138 .BR AT_PLATFORM
139 value in the auxiliary vector (see
140 .BR getauxval (3)).
141 .\" To get an idea of the places that $PLATFORM would match,
142 .\" look at the output of the following:
143 .\"
144 .\" mkdir /tmp/d
145 .\" LD_LIBRARY_PATH=/tmp/d strace -e open /bin/date 2>&1 | grep /tmp/d
146 .\"
147 .\" ld.so lets names be abbreviated, so $O will work for $ORIGIN;
148 .\" Don't do this!!
149 .SH OPTIONS
150 .TP
151 .B \-\-list
152 List all dependencies and how they are resolved.
153 .TP
154 .B \-\-verify
155 Verify that program is dynamically linked and this dynamic linker can handle
156 it.
157 .TP
158 .B \-\-inhibit-cache
159 Do not use
160 .IR /etc/ld.so.cache .
161 .TP
162 .BI \-\-library\-path " path"
163 Use
164 .I path
165 instead of
166 .B LD_LIBRARY_PATH
167 environment variable setting (see below).
168 The names
169 .IR ORIGIN ,
170 .IR LIB ,
171 and
172 .IR PLATFORM
173 are interpreted as for the
174 .BR LD_LIBRARY_PATH
175 environment variable.
176 .TP
177 .BI \-\-inhibit\-rpath " list"
178 Ignore RPATH and RUNPATH information in object names in
179 .IR list .
180 This option is ignored when running in secure-execution mode (see below).
181 .TP
182 .BI \-\-audit " list"
183 Use objects named in
184 .I list
185 as auditors.
186 .SH ENVIRONMENT
187 Various environment variables influence the operation of the dynamic linker.
188 .\"
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
196 .B AT_SECURE
197 entry in the auxiliary vector (see
198 .BR getauxval (3))
199 has a nonzero value.
200 This entry may have a nonzero value for various reasons, including:
201 .IP * 3
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.
206 .IP *
207 A process with a non-root user ID executed a binary that
208 conferred permitted or effective capabilities.
209 .IP *
210 A nonzero value may have been set by a Linux Security Module.
211 .\"
212 .SS Environment variables
213 Among the more important environment variables are the following:
214 .TP
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
219 .IR "readelf\ \-n"
220 as a section labeled
221 .BR NT_GNU_ABI_TAG .)
222 At run time,
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.
226
227 .BR LD_ASSUME_KERNEL
228 can be used to
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
234 .IR myprog :
235
236 .in +4n
237 .nf
238 $ \fBLD_ASSUME_KERNEL=2.2.5 ./myprog\fP
239 .fi
240 .in
241
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,
245 .BR LD_ASSUME_KERNEL
246 can be used to select the version of the object that is used
247 (dependent on the directory search order).
248 Historically, the most common use of the
249 .BR LD_ASSUME_KERNEL
250 feature was to manually select the older
251 LinuxThreads POSIX threads implementation on systems that provided both
252 LinuxThreads and NPTL
253 (which latter was typically the default on such systems);
254 see
255 .BR pthreads (7).
256 .TP
257 .BR LD_BIND_NOW " (since glibc 2.1.1)"
258 If set to a nonempty string,
259 causes the dynamic linker to resolve all symbols
260 at program startup instead of deferring function call resolution to the point
261 when they are first referenced.
262 This is useful when using a debugger.
263 .TP
264 .B LD_LIBRARY_PATH
265 A list of directories in which to search for
266 ELF libraries at execution-time.
267 The items in the list are separated by either colons or semicolons.
268 Similar to the
269 .B PATH
270 environment variable.
271 This variable is ignored in secure-execution mode.
272
273 Within the pathnames specified in
274 .BR LD_LIBRARY_PATH ,
275 the dynamic linker expands the tokens
276 .IR $ORIGIN ,
277 .IR $LIB ,
278 and
279 .IR $PLATFORM
280 (or the versions using curly braces around the names)
281 as described above in
282 .IR "Rpath token expansion" .
283 Thus, for example,
284 the following would cause a library to be searched for in either the
285 .I lib
286 or
287 .I lib64
288 subdirectory below the directory containing the program to be executed:
289
290 $ \fBLD_LIBRARY_PATH='$ORIGIN/$LIB' prog\fP
291
292 (Note the use of single quotes, which prevent expansion of
293 .I $ORIGIN
294 and
295 .I $LIB
296 as shell variables!)
297 .TP
298 .B LD_PRELOAD
299 A list of additional, user-specified, ELF shared
300 objects to be loaded before all others.
301 The items of the list can be separated by spaces or colons.
302 This can be used to selectively override functions in other shared objects.
303 The objects are searched for using the rules given under DESCRIPTION.
304
305 In secure-execution mode,
306 preload pathnames containing slashes are ignored,
307 and only shared objects in the standard search directories that
308 have the set-user-ID mode bit enabled are loaded.
309
310 Within the names specified in the
311 .BR LD_PRELOAD
312 list, the dynamic linker understands the tokens
313 .IR $ORIGIN ,
314 .IR $LIB ,
315 and
316 .IR $PLATFORM
317 (or the versions using curly braces around the names)
318 as described above in
319 .IR "Rpath token expansion" .
320 (See also the discussion of quoting under the description of
321 .BR LD_LIBRARY_PATH .)
322 .\" Tested with the following:
323 .\"
324 .\" LD_PRELOAD='$LIB/libmod.so' LD_LIBRARY_PATH=. ./prog
325 .\"
326 .\" which will preload the libmod.so in 'lib' or 'lib64', using it
327 .\" in preference to the version in '.'.
328 .TP
329 .BR LD_TRACE_LOADED_OBJECTS
330 If set (to any value), causes the program to list its dynamic
331 dependencies, as if run by
332 .BR ldd (1),
333 instead of running normally.
334 .LP
335 Then there are lots of more or less obscure variables,
336 many obsolete or only for internal use.
337 .TP
338 .BR LD_AUDIT " (since glibc 2.4)"
339 A colon-separated list of user-specified, ELF shared objects
340 to be loaded before all others in a separate linker namespace
341 (i.e., one that does not intrude upon the normal symbol bindings that
342 would occur in the process).
343 These objects can be used to audit the operation of the dynamic linker.
344 .B LD_AUDIT
345 is ignored in secure-execution mode.
346
347 The dynamic linker will notify the audit
348 shared objects at so-called auditing checkpoints\(emfor example,
349 loading a new shared object, resolving a symbol,
350 or calling a symbol from another shared object\(emby
351 calling an appropriate function within the audit shared object.
352 For details, see
353 .BR rtld-audit (7).
354 The auditing interface is largely compatible with that provided on Solaris,
355 as described in its
356 .IR "Linker and Libraries Guide" ,
357 in the chapter
358 .IR "Runtime Linker Auditing Interface" .
359
360 Within the names specified in the
361 .BR LD_AUDIT
362 list, the dynamic linker understands the tokens
363 .IR $ORIGIN ,
364 .IR $LIB ,
365 and
366 .IR $PLATFORM
367 (or the versions using curly braces around the names)
368 as described above in
369 .IR "Rpath token expansion" .
370 (See also the discussion of quoting under the description of
371 .BR LD_LIBRARY_PATH .)
372
373 Since glibc 2.13,
374 .\" commit 8e9f92e9d5d7737afdacf79b76d98c4c42980508
375 in secure-execution mode,
376 names in the audit list that contain slashes are ignored,
377 and only shared objects in the standard search directories that
378 have the set-user-ID mode bit enabled are loaded.
379 .TP
380 .BR LD_BIND_NOT " (since glibc 2.1.95)"
381 If this environment variable is set to a nonempty string,
382 do not update the GOT (global offset table) and PLT (procedure linkage table)
383 after resolving a function symbol.
384 By combining the use of this variable with
385 .BR LD_DEBUG
386 (with the categories
387 .IR bindings
388 and
389 .IR symbols ),
390 one can observe all run-time function bindings.
391 .TP
392 .BR LD_DEBUG " (since glibc 2.1)"
393 Output verbose debugging information about the dynamic linker.
394 If set to
395 .BR all ,
396 print all debugging information,
397 Setting this variable to
398 .BR help
399 does not run the specified program,
400 and displays a help message about which categories can be specified in this
401 environment variable.
402 The categories are:
403 .RS
404 .TP 12
405 .I bindings
406 Display information about which definition each symbol is bound to.
407 .TP
408 .I files
409 Display progress for input file.
410 .TP
411 .I libs
412 Display library search paths.
413 .TP
414 .I reloc
415 Display relocation processing.
416 .TP
417 .I scopes
418 Display scope information.
419 .TP
420 .I statistics
421 Display relocation statistics.
422 .TP
423 .I symbols
424 Display search paths for each symbol look-up.
425 .TP
426 .I unused
427 Determine unused DSOs.
428 .TP
429 .I versions
430 Display version dependencies.
431 .RE
432 .IP
433 The value in
434 .BR LD_DEBUG
435 can specify multiple categories, separated by colons, commas,
436 or (if the value is quoted) spaces.
437
438 Since glibc 2.3.4,
439 .B LD_DEBUG
440 is ignored in secure-execution mode, unless the file
441 .IR /etc/suid\-debug
442 exists (the content of the file is irrelevant).
443 .TP
444 .BR LD_DEBUG_OUTPUT " (since glibc 2.1)"
445 File in which
446 .B LD_DEBUG
447 output should be written.
448 The default is standard error.
449 .B LD_DEBUG_OUTPUT
450 is ignored in secure-execution mode.
451 .TP
452 .BR LD_DYNAMIC_WEAK " (since glibc 2.1.91)"
453 If this environment variable is defined (with any value),
454 allow weak symbols to be overridden (reverting to old glibc behavior).
455 .\" See weak handling
456 .\" https://www.sourceware.org/ml/libc-hacker/2000-06/msg00029.html
457 .\" To: GNU libc hacker <libc-hacker at sourceware dot cygnus dot com>
458 .\" Subject: weak handling
459 .\" From: Ulrich Drepper <drepper at redhat dot com>
460 .\" Date: 07 Jun 2000 20:08:12 -0700
461 .\" Reply-To: drepper at cygnus dot com (Ulrich Drepper)
462 Since glibc 2.3.4,
463 .B LD_DYNAMIC_WEAK
464 is ignored in secure-execution mode.
465 .TP
466 .BR LD_HWCAP_MASK " (since glibc 2.1)"
467 Mask for hardware capabilities.
468 .TP
469 .BR LD_ORIGIN_PATH " (since glibc 2.1)"
470 Path where the binary is found.
471 Since glibc 2.4,
472 .B LD_ORIGIN_PATH
473 is ignored in secure-execution mode.
474 .\" Used only if $ORIGIN can't be determined by normal means
475 .\" (from the origin path saved at load time, or from /proc/self/exe)?
476 .TP
477 .BR LD_POINTER_GUARD " (glibc from 2.4 to 2.22)"
478 Set to 0 to disable pointer guarding.
479 Any other value enables pointer guarding, which is also the default.
480 Pointer guarding is a security mechanism whereby some pointers to code
481 stored in writable program memory (return addresses saved by
482 .BR setjmp (3)
483 or function pointers used by various glibc internals) are mangled
484 semi-randomly to make it more difficult for an attacker to hijack
485 the pointers for use in the event of a buffer overrun or
486 stack-smashing attack.
487 Since glibc 2.23,
488 .\" commit a014cecd82b71b70a6a843e250e06b541ad524f7
489 .B LD_POINTER_GUARD
490 can no longer be used to disable pointer guarding,
491 which is now always enabled.
492 .TP
493 .BR LD_PROFILE " (since glibc 2.1)"
494 The name of a (single) shared object to be profiled,
495 specified either as a pathname or a soname.
496 Profiling output is appended to the file whose name is:
497 "\fI$LD_PROFILE_OUTPUT\fP/\fI$LD_PROFILE\fP.profile".
498 .TP
499 .BR LD_PROFILE_OUTPUT " (since glibc 2.1)"
500 Directory where
501 .B LD_PROFILE
502 output should be written.
503 If this variable is not defined, or is defined as an empty string,
504 then the default is
505 .IR /var/tmp .
506 .B LD_PROFILE_OUTPUT
507 is ignored in secure-execution mode; instead
508 .IR /var/profile
509 is always used.
510 .TP
511 .BR LD_SHOW_AUXV " (since glibc 2.1)"
512 If this environment variable is defined (with any value),
513 show the auxiliary array passed up from the kernel (see also
514 .BR getauxval (3)).
515 Since glibc 2.3.5,
516 .B LD_SHOW_AUXV
517 is ignored in secure-execution mode.
518 .TP
519 .BR LD_TRACE_PRELINKING " (since glibc 2.4)"
520 If this environment variable is defined,
521 trace prelinking of the object whose name is assigned to
522 this environment variable.
523 (Use
524 .BR ldd (1)
525 to get a list of the objects that might be traced.)
526 If the object name is not recognized,
527 .\" (This is what seems to happen, from experimenting)
528 then all prelinking activity is traced.
529 .TP
530 .BR LD_USE_LOAD_BIAS " (since glibc 2.3.3)"
531 .\" http://sources.redhat.com/ml/libc-hacker/2003-11/msg00127.html
532 .\" Subject: [PATCH] Support LD_USE_LOAD_BIAS
533 .\" Jakub Jelinek
534 By default (i.e., if this variable is not defined),
535 executables and prelinked
536 shared objects will honor base addresses of their dependent shared objects
537 and (nonprelinked) position-independent executables (PIEs)
538 and other shared objects will not honor them.
539 If
540 .B LD_USE_LOAD_BIAS
541 is defined with the value 1, both executables and PIEs
542 will honor the base addresses.
543 If
544 .B LD_USE_LOAD_BIAS
545 is defined with the value 0,
546 neither executables nor PIEs will honor the base addresses.
547 This variable is ignored in secure-execution mode.
548 .TP
549 .BR LD_VERBOSE " (since glibc 2.1)"
550 If set to a nonempty string,
551 output symbol versioning information about the
552 program if the
553 .B LD_TRACE_LOADED_OBJECTS
554 environment variable has been set.
555 .TP
556 .BR LD_WARN " (since glibc 2.1.3)
557 If set to a nonempty string, warn about unresolved symbols.
558 .TP
559 .BR LD_PREFER_MAP_32BIT_EXEC " (x86-64 only; since glibc 2.23)"
560 According to the Intel Silvermont software optimization guide, for 64-bit
561 applications, branch prediction performance can be negatively impacted
562 when the target of a branch is more than 4GB away from the branch.
563 If this environment variable is set (to any value),
564 .BR ld.so
565 will first try to map executable pages using the
566 .BR mmap (2)
567 .BR MAP_32BIT
568 flag, and fall back to mapping without that flag if that attempt fails.
569 NB: MAP_32BIT will map to the low 2GB (not 4GB) of the address space.
570 Because
571 .B MAP_32BIT
572 reduces the address range available for address space layout
573 randomization (ASLR),
574 .B LD_PREFER_MAP_32BIT_EXEC
575 is always disabled in secure-execution mode.
576 .SH FILES
577 .PD 0
578 .TP
579 .I /lib/ld.so
580 a.out dynamic linker/loader
581 .TP
582 .IR /lib/ld\-linux.so. { 1 , 2 }
583 ELF dynamic linker/loader
584 .TP
585 .I /etc/ld.so.cache
586 File containing a compiled list of directories in which to search for
587 shared objects and an ordered list of candidate shared objects.
588 .TP
589 .I /etc/ld.so.preload
590 File containing a whitespace-separated list of ELF shared objects to
591 be loaded before the program.
592 .TP
593 .B lib*.so*
594 shared objects
595 .PD
596 .SH NOTES
597 .SS Hardware capabilities
598 Some shared objects are compiled using hardware-specific instructions which do
599 not exist on every CPU.
600 Such objects should be installed in directories whose names define the
601 required hardware capabilities, such as
602 .IR /usr/lib/sse2/ .
603 The dynamic linker checks these directories against the hardware of the
604 machine and selects the most suitable version of a given shared object.
605 Hardware capability directories can be cascaded to combine CPU features.
606 The list of supported hardware capability names depends on the CPU.
607 The following names are currently recognized:
608 .TP
609 .B Alpha
610 ev4, ev5, ev56, ev6, ev67
611 .TP
612 .B MIPS
613 loongson2e, loongson2f, octeon, octeon2
614 .TP
615 .B PowerPC
616 4xxmac, altivec, arch_2_05, arch_2_06, booke, cellbe, dfp, efpdouble, efpsingle,
617 fpu, ic_snoop, mmu, notb, pa6t, power4, power5, power5+, power6x, ppc32, ppc601,
618 ppc64, smt, spe, ucache, vsx
619 .TP
620 .B SPARC
621 flush, muldiv, stbar, swap, ultra3, v9, v9v, v9v2
622 .TP
623 .B s390
624 dfp, eimm, esan3, etf3enh, g5, highgprs, hpage, ldisp, msa, stfle,
625 z900, z990, z9-109, z10, zarch
626 .TP
627 .B x86 (32-bit only)
628 acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx,
629 mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm
630 .SH SEE ALSO
631 .BR ld (1),
632 .BR ldd (1),
633 .BR pldd (1),
634 .BR sprof (1),
635 .BR dlopen (3),
636 .BR getauxval (3),
637 .BR capabilities (7),
638 .BR rtld-audit (7),
639 .BR ldconfig (8),
640 .BR sln (8)
641 .\" .SH AUTHORS
642 .\" ld.so: David Engel, Eric Youngdale, Peter MacDonald, Hongjiu Lu, Linus
643 .\" Torvalds, Lars Wirzenius and Mitch D'Souza
644 .\" ld-linux.so: Roland McGrath, Ulrich Drepper and others.
645 .\"
646 .\" In the above, (libc5) stands for David Engel's ld.so/ld-linux.so.