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