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