1 .\" This file is distributed under the University of Illinois Open Source
2 .\" License. See LICENSE.TXT for details.
4 .\" This man page documents only lld's ELF linking support, obtained originally
11 .Nd ELF linker from the LLVM project
17 A linker takes one or more object, archive, and library files, and combines
18 them into an output file (an executable, a shared library, or another object
20 It relocates code and data from the input files and resolves symbol
21 references between them.
24 is a drop-in replacement for the GNU BFD and gold linkers.
25 It accepts most of the same command line arguments and linker scripts
28 These options are available:
29 .Bl -tag -width indent
30 .It Fl -allow-multiple-definition
31 Do not error if a symbol is defined multiple times.
32 The first definition will be used.
36 for shared libraries if used.
37 .It Fl -auxiliary Ns = Ns Ar value
40 field to the specified name.
42 Link against shared libraries.
44 Do not link against shared libraries.
45 .It Fl -Bsymbolic-functions
46 Bind defined function symbols locally.
48 Bind defined symbols locally.
49 .It Fl -build-id Ns = Ns Ar value
50 Generate a build ID note.
58 .Cm 0x Ns Ar hex-string ,
70 are calculated from the object contents.
72 is not intended to be cryptographically secure.
75 .Fl -build-id Ns = Ns Cm fast .
76 .It Fl -color-diagnostics Ns = Ns Ar value
77 Use colors in diagnostics.
85 enables color if and only if output is to a terminal.
86 .It Fl -color-diagnostics
88 .Fl -color-diagnostics Ns = Ns Cm auto .
89 .It Fl -compress-debug-sections Ns = Ns Ar value
90 Compress DWARF debug sections.
97 Assign space to common symbols.
98 .It Fl -defsym Ns = Ns Ar symbol Ns = Ns Ar expression
99 Define a symbol alias.
101 may be another symbol or a linker script expression.
105 .Ql --defsym=foo=bar+0x100 .
107 Demangle symbol names.
108 .It Fl -disable-new-dtags
109 Disable new dynamic tags.
111 Delete all local symbols.
112 .It Fl -discard-locals
113 Delete temporary local symbols.
115 Keep all symbols in the symbol table.
116 .It Fl -dynamic-linker Ns = Ns Ar value
117 Specify the dynamic linker to be used for a dynamically linked executable.
118 This is recorded in an ELF segment of type
120 .It Fl -dynamic-list Ns = Ns Ar file
121 Read a list of dynamic symbols from
130 Generate relocations in the output.
131 .It Fl -enable-new-dtags
132 Enable new dynamic tags.
134 End a grouping of objects that should be treated as if they were together
136 .It Fl -entry Ns = Ns Ar entry
137 Name of entry point symbol.
138 .It Fl -error-limit Ns = Ns Ar value
139 Maximum number of errors to emit before stopping.
140 A value of zero indicates that there is no limit.
141 .It Fl -error-unresolved-symbols
142 Report unresolved symbols as errors.
143 .It Fl -exclude-libs Ns = Ns Ar value
144 Exclude static libraries from automatic export.
145 .It Fl -export-dynamic-symbol Ns = Ns Ar symbol
148 in the dynamic symbol table.
149 .It Fl -export-dynamic
150 Put symbols in the dynamic symbol table.
151 .It Fl -fatal-warnings
152 Treat warnings as errors.
153 .It Fl -filter Ns = Ns Ar value
156 field to the specified value.
157 .It Fl -fini Ns = Ns Ar symbol
158 Specify a finalizer function.
159 .It Fl -format Ns = Ns Ar input-format
160 Specify the format of the inputs following this option.
171 Enable garbage collection of unused sections.
176 .It Fl -hash-style Ns = Ns Ar value
187 Print a help message.
188 .It Fl -icf Ns = Ns Cm all
189 Enable identical code folding.
190 .It Fl -icf Ns = Ns Cm safe
191 Enable safe identical code folding.
192 .It Fl -icf Ns = Ns Cm none
193 Disable identical code folding.
194 .It Fl -image-base Ns = Ns Ar value
195 Set the base address to
197 .It Fl -init Ns = Ns Ar symbol
198 Specify an initializer function.
199 .It Fl -lto-aa-pipeline Ns = Ns Ar value
200 AA pipeline to run during LTO.
201 Used in conjunction with
202 .Fl -lto-newpm-passes .
203 .It Fl -lto-newpm-passes Ns = Ns Ar value
204 Passes to run during LTO.
205 .It Fl -lto-O Ns Ar opt-level
206 Optimization level for LTO.
207 .It Fl -lto-partitions Ns = Ns Ar value
208 Number of LTO codegen partitions.
210 Add a directory to the library search path.
212 Root name of library to use.
213 .It Fl -Map Ns = Ns Ar file
217 Set target emulation.
221 for shared libraries.
222 .It Fl -no-color-diagnostics
223 Do not use colors in diagnostics.
224 .It Fl -no-define-common
225 Do not assign space to common symbols.
227 Do not demangle symbol names.
228 .It Fl -no-dynamic-linker
232 .It Fl -no-gc-sections
233 Disable garbage collection of unused sections.
234 .It Fl -no-gnu-unique
235 Disable STB_GNU_UNIQUE symbol binding.
237 Do not put read-only non-executable sections in their own segment.
239 Do not run the linker multi-threaded.
240 .It Fl -no-undefined-version
241 Report version scripts that refer undefined symbols.
243 Report unresolved symbols even if the linker is creating a shared library.
244 .It Fl -no-whole-archive
245 Restores the default behavior of loading archive members.
246 .It Fl -noinhibit-exec
247 Retain the executable output file whenever it is still usable.
249 Do not create a position independent executable.
251 Only search directories specified on the command line.
252 .It Fl -oformat Ns = Ns Ar format
253 Specify the format for the output object file.
258 which produces output with no ELF header.
260 Set the text and data sections to be readable and writable.
261 .It Fl -opt-remarks-filename Ar file
262 Write optimization remarks in YAML format to
264 .It Fl -opt-remarks-with-hotness
265 Include hotness information in the optimization remarks file.
267 Optimize output file size.
271 .Bl -tag -width 2n -compact
273 Disable string merging.
275 Enable string merging.
277 Enable string tail merging.
283 Write the output executable, library, or object to
287 is used as a default.
289 Create a position independent executable.
290 .It Fl -print-gc-sections
291 List removed unused sections.
293 Print a link map to the standard output.
295 Save the current state of
304 Create relocatable object file.
305 .It Fl -reproduce Ns = Ns Ar value
306 Dump linker invocation and input files for debugging.
307 .It Fl -retain-symbols-file Ns = Ns Ar file
308 Retain only the symbols listed in the file.
309 .It Fl -rpath Ns = Ns Ar value
313 .It Fl -rsp-quoting Ns = Ns Ar value
314 Quoting style for response files.
315 The supported values are
319 .It Fl -script Ns = Ns Ar file
320 Read linker script from
322 .It Fl -section-start Ns = Ar section Ns = Ns Ar address
323 Set address of section.
325 Build a shared object.
326 .It Fl -soname Ns = Ns Ar value
331 .It Fl -sort-section Ns = Ns Ar value
332 Specifies sections sorting rule when linkerscript is used.
334 Start a grouping of objects that should be treated as if they were together
339 Strip debugging information.
340 .It Fl -symbol-ordering-file Ns = Ns Ar file
341 Lay out sections in the order specified by
343 .It Fl -sysroot Ns = Ns Ar value
355 .It Fl -target2 Ns = Ns Ar type
367 .It Fl -Tbss Ns = Ns Ar value
373 .It Fl -Tdata Ns = Ns Ar value
379 .It Fl -thinlto-cache-dir Ns = Ns Ar value
380 Path to ThinLTO cached object file directory.
381 .It Fl -thinlto-cache-policy Ns = Ns Ar value
382 Pruning policy for the ThinLTO cache.
383 .It Fl -thinlto-jobs Ns = Ns Ar value
384 Number of ThinLTO jobs.
386 Run the linker multi-threaded.
387 This option is enabled by default.
388 .It Fl -trace-symbol Ns = Ns Ar symbol
392 Print the names of the input files.
393 .It Fl -Ttext Ns = Ns Ar value
399 .It Fl -undefined Ns = Ns Ar symbol
402 to be an undefined symbol during linking.
403 .It Fl -unresolved-symbols Ns = Ns Ar value
404 Determine how to handle unresolved symbols.
407 .It Fl -version-script Ns = Ns Ar file
408 Read version script from
410 .It Fl V , Fl -version
411 Display the version number and exit.
413 Display the version number and proceed with linking if object files are
415 .It Fl -warn-backrefs
416 Warn about reverse or cyclic dependencies to or between static archives.
417 This can be used to ensure linker invocation remains compatible with
418 traditional Unix-like linkers.
420 Warn about duplicate common symbols.
421 .It Fl -warn-unresolved-symbols
422 Report unresolved symbols as warnings.
423 .It Fl -whole-archive
424 Force load of all members in a static library.
425 .It Fl -wrap Ns = Ns Ar symbol
426 Use wrapper functions for symbol.
428 Linker option extensions.
429 .Bl -tag -width indent
431 Make the main stack executable.
432 Stack permissions are recorded in the
436 Do not error if a symbol is defined multiple times.
437 The first definition will be used.
438 This is a synonym for
439 .Fl -allow-multiple-definition.
441 Disable combining and sorting multiple relocation sections.
443 Disable the creation of copy relocations.
447 flag to indicate that the object cannot be unloaded from a process.
451 flag to indcate that the object may not be opened by
454 Do not indicate that portions of the object shold be mapped read-only
455 after initial relocation processing.
456 The object will omit the
460 Allow relocations against read-only segments.
462 .Dv DT_TEXTREL flag in the
468 flag to indicate that the run-time loader should perform all relocation
469 processing as part of object initialization.
470 By default relocations may be performed on demand.
474 flag to indicate that the object requires
478 Emit retpoline format PLT entries as a mitigation for CVE-2017-5715.
485 tag will not be emitted.
486 .It Cm stack-size Ns = Ns Ar size
487 Set the main thread's stack size to
489 The stack size is recorded as the size of the
494 Do not allow relocations against read-only segments.
498 .Dv PT_OPENBSD_WXNEEDED
502 .Sh IMPLEMENTATION NOTES
504 handing of archive files (those with a
506 file extension) is different from traditional linkers used on Unix-like
509 Traditional linkers maintain a set of undefined symbols during linking.
510 The linker processes each file in the order in which it appears on the
511 command line, until the set of undefined symbols becomes empty.
512 An object file is linked into the output object when it is encountered,
513 with its undefined symbols added to the set.
514 Upon encountering an archive file a traditional linker searches the objects
515 contained therein, and processes those that satisfy symbols in the unresolved
518 Handling mutually dependent archives may be awkward when using a traditional
520 Archive files may have to be specified multiple times, or the special command
525 may be used to have the linker loop over the files in the group until no new
526 symbols are added to the set.
529 records all symbols found in objects and archives as it iterates over
530 command line arguments.
533 encounters an undefined symbol that can be resolved by an object file
534 contained in a previously processed archive file, it immediately extracts
535 and links it into the output object.
537 With certain archive inputs
539 may produce different results compared to traditional linkers.
540 In practice, large bodies of third party software have been linked with
542 without material issues.
546 option may be used to identify a linker invocation that may be incompatible
547 with traditional Unix-like linker behavior.