1 .\" $FreeBSD: src/libexec/rtld-elf/rtld.1,v 1.18.2.7 2002/01/10 17:51:28 ru Exp $
3 .\" Copyright (c) 1995 Paul Kranenburg
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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
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.
39 .Nd run-time link-editor
42 .Fn _rtld_functrace "const char *callerso" "const char *calleeso" "const char *calleefun" "void *stack"
45 is a self-contained shared object providing run-time
46 support for loading and link-editing shared objects into a process'
48 It is also commonly known as the dynamic linker.
49 It uses the data structures
50 contained within dynamically linked programs to determine which shared
51 libraries are needed and loads them using the
55 After all shared libraries have been successfully loaded,
57 proceeds to resolve external references from both the main program and
59 A mechanism is provided for initialization routines
60 to be called on a per-object basis, giving a shared object an opportunity
61 to perform any extra set-up before execution of the program proper begins.
62 This is useful for C++ libraries that contain static constructors.
65 itself is loaded by the kernel together with any dynamically-linked
66 program that is to be executed.
67 The kernel transfers control to the
69 After the dynamic linker has finished loading,
70 relocating, and initializing the program and its required shared
71 objects, it transfers control to the entry point of the program.
73 To locate the required shared objects in the filesystem,
82 recognizes a number of environment variables that can be used to modify
83 its behaviour as follows:
84 .Bl -tag -width ".Ev LD_LIBRARY_PATH"
85 .It Ev LD_LIBRARY_PATH
86 A colon separated list of directories, overriding the default search path
88 This is ignored for set-user-ID and set-group-ID programs.
90 A list of shared libraries, separated by colons and/or white space,
91 to be linked in before any
92 other shared libraries.
93 If the directory is not specified then
94 the directories specified by
96 will be searched first
97 followed by the set of built-in standard directories.
98 This is ignored for set-user-ID and set-group-ID programs.
100 When set to a nonempty string, causes
102 to relocate all external function calls before starting execution of the
104 Normally, function calls are bound lazily, at the first call
107 increases the start-up time of a program, but it avoids run-time
108 surprises caused by unexpectedly undefined functions.
109 .It Ev LD_TRACE_LOADED_OBJECTS
110 When set to a nonempty string, causes
112 to exit after loading the shared objects and printing a summary which includes
113 the absolute pathnames of all objects, to standard output.
114 .It Ev LD_TRACE_LOADED_OBJECTS_FMT1
115 .It Ev LD_TRACE_LOADED_OBJECTS_FMT2
116 When set, these variables are interpreted as format strings a la
118 to customize the trace output and are used by
123 to be operated as a filter more conveniently.
124 The following conversions can be used:
127 The main program's name
131 The value of the environment variable
132 .Ev LD_TRACE_LOADED_OBJECTS_PROGNAME
136 The library's major version number.
138 The full pathname as determined by
140 library search rules.
142 The library's load address.
149 are recognized and have their usual meaning.
152 If a shared object preloaded by the
154 mechanism contains a public symbol
155 .Dq _rtld_functrace ,
157 will transfer control to this function each time
158 it needs to resolve an unbound function symbol.
159 By returning a non-zero value,
161 can advise the linker to keep tracing the specified
162 combination of caller shared object and called function;
163 returning 0 will prevent
165 to be called for this combination again.
167 When implementing a custom
169 function, be aware of the possibility that
171 might be called for functions called on its behalf,
172 or that multiple threads could enter
175 .Sh DIFFERENCES BETWEEN .1 and .2
176 ABI changes have been made to support TLS allocation and initialization
177 and to give threading libraries a chance to complete initialization of the
178 TCB prior to the calling of the _init() functions for the dynamically loaded
181 .Bl -tag -width indent
182 .It Pa /var/run/ld-elf.so.hints
187 for printing out the functions as they are called, this code can be used:
188 .Bd -literal -offset indent
194 _rtld_functrace(const char *callerso, const char *calleeso,
195 const char *calleefun, void *stack)
197 write(2, "calling ", 8);
198 write(2, calleefun, strlen(calleefun));
204 If put in a file named
207 .Bd -literal -offset indent
208 $ cc -shared ft.c -o ft.so