1 .\" Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 .\" See https://llvm.org/LICENSE.txt for license information.
3 .\" SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 .\" This man page documents only lld's ELF linking support, obtained originally
12 .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.
43 Many options have both a single-letter and long form.
44 When using the long form options other than those beginning with the
47 may be specified using either one or two dashes preceding the option name.
48 Long options beginning with
50 require two dashes to avoid confusion with the
54 .Bl -tag -width indent
55 .It Fl -allow-multiple-definition
56 Do not error if a symbol is defined multiple times.
57 The first definition will be used.
58 .It Fl -allow-shlib-undefined
59 Allow unresolved references in shared libraries.
60 This option is enabled by default when linking a shared library.
61 .It Fl -apply-dynamic-relocs
62 Apply link-time values for dynamic relocations.
66 for shared libraries if used.
67 .It Fl -auxiliary Ns = Ns Ar value
70 field to the specified name.
71 .It Fl -Bdynamic , Fl -dy
72 Link against shared libraries.
73 .It Fl -Bstatic , Fl -static , Fl -dn
74 Do not link against shared libraries.
76 Bind defined symbols locally.
77 .It Fl -Bsymbolic-functions
78 Bind defined function symbols locally.
79 .It Fl -build-id Ns = Ns Ar value
80 Generate a build ID note.
88 .Cm 0x Ns Ar hex-string ,
100 are calculated from the object contents.
102 is not intended to be cryptographically secure.
105 .Fl -build-id Ns = Ns Cm fast .
106 .It Fl -color-diagnostics Ns = Ns Ar value
107 Use colors in diagnostics.
115 enables color if and only if output is to a terminal.
116 .It Fl -color-diagnostics
118 .Fl -color-diagnostics Ns = Ns Cm auto .
119 .It Fl -compress-debug-sections Ns = Ns Ar value
120 Compress DWARF debug sections.
127 Output cross reference table.
128 .It Fl -define-common , Fl d
129 Assign space to common symbols.
130 .It Fl -defsym Ns = Ns Ar symbol Ns = Ns Ar expression
131 Define a symbol alias.
133 may be another symbol or a linker script expression.
137 .Ql --defsym=foo=bar+0x100 .
139 Demangle symbol names.
140 .It Fl -disable-new-dtags
141 Disable new dynamic tags.
142 .It Fl -discard-all , Fl x
143 Delete all local symbols.
144 .It Fl -discard-locals , Fl X
145 Delete temporary local symbols.
147 Keep all symbols in the symbol table.
148 .It Fl -dynamic-linker Ns = Ns Ar value
149 Specify the dynamic linker to be used for a dynamically linked executable.
150 This is recorded in an ELF segment of type
152 .It Fl -dynamic-list Ns = Ns Ar file
153 Read a list of dynamic symbols from
161 .It Fl -emit-relocs , Fl q
162 Generate relocations in the output.
163 .It Fl -enable-new-dtags
164 Enable new dynamic tags.
166 End a grouping of objects that should be treated as if they were together
168 .It Fl -entry Ns = Ns Ar entry
169 Name of entry point symbol.
170 .It Fl -error-limit Ns = Ns Ar value
171 Maximum number of errors to emit before stopping.
172 A value of zero indicates that there is no limit.
173 .It Fl -error-unresolved-symbols
174 Report unresolved symbols as errors.
176 Mark executable sections unreadable.
177 This option is currently only supported on AArch64.
178 .It Fl -exclude-libs Ns = Ns Ar value
179 Exclude static libraries from automatic export.
180 .It Fl -export-dynamic , Fl E
181 Put symbols in the dynamic symbol table.
182 .It Fl -export-dynamic-symbol Ns = Ns Ar symbol
185 in the dynamic symbol table.
186 .It Fl -fatal-warnings
187 Treat warnings as errors.
188 .It Fl -filter Ns = Ns Ar value , Fl F Ar value
191 field to the specified value.
192 .It Fl -fini Ns = Ns Ar symbol
193 Specify a finalizer function.
195 Force enable AArch64 BTI instruction in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property.
196 .It Fl -format Ns = Ns Ar input-format , Fl b Ar input-format
197 Specify the format of the inputs following this option.
208 Enable garbage collection of unused sections.
213 .It Fl -hash-style Ns = Ns Ar value
224 Print a help message.
225 .It Fl -icf Ns = Ns Cm all
226 Enable identical code folding.
227 .It Fl -icf Ns = Ns Cm safe
228 Enable safe identical code folding.
229 .It Fl -icf Ns = Ns Cm none
230 Disable identical code folding.
231 .It Fl -ignore-data-address-equality
232 Ignore address equality of data. C/C++ requires each data to have a unique
234 This option allows lld to do unsafe optimization that breaks the
235 requirement: create copies of read-only data or merge two or more read-only data
236 that happen to have the same value.
237 .It Fl -ignore-function-address-equality
238 Ignore address equality of functions.
239 This option allows non-PIC calls to a function with non-default visibility in
241 The function may have different addresses within the executable and within the
243 .It Fl -image-base Ns = Ns Ar value
244 Set the base address to
246 .It Fl -init Ns = Ns Ar symbol
247 Specify an initializer function.
248 .It Fl -keep-unique Ns = Ns Ar symbol
252 .It Fl l Ar libName, Fl -library Ns = Ns Ar libName
253 Root name of library to use.
254 .It Fl L Ar dir , Fl -library-path Ns = Ns Ar dir
255 Add a directory to the library search path.
256 .It Fl -lto-aa-pipeline Ns = Ns Ar value
257 AA pipeline to run during LTO.
258 Used in conjunction with
259 .Fl -lto-newpm-passes .
260 .It Fl -lto-newpm-passes Ns = Ns Ar value
261 Passes to run during LTO.
262 .It Fl -lto-O Ns Ar opt-level
263 Optimization level for LTO.
264 .It Fl -lto-partitions Ns = Ns Ar value
265 Number of LTO codegen partitions.
267 Set target emulation.
268 .It Fl -Map Ns = Ns Ar file , Fl M Ar file
271 .It Fl -nmagic , Fl n
272 Do not page align sections, link against static libraries.
273 .It Fl -no-allow-shlib-undefined
274 Do not allow unresolved references in shared libraries.
275 This option is enabled by default when linking an executable.
279 for shared libraries.
280 .It Fl -no-color-diagnostics
281 Do not use colors in diagnostics.
282 .It Fl -no-define-common
283 Do not assign space to common symbols.
285 Do not demangle symbol names.
286 .It Fl -no-dynamic-linker
290 .It Fl -no-gc-sections
291 Disable garbage collection of unused sections.
292 .It Fl -no-gnu-unique
293 Disable STB_GNU_UNIQUE symbol binding.
294 .It Fl -no-merge-exidx-entries
295 Disable merging .ARM.exidx entries.
299 Do not set the text data sections to be writable, page align sections.
301 Do not put read-only non-executable sections in their own segment.
303 Do not run the linker multi-threaded.
304 .It Fl -no-undefined-version
305 Report version scripts that refer undefined symbols.
307 Report unresolved symbols even if the linker is creating a shared library.
308 .It Fl -no-warn-symbol-ordering
309 Do not warn about problems with the symbol ordering file or call graph profile.
310 .It Fl -no-whole-archive
311 Restores the default behavior of loading archive members.
312 .It Fl -no-pie , Fl -no-pic-executable
313 Do not create a position independent executable.
314 .It Fl -noinhibit-exec
315 Retain the executable output file whenever it is still usable.
317 Only search directories specified on the command line.
319 Write the output executable, library, or object to
323 is used as a default.
325 Optimize output file size.
329 .Bl -tag -width 2n -compact
331 Disable string merging.
333 Enable string merging.
335 Enable string tail merging.
340 .It Fl -oformat Ns = Ns Ar format
341 Specify the format for the output object file.
346 which produces output with no ELF header.
347 .It Fl -omagic , Fl N
348 Set the text and data sections to be readable and writable, do not page align
349 sections, link against static libraries.
350 .It Fl -opt-remarks-filename Ar file
351 Write optimization remarks in YAML format to
353 .It Fl -opt-remarks-passes Ar pass-regex
354 Filter optimization remarks by only allowing the passes matching
356 .It Fl -opt-remarks-with-hotness
357 Include hotness information in the optimization remarks file.
358 .It Fl -orphan-handling Ns = Ns Ar mode
359 Control how orphan sections are handled.
360 An orphan section is one not specifically mentioned in a linker script.
364 .Bl -tag -width 2n -compact
366 Place orphan sections in suitable output sections.
368 Place orphan sections as for
370 and also report a warning.
372 Place orphan sections as for
374 and also report an error.
379 .It Fl -pack-dyn-relocs Ns = Ns Ar format
380 Pack dynamic relocations in the given format.
384 .Bl -tag -width 2n -compact
387 Dynamic relocations are encoded in SHT_REL(A).
389 Pack dynamic relocations in SHT_ANDROID_REL(A).
391 Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
394 Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
401 .Fl -use-android-relr-tags
402 is specified, use SHT_ANDROID_RELR instead of SHT_RELR.
405 AArch64 only, use pointer authentication in PLT.
407 Always generate position independent thunks.
408 .It Fl -pie , Fl -pic-executable
409 Create a position independent executable.
410 .It Fl -print-gc-sections
411 List removed unused sections.
412 .It Fl -print-icf-sections
413 List identical folded sections.
415 Print a link map to the standard output.
417 Save the current state of
425 .It Fl -relocatable , Fl r
426 Create relocatable object file.
427 .It Fl -reproduce Ns = Ns Ar path
430 containing all the input files needed to reproduce the link, a text file called
431 response.txt containing the command line options and a text file called
432 version.txt containing the output of ld.lld --version.
434 unpacked can be used to re-run the linker with the same options and input files.
435 .It Fl -retain-symbols-file Ns = Ns Ar file
436 Retain only the symbols listed in the file.
437 .It Fl -rpath Ns = Ns Ar value , Fl R Ar value
441 .It Fl -rsp-quoting Ns = Ns Ar value
442 Quoting style for response files.
443 The supported values are
447 .It Fl -script Ns = Ns Ar file , Fl T Ar file
448 Read linker script from
450 If multiple linker scripts are given, they are processed as if they
451 were concatenated in the order they appeared on the command line.
452 .It Fl -section-start Ns = Ns Ar section Ns = Ns Ar address
453 Set address of section.
454 .It Fl -shared , Fl -Bsharable
455 Build a shared object.
456 .It Fl -soname Ns = Ns Ar value , Fl h Ar value
462 This option is ignored for GNU compatibility.
463 .It Fl -sort-section Ns = Ns Ar value
464 Specifies sections sorting rule when linkerscript is used.
466 Start a grouping of objects that should be treated as if they were together
468 .It Fl -strip-all , Fl s
470 .It Fl -strip-debug , Fl S
471 Strip debugging information.
472 .It Fl -symbol-ordering-file Ns = Ns Ar file
473 Lay out sections in the order specified by
475 .It Fl -sysroot Ns = Ns Ar value
487 .It Fl -target2 Ns = Ns Ar type
499 .It Fl -Tbss Ns = Ns Ar value
505 .It Fl -Tdata Ns = Ns Ar value
511 .It Fl -Ttext Ns = Ns Ar value
517 .It Fl -thinlto-cache-dir Ns = Ns Ar value
518 Path to ThinLTO cached object file directory.
519 .It Fl -thinlto-cache-policy Ns = Ns Ar value
520 Pruning policy for the ThinLTO cache.
521 .It Fl -thinlto-jobs Ns = Ns Ar value
522 Number of ThinLTO jobs.
524 Run the linker multi-threaded.
525 This option is enabled by default.
527 Print the names of the input files.
528 .It Fl -trace-symbol Ns = Ns Ar symbol , Fl y Ar symbol
531 .It Fl -undefined Ns = Ns Ar symbol , Fl u Ar symbol
534 is not defined after symbol resolution, and there's a static library
535 that contains an object file defining the symbol, load the member
536 to include the object file in the output file.
537 .It Fl -undefined-glob Ns = Ns Ar pattern
540 except that it takes a glob pattern.
543 matches zero or more characters,
545 matches any single character, and
547 matches the characters within brackets.
548 All symbols that match
549 a given pattern are handled as if they were given as arguments of
551 .It Fl -unresolved-symbols Ns = Ns Ar value
552 Determine how to handle unresolved symbols.
553 .It Fl -use-android-relr-tags
554 Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*.
556 Display the version number and proceed with linking if object files are
558 .It Fl V , Fl -version
559 Display the version number and exit.
562 .It Fl -version-script Ns = Ns Ar file
563 Read version script from
565 .It Fl -warn-backrefs
566 Warn about reverse or cyclic dependencies to or between static archives.
567 This can be used to ensure linker invocation remains compatible with
568 traditional Unix-like linkers.
570 Warn about duplicate common symbols.
571 .It Fl -warn-ifunc-textrel
572 Warn about using ifunc symbols in conjunction with text relocations.
573 Older versions of glibc library (2.28 and earlier) has a bug that causes
574 the segment that includes ifunc symbols to be marked as not executable when
576 As a result, although the program compiles and links
577 successfully, it gives segmentation fault when the instruction pointer reaches
579 Use -warn-ifunc-textrel to let lld give a warning, if the
580 code may include ifunc symbols, may do text relocations and be linked with
581 an older glibc version.
582 Otherwise, there is no need to use it, as the default value does not give a
584 This flag has been introduced in late 2018, has no counter part in ld and gold
585 linkers, and may be removed in the future.
586 .It Fl -warn-unresolved-symbols
587 Report unresolved symbols as warnings.
588 .It Fl -whole-archive
589 Force load of all members in a static library.
590 .It Fl -wrap Ns = Ns Ar symbol
591 Use wrapper functions for symbol.
593 Linker option extensions.
594 .Bl -tag -width indent -compact
597 Make the main stack executable.
598 Stack permissions are recorded in the
604 .Dv DF_1_GLOBAL flag in the
607 Different loaders can decide how to handle this flag on their own.
610 Do not emit PLT entries for ifunc symbols.
611 Instead, emit text relocations referencing the resolver.
612 This is an experimental optimization and only suitable for standalone
613 environments where text relocations do not have the usual drawbacks.
614 This option must be combined with the
621 flag to indicate the module should be initialized first.
626 flag to indicate to the runtime linker that the object is an interposer.
627 During symbol resolution interposers are searched after the application
628 but before other dependencies.
631 Do not error if a symbol is defined multiple times.
632 The first definition will be used.
633 This is a synonym for
634 .Fl -allow-multiple-definition.
637 Disable combining and sorting multiple relocation sections.
640 Disable the creation of copy relocations.
645 flag to indicate that default library search paths should be ignored.
650 flag to indicate that the object cannot be unloaded from a process.
655 flag to indicate that the object may not be opened by
659 Do not indicate that portions of the object shold be mapped read-only
660 after initial relocation processing.
661 The object will omit the
666 Allow relocations against read-only segments.
668 .Dv DT_TEXTREL flag in the
675 flag to indicate that the run-time loader should perform all relocation
676 processing as part of object initialization.
677 By default relocations may be performed on demand.
682 flag to indicate that the object requires
687 Emit retpoline format PLT entries as a mitigation for CVE-2017-5715.
695 tag will not be emitted.
697 .It Cm separate-loadable-segments
699 .It Cm noseparate-code
700 Specify whether two adjacent PT_LOAD segments are allowed to overlap in pages.
702 (default) allows overlap.
704 allows overlap between two executable segments, or two non-executable segments.
705 .Cm separate-loadable-segments
708 .It Cm stack-size Ns = Ns Ar size
709 Set the main thread's stack size to
711 The stack size is recorded as the size of the
717 Do not allow relocations against read-only segments.
722 .Dv PT_OPENBSD_WXNEEDED
726 .Sh IMPLEMENTATION NOTES
728 handing of archive files (those with a
730 file extension) is different from traditional linkers used on Unix-like
733 Traditional linkers maintain a set of undefined symbols during linking.
734 The linker processes each file in the order in which it appears on the
735 command line, until the set of undefined symbols becomes empty.
736 An object file is linked into the output object when it is encountered,
737 with its undefined symbols added to the set.
738 Upon encountering an archive file a traditional linker searches the objects
739 contained therein, and processes those that satisfy symbols in the unresolved
742 Handling mutually dependent archives may be awkward when using a traditional
744 Archive files may have to be specified multiple times, or the special command
749 may be used to have the linker loop over the files in the group until no new
750 symbols are added to the set.
753 records all symbols found in objects and archives as it iterates over
754 command line arguments.
757 encounters an undefined symbol that can be resolved by an object file
758 contained in a previously processed archive file, it immediately extracts
759 and links it into the output object.
761 With certain archive inputs
763 may produce different results compared to traditional linkers.
764 In practice, large bodies of third party software have been linked with
766 without material issues.
770 option may be used to identify a linker invocation that may be incompatible
771 with traditional Unix-like linker behavior.