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 -allow-shlib-undefined
60 Allow unresolved references in shared libraries.
61 This option is enabled by default when linking a shared library.
62 .It Fl -apply-dynamic-relocs
63 Apply link-time values for dynamic relocations.
67 for shared libraries if used.
68 .It Fl -auxiliary Ns = Ns Ar value
71 field to the specified name.
72 .It Fl -Bdynamic , Fl -dy
73 Link against shared libraries.
74 .It Fl -Bstatic , Fl -static , Fl -dn
75 Do not link against shared libraries.
77 Bind defined symbols locally.
78 .It Fl -Bsymbolic-functions
79 Bind defined function symbols locally.
80 .It Fl -build-id Ns = Ns Ar value
81 Generate a build ID note.
89 .Cm 0x Ns Ar hex-string ,
101 are calculated from the object contents.
103 is not intended to be cryptographically secure.
106 .Fl -build-id Ns = Ns Cm fast .
107 .It Fl -color-diagnostics Ns = Ns Ar value
108 Use colors in diagnostics.
116 enables color if and only if output is to a terminal.
117 .It Fl -color-diagnostics
119 .Fl -color-diagnostics Ns = Ns Cm auto .
120 .It Fl -compress-debug-sections Ns = Ns Ar value
121 Compress DWARF debug sections.
128 Output cross reference table.
129 .It Fl -define-common , Fl d
130 Assign space to common symbols.
131 .It Fl -defsym Ns = Ns Ar symbol Ns = Ns Ar expression
132 Define a symbol alias.
134 may be another symbol or a linker script expression.
138 .Ql --defsym=foo=bar+0x100 .
140 Demangle symbol names.
141 .It Fl -disable-new-dtags
142 Disable new dynamic tags.
143 .It Fl -discard-all , Fl x
144 Delete all local symbols.
145 .It Fl -discard-locals , Fl X
146 Delete temporary local symbols.
148 Keep all symbols in the symbol table.
149 .It Fl -dynamic-linker Ns = Ns Ar value
150 Specify the dynamic linker to be used for a dynamically linked executable.
151 This is recorded in an ELF segment of type
153 .It Fl -dynamic-list Ns = Ns Ar file
154 Read a list of dynamic symbols from
162 .It Fl -emit-relocs , Fl q
163 Generate relocations in the output.
164 .It Fl -enable-new-dtags
165 Enable new dynamic tags.
167 End a grouping of objects that should be treated as if they were together
169 .It Fl -entry Ns = Ns Ar entry
170 Name of entry point symbol.
171 .It Fl -error-limit Ns = Ns Ar value
172 Maximum number of errors to emit before stopping.
173 A value of zero indicates that there is no limit.
174 .It Fl -error-unresolved-symbols
175 Report unresolved symbols as errors.
177 Mark executable sections unreadable. This option is currently only
178 supported on AArch64.
179 .It Fl -exclude-libs Ns = Ns Ar value
180 Exclude static libraries from automatic export.
181 .It Fl -export-dynamic , Fl E
182 Put symbols in the dynamic symbol table.
183 .It Fl -export-dynamic-symbol Ns = Ns Ar symbol
186 in the dynamic symbol table.
187 .It Fl -fatal-warnings
188 Treat warnings as errors.
189 .It Fl -filter Ns = Ns Ar value , Fl F Ar value
192 field to the specified value.
193 .It Fl -fini Ns = Ns Ar symbol
194 Specify a finalizer function.
195 .It Fl -format Ns = Ns Ar input-format , Fl b Ar input-format
196 Specify the format of the inputs following this option.
207 Enable garbage collection of unused sections.
212 .It Fl -hash-style Ns = Ns Ar value
223 Print a help message.
224 .It Fl -icf Ns = Ns Cm all
225 Enable identical code folding.
226 .It Fl -icf Ns = Ns Cm safe
227 Enable safe identical code folding.
228 .It Fl -icf Ns = Ns Cm none
229 Disable identical code folding.
230 .It Fl -image-base Ns = Ns Ar value
231 Set the base address to
233 .It Fl -init Ns = Ns Ar symbol
234 Specify an initializer function.
235 .It Fl -keep-unique Ns = Ns Ar symbol
239 .It Fl l Ar libName, Fl -library Ns = Ns Ar libName
240 Root name of library to use.
241 .It Fl L Ar dir , Fl -library-path Ns = Ns Ar dir
242 Add a directory to the library search path.
243 .It Fl -lto-aa-pipeline Ns = Ns Ar value
244 AA pipeline to run during LTO.
245 Used in conjunction with
246 .Fl -lto-newpm-passes .
247 .It Fl -lto-newpm-passes Ns = Ns Ar value
248 Passes to run during LTO.
249 .It Fl -lto-O Ns Ar opt-level
250 Optimization level for LTO.
251 .It Fl -lto-partitions Ns = Ns Ar value
252 Number of LTO codegen partitions.
254 Set target emulation.
255 .It Fl -Map Ns = Ns Ar file , Fl M Ar file
258 .It Fl -no-allow-shlib-undefined
259 Do not allow unresolved references in shared libraries.
260 This option is enabled by default when linking an executable.
264 for shared libraries.
265 .It Fl -no-color-diagnostics
266 Do not use colors in diagnostics.
267 .It Fl -no-define-common
268 Do not assign space to common symbols.
270 Do not demangle symbol names.
271 .It Fl -no-dynamic-linker
275 .It Fl -no-gc-sections
276 Disable garbage collection of unused sections.
277 .It Fl -no-gnu-unique
278 Disable STB_GNU_UNIQUE symbol binding.
280 Do not put read-only non-executable sections in their own segment.
282 Do not run the linker multi-threaded.
283 .It Fl -no-undefined-version
284 Report version scripts that refer undefined symbols.
286 Report unresolved symbols even if the linker is creating a shared library.
287 .It Fl -no-whole-archive
288 Restores the default behavior of loading archive members.
290 Do not create a position independent executable.
291 .It Fl -noinhibit-exec
292 Retain the executable output file whenever it is still usable.
294 Only search directories specified on the command line.
296 Write the output executable, library, or object to
300 is used as a default.
302 Optimize output file size.
306 .Bl -tag -width 2n -compact
308 Disable string merging.
310 Enable string merging.
312 Enable string tail merging.
317 .It Fl -oformat Ns = Ns Ar format
318 Specify the format for the output object file.
323 which produces output with no ELF header.
324 .It Fl -omagic , Fl N
325 Set the text and data sections to be readable and writable.
326 .It Fl -opt-remarks-filename Ar file
327 Write optimization remarks in YAML format to
329 .It Fl -opt-remarks-with-hotness
330 Include hotness information in the optimization remarks file.
332 Always generate position independent thunks.
334 Create a position independent executable.
335 .It Fl -print-gc-sections
336 List removed unused sections.
337 .It Fl -print-icf-sections
338 List identical folded sections.
340 Print a link map to the standard output.
342 Save the current state of
350 .It Fl -relocatable , Fl r
351 Create relocatable object file.
352 .It Fl -reproduce Ns = Ns Ar value
353 Dump linker invocation and input files for debugging.
354 .It Fl -retain-symbols-file Ns = Ns Ar file
355 Retain only the symbols listed in the file.
356 .It Fl -rpath Ns = Ns Ar value , Fl R Ar value
360 .It Fl -rsp-quoting Ns = Ns Ar value
361 Quoting style for response files.
362 The supported values are
366 .It Fl -script Ns = Ns Ar file , Fl T Ar file
367 Read linker script from
369 .It Fl -section-start Ns = Ns Ar section Ns = Ns Ar address
370 Set address of section.
371 .It Fl -shared , Fl -Bsharable
372 Build a shared object.
373 .It Fl -soname Ns = Ns Ar value , Fl h Ar value
378 .It Fl -sort-section Ns = Ns Ar value
379 Specifies sections sorting rule when linkerscript is used.
381 Start a grouping of objects that should be treated as if they were together
383 .It Fl -strip-all , Fl s
385 .It Fl -strip-debug , Fl S
386 Strip debugging information.
387 .It Fl -symbol-ordering-file Ns = Ns Ar file
388 Lay out sections in the order specified by
390 .It Fl -sysroot Ns = Ns Ar value
402 .It Fl -target2 Ns = Ns Ar type
414 .It Fl -Tbss Ns = Ns Ar value
420 .It Fl -Tdata Ns = Ns Ar value
426 .It Fl -Ttext Ns = Ns Ar value
432 .It Fl -thinlto-cache-dir Ns = Ns Ar value
433 Path to ThinLTO cached object file directory.
434 .It Fl -thinlto-cache-policy Ns = Ns Ar value
435 Pruning policy for the ThinLTO cache.
436 .It Fl -thinlto-jobs Ns = Ns Ar value
437 Number of ThinLTO jobs.
439 Run the linker multi-threaded.
440 This option is enabled by default.
442 Print the names of the input files.
443 .It Fl -trace-symbol Ns = Ns Ar symbol , Fl y Ar symbol
446 .It Fl -undefined Ns = Ns Ar symbol , Fl u Ar symbol
449 to be an undefined symbol during linking.
450 .It Fl -unresolved-symbols Ns = Ns Ar value
451 Determine how to handle unresolved symbols.
453 Display the version number and proceed with linking if object files are
455 .It Fl V , Fl -version
456 Display the version number and exit.
459 .It Fl -version-script Ns = Ns Ar file
460 Read version script from
462 .It Fl -warn-backrefs
463 Warn about reverse or cyclic dependencies to or between static archives.
464 This can be used to ensure linker invocation remains compatible with
465 traditional Unix-like linkers.
467 Warn about duplicate common symbols.
468 .It Fl -warn-ifunc-textrel
469 Warn about using ifunc symbols in conjunction with text relocations.
470 Older versions of glibc library (2.28 and earlier) has a bug that causes
471 the segment that includes ifunc symbols to be marked as not executable when
472 they are relocated. As a result, although the program compiles and links
473 successfully, it gives segmentation fault when the instruction pointer reaches
474 an ifunc symbol. Use -warn-ifunc-textrel to let lld give a warning, if the
475 code may include ifunc symbols, may do text relocations and be linked with
476 an older glibc version. Otherwise, there is no need to use it, as the default
477 value does not give a warning. This flag has been introduced in late 2018,
478 has no counter part in ld and gold linkers, and may be removed in the future.
479 .It Fl -warn-unresolved-symbols
480 Report unresolved symbols as warnings.
481 .It Fl -whole-archive
482 Force load of all members in a static library.
483 .It Fl -wrap Ns = Ns Ar symbol
484 Use wrapper functions for symbol.
486 Linker option extensions.
487 .Bl -tag -width indent
489 Make the main stack executable.
490 Stack permissions are recorded in the
495 .Dv DF_1_GLOBAL flag in the
498 Different loaders can decide how to handle this flag on their own.
500 Do not emit PLT entries for GNU ifuncs.
501 Instead, preserve relocations for ifunc call sites so that they may
502 be applied by a run-time loader.
503 Note that this feature requires special loader support and will
504 generally result in application crashes when used outside of freestanding
509 flag to indicate the module should be initialized first.
513 flag to indicate to the runtime linker that the object is an interposer.
514 During symbol resolution interposers are searched after the application
515 but before other dependencies.
517 Do not error if a symbol is defined multiple times.
518 The first definition will be used.
519 This is a synonym for
520 .Fl -allow-multiple-definition.
522 Disable combining and sorting multiple relocation sections.
524 Disable the creation of copy relocations.
528 flag to indicate that default library search paths should be ignored.
532 flag to indicate that the object cannot be unloaded from a process.
536 flag to indicate that the object may not be opened by
539 Do not indicate that portions of the object shold be mapped read-only
540 after initial relocation processing.
541 The object will omit the
545 Allow relocations against read-only segments.
547 .Dv DT_TEXTREL flag in the
553 flag to indicate that the run-time loader should perform all relocation
554 processing as part of object initialization.
555 By default relocations may be performed on demand.
559 flag to indicate that the object requires
563 Emit retpoline format PLT entries as a mitigation for CVE-2017-5715.
570 tag will not be emitted.
571 .It Cm stack-size Ns = Ns Ar size
572 Set the main thread's stack size to
574 The stack size is recorded as the size of the
579 Do not allow relocations against read-only segments.
583 .Dv PT_OPENBSD_WXNEEDED
587 .Sh IMPLEMENTATION NOTES
589 handing of archive files (those with a
591 file extension) is different from traditional linkers used on Unix-like
594 Traditional linkers maintain a set of undefined symbols during linking.
595 The linker processes each file in the order in which it appears on the
596 command line, until the set of undefined symbols becomes empty.
597 An object file is linked into the output object when it is encountered,
598 with its undefined symbols added to the set.
599 Upon encountering an archive file a traditional linker searches the objects
600 contained therein, and processes those that satisfy symbols in the unresolved
603 Handling mutually dependent archives may be awkward when using a traditional
605 Archive files may have to be specified multiple times, or the special command
610 may be used to have the linker loop over the files in the group until no new
611 symbols are added to the set.
614 records all symbols found in objects and archives as it iterates over
615 command line arguments.
618 encounters an undefined symbol that can be resolved by an object file
619 contained in a previously processed archive file, it immediately extracts
620 and links it into the output object.
622 With certain archive inputs
624 may produce different results compared to traditional linkers.
625 In practice, large bodies of third party software have been linked with
627 without material issues.
631 option may be used to identify a linker invocation that may be incompatible
632 with traditional Unix-like linker behavior.