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