LD.LLD(1)
β¨ LD.LLD(1) β General Commands Manual β¨
πΈ NAME πΈ
ld.lld β ELF linker from the LLVM project π
π¦ SYNOPSIS π¦
ld.lld [options] objfile ...
π DESCRIPTION π
okay so picture this, bestie: a linker takes one or more object, archive, and library files, and combines them into an output file β an executable, a shared library, or another object file. It relocates code and data from the input files and resolves symbol references between them. that's the whole gig β¨
ld.lld is a drop-in replacement for the GNU BFD and gold linkers. It accepts most of the same command line arguments and linker scripts as GNU linkers. no notes.
ld.lld currently supports i386, x86-64, ARM, AArch64, PowerPC32, PowerPC64, MIPS32, MIPS64, RISC-V, AMDGPU, Hexagon and SPARC V9 targets. If you invoke it as lld-link, it acts as a Microsoft link.exe-compatible linker, and if you invoke it as ld.ld64, it acts as macOS's ld. All these targets are always supported however ld.lld was built, so you can always use ld.lld as a native linker as well as a cross linker. main character energy fr fr.
β¨ OPTIONS β¨
Okay so first, some option etiquette π: many options have both a single-letter and long form. When you're using the long form options other than those beginning with the letter o, you can specify them using either one or two dashes preceding the option name. Long options beginning with o require two dashes to avoid confusion with the -o path option. iykyk.
--allow-multiple-definitionβ Do not error if a symbol is defined multiple times. The first definition will be used.--allow-shlib-undefinedβ Allow unresolved references in shared libraries. This option is enabled by default when linking a shared library.--apply-dynamic-relocsβ Apply link-time values for dynamic relocations.--as-neededβ Only setDT_NEEDEDfor shared libraries if used.--auxiliary=valueβ Set theDT_AUXILIARYfield to the specified name.--Bdynamic,--dyβ Link against shared libraries.--Bstatic,--static,--dnβ Do not link against shared libraries.-Bno-symbolicβ Don't bind default visibility defined symbols locally for-shared(default).-Bsymbolicβ Bind default visibility defined symbols locally for-shared. Also set theDF_SYMBOLICflag.-Bsymbolic-functionsβ Bind default visibility defined function symbols locally for-shared.-Bsymbolic-non-weak-functionsβ Bind default visibility definedSTB_GLOBALfunction symbols locally for-shared.--build-id=valueβ Generate a build ID note. value may be one offast,md5,sha1,tree,uuid,0xhex-string, andnone.treeis an alias forsha1. Build-IDs of typefast,md5,sha1, andtreeare calculated from the object contents.fastis not intended to be cryptographically secure.--build-idβ Synonym for--build-id=fast.--color-diagnostics=valueβ Use colors in diagnostics. value may be one ofalways,auto, andnever.autoenables color if and only if output is to a terminal.--color-diagnosticsβ Alias for--color-diagnostics=auto.--compress-debug-sections=valueβ Compress DWARF debug sections. value may benoneorzlib. The default compression level is1(fastest) as the debug info usually compresses well at that level, but if you want to compress it more, you can specify-O2to set the compression level to6.--crefβ Output cross reference table. If-Mapis specified, print to the map file.--defsym=symbol=expressionβ Define a symbol alias. expression may be another symbol or a linker script expression. For example,--defsym=foo=baror--defsym=foo=bar+0x100.--demangleβ Demangle symbol names.--disable-new-dtagsβ Disable new dynamic tags.--discard-all,-xβ Delete all local symbols.--discard-locals,-Xβ Delete temporary local symbols.--discard-noneβ Keep all symbols in the symbol table.--dynamic-linker=valueβ Specify the dynamic linker to be used for a dynamically linked executable. This is recorded in an ELF segment of typePT_INTERP.--dynamic-list=fileβ Similar to--export-dynamic-symbol-list. When creating a shared object, implies-Bsymbolicbut does not setDF_SYMBOLIC--EBβ Select the big-endian format in theOUTPUT_FORMATcommand.--ELβ Select the little-endian format in theOUTPUT_FORMATcommand.--eh-frame-hdrβ Request creation of.eh_frame_hdrsection andPT_GNU_EH_FRAMEsegment header.--emit-relocs,-qβ Generate relocations in the output.--enable-new-dtagsβ Enable new dynamic tags.--end-libβ End a grouping of objects that should be treated as if they were together in an archive.--entry=entryβ Name of entry point symbol.--error-limit=valueβ Maximum number of errors to emit before stopping. A value of zero indicates that there is no limit.--error-unresolved-symbolsβ Report unresolved symbols as errors.--error-handing-script=script_pathβ Call scriptscript_pathupon some error, withtagas first argument, and an extra parameter as second argument. The script is expected to return0on success. Any other value is considered a generic error.tagmay bemissing-libfollowed by the name of the missing library.undefined-symbolfollowed by the name of the undefined symbol.--execute-onlyβ Mark executable sections unreadable. This option is currently only supported on AArch64.--exclude-libs=valueβ Exclude static libraries from automatic export.--export-dynamic,-Eβ Put symbols in the dynamic symbol table.--export-dynamic-symbol=globβ (executable) Put matched non-local defined symbols to the dynamic symbol table. (shared object) References to matched non-localSTV_DEFAULTsymbols shouldn't be bound to definitions within the shared object even if they would otherwise be due to-Bsymbolic,-Bsymbolic-functionsor--dynamic-list--export-dynamic-symbol-list=fileβ Read a list of dynamic symbol patterns fromfile. Apply--export-dynamic-symbolon each pattern.--fatal-warningsβ Treat warnings as errors.--filter=value,-F valueβ Set theDT_FILTERfield to the specified value.--fini=symbolβ Specify a finalizer function.--format=input-format,-b input-formatβ Specify the format of the inputs following this option. input-format may be one ofbinary,elf, anddefault.defaultis a synonym forelf.--gc-sectionsβ Enable garbage collection of unused sections.--gdb-indexβ Generate.gdb_indexsection.--hash-style=valueβ Specify hash style. value may besysv,gnu, orboth.bothis the default.--helpβ Print a help message.--icf=allβ Enable identical code folding.--icf=safeβ Enable safe identical code folding.--icf=noneβ Disable identical code folding.--ignore-data-address-equalityβ Ignore address equality of data. C/C++ requires each data to have a unique address. This option allows lld to do unsafe optimization that breaks the requirement: create copies of read-only data or merge two or more read-only data that happen to have the same value.--ignore-function-address-equalityβ Ignore address equality of functions. This option allows non-PIC calls to a function with non-default visibility in a shared object. The function may have different addresses within the executable and within the shared object.--image-base=valueβ Set the base address to value.--init=symbolβ Specify an initializer function.--keep-unique=symbolβ Do not foldsymbolduring ICF.-l libName,--library=libNameβ Root name of library to use.-L dir,--library-path=dirβ Add a directory to the library search path.--lto-aa-pipeline=valueβ AA pipeline to run during LTO. Used in conjunction with--lto-newpm-passes.--lto-newpm-passes=valueβ Passes to run during LTO.--lto-Oopt-levelβ Optimization level for LTO.--lto-partitions=valueβ Number of LTO codegen partitions.-m valueβ Set target emulation.--Map=file,-M fileβ Print a link map tofile.--nmagic,-nβ Do not page align sections, link against static libraries.--no-allow-shlib-undefinedβ Do not allow unresolved references in shared libraries. This option is enabled by default when linking an executable.--no-as-neededβ Always setDT_NEEDEDfor shared libraries.--no-color-diagnosticsβ Do not use colors in diagnostics.--no-demangleβ Do not demangle symbol names.--no-dynamic-linkerβ Inhibit output of an.interpsection.--no-fortran-commonβ Do not search archive members for definitions to overrideCOMMONsymbols.--no-gc-sectionsβ Disable garbage collection of unused sections.--no-gnu-uniqueβ DisableSTB_GNU_UNIQUEsymbol binding.--no-merge-exidx-entriesβ Disable merging.ARM.exidxentries.--no-nmagicβ Page align sections.--no-omagicβ Do not set the text data sections to be writable, page align sections.--no-relaxβ Disable target-specific relaxations. For x86-64 this disablesR_X86_64_GOTPCRELXandR_X86_64_REX_GOTPCRELXGOT optimization.--no-rosegmentβ Do not put read-only non-executable sections in their own segment.--no-undefined-versionβ Report version scripts that refer undefined symbols.--no-undefinedβ Report unresolved symbols even if the linker is creating a shared library.--no-warn-symbol-orderingβ Do not warn about problems with the symbol ordering file or call graph profile.--no-whole-archiveβ Restores the default behavior of loading archive members.--no-pie,--no-pic-executableβ Do not create a position independent executable.--noinhibit-execβ Retain the executable output file whenever it is still usable.--nostdlibβ Only search directories specified on the command line.-opath β write the output executable, library, or object to path. If you don't specify it, bestie, the default isa.out. That's the classic. π-Ovalueβ optimize output file size. value may be:0β disable string merging. π1β enable string merging. β¨2β enable string tail merging. If--compress-debug-sectionsis given, compress debug sections at compression level6instead of1. π₯
-O1 is the default. Periodt. π
--oformat=formatβ specify the format for the output object file. The only supported format isbinary, which produces output with no ELF header. π¦--omagic,-Nβ set the text and data sections to be readable and writable, do not page align sections, link against static libraries. π₯--opt-remarks-filenamefile β write optimization remarks in YAML format to file. π--opt-remarks-passespass-regex β filter optimization remarks by only allowing the passes matching pass-regex. π―--opt-remarks-with-hotnessβ include hotness information in the optimization remarks file. π₯--orphan-handling=modeβ control how orphan sections are handled. An orphan section is one not specifically mentioned in a linker script. mode may be:placeβ place orphan sections in suitable output sections. πwarnβ place orphan sections as forplaceand also report a warning. β οΈerrorβ place orphan sections as forplaceand also report an error. π
place is the default. π
--pack-dyn-relocs=formatβ pack dynamic relocations in the given format. format may be:noneβ do not pack. Dynamic relocations are encoded inSHT_REL(A). π«androidβ pack dynamic relocations inSHT_ANDROID_REL(A). π€relrβ pack relative relocations inSHT_RELR, and the rest of dynamic relocations inSHT_REL(A). π«android+relrβ pack relative relocations inSHT_RELR, and the rest of dynamic relocations inSHT_ANDROID_REL(A). π€π«
none is the default. If --use-android-relr-tags is specified, use SHT_ANDROID_RELR instead of SHT_RELR. π«Ά
--pic-veneerβ always generate position independent thunks. π§--pie,--pic-executableβ create a position independent executable. π--power10-stubs=modeβ whether to use Power10 instructions in call stubs forR_PPC64_REL24_NOTOCand TOC/NOTOC interworking. mode may be:yesβ (default) use. βautoβ currently the same asyes. π€·ββοΈnoβ don't use. π ββοΈ
--print-gc-sectionsβ list removed unused sections. ποΈ--print-icf-sectionsβ list identical folded sections. π--print-mapβ print a link map to the standard output. πΊοΈ--print-archive-stats=fileβ write archive usage statistics to the specified file. Print the numbers of members and fetched members for each archive. π--push-stateβ save the current state of--as-needed,--static, and--whole-archive. πΎ--pop-stateβ restore the states saved by--push-state. βͺ--relocatable,-rβ create relocatable object file. π§©--reproduce=pathβ write a tar file to path, containing all the input files needed to reproduce the link, a text file calledresponse.txtcontaining the command line options and a text file calledversion.txtcontaining the output ofld.lld --version. The archive when unpacked can be used to re-run the linker with the same options and input files. π¦--retain-symbols-file=fileβ retain only the symbols listed in the file. βοΈ--rpath=value,-Rvalue β add aDT_RUNPATHto the output. π£οΈ--rsp-quoting=valueβ quoting style for response files. The supported values arewindowsandposix. πͺπ§--script=file,-Tfile β read linker script from file. If multiple linker scripts are given, they are processed as if they were concatenated in the order they appeared on the command line. π--section-start=section=addressβ set address of section. π--shared,--Bsharableβ build a shared object. π«Ά--shuffle-sections=seedβ shuffle matched sections using the given seed before mapping them to the output sections. If-1, reverse the section order. If0, use a random seed. π²--soname=value,-hvalue β setDT_SONAMEto value. π·οΈ--sort-commonβ this option is ignored for GNU compatibility. π--sort-section=valueβ specifies sections sorting rule when linkerscript is used. π€--start-libβ start a grouping of objects that should be treated as if they were together in an archive. π--strip-all,-sβ strip all symbols. Implies--strip-debug. πͺ--strip-debug,-Sβ strip debugging information. π--symbol-ordering-file=fileβ lay out sections in the order specified by file. π--sysroot=valueβ set the system root. π³--target1-absβ interpretR_ARM_TARGET1asR_ARM_ABS32. π―--target1-relβ interpretR_ARM_TARGET1asR_ARM_REL32. π―--target2=typeβ interpretR_ARM_TARGET2as type, where type is one ofrel,abs, orgot-rel. π―--Tbss=valueβ same as--section-startwith.bssas the sectionname. π--Tdata=valueβ same as--section-startwith.dataas the sectionname. π--Ttext=valueβ same as--section-startwith.textas the sectionname. π--thinlto-cache-dir=valueβ path to ThinLTO cached object file directory. π--thinlto-cache-policy=valueβ pruning policy for the ThinLTO cache. π§Ή--thinlto-jobs=valueβ number of ThinLTO jobs. πΌ--threads=Nβ number of threads.all(default) means all of concurrent threads supported.1disables multi-threading. π§΅--time-traceβ record time trace. β±οΈ--time-trace-file=fileβ write time trace output to file. π--time-trace-granularity=valueβ minimum time granularity (in microseconds) traced by time profiler. β±οΈ--traceβ print the names of the input files. π¨οΈ--trace-symbol=symbol,-ysymbol β trace references to symbol. π--undefined=symbol,-usymbol β if symbol is not defined after symbol resolution, and there's a static library that contains an object file defining the symbol, load the member to include the object file in the output file. π«Ά--undefined-glob=patternβ synonym for--undefined, except that it takes a glob pattern. In a glob pattern,*matches zero or more characters,?matches any single character, and[...]matches the characters within brackets. All symbols that match a given pattern are handled as if they were given as arguments of--undefined. π--uniqueβ creates a separate output section for every orphan input section. π¦--unresolved-symbols=valueβ determine how to handle unresolved symbols. β--use-android-relr-tagsβ useSHT_ANDROID_RELR/DT_ANDROID_RELR*tags instead ofSHT_RELR/DT_RELR*. π€-vβ display the version number and proceed with linking if object files are specified. π’-V,--versionβ display the version number and exit. πͺ--verboseβ verbose mode. π£οΈ--version-script=fileβ read version script from file. π--warn-backrefsβ warn about reverse or cyclic dependencies to or between static archives. This can be used to ensure linker invocation remains compatible with traditional Unix-like linkers. β οΈ--warn-backrefs-exclude=globβ glob describing an archive (or an object file within--start-lib) which should be ignored for--warn-backrefs. π--warn-commonβ warn about duplicate common symbols. β οΈ--warn-ifunc-textrelβ warn about using ifunc symbols in conjunction with text relocations. Older versions of glibc library (2.28and earlier) has a bug that causes the segment that includes ifunc symbols to be marked as not executable when they are relocated. As a result, although the program compiles and links successfully, it gives segmentation fault when the instruction pointer reaches an ifunc symbol. Use-warn-ifunc-textrelto let lld give a warning, if the code may include ifunc symbols, may do text relocations and be linked with an older glibc version. Otherwise, there is no need to use it, as the default value does not give a warning. This flag has been introduced in late 2018, has no counter part in ld and gold linkers, and may be removed in the future. π--warn-unresolved-symbolsβ report unresolved symbols as warnings. β οΈ--whole-archiveβ force load of all members in a static library. π--why-extract=fileβ print to a file about why archive members are extracted. π€--wrap=symbolβ redirect symbol references to__wrap_symboland__real_symbolreferences to symbol. π-zoption β linker option extensions. option can be:dead-reloc-in-nonalloc=section_glob=valueβ Resolve a relocation in a matched non-SHF_ALLOCsection referencing a discarded symbol to value Accepts globs, in the event of a section matching more than one option, the last option takes precedence. An order of least specific to most specific match is recommended. π§execstackβ Make the main stack executable. Stack permissions are recorded in thePT_GNU_STACKsegment. π₯bti-report=[none|warning|error]β Specify how to report the missingGNU_PROPERTY_AARCH64_FEATURE_1_BTIproperty.noneis the default, linker will not report the missing property otherwise will be reported as a warning or an error. πcet-report=[none|warning|error]β Specify how to report the missingGNU_PROPERTY_X86_FEATURE_1_IBTorGNU_PROPERTY_X86_FEATURE_1_SHSTKproperties.noneis the default, linker will not report the missing property otherwise will be reported as a warning or an error. π
force-btiβ bestie, this one forces the AArch64 BTI instruction into the PLT β¨ and it will warn you if your input ELF file doesn't have theGNU_PROPERTY_AARCH64_FEATURE_1_BTIproperty. Rude? Maybe. Helpful? Yes.force-ibtβ same energy, Intel flavour π Force-enables Intel Indirect Branch Tracking in the PLT, and warns if an input ELF file is missing theGNU_PROPERTY_X86_FEATURE_1_IBTproperty.globalβ sets theDF_1_GLOBALflag in theDYNAMICsection. And likeβ¦ different loaders can decide how to handle this flag on their own, so it's very "you do you" of them π«Άifunc-nopltβ do not emit PLT entries for ifunc symbols. Instead it emits text relocations referencing the resolver. Heads up though: this is an experimental optimization and it's only suitable for standalone environments where text relocations don't have the usual drawbacks π This option must be combined with the-z notextoption. No solo runs, periodt.initfirstβ sets theDF_1_INITFIRSTflag, which says the module should be initialized first π main character gets to go first, obviously.interposeβ sets theDF_1_INTERPOSEflag to tell the runtime linker that the object is an interposer π§ During symbol resolution, interposers are searched after the application but before other dependencies. The way that order mattersβ¦ iconic.muldefsβ does not error if a symbol is defined multiple times. The first definition will be used. It's a synonym for--allow-multiple-definitionπnocombrelocβ disables combining and sorting multiple relocation sections.nocopyrelocβ disables the creation of copy relocations.nodefaultlibβ sets theDF_1_NODEFLIBflag, meaning default library search paths should be ignored π«nodeleteβ sets theDF_1_NODELETEflag, which says the object can't be unloaded from a process. It's staying. Forever. πnodlopenβ sets theDF_1_NOOPENflag, meaning the object may not be opened bydlopen(3)πnognustackβ do not emit thePT_GNU_STACKsegment.norelroβ do not indicate that portions of the object should be mapped read-only after initial relocation processing. The object will omit thePT_GNU_RELROsegment.notextβ allows relocations against read-only segments. Sets theDT_TEXTRELflag in theDYNAMICsection.nowβ sets theDF_BIND_NOWflag, telling the run-time loader to do all relocation processing as part of object initialization β‘ By default, relocations may be performed on demand.originβ sets theDF_ORIGINflag, which indicates the object requires$ORIGINprocessing.pac-pltβ AArch64 only, uses pointer authentication in the PLT πpack-relative-relocsβ similar to-pack-dyn-relocs=relr, but it synthesizes theGLIBC_ABI_DT_RELRversion dependency if there's aGLIBC_2.*version dependency. Why tho? Because glibcld.sorejects loading a dynamically linked object without theGLIBC_ABI_DT_RELRversion dependency π so it's giving it what it wants.relβ useRELformat for dynamic relocations.relaβ useRELAformat for dynamic relocations.retpolinepltβ emits retpoline format PLT entries as a mitigation forCVE-2017-5715π‘οΈrodynamicβ makes the.dynamicsection read-only. TheDT_DEBUGtag will not be emitted.separate-loadable-segments,separate-code,noseparate-codeβ these three decide whether two adjacentPT_LOADsegments are allowed to overlap in pages.noseparate-code(the default) allows overlap.separate-codeallows overlap between two executable segments, or two non-executable segments.separate-loadable-segmentsdisallows overlap entirely β¨shstkβ x86 only, uses shadow stack.stack-size=sizeβ sets the main thread's stack size to size. The stack size is recorded as the size of the size.PT_GNU_STACKprogram segment.start-stop-gcβ don't let__start_/__stop_references retain the associated C identifier name sections (this is the default).nostart-stop-gcβ let__start_/__stop_references retain the associated C identifier name sections.textβ do not allow relocations against read-only segments. This is the default.wxneededβ creates aPT_OPENBSD_WXNEEDEDsegment.
π¦ IMPLEMENTATION NOTES π¦
okay so real talk, this is the part where ld.lld is justβ¦ built different π
ld.lld's handling of archive files (those with a .a file extension) is different from traditional linkers used on Unix-like systems. Not bad, just different. Vibe check time π
Traditional linkers maintain a set of undefined symbols during linking. The linker processes each file in the order in which it appears on the command line, until the set of undefined symbols becomes empty. An object file is linked into the output object when it is encountered, with its undefined symbols added to the set. Upon encountering an archive file, a traditional linker searches the objects contained therein, and processes those that satisfy symbols in the unresolved set.
Handling mutually dependent archives may be awkward when you're using a traditional linker π¬ Archive files may have to be specified multiple times, or the special command line options --start-group and --end-group may be used to have the linker loop over the files in the group until no new symbols are added to the set.
ld.lld records all symbols found in objects and archives as it iterates over command line arguments. When ld.lld encounters an undefined symbol that can be resolved by an object file contained in a previously processed archive file, it immediately extracts and links it into the output object. Instant. No waiting around π
With certain archive inputs, ld.lld may produce different results compared to traditional linkers. In practice, though, large bodies of third party software have been linked with ld.lld without material issues π«Ά so it's fine, fr fr.
The --warn-backrefs option may be used to identify a linker invocation that may be incompatible with traditional Unix-like linker behavior. Use it if you're feeling cautious bestie π
and that's a wrap on LD.LLD(1) π this page came from Debian, dated May 12, 2019, and honestly? she ate. go link something iconic π β¨
π¦ where this page comes from
- debian bookworm: lld-15 1:15.0.6-4+b1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu jammy: lld-15 1:15.0.7-0ubuntu0.22.04.3 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu noble: lld-15 1:15.0.7-14build3 Β· APACHE-2-LLVM-EXCEPTIONS
- π the page's license: Apache-2.0 WITH LLVM-exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms