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 Don't bind default visibility defined symbols locally for
80 Bind default visibility defined symbols locally for
85 .It Fl Bsymbolic-functions
86 Bind default visibility defined function symbols locally for
88 .It Fl Bsymbolic-non-weak-functions
89 Bind default visibility defined STB_GLOBAL function symbols locally for
91 .It Fl -build-id Ns = Ns Ar value
92 Generate a build ID note.
100 .Cm 0x Ns Ar hex-string ,
112 are calculated from the object contents.
114 is not intended to be cryptographically secure.
117 .Fl -build-id Ns = Ns Cm fast .
118 .It Fl -color-diagnostics Ns = Ns Ar value
119 Use colors in diagnostics.
127 enables color if and only if output is to a terminal.
128 .It Fl -color-diagnostics
130 .Fl -color-diagnostics Ns = Ns Cm auto .
131 .It Fl -compress-debug-sections Ns = Ns Ar value
132 Compress DWARF debug sections.
136 .Bl -tag -width 2n -compact
140 The default compression level is 1 (fastest) as the debug info usually
141 compresses well at that level. If you want to compress it more,
144 to set the compression level to 6.
146 The compression level is 5.
150 Output cross reference table. If
152 is specified, print to the map file.
153 .It Fl -defsym Ns = Ns Ar symbol Ns = Ns Ar expression
154 Define a symbol alias.
156 may be another symbol or a linker script expression.
160 .Ql --defsym=foo=bar+0x100 .
162 Demangle symbol names.
163 .It Fl -disable-new-dtags
164 Disable new dynamic tags.
165 .It Fl -discard-all , Fl x
166 Delete all local symbols.
167 .It Fl -discard-locals , Fl X
168 Delete temporary local symbols.
170 Keep all symbols in the symbol table.
171 .It Fl -dynamic-linker Ns = Ns Ar value
172 Specify the dynamic linker to be used for a dynamically linked executable.
173 This is recorded in an ELF segment of type
175 .It Fl -dynamic-list Ns = Ns Ar file
177 .Cm --export-dynamic-symbol-list .
178 When creating a shared object, implies
180 but does not set DF_SYMBOLIC
182 Select the big-endian format in the OUTPUT_FORMAT command.
184 Select the little-endian format in the OUTPUT_FORMAT command.
191 .It Fl -emit-relocs , Fl q
192 Generate relocations in the output.
193 .It Fl -enable-new-dtags
194 Enable new dynamic tags.
196 End a grouping of objects that should be treated as if they were together
198 .It Fl -entry Ns = Ns Ar entry
199 Name of entry point symbol.
200 .It Fl -error-limit Ns = Ns Ar value
201 Maximum number of errors to emit before stopping.
202 A value of zero indicates that there is no limit.
203 .It Fl -error-unresolved-symbols
204 Report unresolved symbols as errors.
205 .It Fl -error-handing-script Ns = Ns Ar script_path
208 upon some error, with
210 as first argument, and an extra parameter as second argument. The script is
211 expected to return 0 on success. Any other value is considered a generic error.
215 followed by the name of the missing library.
217 followed by the name of the undefined symbol.
219 Mark executable sections unreadable.
220 This option is currently only supported on AArch64.
221 .It Fl -exclude-libs Ns = Ns Ar value
222 Exclude static libraries from automatic export.
223 .It Fl -export-dynamic , Fl E
224 Put symbols in the dynamic symbol table.
225 .It Fl -export-dynamic-symbol Ns = Ns Ar glob
226 (executable) Put matched non-local defined symbols to the dynamic symbol table.
227 (shared object) References to matched non-local STV_DEFAULT symbols shouldn't be bound to definitions within the shared object even if they would otherwise be due to
230 .Cm -Bsymbolic-functions
233 .It Fl -export-dynamic-symbol-list Ns = Ns Ar file
234 Read a list of dynamic symbol patterns from
237 .Cm --export-dynamic-symbol
239 .It Fl -fatal-warnings
240 Treat warnings as errors.
241 .It Fl -filter Ns = Ns Ar value , Fl F Ar value
244 field to the specified value.
245 .It Fl -fini Ns = Ns Ar symbol
246 Specify a finalizer function.
247 .It Fl -format Ns = Ns Ar input-format , Fl b Ar input-format
248 Specify the format of the inputs following this option.
259 Enable garbage collection of unused sections.
264 .It Fl -hash-style Ns = Ns Ar value
275 Print a help message.
276 .It Fl -icf Ns = Ns Cm all
277 Enable identical code folding.
278 .It Fl -icf Ns = Ns Cm safe
279 Enable safe identical code folding.
280 .It Fl -icf Ns = Ns Cm none
281 Disable identical code folding.
282 .It Fl -ignore-data-address-equality
283 Ignore address equality of data. C/C++ requires each data to have a unique
285 This option allows lld to do unsafe optimization that breaks the
286 requirement: create copies of read-only data or merge two or more read-only data
287 that happen to have the same value.
288 .It Fl -ignore-function-address-equality
289 Ignore address equality of functions.
290 This option allows non-PIC calls to a function with non-default visibility in
292 The function may have different addresses within the executable and within the
294 .It Fl -image-base Ns = Ns Ar value
295 Set the base address to
297 .It Fl -init Ns = Ns Ar symbol
298 Specify an initializer function.
299 .It Fl -keep-unique Ns = Ns Ar symbol
303 .It Fl l Ar libName, Fl -library Ns = Ns Ar libName
304 Root name of library to use.
305 .It Fl L Ar dir , Fl -library-path Ns = Ns Ar dir
306 Add a directory to the library search path.
307 .It Fl -lto-aa-pipeline Ns = Ns Ar value
308 AA pipeline to run during LTO.
309 Used in conjunction with
310 .Fl -lto-newpm-passes .
311 .It Fl -lto-newpm-passes Ns = Ns Ar value
312 Passes to run during LTO.
313 .It Fl -lto-O Ns Ar opt-level
314 Optimization level for LTO.
315 .It Fl -lto-partitions Ns = Ns Ar value
316 Number of LTO codegen partitions.
318 Set target emulation.
319 .It Fl -Map Ns = Ns Ar file , Fl M Ar file
322 .It Fl -nmagic , Fl n
323 Do not page align sections, link against static libraries.
324 .It Fl -no-allow-shlib-undefined
325 Do not allow unresolved references in shared libraries.
326 This option is enabled by default when linking an executable.
330 for shared libraries.
331 .It Fl -no-color-diagnostics
332 Do not use colors in diagnostics.
334 Do not demangle symbol names.
335 .It Fl -no-dynamic-linker
339 .It Fl -no-fortran-common
340 Do not search archive members for definitions to override COMMON symbols.
341 .It Fl -no-gc-sections
342 Disable garbage collection of unused sections.
343 .It Fl -no-gnu-unique
344 Disable STB_GNU_UNIQUE symbol binding.
345 .It Fl -no-merge-exidx-entries
346 Disable merging .ARM.exidx entries.
350 Do not set the text data sections to be writable, page align sections.
352 Disable target-specific relaxations. For x86-64 this disables R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX GOT optimization.
354 Do not put read-only non-executable sections in their own segment.
355 .It Fl -undefined-version
356 Do not report version scripts that refer to undefined symbols.
358 Report unresolved symbols even if the linker is creating a shared library.
359 .It Fl -no-warn-symbol-ordering
360 Do not warn about problems with the symbol ordering file or call graph profile.
361 .It Fl -no-warnings , Fl w
362 Suppress warnings and cancel
363 .Cm --fatal-warnings.
364 .It Fl -no-whole-archive
365 Restores the default behavior of loading archive members.
366 .It Fl -no-pie , Fl -no-pic-executable
367 Do not create a position independent executable.
368 .It Fl -noinhibit-exec
369 Retain the executable output file whenever it is still usable.
371 Only search directories specified on the command line.
373 Write the output executable, library, or object to
377 is used as a default.
379 Optimize output file size.
383 .Bl -tag -width 2n -compact
385 Disable string merging.
387 Enable string merging.
389 Enable string tail merging. If
390 .Fl -compress-debug-sections
391 is given, compress debug sections at compression level 6 instead of 1.
396 .It Fl -oformat Ns = Ns Ar format
397 Specify the format for the output object file.
402 which produces output with no ELF header.
403 .It Fl -omagic , Fl N
404 Set the text and data sections to be readable and writable, do not page align
405 sections, link against static libraries.
406 .It Fl -opt-remarks-filename Ar file
407 Write optimization remarks in YAML format to
409 .It Fl -opt-remarks-passes Ar pass-regex
410 Filter optimization remarks by only allowing the passes matching
412 .It Fl -opt-remarks-with-hotness
413 Include hotness information in the optimization remarks file.
414 .It Fl -orphan-handling Ns = Ns Ar mode
415 Control how orphan sections are handled.
416 An orphan section is one not specifically mentioned in a linker script.
420 .Bl -tag -width 2n -compact
422 Place orphan sections in suitable output sections.
424 Place orphan sections as for
426 and also report a warning.
428 Place orphan sections as for
430 and also report an error.
435 .It Fl -pack-dyn-relocs Ns = Ns Ar format
436 Pack dynamic relocations in the given format.
440 .Bl -tag -width 2n -compact
443 Dynamic relocations are encoded in SHT_REL(A).
445 Pack dynamic relocations in SHT_ANDROID_REL(A).
447 Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
450 Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
457 .Fl -use-android-relr-tags
458 is specified, use SHT_ANDROID_RELR instead of SHT_RELR.
461 Always generate position independent thunks.
462 .It Fl -pie , Fl -pic-executable
463 Create a position independent executable.
464 .It Fl -power10-stubs Ns = Ns Cm mode
465 Whether to use Power10 instructions in call stubs for R_PPC64_REL24_NOTOC and TOC/NOTOC interworking.
469 .Bl -tag -width 2n -compact
473 Currently the same as yes.
478 .It Fl -print-gc-sections
479 List removed unused sections.
480 .It Fl -print-icf-sections
481 List identical folded sections.
483 Print a link map to the standard output.
484 .It Fl -print-archive-stats Ns = Ns Ar file
485 Write archive usage statistics to the specified file.
486 Print the numbers of members and fetched members for each archive.
488 Save the current state of
494 Restore the states saved by
497 Enable global pointer relaxation for RISC-V.
498 .It Fl -relocatable , Fl r
499 Create relocatable object file.
500 .It Fl -remap-inputs Ns = Ns Ar from-glob=to-file
507 to ignore an input file.
508 .It Fl -remap-inputs-file Ns = Ns Ar file
509 Remap input files based on patterns in
511 Each line in the remap file is of the format
512 .Cm from-glob=to-file
513 or a comment starting with
515 .It Fl -reproduce Ns = Ns Ar path
518 containing all the input files needed to reproduce the link, a text file called
519 response.txt containing the command line options and a text file called
520 version.txt containing the output of ld.lld --version.
522 unpacked can be used to re-run the linker with the same options and input files.
523 .It Fl -retain-symbols-file Ns = Ns Ar file
524 Retain only the symbols listed in the file.
525 .It Fl -rpath Ns = Ns Ar value , Fl R Ar value
529 .It Fl -rsp-quoting Ns = Ns Ar value
530 Quoting style for response files.
531 The supported values are
535 .It Fl -script Ns = Ns Ar file , Fl T Ar file
536 Read linker script from
538 If multiple linker scripts are given, they are processed as if they
539 were concatenated in the order they appeared on the command line.
540 .It Fl -section-start Ns = Ns Ar section Ns = Ns Ar address
541 Set address of section.
542 .It Fl -shared , Fl -Bsharable
543 Build a shared object.
544 .It Fl -shuffle-sections Ns = Ns Ar seed
545 Shuffle matched sections using the given seed before mapping them to the output sections.
546 If -1, reverse the section order. If 0, use a random seed.
547 .It Fl -soname Ns = Ns Ar value , Fl h Ar value
553 This option is ignored for GNU compatibility.
554 .It Fl -sort-section Ns = Ns Ar value
555 Specifies sections sorting rule when linkerscript is used.
557 Start a grouping of objects that should be treated as if they were together
559 .It Fl -strip-all , Fl s
563 .It Fl -strip-debug , Fl S
564 Strip debugging information.
565 .It Fl -symbol-ordering-file Ns = Ns Ar file
566 Lay out sections in the order specified by
568 .It Fl -sysroot Ns = Ns Ar value
580 .It Fl -target2 Ns = Ns Ar type
592 .It Fl -Tbss Ns = Ns Ar value
598 .It Fl -Tdata Ns = Ns Ar value
604 .It Fl -Ttext Ns = Ns Ar value
610 .It Fl -thinlto-cache-dir Ns = Ns Ar value
611 Path to ThinLTO cached object file directory.
612 .It Fl -thinlto-cache-policy Ns = Ns Ar value
613 Pruning policy for the ThinLTO cache.
614 .It Fl -thinlto-jobs Ns = Ns Ar value
615 Number of ThinLTO jobs.
616 .It Fl -threads Ns = Ns Ar N
619 (default) means all of concurrent threads supported.
621 disables multi-threading.
624 .It Fl -time-trace-file Ns = Ns Ar file
625 Write time trace output to
627 .It Fl -time-trace-granularity Ns = Ns Ar value
628 Minimum time granularity (in microseconds) traced by time profiler.
630 Print the names of the input files.
631 .It Fl -trace-symbol Ns = Ns Ar symbol , Fl y Ar symbol
634 .It Fl -undefined Ns = Ns Ar symbol , Fl u Ar symbol
637 is not defined after symbol resolution, and there's a static library
638 that contains an object file defining the symbol, load the member
639 to include the object file in the output file.
640 .It Fl -undefined-glob Ns = Ns Ar pattern
643 except that it takes a glob pattern.
646 matches zero or more characters,
648 matches any single character, and
650 matches the characters within brackets.
651 All symbols that match
652 a given pattern are handled as if they were given as arguments of
655 Creates a separate output section for every orphan input section.
656 .It Fl -unresolved-symbols Ns = Ns Ar value
657 Determine how to handle unresolved symbols.
658 .It Fl -use-android-relr-tags
659 Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*.
661 Display the version number and proceed with linking if object files are
664 Display the version number and exit.
667 .It Fl -version-script Ns = Ns Ar file
668 Read version script from
670 .It Fl -warn-backrefs
671 Warn about reverse or cyclic dependencies to or between static archives.
672 This can be used to ensure linker invocation remains compatible with
673 traditional Unix-like linkers.
674 .It Fl -warn-backrefs-exclude Ns = Ns Ar glob
675 Glob describing an archive (or an object file within --start-lib)
676 which should be ignored for
679 Warn about duplicate common symbols.
680 .It Fl -warn-ifunc-textrel
681 Warn about using ifunc symbols in conjunction with text relocations.
682 Older versions of glibc library (2.28 and earlier) has a bug that causes
683 the segment that includes ifunc symbols to be marked as not executable when
685 As a result, although the program compiles and links
686 successfully, it gives segmentation fault when the instruction pointer reaches
688 Use -warn-ifunc-textrel to let lld give a warning, if the
689 code may include ifunc symbols, may do text relocations and be linked with
690 an older glibc version.
691 Otherwise, there is no need to use it, as the default value does not give a
693 This flag has been introduced in late 2018, has no counter part in ld and gold
694 linkers, and may be removed in the future.
695 .It Fl -warn-unresolved-symbols
696 Report unresolved symbols as warnings.
697 .It Fl -whole-archive
698 Force load of all members in a static library.
699 .It Fl -why-extract Ns = Ns Ar file
700 Print to a file about why archive members are extracted.
701 .It Fl -wrap Ns = Ns Ar symbol
711 Linker option extensions.
712 .Bl -tag -width indent -compact
714 .It Cm dead-reloc-in-nonalloc Ns = Ns Ar section_glob=value
715 Resolve a relocation in a matched non-SHF_ALLOC section referencing a discarded symbol to
717 Accepts globs, in the event of a section matching more than one option, the last
718 option takes precedence. An order of least specific to most specific match is
722 Make the main stack executable.
723 Stack permissions are recorded in the
727 .It Cm bti-report Ns = Ns Ar [none|warning|error]
728 Specify how to report the missing GNU_PROPERTY_AARCH64_FEATURE_1_BTI property.
730 is the default, linker will not report the missing property otherwise will be reported as a warning or an error.
732 .It Cm cet-report Ns = Ns Ar [none|warning|error]
733 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT or GNU_PROPERTY_X86_FEATURE_1_SHSTK properties.
735 is the default, linker will not report the missing property otherwise will be reported as a warning or an error.
738 Force enable AArch64 BTI instruction in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property.
741 Force enable Intel Indirect Branch Tracking in PLT, warn if an input ELF file
742 does not have GNU_PROPERTY_X86_FEATURE_1_IBT property.
746 .Dv DF_1_GLOBAL flag in the
749 Different loaders can decide how to handle this flag on their own.
752 Do not emit PLT entries for ifunc symbols.
753 Instead, emit text relocations referencing the resolver.
754 This is an experimental optimization and only suitable for standalone
755 environments where text relocations do not have the usual drawbacks.
756 This option must be combined with the
763 flag to indicate the module should be initialized first.
768 flag to indicate to the runtime linker that the object is an interposer.
769 During symbol resolution interposers are searched after the application
770 but before other dependencies.
773 Do not error if a symbol is defined multiple times.
774 The first definition will be used.
775 This is a synonym for
776 .Fl -allow-multiple-definition.
779 Disable combining and sorting multiple relocation sections.
782 Disable the creation of copy relocations.
787 flag to indicate that default library search paths should be ignored.
792 flag to indicate that the object cannot be unloaded from a process.
797 flag to indicate that the object may not be opened by
806 Do not indicate that portions of the object should be mapped read-only
807 after initial relocation processing.
808 The object will omit the
813 Allow relocations against read-only segments.
815 .Dv DT_TEXTREL flag in the
822 flag to indicate that the run-time loader should perform all relocation
823 processing as part of object initialization.
824 By default relocations may be performed on demand.
829 flag to indicate that the object requires
834 AArch64 only, use pointer authentication in PLT.
836 .It Cm pack-relative-relocs
838 .Cm -pack-dyn-relocs=relr
839 , but synthesizes the GLIBC_ABI_DT_RELR version dependency if there is a GLIBC_2.* version dependency.
840 glibc ld.so rejects loading a dynamically linked object without the GLIBC_ABI_DT_RELR version dependency.
843 Use REL format for dynamic relocations.
846 Use RELA format for dynamic relocations.
849 Emit retpoline format PLT entries as a mitigation for CVE-2017-5715.
857 tag will not be emitted.
859 .It Cm separate-loadable-segments
861 .It Cm noseparate-code
862 Specify whether two adjacent PT_LOAD segments are allowed to overlap in pages.
864 (default) allows overlap.
866 allows overlap between two executable segments, or two non-executable segments.
867 .Cm separate-loadable-segments
871 x86 only, use shadow stack.
873 .It Cm stack-size Ns = Ns Ar size
874 Set the main thread's stack size to
876 The stack size is recorded as the size of the
882 Don't let __start_/__stop_ references retain the associated C identifier name sections (default).
884 .It Cm nostart-stop-gc
885 Let __start_/__stop_ references retain the associated C identifier name sections.
888 Do not allow relocations against read-only segments.
893 .Dv PT_OPENBSD_WXNEEDED
898 .Sh ENVIRONMENT VARIABLES
899 .Bl -tag -width LC_CTYPE
901 Create a reproduce tarball with the specified filename. If
907 ld.lld creates a section named
909 containing the LLD version string. The version string can be overridden by this environment variable,
910 which is useful to eliminate differences in the binary caused by LLD version number differences.
913 .Sh IMPLEMENTATION NOTES
915 handing of archive files (those with a
917 file extension) is different from traditional linkers used on Unix-like
920 Traditional linkers maintain a set of undefined symbols during linking.
921 The linker processes each file in the order in which it appears on the
922 command line, until the set of undefined symbols becomes empty.
923 An object file is linked into the output object when it is encountered,
924 with its undefined symbols added to the set.
925 Upon encountering an archive file a traditional linker searches the objects
926 contained therein, and processes those that satisfy symbols in the unresolved
929 Handling mutually dependent archives may be awkward when using a traditional
931 Archive files may have to be specified multiple times, or the special command
936 may be used to have the linker loop over the files in the group until no new
937 symbols are added to the set.
940 records all symbols found in objects and archives as it iterates over
941 command line arguments.
944 encounters an undefined symbol that can be resolved by an object file
945 contained in a previously processed archive file, it immediately extracts
946 and links it into the output object.
948 With certain archive inputs
950 may produce different results compared to traditional linkers.
951 In practice, large bodies of third party software have been linked with
953 without material issues.
957 option may be used to identify a linker invocation that may be incompatible
958 with traditional Unix-like linker behavior.