]> git.saurik.com Git - apple/ld64.git/blob - doc/man/man1/ld.1
53fbaa5e777ac142545649319ed6d55149e7f811
[apple/ld64.git] / doc / man / man1 / ld.1
1 .Dd March 7, 2011
2 .Dt ld 1
3 .Os Darwin
4 .Sh NAME
5 .Nm ld
6 .Nd "linker"
7 .Sh SYNOPSIS
8 .Nm
9 files...
10 .Op options
11 .Op Fl o Ar outputfile
12 .Sh DESCRIPTION
13 The
14 .Nm ld
15 command combines several object files and libraries, resolves references, and
16 produces an ouput file.
17 .Nm ld
18 can produce a final linked image (executable, dylib, or bundle), or with the -r
19 option, produce another object file. If the -o option is not used, the output
20 file produced is named "a.out".
21 .Ss Universal
22 The linker accepts universal (multiple-architecture) input files, but
23 always creates a "thin" (single-architecture), standard Mach-O output file.
24 The architecture for the output file is specified using the -arch option.
25 If this option is not used,
26 .Nm ld
27 attempts to determine the output architecture by examining the object
28 files in command line order. The first "thin"
29 architecture determines that of the output file. If no input
30 object file is a "thin" file, the native 32-bit architecture for the host is used.
31 .Pp
32 Usually,
33 .Nm ld
34 is not used directly. Instead the
35 .Xr gcc(1)
36 compiler driver invokes
37 .Nm ld.
38 The compiler driver can be passed multiple -arch options and it will create a
39 universal final linked image by invoking
40 .Nm ld
41 multiple times and then running
42 .Xr lipo(1)
43 merge the outputs into a universal file.
44 .Ss Layout
45 The object files are loaded in the order in which they are specified on the
46 command line. The segments and the sections in those segments will appear in
47 the output file in the order they are encountered in the object files being linked.
48 All zero fill sections will appear after all non-zero fill sections in their segments.
49 Sections created from files with the -sectcreate option will be laid out at after
50 sections from .o files. The use of the -order_file option will alter the layout
51 rules above, and move the symbols specified to start of their section.
52 .Ss Libraries
53 A static library (aka static archive) is a collection of .o files with a table of contents
54 that lists the global symbols in the .o files.
55 .Nm ld
56 will only pull .o files out of a static library if needed to resolve some symbol reference.
57 Unlike traditional linkers,
58 .Nm ld
59 will continually search a static library while linking. There is no need to specify a static
60 library multiple times on the command line.
61 .Pp
62 A dynamic library (aka dylib or framework) is a final linked image. Putting a dynamic
63 library on the command line causes two things: 1) The generated final linked image
64 will have encoded that it depends on that dynamic library. 2) Exported symbols from the
65 dynamic library are used to resolve references.
66 .Pp
67 Both dynamic and static libraries are searched as they appear on the command line.
68 .Ss Search paths
69 .Nm ld
70 maintains a list of directories to search for a library or framework to use. The default
71 library search path is /usr/lib then /usr/local/lib. The -L option will add a new library search
72 path. The default framework search path is /Library/Frameworks then /System/Library/Frameworks.
73 (Note: previously, /Network/Library/Frameworks was at the end of the default path. If you need
74 that functionality, you need to explicitly add -F/Network/Library/Frameworks).
75 The -F option will add a new framework search path. The -Z option will remove
76 the standard search paths. The -syslibroot option will prepend a prefix to all search
77 paths.
78 .Ss Two-level namespace
79 By default all references resolved to a dynamic library record the library to which
80 they were resolved. At runtime, dyld uses that information to directly resolve
81 symbols. The alternative is to use the -flat_namespace option. With flat namespace,
82 the library is not recorded. At runtime, dyld will search each dynamic library in load
83 order when resolving symbols. This is slower, but more like how other operating systems
84 resolve symbols.
85 .Ss Indirect dynamic libraries
86 If the command line specifies to link against dylib A, and when dylib A was built it linked
87 against dylib B, then B is considered an indirect dylib.
88 When linking for two-level namespace, ld does not look at indirect dylibs, except when
89 re-exported by a direct dylibs. On the other hand when linking for flat namespace,
90 ld does load all indirect dylibs and uses them to resolve references.
91 Even though indirect dylibs are specified via a full path,
92 .Nm ld
93 first uses the specified search paths to locate each indirect dylib. If one cannot
94 be found using the search paths, the full path is used.
95 .Ss Dynamic libraries undefines
96 When linking for two-level namespace,
97 .Nm ld
98 does not verify that undefines in dylibs actually
99 exist. But when linking for flat namespace,
100 .Nm ld
101 does check that all undefines from all loaded dylibs have a matching definition.
102 This is sometimes used to force selected functions to be loaded from a static library.
103 .Sh OPTIONS
104 .Ss Options that control the kind of output
105 .Bl -tag
106 .It Fl execute
107 The default. Produce a mach-o main executable that has file type MH_EXECUTE.
108 .It Fl dylib
109 Produce a mach-o shared library that has file type MH_DYLIB.
110 .It Fl bundle
111 Produce a mach-o bundle that has file type MH_BUNDLE.
112 .It Fl r
113 Merges object files to produce another mach-o object file with file type MH_OBJECT.
114 .It Fl dylinker
115 Produce a mach-o dylinker that has file type MH_DYLINKER. Only used when building dyld.
116 .It Fl dynamic
117 The default. Implied by -dylib, -bundle, or -execute
118 .It Fl static
119 Produces a mach-o file that does not use the dyld. Only used building the kernel.
120 .It Fl preload
121 Produces a mach-o file in which the mach_header, load commands, and symbol table are
122 not in any segment. This output type is used for firmware or embedded development
123 where the segments are copied out of the mach-o into ROM/Flash.
124 .It Fl arch Ar arch_name
125 Specifies which architecture (e.g. ppc, ppc64, i386, x86_64) the output file should be.
126 .It Fl o Ar path
127 Specifies the name and location of the output file. If not specified, `a.out' is used.
128 .El
129 .Ss Options that control libraries
130 .Bl -tag
131 .It Fl l Ns x
132 This option tells the linker to search for libx.dylib or libx.a in the library search path.
133 If string x is of the form y.o, then that file is searched for in the same places, but without
134 prepending `lib' or appending `.a' or `.dylib' to the filename.
135 .It Fl weak-l Ns Ar x
136 This is the same as the -lx but forces the library and all references to it to be marked as weak imports.
137 That is, the library is allowed to be missing at runtime.
138 .It Fl weak_library Ar path_to_library
139 This is the same as listing a file name path to a library on the link line except that it forces the
140 library and all references to it to be marked as weak imports.
141 .It Fl reexport-l Ns Ar x
142 This is the same as the -lx but specifies that the all symbols in library x should be available to
143 clients linking to the library being created. This was previously done with a separate -sub_library option.
144 .It Fl reexport_library Ar path_to_library
145 This is the same as listing a file name path to a library on the link line and it specifies that the
146 all symbols in library path should be available to clients linking to the library being created.
147 This was previously done with a separate -sub_library option.
148 .It Fl lazy-l Ns Ar x
149 This is the same as the -lx but it is only for shared libraries and the linker
150 will construct glue code so that the shared library is not loaded until
151 the first function in it is called.
152 .It Fl lazy_library Ar path_to_library
153 This is the same as listing a file name path to a shared library on the link line
154 except that the linker will construct glue code so that the shared library is not
155 loaded until the first function in it is called.
156 .It Fl upward-l Ns Ar x
157 This is the same as the -lx but specifies that the dylib is an upward dependency.
158 .It Fl upward_library Ar path_to_library
159 This is the same as listing a file name path to a library on the link line but also marks
160 the dylib as an upward dependency.
161 .It Fl L Ns dir
162 Add
163 .Ar dir
164 to the list of directories in which to search for libraries.
165 Directories specified with -L are searched in the order they appear on the command line
166 and before the default search path. In Xcode4 and later, there can be a space between
167 the -L and directory.
168 .It Fl Z
169 Do not search the standard directories when searching for libraries and frameworks.
170 .It Fl syslibroot Ar rootdir
171 Prepend
172 .Ar rootdir
173 to all search paths when searching for libraries or frameworks.
174 .It Fl search_paths_first
175 This is now the default (in Xcode4 tools). When processing -lx the linker now searches each directory
176 in its library search paths for `libx.dylib' then `libx.a' before the moving on to the next path
177 in the library search path.
178 .It Fl search_dylibs_first
179 Changes the searching behavior for libraries. The default is that when processing -lx the linker
180 searches each directory in its library search paths for `libx.dylib' then `libx.a'.
181 This option changes the behavior to first search for a file of the form `libx.dylib' in each directory
182 in the library search path, then a file of the form `libx.a' is searched for in the library search paths.
183 This option restores the search behavior of the linker prior to Xcode4.
184 .It Fl framework Ar name[,suffix]
185 This option tells the linker to search for `name.framework/name' the framework search path.
186 If the optional suffix is specified the framework is first searched for the name with the suffix and then without
187 (e.g. look for `name.framework/name_suffix' first, if not there try `name.framework/name').
188 .It Fl weak_framework Ar name[,suffix]
189 This is the same as the -framework name[,suffix] but forces the framework and all
190 references to it to be marked as weak imports.
191 .It Fl reexport_framework Ar name[,suffix]
192 This is the same as the -framework name[,suffix] but also specifies that the
193 all symbols in that framework should be available to clients linking to the library being created.
194 This was previously done with a separate -sub_umbrella option.
195 .It Fl lazy_framework Ar name[,suffix]
196 This is the same as the -framework name[,suffix] except that the linker will
197 construct glue code so that the framework is not
198 loaded until the first function in it is called. You cannot directly access
199 data or Objective-C classes in a framework linked this way.
200 .It Fl upward_framework Ar name[,suffix]
201 This is the same as the -framework name[,suffix] but also specifies that the
202 framework is an upward dependency.
203 .It Fl F Ns dir
204 Add
205 .Ar dir
206 to the list of directories in which to search for frameworks.
207 Directories specified with -F are searched in the order they appear on the command line
208 and before the default search path. In Xcode4 and later, there can be a space between
209 the -F and directory.
210 .It Fl all_load
211 Loads all members of static archive libraries.
212 .It Fl ObjC
213 Loads all members of static archive libraries that implement an Objective-C class or category.
214 .It Fl force_load Ar path_to_archive
215 Loads all members of the specified static archive library. Note: -all_load forces all members of all
216 archives to be loaded. This option allows you to target a specific archive.
217 .El
218 .Ss Options that control additional content
219 .Bl -tag
220 .It Fl sectcreate Ar segname sectname file
221 The section
222 .Ar sectname
223 in the segment
224 .Ar segname
225 is created from the contents of file
226 .Ar file.
227 The combination of segname and sectname must be unique Ð there cannot already be a section (segname,sectname)
228 from any other input.
229 .It Fl filelist Ar file[,dirname]
230 Specifies that the linker should link the files listed in
231 .Ar file .
232 This is an alternative to listing the files on the command line.
233 The file names are listed one per line separated only by newlines. (Spaces and tabs are assumed to be part of the file name.)
234 If the optional directory name,
235 .Ar dirname
236 is specified, it is prepended to each name in the list file.
237 .It Fl dtrace Ar file
238 Enables dtrace static probes when producing a final linked image. The file
239 .Ar file
240 must be a DTrace script which declares the static probes.
241 .El
242 .Ss Options that control optimizations
243 .Bl -tag
244 .It Fl dead_strip
245 Remove functions and data that are unreachable by the entry point or exported symbols.
246 .It Fl order_file Ar file
247 Alters the order in which functions and data are laid out. For each section in the output file,
248 any symbol in that section that are specified in the order file
249 .Ar file
250 is moved to the start of its section and laid out in the same order as in the order file
251 .Ar file .
252 Order files are text files with one symbol name per line. Lines starting with a # are comments.
253 A symbol name may be optionally preceded with its object file leaf name and a colon (e.g. foo.o:_foo).
254 This is useful for static functions/data that occur in multiple files.
255 A symbol name may also be optionally preceded with the architecture (e.g. ppc:_foo or ppc:foo.o:_foo).
256 This enables you to have one order file that works for multiple architectures.
257 Literal c-strings may be ordered by by quoting the string (e.g. "Hello, world\\n") in the order file.
258 .It Fl no_order_inits
259 When the -order_file option is not used, the linker lays out functions in object file order and
260 it moves all initializer routines to the start of the __text section and terminator routines
261 to the end. Use this option to disable the automatic rearrangement of initializers and terminators.
262 .It Fl no_order_data
263 By default the linker reorders global data in the __DATA segment so that all global variables that
264 dyld will need to adjust at launch time will early in the __DATA segment. This reduces the number
265 of dirty pages at launch time. This option disables that optimization.
266 .It Fl macosx_version_min Ar version
267 This is set to indicate the oldest Mac OS X version that that the output is to be used on. Specifying
268 a later version enables the linker to assumes features of that OS in the output file. The format of
269 .Ar version
270 is a Mac OS X version number such as 10.4 or 10.5
271 .It Fl ios_version_min Ar version
272 This is set to indicate the oldest iOS version that that the output is to be used on. Specifying
273 a later version enables the linker to assumes features of that OS in the output file. The format of
274 .Ar version
275 is an iOS version number such as 3.1 or 4.0
276 .It Fl image_base Ar address
277 Specifies the perferred load address for a dylib or bundle. The argument
278 .Ar address
279 is a hexadecimal number with an optional leading 0x. By choosing non-overlapping address for all
280 dylibs and bundles that a program loads, launch time can be improved because dyld will not need to
281 "rebase" the image (that is, adjust pointers within the image to work at the loaded address).
282 It is often easier to not use this option, but instead use the rebase(1) tool, and give it a list of dylibs.
283 It will then choose non-overlapping addresses for the list and rebase them all.
284 This option is also called -seg1addr for compatibility.
285 .It Fl no_implicit_dylibs
286 When creating a two-level namespace final linked image, normally the linker will hoist up public dylibs
287 that are implicitly linked to make the two-level namespace
288 encoding more efficient for dyld. For example, Cocoa re-exports AppKit and AppKit re-exports Foundation.
289 If you link with -framework Cocoa and use a symbol from Foundation, the linker will implicitly add a load
290 command to load Foundation and encode the symbol as coming from Foundation. If you use this option,
291 the linker will not add a load command for Foundation and encode the symbol as coming from Cocoa. Then
292 at runtime dyld will have to search Cocoa and AppKit before finding the symbol in Foundation.
293 .It Fl exported_symbols_order Ar file
294 When targeting Mac OS X 10.6 or later, the format of the exported symbol information can be optimized to
295 make lookups of popular symbols faster. This option is used to pass a file containing a list of
296 the symbols most frequently used by clients of the dynamic library being built. Not all exported symbols
297 need to be listed.
298 .It Fl no_zero_fill_sections
299 By default the linker moves all zero fill sections to the end of the __DATA segment and configures
300 them to use no space on disk. This option suppresses that optimization, so zero-filled data occupies
301 space on disk in a final linked image.
302 .It Fl merge_zero_fill_sections
303 Causes all zero-fill sections in the __DATA segment to be merged into one __zerofill section.
304 .It Fl no_branch_islands
305 Disables linker creation of branch islands which allows images to be created that are larger than the
306 maximum branch distance. Useful with -preload when code is in multiple sections but all are within
307 the branch range.
308 .El
309 .Ss Options when creating a dynamic library (dylib)
310 .Bl -tag
311 .It Fl install_name Ar name
312 Sets an internal "install path" (LC_ID_DYLIB) in a dynamic library. Any clients linked against the library
313 will record that path as the way dyld should locate this library. If this option is not specified, then
314 the -o path will be used. This option is also called -dylib_install_name for compatibility.
315 .It Fl mark_dead_strippable_dylib
316 Specifies that the dylib being built can be dead strip by any client. That is, the dylib has
317 no initialization side effects. So if a client links against the dylib, but never uses
318 any symbol from it, the linker can optimize away the use of the dylib.
319 .It Fl compatibility_version Ar number
320 Specifies the compatibility version number of the library. When a library is loaded by dyld, the
321 compatibility version is checked and if the program's version is greater that the library's version, it is an error.
322 The format of
323 .Ar number
324 is X[.Y[.Z]] where X must be a positive non-zero number less than or equal to 65535,
325 and .Y and .Z are optional and if present must be non-negative numbers less than or equal to 255.
326 If the compatibility version number is not specified, it has a value of 0 and no checking is done when the library is used.
327 This option is also called -dylib_compatibility_version for compatibility.
328 .It Fl current_version Ar number
329 Specifies the current version number of the library. The current version of the library can be obtained
330 programmatically by the user of the library so it can determine exactly which version of the library it is using.
331 The format of
332 .Ar number
333 is X[.Y[.Z]] where X must be a positive non-zero number less than or equal to 65535,
334 and .Y and .Z are optional and if present must be non-negative numbers less than or equal to 255.
335 If the version number is not specified, it has a value of 0.
336 This option is also called -dylib_current_version for compatibility.
337 .El
338 .Ss Options when creating a main executable
339 .Bl -tag
340 .It Fl pie
341 This makes a special kind of main executable that is position independent (PIE). On Mac OS X 10.5 and later, the OS
342 the OS will load a PIE at a random address each time it is executed. You cannot create a PIE from .o files compiled
343 with -mdynamic-no-pic. That means the codegen is less optimal, but the address randomization adds some
344 security. When targeting Mac OS X 10.7 or later PIE is the default for main executables.
345 .It Fl no_pie
346 Do not make a position independent executable (PIE). This is the default, when targeting 10.6 and earlier.
347 .It Fl pagezero_size Ar size
348 By default the linker creates an unreadable segment starting at address zero named __PAGEZERO. Its existence
349 will cause a bus error if a NULL pointer is dereferenced. The argument
350 .Ar size
351 is a hexadecimal number with an optional leading 0x. If
352 .Ar size
353 is zero, the linker will not generate a page zero segment. By default on 32-bit architectures the page zero size
354 is 4KB. On 64-bit architectures, the default size is 4GB. The ppc64 architecture has some special cases. Since Mac
355 OS X 10.4 did not support 4GB page zero programs, the default page zero size for ppc64 will be 4KB unless
356 -macosx_version_min is 10.5 or later. Also, the -mdynamic-no-pic codegen model for ppc64 will only work if the
357 code is placed in the lower 2GB of the address space, so the if the linker detects any such code, the page zero
358 size is set to 4KB and then a new unreadable trailing segment is created after the code, filling up the lower 4GB.
359 .It Fl stack_size Ar size
360 Specifies the maximum stack size for the main thread in a program. Without this option a program has a 8MB stack.
361 The argument
362 .Ar size
363 is a hexadecimal number with an optional leading 0x. The
364 .Ar size
365 should be a multiple of the architecture's page size (4KB or 16KB).
366 .It Fl allow_stack_execute
367 Marks executable so that all stacks in the task will be given stack execution privilege. This includes pthread stacks.
368 .It Fl export_dynamic
369 Preserves all global symbols in main executables during LTO. Without this option, Link Time Optimization
370 is allowed to inline and remove global functions. This option is used when a main executable may load
371 a plug-in which requires certain symbols from the main executable.
372 .El
373 .Ss Options when creating a bundle
374 .Bl -tag
375 .It Fl bundle_loader Ar executable
376 This specifies the
377 .Ar executable
378 that will be loading the bundle output file being linked.
379 Undefined symbols from the bundle are checked against the specified
380 .Ar executable
381 like it was one of the
382 dynamic libraries the bundle was linked with.
383 .El
384 .Ss Options when creating an object file
385 .Bl -tag
386 .It Fl keep_private_externs
387 Don't turn private external (aka visibility=hidden) symbols into static symbols,
388 but rather leave them as private external in the resulting object file.
389 .It Fl d
390 Force definition of common symbols. That is, transform tentative definitions into real definitions.
391 .El
392 .Ss Options that control symbol resolution
393 .Bl -tag
394 .It Fl exported_symbols_list Ar filename
395 The specified
396 .Ar filename
397 contains a list of global symbol names that will remain as global symbols in the output file.
398 All other global symbols will be treated as if they were marked as __private_extern__ (aka visibility=hidden)
399 and will not be global in the output file. The symbol names listed in filename must be one per line.
400 Leading and trailing white space are not part of the symbol name.
401 Lines starting with # are ignored, as are lines with only white space.
402 Some wildcards (similar to shell file matching) are supported. The * matches zero or more characters.
403 The ? matches one character. [abc] matches one character which must be an 'a', 'b', or 'c'. [a-z] matches
404 any single lower case letter from 'a' to 'z'.
405 .It Fl exported_symbol Ar symbol
406 The specified
407 .Ar symbol
408 is added to the list of global symbols names that will remain as global symbols in the output file. This
409 option can be used multiple times. For short lists, this can be more convenient than creating a file and using
410 -exported_symbols_list.
411 .It Fl unexported_symbols_list Ar file
412 The specified
413 .Ar filename
414 contains a list of global symbol names that will not remain as global symbols in the output file.
415 The symbols will be treated as if they were marked as __private_extern__ (aka visibility=hidden) and will not be global
416 in the output file. The symbol names listed in filename must be one per line.
417 Leading and trailing white space are not part of the symbol name.
418 Lines starting with # are ignored, as are lines with only white space.
419 Some wildcards (similar to shell file matching) are supported. The * matches zero or more characters.
420 The ? matches one character. [abc] matches one character which must be an 'a', 'b', or 'c'. [a-z] matches
421 any single lower case letter from 'a' to 'z'.
422 .It Fl unexported_symbol Ar symbol
423 The specified
424 .Ar symbol
425 is added to the list of global symbols names that will not remain as global symbols in the output file. This
426 option can be used multiple times. For short lists, this can be more convenient than creating a file and using
427 -unexported_symbols_list.
428 .It Fl reexported_symbols_list Ar file
429 The specified
430 .Ar filename
431 contains a list of symbol names that are implemented in a dependent dylib and should be re-exported
432 through the dylib being created.
433 .It Fl alias Ar symbol_name Ar alternate_symbol_name
434 Create an alias named
435 .Ar alternate_symbol_name
436 for the symbol
437 .Ar symbol_name .
438 By default the alias symbol has global visibility. This option was previous the -idef:indir option.
439 .It Fl alias_list Ar filename
440 The specified
441 .Ar filename
442 contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace.
443 Lines starting with # are ignored.
444 .It Fl flat_namespace
445 Alters how symbols are resolved at build time and runtime. With -two_levelnamespace (the default), the linker
446 only searches dylibs on the command line for symbols, and records in which dylib they were found. With -flat_namespace,
447 the linker searches all dylibs on the command line and all dylibs those original dylibs depend on. The linker
448 does not record which dylib an external symbol came from, so at runtime dyld again searches all images and uses
449 the first definition it finds. In addition, any undefines in loaded flat_namespace dylibs must be resolvable
450 at build time.
451 .It Fl u Ar symbol_name
452 Specified that symbol
453 .Ar symbol_name
454 must be defined for the link to succeed. This is useful to force selected functions to be loaded
455 from a static library.
456 .It Fl U Ar symbol_name
457 Specified that it is ok for
458 .Ar symbol_name
459 to have no definition. With -two_levelnamespace, the resulting symbol will be marked dynamic_lookup which
460 means dyld will search all loaded images.
461 .It Fl undefined Ar treatment
462 Specifies how undefined symbols are to be treated. Options are: error, warning, suppress, or dynamic_lookup. The
463 default is error.
464 .It Fl rpath Ar path
465 Add
466 .Ar path
467 to the runpath search path list for image being created. At runtime, dyld uses the runpath when searching
468 for dylibs whose load path begins with @rpath/.
469 .It Fl commons Ar treatment
470 Specifies how commons (aka tentative definitions) are resolved with respect to dylibs. Options are:
471 ignore_dylibs, use_dylibs, error. The default is ignore_dylibs which means the linker will turn a tentative
472 definition in an object file into a real definition and not even check dylibs for conflicts. The dylibs
473 option means the linker should check linked dylibs for definitions and use them to replace tentative definitions
474 from object files. The error option means the linker should issue an error whenever a tentative definition in an
475 object file conflicts with an external symbol in a linked dylib. See also -warn_commons.
476 .El
477 .Ss Options for introspecting the linker
478 .Bl -tag
479 .It Fl why_load
480 Log why each object file in a static library is loaded. That is, what symbol was needed. Also called -whyload
481 for compatibility.
482 .It Fl why_live Ar symbol_name
483 Logs a chain of references to
484 .Ar symbol_name .
485 Only applicable with -dead_strip .
486 It can help debug why something that you think should be dead strip removed is not removed.
487 See -exported_symbols_list for syntax and use of wildcards.
488 .It Fl print_statistics
489 Logs information about the amount of memory and time the linker used.
490 .It Fl t
491 Logs each file (object, archive, or dylib) the linker loads. Useful for debugging problems with search paths where the wrong library is loaded.
492 .It Fl whatsloaded
493 Logs just object files the linker loads.
494 .It Fl order_file_statistics
495 Logs information about the processing of a -order_file.
496 .It Fl map Ar map_file_path
497 Writes a map file to the specified path which details all symbols and their addresses in the output image.
498 .El
499 .Ss Options for controling symbol table optimizations
500 .Bl -tag
501 .It Fl S
502 Do not put debug information (STABS or DWARF) in the output file.
503 .It Fl x
504 Do not put non-global symbols in the output file's symbol table. Non-global symbols are useful when debugging and
505 getting symbol names in back traces, but are not used at runtime. If -x is used with -r
506 non-global symbol names are not removed, but instead replaced with a unique, dummy name
507 that will be automatically removed when linked into a final linked image. This
508 allows dead code stripping, which uses symbols to break up code and data, to
509 work properly and provides the security of having source symbol names removed.
510 .It Fl non_global_symbols_strip_list Ar filename
511 The specified
512 .Ar filename
513 contains a list of non-global symbol names that should be removed from the output file's symbol table. All other
514 non-global symbol names will remain in the output files symbol table. See -exported_symbols_list for syntax and use
515 of wildcards.
516 .It Fl non_global_symbols_no_strip_list Ar filename
517 The specified
518 .Ar filename
519 contains a list of non-global symbol names that should be remain in the output file's symbol table. All other
520 symbol names will be removed from the output file's symbol table. See -exported_symbols_list for syntax and use
521 of wildcards.
522 .El
523 .Ss Options for Bitcode build flow
524 .Bl -tag
525 .It Fl bitcode_bundle
526 Generates an embedded bitcode bundle in the output binary. The bitcode bundle is embedded in __LLVM, __bundle section.
527 This option requires all the object files, static libraries and user frameworks/dylibs contain bitcode.
528 Note: not all the linker options are supported to use together with -bitcode_bundle.
529 .It Fl bitcode_hide_symbol
530 Specifies this option together with -bitcode_bundle to hide all non-exported symbols from output bitcode bundle.
531 The hide symbol process might not be reversible. To obtain a reverse mapping file to recover all the symbols, use
532 -bitcode_symbol_map option.
533 .It Fl bitcode_symbol_map Ar path
534 Specifies the output for bitcode symbol reverse mapping (.bcsymbolmap). If
535 .Ar path
536 is an existing directory, UUID.bcsymbolmap will be written to that directory.
537 Otherwise, the reverse map will be written to a file at
538 .Ar path .
539 .El
540 .Ss Rarely used Options
541 .Bl -tag
542 .It Fl v
543 Prints the version of the linker.
544 .It Fl no_deduplicate
545 Don't run deduplication pass in linker
546 .It Fl verbose_deduplicate
547 Prints names of functions that are eliminated by deduplication and total code savings size.
548 .It Fl dirty_data_list Ar filename
549 Specifies a file containing the names of data symbols likely to be dirtied.
550 If the linker is creating a __DATA_DIRTY segment, those symbols will be moved
551 to that segment.
552 .It Fl max_default_common_align Ar value
553 Any common symbols (aka tentative definitions, or uninitialized (zeroed) variables) that have no explicit alignment
554 are normally aligned to their next power of two size (e.g. a 240 byte array is 256 aligned).
555 This option lets you reduce the max alignment. For instance, a value of 0x40 would reduce
556 the alignment for a 240 byte array to 64 bytes (instead of 256). The value specified must be a hexadecimal power of two
557 If -max_default_common_align is not used, the default alignment is already
558 limited to 0x8 (2^3) bytes for -preload and 0x8000 (2^15) for all other output types.
559 .It Fl move_to_rw_segment Ar segment_name Ar filename
560 Moves data symbols to another segment. The command line option specifies the
561 target segment name and a path to a file containing a list of symbols to move.
562 Comments can be added to the symbol file by starting a line with a #.
563 If there are multiple instances of a symbol name (for instance a "static int foo=5;" in multiple files)
564 the symbol name in the symbol list file can be prefixed with the object file name
565 (e.g. "init.o:_foo") to move a specific instance.
566 .It Fl move_to_ro_section Ar segment_name Ar section_name Ar filename
567 Moves code symbols to another segment. The command line option specifies the
568 target segment name and a path to a file containing a list of symbols to move.
569 Comments can be added to the symbol file by starting a line with a #.
570 If there are multiple instances of a symbol name (for instance a "static int foo() {}" in multiple files)
571 the symbol name in the symbol list file can be prefixed with the object file name
572 (e.g. "init.o:_foo") to move a specific instance.
573 .It Fl rename_section Ar orgSegment orgSection newSegment newSection
574 Renames section orgSegment/orgSection to newSegment/newSection.
575 .It Fl rename_segment Ar orgSegment newSegment
576 Renames all sections with orgSegment segment name to have newSegment segment name.
577 .It Fl trace_symbol_layout
578 For using in debugging -rename_section, -rename_segment, -move_to_ro_segment, and -move_to_rw_segment.
579 This option prints out a line show where and why each symbol was moved.
580 Note: These options do not chain. For each symbol, the linker first checks
581 -move_to_ro_segment and -move_to_rw_segment. If the symbol is not moved,
582 it checks for an applicable -rename_section. Only if the symbol still has
583 not been moved, does the linker look for an applicable -rename_segment option.
584 .It Fl section_order Ar segname Ar colon_separated_section_list
585 Only for use with -preload. Specifies the order that sections with the specified segment should be layout out.
586 For example: "-section_order __ROM __text:__const:__cstring".
587 .It Fl segment_order Ar colon_separated_segment_list
588 Only for use with -preload. Specifies the order segments should be layout out.
589 For example: "-segment_order __ROM:__ROM2:__RAM".
590 .It Fl allow_heap_execute
591 Normally i386 main executables will be marked so that the Mac OS X 10.7 and later kernel
592 will only allow pages with the x-bit to execute instructions. This option overrides that
593 behavior and allows instructions on any page to be executed.
594 .It Fl application_extension
595 Specifies that the code is being linked for use in an application extension. The linker
596 will then validiate that any dynamic libraries linked against are safe for use in
597 application extensions.
598 .It Fl no_application_extension
599 Specifies that the code is being linked is not safe for use in an application extension.
600 For instance, can be used when creating a framework that should not be used in
601 an application extension.
602 .It Fl fatal_warnings
603 Causes the linker to exit with a non-zero value if any warnings were emitted.
604 .It Fl no_eh_labels
605 Normally in -r mode, the linker produces .eh labels on all FDEs in the __eh_frame section.
606 This option suppresses those labels. Those labels are not needed by the Mac OS X 10.6
607 linker but are needed by earlier linker tools.
608 .It Fl warn_compact_unwind
609 When producing a final linked image, the linker processes the __eh_frame section and
610 produces an __unwind_info section. Most FDE entries in the __eh_frame can be represented
611 by a 32-bit value in the __unwind_info section. The option issues a warning for
612 any function whose FDE cannot be expressed in the compact unwind format.
613 .It Fl warn_weak_exports
614 Issue a warning if the resulting final linked image contains weak external symbols. Such
615 symbols require dyld to do extra work at launch time to coalesce those symbols.
616 .It Fl objc_gc_compaction
617 Marks the Objective-C image info in the final linked image with the bit that says that the
618 code was built to work the compacting garbage collection.
619 .It Fl objc_gc
620 Verifies all code was compiled with -fobjc-gc or -fobjc-gc-only.
621 .It Fl objc_gc_only
622 Verifies all code was compiled with -fobjc-gc-only.
623 .It Fl dead_strip_dylibs
624 Remove dylibs that are unreachable by the entry point or exported symbols. That is,
625 suppresses the generation of load command commands for dylibs which supplied no
626 symbols during the link. This option should not be used when linking against a dylib which
627 is required at runtime for some indirect reason such as the dylib has an important initializer.
628 .It Fl allow_sub_type_mismatches
629 Normally the linker considers different cpu-subtype for ARM (e.g. armv4t and armv6) to be different
630 different architectures that cannot be mixed at build time. This option relaxes that requirement,
631 allowing you to mix object files compiled for different ARM subtypes.
632 .It Fl no_uuid
633 Do not generate an LC_UUID load command in the output file.
634 .It Fl root_safe
635 Sets the MH_ROOT_SAFE bit in the mach header of the output file.
636 .It Fl setuid_safe
637 Sets the MH_SETUID_SAFE bit in the mach header of the output file.
638 .It Fl interposable
639 Indirects access to all to exported symbols when creating a dynamic library.
640 .It Fl init Ar symbol_name
641 The specified symbol_name will be run as the first initializer. Only used when creating a dynamic library.
642 .It Fl sub_library Ar library_name
643 The specified dylib will be re-exported. For example the library_name for /usr/lib/libobjc_profile.A.dylib would be libobjc.
644 Only used when creating a dynamic library.
645 .It Fl sub_umbrella Ar framework_name
646 The specified framework will be re-exported. Only used when creating a dynamic library.
647 .It Fl allowable_client Ar name
648 Restricts what can link against the dynamic library being created. By default any code
649 can link against any dylib. But if a dylib is supposed to be private to a small
650 set of clients, you can formalize that by adding a -allowable_client for each client.
651 If a client is libfoo.1.dylib its -allowable_client name would be "foo". If a
652 client is Foo.framework its -allowable_client name would be "Foo". For the degenerate
653 case where you want no one to ever link against a dylib, you can set the
654 -allowable_client to "!".
655 .It Fl client_name Ar name
656 Enables a bundle to link against a dylib that was built with -allowable_client.
657 The name specified must match one of the -allowable_client names specified when the dylib was created.
658 .It Fl umbrella Ar framework_name
659 Specifies that the dylib being linked is re-exported through an umbrella framework of the specified name.
660 .It Fl headerpad Ar size
661 Specifies the minimum space for future expansion of the load commands. Only useful if intend to run
662 install_name_tool to alter the load commands later. Size is a hexadecimal number.
663 .It Fl headerpad_max_install_names
664 Automatically adds space for future expansion of load commands such that all paths could expand to MAXPATHLEN.
665 Only useful if intend to run install_name_tool to alter the load commands later.
666 .It Fl bind_at_load
667 Sets a bit in the mach header of the resulting binary which tells dyld to bind all symbols when the binary is loaded, rather than lazily.
668 .It Fl force_flat_namespace
669 Sets a bit in the mach header of the resulting binary which tells dyld to not only use flat namespace for the binary,
670 but force flat namespace binding on all dylibs and bundles loaded in the process. Can only be used when linking main executables.
671 .It Fl sectalign Ar segname Ar sectname Ar value
672 The section named sectname in the segment segname will have its alignment set to value, where value is a hexadecimal
673 number that must be an integral power of 2.
674 .It Fl stack_addr Ar address
675 Specifies the initial address of the stack pointer value, where value is a hexadecimal number rounded to a page boundary.
676 .It Fl segprot Ar segname Ar max_prot Ar init_prot
677 Specifies the maximum and initial virtual memory protection of the named segment, name, to be max and init ,respectively.
678 The values for max and init are any combination of the characters `r' (for read), `w' (for write), `x' (for execute) and `-' (no access).
679 .It Fl seg_addr_table Ar filename
680 Specifies a file containing base addresses for dynamic libraries. Each line of the file is a hexadecimal base address
681 followed by whitespace then the install name of the corresponding dylib. The # character denotes a comment.
682 .It Fl segs_read_write_addr Ar address
683 Allows a dynamic library to be built where the read-only and read-write segments are not contiguous. The address
684 specified is a hexadecimal number that indicates the base address for the read-write segments.
685 .It Fl segs_read_only_addr Ar address
686 Allows a dynamic library to be built where the read-only and read-write segments are not contiguous. The address
687 specified is a hexadecimal number that indicates the base address for the read-only segments.
688 .It Fl segaddr Ar name Ar address
689 Specifies the starting address of the segment named name to be address. The address must be a hexadecimal number
690 that is a multiple of 4K page size.
691 .It Fl seg_page_size Ar name Ar size
692 Specifies the page size used by the specified segment. By default the page size is 4096 for all segments.
693 The linker will lay out segments such that size of a segment is always an even multiple of its page size.
694 .It Fl dylib_file Ar install_name:file_name
695 Specifies that a dynamic shared library is in a different location than its standard location. Use this option
696 when you link with a library that is dependent on a dynamic library, and the dynamic library is in a location other
697 than its default location. install_name specifies the path where the library normally resides. file_name specifies
698 the path of the library you want to use instead. For example, if you link to a library that depends upon the dynamic
699 library libsys and you have libsys installed in a nondefault location, you would use this option:
700 -dylib_file /lib/libsys_s.A.dylib:/me/lib/libsys_s.A.dylib.
701 .It Fl prebind
702 The created output file will be in the prebound format. This was used in Mac OS X 10.3 and earlier to improve launch performance.
703 .It Fl weak_reference_mismatches Ar treatment
704 Specifies what to do if a symbol is weak-imported in one object file but not weak-imported in another. The valid
705 treatments are: error, weak, or non-weak. The default is non-weak.
706 .It Fl read_only_relocs Ar treatment
707 Enables the use of relocations which will cause dyld to modify (copy-on-write) read-only pages. The compiler will
708 normally never generate such code.
709 .It Fl force_cpusubtype_ALL
710 The is only applicable with -arch ppc. It tells the linker to ignore the PowerPC cpu requirements (e.g. G3, G4 or G5) encoded
711 in the object files and mark the resulting binary as runnable on any PowerPC cpu.
712 .It Fl dylinker_install_name Ar path
713 Only used when building dyld.
714 .It Fl no_arch_warnings
715 Suppresses warning messages about files that have the wrong architecture for the -arch flag
716 .It Fl arch_errors_fatal
717 Turns into errors, warnings about files that have the wrong architecture for the -arch flag.
718 .It Fl e Ar symbol_name
719 Specifies the entry point of a main executable. By default the entry name is "start" which is found in crt1.o which contains
720 the glue code need to set up and call main().
721 .It Fl w
722 Suppress all warning messages
723 .It Fl final_output Ar name
724 Specifies the install name of a dylib if -install_name is not used. This option is used by gcc driver when it is invoked
725 with multiple -arch arguments.
726 .It Fl arch_multiple
727 Specifes that the linker should augment error and warning messages with the architecture name. This option is used by gcc
728 driver when it is invoked with multiple -arch arguments.
729 .It Fl twolevel_namespace_hints
730 Specifies that hints should be added to the resulting binary that can help speed up runtime binding by dyld as long as the
731 libraries being linked against have not changed.
732 .It Fl dot Ar path
733 Create a file at the specified path containing a graph of symbol dependencies. The .dot file can be viewed in GraphViz.
734 .It Fl keep_relocs
735 Add section based relocation records to a final linked image. These relocations are ignored at runtime by dyld.
736 .It Fl warn_stabs
737 Print a warning when the linker cannot do a BINCL/EINCL optimization because the compiler put a bad stab symbol inside
738 a BINCL/EINCL range.
739 .It Fl warn_commons
740 Print a warning whenever the a tentative definition in an object file is found and a external symbol by the same name
741 is also found in a linked dylib. This often means that the extern keyword is missing from a variable declaration
742 in a header file.
743 .It Fl read_only_stubs
744 [i386 only] Makes the __IMPORT segment of a final linked images read-only. This option makes a program slightly more
745 secure in that the JMP instructions in the i386 fast stubs cannot be easily overwritten by malicious code. The downside
746 is the dyld must use mprotect() to temporarily make the segment writable while it is binding the stubs.
747 .It Fl slow_stubs
748 [i386 only] Instead of using single JMP instruction stubs, the linker creates code in the __TEXT segment which
749 calls through a lazy pointer in the __DATA segment.
750 .It Fl interposable_list Ar filename
751 The specified
752 .Ar filename
753 contains a list of global symbol names that should always be accessed indirectly. For instance, if libSystem.dylib
754 is linked such that _malloc is interposable, then calls to malloc() from within libSystem will go through a dyld
755 stub and could potentially indirected to an alternate malloc. If libSystem.dylib were built without making _malloc
756 interposable then if _malloc was interposed at runtime, calls to malloc from with libSystem would be missed
757 (not interposed) because they would be direct calls.
758 .It Fl no_function_starts
759 By default the linker creates a compress table of function start addresses in the LINKEDIT of
760 final linked image. This option disables that behavior.
761 .It Fl no_version_load_command
762 By default the linker creates a load command in final linked images that contains the -macosx_version_min.
763 This option disables that behavior.
764 .It Fl no_objc_category_merging
765 By default when producing final linked image, the linker will optimize Objective-C classes by merging
766 any categories on a class into the class. Both the class and its categories must be defined in the image
767 being linked for the optimization to occur. Using this option disables that behavior.
768 .It Fl object_path_lto Ar filename
769 When performing Link Time Optimization (LTO) and a temporary mach-o object file is needed, if this
770 option is used, the temporary file will be stored at the specified path and remain after the link
771 is complete. Without the option, the linker picks a path and deletes the object file before the linker
772 tool completes, thus tools such as the debugger or dsymutil will not be able to access the DWARF debug
773 info in the temporary object file.
774 .It Fl lto_library Ar path
775 When performing Link Time Optimization (LTO), the linker normally loads libLTO.dylib relative to the linker
776 binary (../lib/libLTO.dylib). This option allows the user to specify the path to a specific libLTO.dylib
777 to load instead.
778 .It Fl page_align_data_atoms
779 During development, this option can be used to space out all global variables so each is on a separate page.
780 This is useful when analyzing dirty and resident pages. The information can then be used to create an
781 order file to cluster commonly used/dirty globals onto the same page(s).
782 .It Fl not_for_dyld_shared_cache
783 Normally, the linker will add extra info to dylibs with -install_name starting with /usr/lib or
784 /System/Library/ that allows the dylib to be placed into the dyld shared cache. Adding this option
785 tells the linker to not add that extra info.
786 .El
787 .Ss Obsolete Options
788 .Bl -tag
789 .It Fl segalign Ar value
790 All segments must be page aligned.
791 .It Fl seglinkedit
792 Object files (MH_OBJECT) with a LINKEDIT segment are no longer supported. This option is obsolete.
793 .It Fl noseglinkedit
794 This is the default. This option is obsolete.
795 .It Fl fvmlib
796 Fixed VM shared libraries (MH_FVMLIB) are no longer supported. This option is obsolete.
797 .It Fl sectobjectsymbols Ar segname Ar sectname
798 Adding a local label at a section start is no longer supported. This option is obsolete.
799 .It Fl nofixprebinding
800 The MH_NOFIXPREBINDING bit of mach_headers has been ignored since Mac OS X 10.3.9. This option is obsolete.
801 .It Fl noprebind_all_twolevel_modules
802 Multi-modules in dynamic libraries have been ignored at runtime since Mac OS X 10.4.0. This option is obsolete.
803 .It Fl prebind_all_twolevel_modules
804 Multi-modules in dynamic libraries have been ignored at runtime since Mac OS X 10.4.0. This option is obsolete.
805 .It Fl prebind_allow_overlap
806 When using -prebind, the linker allows overlapping by default, so this option is obsolete.
807 .It Fl noprebind
808 LD_PREBIND is no longer supported as a way to force on prebinding, so there no longer needs to
809 be a command line way to override LD_PREBIND. This option is obsolete.
810 .It Fl sect_diff_relocs Ar treatment
811 This option was an attempt to warn about linking .o files compiled without -mdynamic-no-pic into
812 a main executable, but the false positive rate generated too much noise to make the option useful.
813 This option is obsolete.
814 .It Fl run_init_lazily
815 This option was removed in Mac OS X 10.2.
816 .It Fl single_module
817 This is now the default so does not need to be specified.
818 .It Fl multi_module
819 Multi-modules in dynamic libraries have been ignored at runtime since Mac OS X 10.4.0. This option is obsolete.
820 .It Fl no_dead_strip_inits_and_terms
821 The linker never dead strips initialization and termination routines. They are considered "roots" of the dead strip graph.
822 .It Fl A Ar basefile
823 Obsolete incremental load format. This option is obsolete.
824 .It Fl b
825 Used with -A option to strip base file's symbols. This option is obsolete.
826 ..It Fl M
827 Obsolete option to produce a load map. Use -map option instead.
828 .It Fl Sn
829 Don't strip any symbols. This is the default. This option is obsolete.
830 .It Fl Si
831 Optimize stabs debug symbols to remove duplicates. This is the default. This option is obsolete.
832 .It Fl Sp
833 Write minimal stabs which causes the debugger to open and read the original .o file for full stabs.
834 This style of debugging is obsolete in Mac OS X 10.5. This option is obsolete.
835 .It Fl X
836 Strip local symbols that begin with 'L'. This is the default. This option is obsolete.
837 .It Fl s
838 Completely strip the output, including removing the symbol table. This file format variant is no longer supported.
839 This option is obsolete.
840 .It Fl m
841 Don't treat multiple definitions as an error. This is no longer supported. This option is obsolete.
842 .It Fl y Ns symbol
843 Display each file in which
844 .Ar symbol
845 is used. This was previously used to debug where an undefined symbol was used, but the linker now
846 automatically prints out all usages. The -why_live option can also be used to display what kept
847 a symbol from being dead striped. This option is obsolete.
848 .It Fl Y Ar number
849 Used to control how many occurrences of each symbol specified with -y would be shown. This option is obsolete.
850 .It Fl nomultidefs
851 Only used when linking an umbrella framework. Sets the MH_NOMULTIDEFS bit in the mach_header. The MH_NOMULTIDEFS
852 bit has been obsolete since Mac OS X 10.4. This option is obsolete.
853 .It Fl multiply_defined_unused Ar treatment
854 Previously provided a way to warn or error if any of the symbol definitions in the output file matched any
855 definitions in dynamic library being linked. This option is obsolete.
856 .It Fl multiply_defined Ar treatment
857 Previously provided a way to warn or error if any of the symbols used from a dynamic library were also
858 available in another linked dynamic library. This option is obsolete.
859 .It Fl private_bundle
860 Previously prevented errors when -flat_namespace, -bundle, and -bundle_loader were used and the bundle
861 contained a definition that conflicted with a symbol in the main executable. The linker no longer
862 errors on such conflicts. This option is obsolete.
863 .It Fl noall_load
864 This is the default. This option is obsolete.
865 .It Fl seg_addr_table_filename Ar path
866 Use
867 .Ar path
868 instead of the install name of the library for matching an entry in the seg_addr_table. This option is obsolete.
869 .It Fl sectorder Ar segname sectname orderfile
870 Replaced by more general -order_file option.
871 .It Fl sectorder_detail
872 Produced extra logging about which entries from a sectorder entries were used. Replaced by -order_file_statistics.
873 This option is obsolete.
874 .El
875 .Sh SEE ALSO
876 as(1), ar(1), cc(1), nm(1), otool(1) lipo(1),
877 arch(3), dyld(3), Mach-O(5), strip(1), rebase(1)