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