]> git.saurik.com Git - apple/dyld.git/blob - doc/man/man1/dyld.1
ad1cec34a641cba182bab98acb7a4598c26ceb99
[apple/dyld.git] / doc / man / man1 / dyld.1
1 .TH DYLD 1 "December 14, 2009" "Apple Inc."
2 .SH NAME
3 dyld \- the dynamic link editor
4 .SH SYNOPSIS
5 DYLD_FRAMEWORK_PATH
6 .br
7 DYLD_FALLBACK_FRAMEWORK_PATH
8 .br
9 DYLD_VERSIONED_FRAMEWORK_PATH
10 .br
11 DYLD_LIBRARY_PATH
12 .br
13 DYLD_FALLBACK_LIBRARY_PATH
14 .br
15 DYLD_VERSIONED_LIBRARY_PATH
16 .br
17 DYLD_PRINT_TO_FILE
18 .br
19 DYLD_SHARED_REGION
20 .br
21 DYLD_INSERT_LIBRARIES
22 .br
23 DYLD_FORCE_FLAT_NAMESPACE
24 .br
25 DYLD_IMAGE_SUFFIX
26 .br
27 DYLD_PRINT_OPTS
28 .br
29 DYLD_PRINT_ENV
30 .br
31 DYLD_PRINT_LIBRARIES
32 .br
33 DYLD_PRINT_LIBRARIES_POST_LAUNCH
34 .br
35 DYLD_BIND_AT_LAUNCH
36 .br
37 DYLD_DISABLE_DOFS
38 .br
39 DYLD_PRINT_APIS
40 .br
41 DYLD_PRINT_BINDINGS
42 .br
43 DYLD_PRINT_INITIALIZERS
44 .br
45 DYLD_PRINT_REBASINGS
46 .br
47 DYLD_PRINT_SEGMENTS
48 .br
49 DYLD_PRINT_STATISTICS
50 .br
51 DYLD_PRINT_DOFS
52 .br
53 DYLD_PRINT_RPATHS
54 .br
55 DYLD_SHARED_CACHE_DIR
56 .br
57 DYLD_SHARED_CACHE_DONT_VALIDATE
58 .SH DESCRIPTION
59 The dynamic linker uses the following environment variables.
60 They affect any program that uses the dynamic linker.
61 .TP
62 .B DYLD_FRAMEWORK_PATH
63 This is a colon separated list of directories that contain frameworks.
64 The dynamic linker searches these directories before it searches for the
65 framework by its install name.
66 It allows you to test new versions of existing
67 frameworks. (A framework is a library install name that ends in the form
68 XXX.framework/Versions/YYY/XXX or XXX.framework/XXX, where XXX and YYY are any
69 name.)
70 .IP
71 For each framework that a program uses, the dynamic linker looks for the
72 framework in each directory in
73 .SM DYLD_FRAMEWORK_PATH
74 in turn. If it looks in all the directories and can't find the framework, it
75 searches the directories in
76 .SM DYLD_LIBRARY_PATH
77 in turn. If it still can't find the framework, it then searches
78 .SM DYLD_FALLBACK_FRAMEWORK_PATH
79 and
80 .SM DYLD_FALLBACK_LIBRARY_PATH
81 in turn.
82 .IP
83 Use the
84 .B \-L
85 option to
86 .IR otool (1).
87 to discover the frameworks and shared libraries that the executable
88 is linked against.
89 .TP
90 .B DYLD_FALLBACK_FRAMEWORK_PATH
91 This is a colon separated list of directories that contain frameworks.
92 It is used as the default location for frameworks not found in their install
93 path.
94
95 By default, it is set to
96 /Library/Frameworks:/Network/Library/Frameworks:/System/Library/Frameworks
97 .TP
98 .B DYLD_VERSIONED_FRAMEWORK_PATH
99 This is a colon separated list of directories that contain potential override frameworks.
100 The dynamic linker searches these directories for frameworks. For
101 each framework found dyld looks at its LC_ID_DYLIB and gets the current_version
102 and install name. Dyld then looks for the framework at the install name path.
103 Whichever has the larger current_version value will be used in the process whenever
104 a framework with that install name is required. This is similar to DYLD_FRAMEWORK_PATH
105 except instead of always overriding, it only overrides is the supplied framework is newer.
106 Note: dyld does not check the framework's Info.plist to find its version. Dyld only
107 checks the -currrent_version number supplied when the framework was created.
108 .TP
109 .B DYLD_LIBRARY_PATH
110 This is a colon separated list of directories that contain libraries. The
111 dynamic linker searches these directories before it searches the default
112 locations for libraries. It allows you to test new versions of existing
113 libraries.
114 .IP
115 For each library that a program uses, the dynamic linker looks for it in each
116 directory in
117 .SM DYLD_LIBRARY_PATH
118 in turn. If it still can't find the library, it then searches
119 .SM DYLD_FALLBACK_FRAMEWORK_PATH
120 and
121 .SM DYLD_FALLBACK_LIBRARY_PATH
122 in turn.
123 .IP
124 Use the
125 .B \-L
126 option to
127 .IR otool (1).
128 to discover the frameworks and shared libraries that the executable
129 is linked against.
130 .TP
131 .B DYLD_FALLBACK_LIBRARY_PATH
132 This is a colon separated list of directories that contain libraries.
133 It is used as the default location for libraries not found in their install
134 path.
135 By default, it is set
136 to $(HOME)/lib:/usr/local/lib:/lib:/usr/lib.
137 .TP
138 .B DYLD_VERSIONED_LIBRARY_PATH
139 This is a colon separated list of directories that contain potential override libraries.
140 The dynamic linker searches these directories for dynamic libraries. For
141 each library found dyld looks at its LC_ID_DYLIB and gets the current_version
142 and install name. Dyld then looks for the library at the install name path.
143 Whichever has the larger current_version value will be used in the process whenever
144 a dylib with that install name is required. This is similar to DYLD_LIBRARY_PATH
145 except instead of always overriding, it only overrides is the supplied library is newer.
146 .TP
147 .B DYLD_PRINT_TO_FILE
148 This is a path to a (writable) file. Normally, the dynamic linker writes all
149 logging output (triggered by DYLD_PRINT_* settings) to file descriptor 2
150 (which is usually stderr). But this setting causes the dynamic linker to
151 write logging output to the specified file.
152 .TP
153 .B DYLD_SHARED_REGION
154 This can be "use" (the default), "avoid", or "private". Setting it to
155 "avoid" tells dyld to not use the shared cache. All OS dylibs are loaded
156 dynamically just like every other dylib. Setting it to "private" tells
157 dyld to remove the shared region from the process address space and mmap()
158 back in a private copy of the dyld shared cache in the shared region address
159 range. This is only useful if the shared cache on disk has been updated
160 and is different than the shared cache in use.
161 .TP
162 .B DYLD_INSERT_LIBRARIES
163 This is a colon separated list of dynamic libraries to load before the ones
164 specified in the program. This lets you test new modules of existing dynamic
165 shared libraries that are used in flat-namespace images by loading a temporary
166 dynamic shared library with just the new modules. Note that this has no
167 effect on images built a two-level namespace images using a dynamic shared
168 library unless
169 .SM DYLD_FORCE_FLAT_NAMESPACE
170 is also used.
171 .TP
172 .B DYLD_FORCE_FLAT_NAMESPACE
173 Force all images in the program to be linked as flat-namespace images and ignore
174 any two-level namespace bindings. This may cause programs to fail to execute
175 with a multiply defined symbol error if two-level namespace images are used to
176 allow the images to have multiply defined symbols.
177 .TP
178 .B DYLD_IMAGE_SUFFIX
179 This is set to a string of a suffix to try to be used for all shared libraries
180 used by the program. For libraries ending in ".dylib" the suffix is applied
181 just before the ".dylib". For all other libraries the suffix is appended to the
182 library name. This is useful for using conventional "_profile" and "_debug"
183 libraries and frameworks.
184 .TP
185 .B DYLD_PRINT_OPTS
186 When this is set, the dynamic linker writes to file descriptor 2 (normally
187 standard error) the command line options.
188 .TP
189 .B DYLD_PRINT_ENV
190 When this is set, the dynamic linker writes to file descriptor 2 (normally
191 standard error) the environment variables.
192 .TP
193 .B DYLD_PRINT_LIBRARIES
194 When this is set, the dynamic linker writes to file descriptor 2 (normally
195 standard error) the filenames of the libraries the program is using.
196 This is useful to make sure that the use of
197 .SM DYLD_LIBRARY_PATH
198 is getting what you want.
199 .TP
200 .B DYLD_PRINT_LIBRARIES_POST_LAUNCH
201 This does the same as
202 .SM DYLD_PRINT_LIBRARIES
203 but the printing starts after the program gets to its entry point.
204 .TP
205 .B DYLD_BIND_AT_LAUNCH
206 When this is set, the dynamic linker binds all undefined symbols
207 the program needs at launch time. This includes function symbols that can are normally
208 lazily bound at the time of their first call.
209 .TP
210 .B DYLD_PRINT_STATISTICS
211 Right before the process's main() is called, dyld prints out information about how
212 dyld spent its time. Useful for analyzing launch performance.
213 .TP
214 .B DYLD_PRINT_STATISTICS_DETAILS
215 Right before the process's main() is called, dyld prints out detailed information about how
216 dyld spent its time. Useful for analyzing launch performance.
217 .TP
218 .B DYLD_DISABLE_DOFS
219 Causes dyld not register dtrace static probes with the kernel.
220 .TP
221 .B DYLD_PRINT_INITIALIZERS
222 Causes dyld to print out a line when running each initializers in every image. Initializers
223 run by dyld included constructors for C++ statically allocated objects, functions marked with
224 __attribute__((constructor)), and -init functions.
225 .TP
226 .B DYLD_PRINT_APIS
227 Causes dyld to print a line whenever a dyld API is called (e.g. NSAddImage()).
228 .TP
229 .B DYLD_PRINT_SEGMENTS
230 Causes dyld to print out a line containing the name and address range of each mach-o segment
231 that dyld maps. In addition it prints information about if the image was from the dyld
232 shared cache.
233 .TP
234 .B DYLD_PRINT_BINDINGS
235 Causes dyld to print a line each time a symbolic name is bound.
236 .TP
237 .B DYLD_PRINT_DOFS
238 Causes dyld to print out information about dtrace static probes registered with the kernel.
239 .TP
240 .B DYLD_PRINT_RPATHS
241 Cause dyld to print a line each time it expands an @rpath variable and whether
242 that expansion was successful or not.
243 .TP
244 .B DYLD_SHARED_CACHE_DIR
245 This is a directory containing dyld shared cache files. This variable can be used in
246 conjunction with DYLD_SHARED_REGION=private and DYLD_SHARED_CACHE_DONT_VALIDATE
247 to run a process with an alternate shared cache.
248 .TP
249 .B DYLD_SHARED_CACHE_DONT_VALIDATE
250 Causes dyld to not check that the inode and mod-time of files in the shared cache match
251 the requested dylib on disk. Thus a program can be made to run with the dylib in the
252 shared cache even though the real dylib has been updated on disk.
253 .TP
254 .SH DYNAMIC LIBRARY LOADING
255 Unlike many other operating systems, Darwin does not locate dependent dynamic libraries
256 via their leaf file name. Instead the full path to each dylib is used (e.g. /usr/lib/libSystem.B.dylib).
257 But there are times when a full path is not appropriate; for instance, may want your
258 binaries to be installable in anywhere on the disk.
259 To support that, there are three @xxx/ variables that can be used as a path prefix. At runtime dyld
260 substitutes a dynamically generated path for the @xxx/ prefix.
261 .TP
262 .B @executable_path/
263 This variable is replaced with the path to the directory containing the main executable for
264 the process. This is useful for loading dylibs/frameworks embedded in a .app directory.
265 If the main executable file is at /some/path/My.app/Contents/MacOS/My and a framework dylib
266 file is at /some/path/My.app/Contents/Frameworks/Foo.framework/Versions/A/Foo, then
267 the framework load path could be encoded as
268 @executable_path/../Frameworks/Foo.framework/Versions/A/Foo and the .app directory could be
269 moved around in the file system and dyld will still be able to load the embedded framework.
270 .TP
271 .B @loader_path/
272 This variable is replaced with the path to the directory containing the mach-o binary which
273 contains the load command using @loader_path. Thus, in every binary, @loader_path resolves to
274 a different path, whereas @executable_path always resolves to the same path. @loader_path is
275 useful as the load path for a framework/dylib embedded in a plug-in, if the final file
276 system location of the plugin-in unknown (so absolute paths cannot be used) or if the plug-in
277 is used by multiple applications (so @executable_path cannot be used). If the plug-in mach-o
278 file is at /some/path/Myfilter.plugin/Contents/MacOS/Myfilter and a framework dylib
279 file is at /some/path/Myfilter.plugin/Contents/Frameworks/Foo.framework/Versions/A/Foo, then
280 the framework load path could be encoded as
281 @loader_path/../Frameworks/Foo.framework/Versions/A/Foo and the Myfilter.plugin directory could
282 be moved around in the file system and dyld will still be able to load the embedded framework.
283 .TP
284 .B @rpath/
285 Dyld maintains a current stack of paths called the run path list. When @rpath is encountered
286 it is substituted with each path in the run path list until a loadable dylib if found.
287 The run path stack is built from the LC_RPATH load commands in the depencency chain
288 that lead to the current dylib load.
289 You can add an LC_RPATH load command to an image with the -rpath option to ld(1). You can
290 even add a LC_RPATH load command path that starts with @loader_path/, and it will push a path
291 on the run path stack that relative to the image containing the LC_RPATH.
292 The use of @rpath is most useful when you have a complex directory structure of programs and
293 dylibs which can be installed anywhere, but keep their relative positions. This scenario
294 could be implemented using @loader_path, but every client of a dylib could need a different
295 load path because its relative position in the file system is different. The use of @rpath
296 introduces a level of indirection that simplies things. You pick a location in your directory
297 structure as an anchor point. Each dylib then gets an install path that starts with @rpath
298 and is the path to the dylib relative to the anchor point. Each main executable is linked
299 with -rpath @loader_path/zzz, where zzz is the path from the executable to the anchor point.
300 At runtime dyld sets it run path to be the anchor point, then each dylib is found relative
301 to the anchor point.
302 .SH "SEE ALSO"
303 libtool(1), ld(1), otool(1)