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, LoongArch, PowerPC32,
31 PowerPC64, 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-non-weak
86 Bind default visibility defined STB_GLOBAL symbols locally for
88 .It Fl Bsymbolic-functions
89 Bind default visibility defined function symbols locally for
91 .It Fl Bsymbolic-non-weak-functions
92 Bind default visibility defined STB_GLOBAL function symbols locally for
95 Write a Big Endian ELF File using BE8 format(AArch32 only)
96 .It Fl -build-id Ns = Ns Ar value
97 Generate a build ID note.
105 .Cm 0x Ns Ar hex-string ,
117 are calculated from the object contents.
119 is not intended to be cryptographically secure.
122 .Fl -build-id Ns = Ns Cm fast .
123 .It Fl -call-graph-profile-sort Ns = Ns Ar algorithm
127 .Bl -tag -width 2n -compact
129 Ignore call graph profile.
133 Use cdsort (default).
136 .It Fl -color-diagnostics Ns = Ns Ar value
137 Use colors in diagnostics.
145 enables color if and only if output is to a terminal.
146 .It Fl -color-diagnostics
148 .Fl -color-diagnostics Ns = Ns Cm auto .
149 .It Fl -compress-debug-sections Ns = Ns Ar value
150 Compress DWARF debug sections.
154 .Bl -tag -width 2n -compact
158 The default compression level is 1 (fastest) as the debug info usually
159 compresses well at that level. If you want to compress it more,
162 to set the compression level to 6.
164 The compression level is 5.
168 Output cross reference table. If
170 is specified, print to the map file.
171 .It Fl -defsym Ns = Ns Ar symbol Ns = Ns Ar expression
172 Define a symbol alias.
174 may be another symbol or a linker script expression.
178 .Ql --defsym=foo=bar+0x100 .
180 Demangle symbol names.
181 .It Fl -disable-new-dtags
182 Disable new dynamic tags.
183 .It Fl -discard-all , Fl x
184 Delete all local symbols.
185 .It Fl -discard-locals , Fl X
186 Delete temporary local symbols.
188 Keep all symbols in the symbol table.
189 .It Fl -dynamic-linker Ns = Ns Ar value
190 Specify the dynamic linker to be used for a dynamically linked executable.
191 This is recorded in an ELF segment of type
193 .It Fl -dynamic-list Ns = Ns Ar file
195 .Cm --export-dynamic-symbol-list .
196 When creating a shared object, implies
198 but does not set DF_SYMBOLIC
200 Select the big-endian format in the OUTPUT_FORMAT command.
202 Select the little-endian format in the OUTPUT_FORMAT command.
209 .It Fl -emit-relocs , Fl q
210 Generate relocations in the output.
211 .It Fl -enable-new-dtags
212 Enable new dynamic tags.
214 End a grouping of objects that should be treated as if they were together
216 .It Fl -entry Ns = Ns Ar entry
217 Name of entry point symbol.
218 .It Fl -error-limit Ns = Ns Ar value
219 Maximum number of errors to emit before stopping.
220 A value of zero indicates that there is no limit.
221 .It Fl -error-unresolved-symbols
222 Report unresolved symbols as errors.
223 .It Fl -error-handing-script Ns = Ns Ar script_path
226 upon some error, with
228 as first argument, and an extra parameter as second argument. The script is
229 expected to return 0 on success. Any other value is considered a generic error.
233 followed by the name of the missing library.
235 followed by the name of the undefined symbol.
237 Mark executable sections unreadable.
238 This option is currently only supported on AArch64.
239 .It Fl -exclude-libs Ns = Ns Ar value
240 Exclude static libraries from automatic export.
241 .It Fl -export-dynamic , Fl E
242 Put symbols in the dynamic symbol table.
243 .It Fl -export-dynamic-symbol Ns = Ns Ar glob
244 (executable) Put matched non-local defined symbols to the dynamic symbol table.
245 (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
248 .Cm -Bsymbolic-functions
251 .It Fl -export-dynamic-symbol-list Ns = Ns Ar file
252 Read a list of dynamic symbol patterns from
255 .Cm --export-dynamic-symbol
257 .It Fl -fatal-warnings
258 Treat warnings as errors.
259 .It Fl -filter Ns = Ns Ar value , Fl F Ar value
262 field to the specified value.
263 .It Fl -fini Ns = Ns Ar symbol
264 Specify a finalizer function.
265 .It Fl -format Ns = Ns Ar input-format , Fl b Ar input-format
266 Specify the format of the inputs following this option.
277 Enable garbage collection of unused sections.
282 .It Fl -hash-style Ns = Ns Ar value
293 Print a help message.
294 .It Fl -icf Ns = Ns Cm all
295 Enable identical code folding.
296 .It Fl -icf Ns = Ns Cm safe
297 Enable safe identical code folding.
298 .It Fl -icf Ns = Ns Cm none
299 Disable identical code folding.
300 .It Fl -ignore-data-address-equality
301 Ignore address equality of data. C/C++ requires each data to have a unique
303 This option allows lld to do unsafe optimization that breaks the
304 requirement: create copies of read-only data or merge two or more read-only data
305 that happen to have the same value.
306 .It Fl -ignore-function-address-equality
307 Ignore address equality of functions.
308 This option allows non-PIC calls to a function with non-default visibility in
310 The function may have different addresses within the executable and within the
312 .It Fl -image-base Ns = Ns Ar value
313 Set the base address to
315 .It Fl -init Ns = Ns Ar symbol
316 Specify an initializer function.
317 .It Fl -keep-unique Ns = Ns Ar symbol
321 .It Fl l Ar libName, Fl -library Ns = Ns Ar libName
322 Root name of library to use.
323 .It Fl L Ar dir , Fl -library-path Ns = Ns Ar dir
324 Add a directory to the library search path.
325 .It Fl -lto-aa-pipeline Ns = Ns Ar value
326 AA pipeline to run during LTO.
327 Used in conjunction with
328 .Fl -lto-newpm-passes .
329 .It Fl -lto-newpm-passes Ns = Ns Ar value
330 Passes to run during LTO.
331 .It Fl -lto-O Ns Ar opt-level
332 Optimization level for LTO.
333 .It Fl -lto-partitions Ns = Ns Ar value
334 Number of LTO codegen partitions.
336 Set target emulation.
337 .It Fl -Map Ns = Ns Ar file , Fl M Ar file
340 .It Fl -nmagic , Fl n
341 Do not page align sections, link against static libraries.
342 .It Fl -no-allow-shlib-undefined
343 Do not allow unresolved references in shared libraries.
344 This option is enabled by default when linking an executable.
348 for shared libraries.
349 .It Fl -no-color-diagnostics
350 Do not use colors in diagnostics.
352 Do not demangle symbol names.
353 .It Fl -no-dynamic-linker
357 .It Fl -no-fortran-common
358 Do not search archive members for definitions to override COMMON symbols.
359 .It Fl -no-gc-sections
360 Disable garbage collection of unused sections.
361 .It Fl -no-gnu-unique
362 Disable STB_GNU_UNIQUE symbol binding.
363 .It Fl -no-merge-exidx-entries
364 Disable merging .ARM.exidx entries.
368 Do not set the text data sections to be writable, page align sections.
370 Disable target-specific relaxations. For x86-64 this disables R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX GOT optimization.
372 Do not put read-only non-executable sections in their own segment.
373 .It Fl -undefined-version
374 Do not report version scripts that refer to undefined symbols.
376 Report unresolved symbols even if the linker is creating a shared library.
377 .It Fl -no-warn-symbol-ordering
378 Do not warn about problems with the symbol ordering file or call graph profile.
379 .It Fl -no-warnings , Fl w
380 Suppress warnings and cancel
381 .Cm --fatal-warnings.
382 .It Fl -no-whole-archive
383 Restores the default behavior of loading archive members.
384 .It Fl -no-pie , Fl -no-pic-executable
385 Do not create a position independent executable.
386 .It Fl -noinhibit-exec
387 Retain the executable output file whenever it is still usable.
389 Only search directories specified on the command line.
391 Write the output executable, library, or object to
395 is used as a default.
397 Optimize output file size.
401 .Bl -tag -width 2n -compact
403 Disable string merging.
405 Enable string merging.
407 Enable string tail merging. If
408 .Fl -compress-debug-sections
409 is given, compress debug sections at compression level 6 instead of 1.
414 .It Fl -oformat Ns = Ns Ar format
415 Specify the format for the output object file.
420 which produces output with no ELF header.
421 .It Fl -omagic , Fl N
422 Set the text and data sections to be readable and writable, do not page align
423 sections, link against static libraries.
424 .It Fl -opt-remarks-filename Ar file
425 Write optimization remarks in YAML format to
427 .It Fl -opt-remarks-passes Ar pass-regex
428 Filter optimization remarks by only allowing the passes matching
430 .It Fl -opt-remarks-with-hotness
431 Include hotness information in the optimization remarks file.
432 .It Fl -orphan-handling Ns = Ns Ar mode
433 Control how orphan sections are handled.
434 An orphan section is one not specifically mentioned in a linker script.
438 .Bl -tag -width 2n -compact
440 Place orphan sections in suitable output sections.
442 Place orphan sections as for
444 and also report a warning.
446 Place orphan sections as for
448 and also report an error.
453 .It Fl -pack-dyn-relocs Ns = Ns Ar format
454 Pack dynamic relocations in the given format.
458 .Bl -tag -width 2n -compact
461 Dynamic relocations are encoded in SHT_REL(A).
463 Pack dynamic relocations in SHT_ANDROID_REL(A).
465 Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
468 Pack relative relocations in SHT_RELR, and the rest of dynamic relocations in
475 .Fl -use-android-relr-tags
476 is specified, use SHT_ANDROID_RELR instead of SHT_RELR.
479 Always generate position independent thunks.
480 .It Fl -pie , Fl -pic-executable
481 Create a position independent executable.
482 .It Fl -power10-stubs Ns = Ns Cm mode
483 Whether to use Power10 instructions in call stubs for R_PPC64_REL24_NOTOC and TOC/NOTOC interworking.
487 .Bl -tag -width 2n -compact
491 Currently the same as yes.
496 .It Fl -print-gc-sections
497 List removed unused sections.
498 .It Fl -print-icf-sections
499 List identical folded sections.
501 Print a link map to the standard output.
502 .It Fl -print-archive-stats Ns = Ns Ar file
503 Write archive usage statistics to the specified file.
504 Print the numbers of members and fetched members for each archive.
506 Save the current state of
512 Restore the states saved by
515 Enable global pointer relaxation for RISC-V.
516 .It Fl -relocatable , Fl r
517 Create relocatable object file.
518 .It Fl -remap-inputs Ns = Ns Ar from-glob=to-file
525 to ignore an input file.
526 .It Fl -remap-inputs-file Ns = Ns Ar file
527 Remap input files based on patterns in
529 Each line in the remap file is of the format
530 .Cm from-glob=to-file
531 or a comment starting with
533 .It Fl -reproduce Ns = Ns Ar path
536 containing all the input files needed to reproduce the link, a text file called
537 response.txt containing the command line options and a text file called
538 version.txt containing the output of ld.lld --version.
540 unpacked can be used to re-run the linker with the same options and input files.
541 .It Fl -retain-symbols-file Ns = Ns Ar file
542 Retain only the symbols listed in the file.
543 .It Fl -rpath Ns = Ns Ar value , Fl R Ar value
547 .It Fl -rsp-quoting Ns = Ns Ar value
548 Quoting style for response files.
549 The supported values are
553 .It Fl -script Ns = Ns Ar file , Fl T Ar file
554 Read linker script from
556 If multiple linker scripts are given, they are processed as if they
557 were concatenated in the order they appeared on the command line.
558 .It Fl -section-start Ns = Ns Ar section Ns = Ns Ar address
559 Set address of section.
560 .It Fl -shared , Fl -Bsharable
561 Build a shared object.
562 .It Fl -shuffle-sections Ns = Ns Ar seed
563 Shuffle matched sections using the given seed before mapping them to the output sections.
564 If -1, reverse the section order. If 0, use a random seed.
565 .It Fl -soname Ns = Ns Ar value , Fl h Ar value
571 This option is ignored for GNU compatibility.
572 .It Fl -sort-section Ns = Ns Ar value
573 Specifies sections sorting rule when linkerscript is used.
575 Start a grouping of objects that should be treated as if they were together
577 .It Fl -strip-all , Fl s
581 .It Fl -strip-debug , Fl S
582 Strip debugging information.
583 .It Fl -symbol-ordering-file Ns = Ns Ar file
584 Lay out sections in the order specified by
586 .It Fl -sysroot Ns = Ns Ar value
598 .It Fl -target2 Ns = Ns Ar type
610 .It Fl -Tbss Ns = Ns Ar value
616 .It Fl -Tdata Ns = Ns Ar value
622 .It Fl -Ttext Ns = Ns Ar value
628 .It Fl -thinlto-cache-dir Ns = Ns Ar value
629 Path to ThinLTO cached object file directory.
630 .It Fl -thinlto-cache-policy Ns = Ns Ar value
631 Pruning policy for the ThinLTO cache.
632 .It Fl -thinlto-jobs Ns = Ns Ar value
633 Number of ThinLTO jobs.
634 .It Fl -threads Ns = Ns Ar N
637 (default) means all of concurrent threads supported.
639 disables multi-threading.
640 .It Fl -fat-lto-objects
641 Use the .llvm.lto section, which contains LLVM bitcode, in fat LTO object files to perform LTO.
642 .It Fl -no-fat-lto-objects
643 Ignore the .llvm.lto section in relocatable object files (default).
646 .It Fl -time-trace-file Ns = Ns Ar file
647 Write time trace output to
649 .It Fl -time-trace-granularity Ns = Ns Ar value
650 Minimum time granularity (in microseconds) traced by time profiler.
652 Print the names of the input files.
653 .It Fl -trace-symbol Ns = Ns Ar symbol , Fl y Ar symbol
656 .It Fl -undefined Ns = Ns Ar symbol , Fl u Ar symbol
659 is not defined after symbol resolution, and there's a static library
660 that contains an object file defining the symbol, load the member
661 to include the object file in the output file.
662 .It Fl -undefined-glob Ns = Ns Ar pattern
665 except that it takes a glob pattern.
668 matches zero or more characters,
670 matches any single character, and
672 matches the characters within brackets.
673 All symbols that match
674 a given pattern are handled as if they were given as arguments of
677 Creates a separate output section for every orphan input section.
678 .It Fl -unresolved-symbols Ns = Ns Ar value
679 Determine how to handle unresolved symbols.
680 .It Fl -use-android-relr-tags
681 Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*.
683 Display the version number and proceed with linking if object files are
686 Display the version number and exit.
689 .It Fl -version-script Ns = Ns Ar file
690 Read version script from
692 .It Fl -warn-backrefs
693 Warn about reverse or cyclic dependencies to or between static archives.
694 This can be used to ensure linker invocation remains compatible with
695 traditional Unix-like linkers.
696 .It Fl -warn-backrefs-exclude Ns = Ns Ar glob
697 Glob describing an archive (or an object file within --start-lib)
698 which should be ignored for
701 Warn about duplicate common symbols.
702 .It Fl -warn-ifunc-textrel
703 Warn about using ifunc symbols in conjunction with text relocations.
704 Older versions of glibc library (2.28 and earlier) has a bug that causes
705 the segment that includes ifunc symbols to be marked as not executable when
707 As a result, although the program compiles and links
708 successfully, it gives segmentation fault when the instruction pointer reaches
710 Use -warn-ifunc-textrel to let lld give a warning, if the
711 code may include ifunc symbols, may do text relocations and be linked with
712 an older glibc version.
713 Otherwise, there is no need to use it, as the default value does not give a
715 This flag has been introduced in late 2018, has no counter part in ld and gold
716 linkers, and may be removed in the future.
717 .It Fl -warn-unresolved-symbols
718 Report unresolved symbols as warnings.
719 .It Fl -whole-archive
720 Force load of all members in a static library.
721 .It Fl -why-extract Ns = Ns Ar file
722 Print to a file about why archive members are extracted.
723 .It Fl -wrap Ns = Ns Ar symbol
733 Linker option extensions.
734 .Bl -tag -width indent -compact
736 .It Cm dead-reloc-in-nonalloc Ns = Ns Ar section_glob=value
737 Resolve a relocation in a matched non-SHF_ALLOC section referencing a discarded symbol to
739 Accepts globs, in the event of a section matching more than one option, the last
740 option takes precedence. An order of least specific to most specific match is
744 Make the main stack executable.
745 Stack permissions are recorded in the
749 .It Cm bti-report Ns = Ns Ar [none|warning|error]
750 Specify how to report the missing GNU_PROPERTY_AARCH64_FEATURE_1_BTI property.
752 is the default, linker will not report the missing property otherwise will be reported as a warning or an error.
754 .It Cm cet-report Ns = Ns Ar [none|warning|error]
755 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT or GNU_PROPERTY_X86_FEATURE_1_SHSTK properties.
757 is the default, linker will not report the missing property otherwise will be reported as a warning or an error.
760 Force enable AArch64 BTI instruction in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property.
763 Force enable Intel Indirect Branch Tracking in PLT, warn if an input ELF file
764 does not have GNU_PROPERTY_X86_FEATURE_1_IBT property.
768 .Dv DF_1_GLOBAL flag in the
771 Different loaders can decide how to handle this flag on their own.
774 Do not emit PLT entries for ifunc symbols.
775 Instead, emit text relocations referencing the resolver.
776 This is an experimental optimization and only suitable for standalone
777 environments where text relocations do not have the usual drawbacks.
778 This option must be combined with the
785 flag to indicate the module should be initialized first.
790 flag to indicate to the runtime linker that the object is an interposer.
791 During symbol resolution interposers are searched after the application
792 but before other dependencies.
795 Do not error if a symbol is defined multiple times.
796 The first definition will be used.
797 This is a synonym for
798 .Fl -allow-multiple-definition.
801 Disable combining and sorting multiple relocation sections.
804 Disable the creation of copy relocations.
809 flag to indicate that default library search paths should be ignored.
814 flag to indicate that the object cannot be unloaded from a process.
819 flag to indicate that the object may not be opened by
828 Do not indicate that portions of the object should be mapped read-only
829 after initial relocation processing.
830 The object will omit the
835 Allow relocations against read-only segments.
837 .Dv DT_TEXTREL flag in the
844 flag to indicate that the run-time loader should perform all relocation
845 processing as part of object initialization.
846 By default relocations may be performed on demand.
851 flag to indicate that the object requires
856 AArch64 only, use pointer authentication in PLT.
858 .It Cm pack-relative-relocs
860 .Cm -pack-dyn-relocs=relr
861 , but synthesizes the GLIBC_ABI_DT_RELR version dependency if there is a GLIBC_2.* version dependency.
862 glibc ld.so rejects loading a dynamically linked object without the GLIBC_ABI_DT_RELR version dependency.
865 Use REL format for dynamic relocations.
868 Use RELA format for dynamic relocations.
871 Emit retpoline format PLT entries as a mitigation for CVE-2017-5715.
879 tag will not be emitted.
881 .It Cm separate-loadable-segments
883 .It Cm noseparate-code
884 Specify whether two adjacent PT_LOAD segments are allowed to overlap in pages.
886 (default) allows overlap.
888 allows overlap between two executable segments, or two non-executable segments.
889 .Cm separate-loadable-segments
893 x86 only, use shadow stack.
895 .It Cm stack-size Ns = Ns Ar size
896 Set the main thread's stack size to
898 The stack size is recorded as the size of the
904 Don't let __start_/__stop_ references retain the associated C identifier name sections (default).
906 .It Cm nostart-stop-gc
907 Let __start_/__stop_ references retain the associated C identifier name sections.
910 Do not allow relocations against read-only segments.
915 .Dv PT_OPENBSD_WXNEEDED
920 .Sh ENVIRONMENT VARIABLES
921 .Bl -tag -width LC_CTYPE
923 Create a reproduce tarball with the specified filename. If
929 ld.lld creates a section named
931 containing the LLD version string. The version string can be overridden by this environment variable,
932 which is useful to eliminate differences in the binary caused by LLD version number differences.
935 .Sh IMPLEMENTATION NOTES
937 handing of archive files (those with a
939 file extension) is different from traditional linkers used on Unix-like
942 Traditional linkers maintain a set of undefined symbols during linking.
943 The linker processes each file in the order in which it appears on the
944 command line, until the set of undefined symbols becomes empty.
945 An object file is linked into the output object when it is encountered,
946 with its undefined symbols added to the set.
947 Upon encountering an archive file a traditional linker searches the objects
948 contained therein, and processes those that satisfy symbols in the unresolved
951 Handling mutually dependent archives may be awkward when using a traditional
953 Archive files may have to be specified multiple times, or the special command
958 may be used to have the linker loop over the files in the group until no new
959 symbols are added to the set.
962 records all symbols found in objects and archives as it iterates over
963 command line arguments.
966 encounters an undefined symbol that can be resolved by an object file
967 contained in a previously processed archive file, it immediately extracts
968 and links it into the output object.
970 With certain archive inputs
972 may produce different results compared to traditional linkers.
973 In practice, large bodies of third party software have been linked with
975 without material issues.
979 option may be used to identify a linker invocation that may be incompatible
980 with traditional Unix-like linker behavior.