Merge branch 'vendor/TNFTP'
[dragonfly.git] / libexec / rtld-elf / rtld.1
1 .\" $FreeBSD: src/libexec/rtld-elf/rtld.1,v 1.18.2.7 2002/01/10 17:51:28 ru Exp $
2 .\" $DragonFly: src/libexec/rtld-elf/rtld.1,v 1.7 2008/05/02 02:05:05 swildner Exp $
3 .\"
4 .\" Copyright (c) 1995 Paul Kranenburg
5 .\" All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgment:
17 .\"      This product includes software developed by Paul Kranenburg.
18 .\" 3. The name of the author may not be used to endorse or promote products
19 .\"    derived from this software without specific prior written permission
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 .\"
32 .Dd January 7, 2008
33 .Dt RTLD 1
34 .Os
35 .Sh NAME
36 .Nm ld-elf.so.1 ,
37 .Nm ld-elf.so.2 ,
38 .Nm rtld
39 .Nd run-time link-editor
40 .Sh DESCRIPTION
41 .Nm
42 is a self-contained shared object providing run-time
43 support for loading and link-editing shared objects into a process'
44 address space.
45 It is also commonly known as the dynamic linker.
46 It uses the data structures
47 contained within dynamically linked programs to determine which shared
48 libraries are needed and loads them using the
49 .Xr mmap 2
50 system call.
51 .Pp
52 After all shared libraries have been successfully loaded,
53 .Nm
54 proceeds to resolve external references from both the main program and
55 all objects loaded.
56 A mechanism is provided for initialization routines
57 to be called on a per-object basis, giving a shared object an opportunity
58 to perform any extra set-up before execution of the program proper begins.
59 This is useful for C++ libraries that contain static constructors.
60 .Pp
61 .Nm
62 itself is loaded by the kernel together with any dynamically-linked
63 program that is to be executed.
64 The kernel transfers control to the
65 dynamic linker.
66 After the dynamic linker has finished loading,
67 relocating, and initializing the program and its required shared
68 objects, it transfers control to the entry point of the program.
69 .Pp
70 To locate the required shared objects in the filesystem,
71 .Nm
72 may use a
73 .Dq hints
74 file prepared by the
75 .Xr ldconfig 8
76 utility.
77 .Pp
78 .Nm
79 recognizes a number of environment variables that can be used to modify
80 its behaviour as follows:
81 .Bl -tag -width ".Ev LD_LIBRARY_PATH"
82 .It Ev LD_LIBRARY_PATH
83 A colon separated list of directories, overriding the default search path
84 for shared libraries.
85 This is ignored for set-user-ID and set-group-ID programs.
86 .It Ev LD_PRELOAD
87 A list of shared libraries, separated by colons and/or white space,
88 to be linked in before any
89 other shared libraries.
90 If the directory is not specified then
91 the directories specified by
92 .Ev LD_LIBRARY_PATH
93 will be searched first
94 followed by the set of built-in standard directories.
95 This is ignored for set-user-ID and set-group-ID programs.
96 .It Ev LD_BIND_NOW
97 When set to a nonempty string, causes
98 .Nm
99 to relocate all external function calls before starting execution of the
100 program.
101 Normally, function calls are bound lazily, at the first call
102 of each function.
103 .Ev LD_BIND_NOW
104 increases the start-up time of a program, but it avoids run-time
105 surprises caused by unexpectedly undefined functions.
106 .It Ev LD_TRACE_LOADED_OBJECTS
107 When set to a nonempty string, causes
108 .Nm
109 to exit after loading the shared objects and printing a summary which includes
110 the absolute pathnames of all objects, to standard output.
111 .It Ev LD_TRACE_LOADED_OBJECTS_FMT1
112 .It Ev LD_TRACE_LOADED_OBJECTS_FMT2
113 When set, these variables are interpreted as format strings a la
114 .Xr printf 3
115 to customize the trace output and are used by
116 .Xr ldd 1 Ns 's
117 .Fl f
118 option and allows
119 .Xr ldd 1
120 to be operated as a filter more conveniently.
121 The following conversions can be used:
122 .Bl -tag -width 4n
123 .It Li %a
124 The main program's name
125 (also known as
126 .Dq __progname ) .
127 .It Li \&%A
128 The value of the environment variable
129 .Ev LD_TRACE_LOADED_OBJECTS_PROGNAME
130 .It Li %o
131 The library name.
132 .It Li %m
133 The library's major version number.
134 .It Li %p
135 The full pathname as determined by
136 .Nm rtld Ns 's
137 library search rules.
138 .It Li %x
139 The library's load address.
140 .El
141 .Pp
142 Additionally,
143 .Ql \en
144 and
145 .Ql \et
146 are recognized and have their usual meaning.
147 .El
148 .Pp
149 If a shared object preloaded by the
150 .Ev LD_PRELOAD
151 mechanism contains a public symbol
152 .Dq _rtld_functrace ,
153 .Nm
154 will transfer control to this function each time
155 it needs to resolve an unbound function symbol.
156 By returning a non-zero value,
157 .Fn _rtld_functrace
158 can advise the linker to keep tracing the specified
159 combination of caller shared object and called function;
160 returning 0 will prevent
161 .Fn _rtld_functrace
162 to be called for this combination again.
163 .Pp
164 When implementing a custom
165 .Fn _rtld_functrace
166 function, be aware of the possibility that
167 .Fn _rtld_functrace
168 might be called for functions called on its behalf,
169 or that multiple threads could enter
170 .Fn _rtld_functrace
171 at the same time.
172 .Pp
173 The signature for
174 .Fn _rtld_functrace
175 is specified as follows.
176 .Pp
177 .Ft int
178 .Fn _rtld_functrace "const char *callerso" "const char *calleeso" "const char *calleefun" "void *stack"
179 .Sh DIFFERENCES BETWEEN .1 and .2
180 ABI changes have been made to support TLS allocation and initialization
181 and to give threading libraries a chance to complete initialization of the
182 TCB prior to the calling of the _init() functions for the dynamically loaded
183 libraries.
184 .Sh FILES
185 .Bl -tag -width indent
186 .It Pa /var/run/ld-elf.so.hints
187 .El
188 .Sh SEE ALSO
189 .Xr ld 1 ,
190 .Xr ldd 1 ,
191 .Xr elf 5 ,
192 .Xr ldconfig 8