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
18 A linker takes one or more object, archive, and library files, and combines
19 them into an output file (an executable, a shared library, or another object
21 It relocates code and data from the input files and resolves symbol
22 references between them.
25 is a drop-in replacement for the GNU BFD and gold linkers.
26 It accepts most of the same command line arguments and linker scripts
30 currently supports i386, x86-64, ARM, AArch64, PowerPC32, PowerPC64,
31 MIPS32, MIPS64, RISC-V, AMDGPU, Hexagon and SPARC V9 targets.
33 acts as a Microsoft link.exe-compatible linker if invoked as
35 and as macOS's ld if invoked as
37 All these targets are always supported however
39 was built, so you can always use
41 as a native linker as well as a cross linker.
44 Many options have both a single-letter and long form.
45 When using the long form options other than those beginning with the
48 may be specified using either one or two dashes preceding the option name.
49 Long options beginning with
51 require two dashes to avoid confusion with the
55 .Bl -tag -width indent
56 .It Fl -allow-multiple-definition
57 Do not error if a symbol is defined multiple times.
58 The first definition will be used.
59 .It Fl -apply-dynamic-relocs
60 Apply link-time values for dynamic relocations.
64 for shared libraries if used.
65 .It Fl -auxiliary Ns = Ns Ar value
68 field to the specified name.
69 .It Fl -Bdynamic , Fl -dy
70 Link against shared libraries.
71 .It Fl -Bstatic , Fl -static , Fl -dn
72 Do not link against shared libraries.
74 Bind defined symbols locally.
75 .It Fl -Bsymbolic-functions
76 Bind defined function symbols locally.
77 .It Fl -build-id Ns = Ns Ar value
78 Generate a build ID note.
86 .Cm 0x Ns Ar hex-string ,
98 are calculated from the object contents.
100 is not intended to be cryptographically secure.
103 .Fl -build-id Ns = Ns Cm fast .
104 .It Fl -color-diagnostics Ns = Ns Ar value
105 Use colors in diagnostics.
113 enables color if and only if output is to a terminal.
114 .It Fl -color-diagnostics
116 .Fl -color-diagnostics Ns = Ns Cm auto .
117 .It Fl -compress-debug-sections Ns = Ns Ar value
118 Compress DWARF debug sections.
125 Output cross reference table.
126 .It Fl -define-common , Fl d
127 Assign space to common symbols.
128 .It Fl -defsym Ns = Ns Ar symbol Ns = Ns Ar expression
129 Define a symbol alias.
131 may be another symbol or a linker script expression.
135 .Ql --defsym=foo=bar+0x100 .
137 Demangle symbol names.
138 .It Fl -disable-new-dtags
139 Disable new dynamic tags.
140 .It Fl -discard-all , Fl x
141 Delete all local symbols.
142 .It Fl -discard-locals , Fl X
143 Delete temporary local symbols.
145 Keep all symbols in the symbol table.
146 .It Fl -dynamic-linker Ns = Ns Ar value
147 Specify the dynamic linker to be used for a dynamically linked executable.
148 This is recorded in an ELF segment of type
150 .It Fl -dynamic-list Ns = Ns Ar file
151 Read a list of dynamic symbols from
159 .It Fl -emit-relocs , Fl q
160 Generate relocations in the output.
161 .It Fl -enable-new-dtags
162 Enable new dynamic tags.
164 End a grouping of objects that should be treated as if they were together
166 .It Fl -entry Ns = Ns Ar entry
167 Name of entry point symbol.
168 .It Fl -error-limit Ns = Ns Ar value
169 Maximum number of errors to emit before stopping.
170 A value of zero indicates that there is no limit.
171 .It Fl -error-unresolved-symbols
172 Report unresolved symbols as errors.
174 Mark executable sections unreadable. This option is currently only
175 supported on AArch64.
176 .It Fl -exclude-libs Ns = Ns Ar value
177 Exclude static libraries from automatic export.
178 .It Fl -export-dynamic , Fl E
179 Put symbols in the dynamic symbol table.
180 .It Fl -export-dynamic-symbol Ns = Ns Ar symbol
183 in the dynamic symbol table.
184 .It Fl -fatal-warnings
185 Treat warnings as errors.
186 .It Fl -filter Ns = Ns Ar value , Fl F Ar value
189 field to the specified value.
190 .It Fl -fini Ns = Ns Ar symbol
191 Specify a finalizer function.
192 .It Fl -format Ns = Ns Ar input-format , Fl b Ar input-format
193 Specify the format of the inputs following this option.
204 Enable garbage collection of unused sections.
209 .It Fl -hash-style Ns = Ns Ar value
220 Print a help message.
221 .It Fl -icf Ns = Ns Cm all
222 Enable identical code folding.
223 .It Fl -icf Ns = Ns Cm safe
224 Enable safe identical code folding.
225 .It Fl -icf Ns = Ns Cm none
226 Disable identical code folding.
227 .It Fl -image-base Ns = Ns Ar value
228 Set the base address to
230 .It Fl -init Ns = Ns Ar symbol
231 Specify an initializer function.
232 .It Fl -keep-unique Ns = Ns Ar symbol
236 .It Fl l Ar libName, Fl -library Ns = Ns Ar libName
237 Root name of library to use.
238 .It Fl L Ar dir , Fl -library-path Ns = Ns Ar dir
239 Add a directory to the library search path.
240 .It Fl -lto-aa-pipeline Ns = Ns Ar value
241 AA pipeline to run during LTO.
242 Used in conjunction with
243 .Fl -lto-newpm-passes .
244 .It Fl -lto-newpm-passes Ns = Ns Ar value
245 Passes to run during LTO.
246 .It Fl -lto-O Ns Ar opt-level
247 Optimization level for LTO.
248 .It Fl -lto-partitions Ns = Ns Ar value
249 Number of LTO codegen partitions.
251 Set target emulation.
252 .It Fl -Map Ns = Ns Ar file , Fl M Ar file
258 for shared libraries.
259 .It Fl -no-color-diagnostics
260 Do not use colors in diagnostics.
261 .It Fl -no-define-common
262 Do not assign space to common symbols.
264 Do not demangle symbol names.
265 .It Fl -no-dynamic-linker
269 .It Fl -no-gc-sections
270 Disable garbage collection of unused sections.
271 .It Fl -no-gnu-unique
272 Disable STB_GNU_UNIQUE symbol binding.
274 Do not put read-only non-executable sections in their own segment.
276 Do not run the linker multi-threaded.
277 .It Fl -no-undefined-version
278 Report version scripts that refer undefined symbols.
280 Report unresolved symbols even if the linker is creating a shared library.
281 .It Fl -no-whole-archive
282 Restores the default behavior of loading archive members.
284 Do not create a position independent executable.
285 .It Fl -noinhibit-exec
286 Retain the executable output file whenever it is still usable.
288 Only search directories specified on the command line.
290 Write the output executable, library, or object to
294 is used as a default.
296 Optimize output file size.
300 .Bl -tag -width 2n -compact
302 Disable string merging.
304 Enable string merging.
306 Enable string tail merging.
311 .It Fl -oformat Ns = Ns Ar format
312 Specify the format for the output object file.
317 which produces output with no ELF header.
318 .It Fl -omagic , Fl N
319 Set the text and data sections to be readable and writable.
320 .It Fl -opt-remarks-filename Ar file
321 Write optimization remarks in YAML format to
323 .It Fl -opt-remarks-with-hotness
324 Include hotness information in the optimization remarks file.
326 Always generate position independent thunks.
328 Create a position independent executable.
329 .It Fl -print-gc-sections
330 List removed unused sections.
331 .It Fl -print-icf-sections
332 List identical folded sections.
334 Print a link map to the standard output.
336 Save the current state of
344 .It Fl -relocatable , Fl r
345 Create relocatable object file.
346 .It Fl -reproduce Ns = Ns Ar value
347 Dump linker invocation and input files for debugging.
348 .It Fl -retain-symbols-file Ns = Ns Ar file
349 Retain only the symbols listed in the file.
350 .It Fl -rpath Ns = Ns Ar value , Fl R Ar value
354 .It Fl -rsp-quoting Ns = Ns Ar value
355 Quoting style for response files.
356 The supported values are
360 .It Fl -script Ns = Ns Ar file , Fl T Ar file
361 Read linker script from
363 .It Fl -section-start Ns = Ns Ar section Ns = Ns Ar address
364 Set address of section.
365 .It Fl -shared , Fl -Bsharable
366 Build a shared object.
367 .It Fl -soname Ns = Ns Ar value , Fl h Ar value
372 .It Fl -sort-section Ns = Ns Ar value
373 Specifies sections sorting rule when linkerscript is used.
375 Start a grouping of objects that should be treated as if they were together
377 .It Fl -strip-all , Fl s
379 .It Fl -strip-debug , Fl S
380 Strip debugging information.
381 .It Fl -symbol-ordering-file Ns = Ns Ar file
382 Lay out sections in the order specified by
384 .It Fl -sysroot Ns = Ns Ar value
396 .It Fl -target2 Ns = Ns Ar type
408 .It Fl -Tbss Ns = Ns Ar value
414 .It Fl -Tdata Ns = Ns Ar value
420 .It Fl -Ttext Ns = Ns Ar value
426 .It Fl -thinlto-cache-dir Ns = Ns Ar value
427 Path to ThinLTO cached object file directory.
428 .It Fl -thinlto-cache-policy Ns = Ns Ar value
429 Pruning policy for the ThinLTO cache.
430 .It Fl -thinlto-jobs Ns = Ns Ar value
431 Number of ThinLTO jobs.
433 Run the linker multi-threaded.
434 This option is enabled by default.
436 Print the names of the input files.
437 .It Fl -trace-symbol Ns = Ns Ar symbol , Fl y Ar symbol
440 .It Fl -undefined Ns = Ns Ar symbol , Fl u Ar symbol
443 to be an undefined symbol during linking.
444 .It Fl -unresolved-symbols Ns = Ns Ar value
445 Determine how to handle unresolved symbols.
447 Display the version number and proceed with linking if object files are
449 .It Fl V , Fl -version
450 Display the version number and exit.
453 .It Fl -version-script Ns = Ns Ar file
454 Read version script from
456 .It Fl -warn-backrefs
457 Warn about reverse or cyclic dependencies to or between static archives.
458 This can be used to ensure linker invocation remains compatible with
459 traditional Unix-like linkers.
461 Warn about duplicate common symbols.
462 .It Fl -warn-ifunc-textrel
463 Warn about using ifunc symbols in conjunction with text relocations.
464 Older versions of glibc library (2.28 and earlier) has a bug that causes
465 the segment that includes ifunc symbols to be marked as not executable when
466 they are relocated. As a result, although the program compiles and links
467 successfully, it gives segmentation fault when the instruction pointer reaches
468 an ifunc symbol. Use -warn-ifunc-textrel to let lld give a warning, if the
469 code may include ifunc symbols, may do text relocations and be linked with
470 an older glibc version. Otherwise, there is no need to use it, as the default
471 value does not give a warning. This flag has been introduced in late 2018,
472 has no counter part in ld and gold linkers, and may be removed in the future.
473 .It Fl -warn-unresolved-symbols
474 Report unresolved symbols as warnings.
475 .It Fl -whole-archive
476 Force load of all members in a static library.
477 .It Fl -wrap Ns = Ns Ar symbol
478 Use wrapper functions for symbol.
480 Linker option extensions.
481 .Bl -tag -width indent
483 Make the main stack executable.
484 Stack permissions are recorded in the
489 .Dv DF_1_GLOBAL flag in the
492 Different loaders can decide how to handle this flag on their own.
494 Do not emit PLT entries for GNU ifuncs.
495 Instead, preserve relocations for ifunc call sites so that they may
496 be applied by a run-time loader.
497 Note that this feature requires special loader support and will
498 generally result in application crashes when used outside of freestanding
503 flag to indicate the module should be initialized first.
507 flag to indicate to the runtime linker that the object is an interposer.
508 During symbol resolution interposers are searched after the application
509 but before other dependencies.
511 Do not error if a symbol is defined multiple times.
512 The first definition will be used.
513 This is a synonym for
514 .Fl -allow-multiple-definition.
516 Disable combining and sorting multiple relocation sections.
518 Disable the creation of copy relocations.
522 flag to indicate that default library search paths should be ignored.
526 flag to indicate that the object cannot be unloaded from a process.
530 flag to indicate that the object may not be opened by
533 Do not indicate that portions of the object shold be mapped read-only
534 after initial relocation processing.
535 The object will omit the
539 Allow relocations against read-only segments.
541 .Dv DT_TEXTREL flag in the
547 flag to indicate that the run-time loader should perform all relocation
548 processing as part of object initialization.
549 By default relocations may be performed on demand.
553 flag to indicate that the object requires
557 Emit retpoline format PLT entries as a mitigation for CVE-2017-5715.
564 tag will not be emitted.
565 .It Cm stack-size Ns = Ns Ar size
566 Set the main thread's stack size to
568 The stack size is recorded as the size of the
573 Do not allow relocations against read-only segments.
577 .Dv PT_OPENBSD_WXNEEDED
581 .Sh IMPLEMENTATION NOTES
583 handing of archive files (those with a
585 file extension) is different from traditional linkers used on Unix-like
588 Traditional linkers maintain a set of undefined symbols during linking.
589 The linker processes each file in the order in which it appears on the
590 command line, until the set of undefined symbols becomes empty.
591 An object file is linked into the output object when it is encountered,
592 with its undefined symbols added to the set.
593 Upon encountering an archive file a traditional linker searches the objects
594 contained therein, and processes those that satisfy symbols in the unresolved
597 Handling mutually dependent archives may be awkward when using a traditional
599 Archive files may have to be specified multiple times, or the special command
604 may be used to have the linker loop over the files in the group until no new
605 symbols are added to the set.
608 records all symbols found in objects and archives as it iterates over
609 command line arguments.
612 encounters an undefined symbol that can be resolved by an object file
613 contained in a previously processed archive file, it immediately extracts
614 and links it into the output object.
616 With certain archive inputs
618 may produce different results compared to traditional linkers.
619 In practice, large bodies of third party software have been linked with
621 without material issues.
625 option may be used to identify a linker invocation that may be incompatible
626 with traditional Unix-like linker behavior.