LD.LLD(1)
β¨ NAME β¨
okay so bestie, meet ld.lld β the ELF linker from the LLVM project. π
That's the whole vibe: it links, it's from LLVM, and this manual page is about to tell you everything. No cap.
π¦ SYNOPSIS π¦
ld.lld [options] objfile ...
π DESCRIPTION π
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. literally the glue of the whole build, iconic behavior.
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. slay, compatibility queen.
ld.lld currently supports i386, x86-64, ARM, AArch64, PowerPC32, PowerPC64, MIPS32, MIPS64, RISC-V, AMDGPU, Hexagon and SPARC V9 targets. ld.lld acts as a Microsoft link.exe-compatible linker if invoked as lld-link and as macOS's ld if invoked as ld.ld64. 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 across architectures, periodt.
π OPTIONS π
Many options have both a single-letter and long form. When using the long form options other than those beginning with the letter o may be specified 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.valuemay 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.valuemay 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.valuemay benoneorzlib. The default compression level is 1 (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 to 6.--crefβ Output cross reference table.--define-common,-dβ Assign space to common symbols.--defsym=symbol=expressionβ Define a symbol alias.expressionmay 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β Read a list of dynamic symbols fromfile. (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. 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 return 0 on 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--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-formatmay 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.valuemay 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 tovalue.--init=symbolβ Specify an initializer function.--keep-unique=symbolβ Do not fold symbol during 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-define-commonβ Do not assign space to common symbols.--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. This is currently a no-op.--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β okay so, this one is giving βtrust issuesβ energy: the linker will only search the directories you literally specified on the command line. No default paths, no extra vibes. π-opath β write the output executable, library, or object to path. If you donβt say anything,a.outis the default. classic. π-Ovalueβ optimize output file size. value can 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. β¨
--oformat=formatβ specify the format for the output object file. The only supported format isbinary, which produces output with no ELF header. iconic. π--omagic,-Nβ set the text and data sections to be readable and writable, do not page align sections, link against static libraries. wild. π₯--opt-remarks-filenamefile β write optimization remarks in YAML format to file. fancy. β¨--opt-remarks-passespass-regex β filter optimization remarks by only allowing the passes matching pass-regex. filtered. π--opt-remarks-with-hotnessβ include hotness information in the optimization remarks file. hot. π₯--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. periodt. π
--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. choices. π
--pic-veneerβ always generate position independent thunks. PIC vibes only. π¦--pie,--pic-executableβ create a position independent executable. main character energy. π--print-gc-sectionsβ list removed unused sections. cleanup crew. π§Ή--print-icf-sectionsβ list identical folded sections. twins. π―--print-mapβ print a link map to the standard output. map it out. πΊοΈ--print-archive-stats=fileβ write archive usage statistics to the specified file. Print the numbers of members and fetched members for each archive. receipts. π§Ύ--push-stateβ save the current state of--as-needed,--static, and--whole-archive. save point. πΎ--pop-stateβ undo the effect of--push-state. undo. β©οΈ--relocatable,-rβ create relocatable object file. portable. π¦--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. reproducible queen. π--retain-symbols-file=fileβ retain only the symbols listed in file. keep list. π--rpath=value,-Rvalue β add aDT_RUNPATHto the output. runtime path. π£οΈ--rsp-quoting=valueβ quoting style for response files. The supported values arewindowsandposix. pick your vibe. π--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. scripted. π--section-start=section=addressβ set address of section. address it. π--shared,--Bsharableβ build a shared object. shared is caring. π--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. shuffle mode. π--soname=value,-hvalue β setDT_SONAMEto value. name tag. π·οΈ--sort-commonβ this option is ignored for GNU compatibility. ghosted. π»--sort-section=valueβ specifies sections sorting rule when linkerscript is used. sort it out. π§Ή--start-libβ start a grouping of objects that should be treated as if they were together in an archive. squad up. π―--strip-all,-sβ strip all symbols. Implies--strip-debug. naked. π--strip-debug,-Sβ strip debugging information. debug be gone. π«₯--symbol-ordering-file=fileβ lay out sections in the order specified by file. order up. π--sysroot=valueβ set the system root. root access. π³--target1-absβ interpretR_ARM_TARGET1asR_ARM_ABS32. absolutely. π―--target1-relβ interpretR_ARM_TARGET1asR_ARM_REL32. relative. π--target2=typeβ interpretR_ARM_TARGET2as type, where type is one ofrel,abs, orgot-rel. choose your type. π--Tbss=valueβ same as--section-startwith.bssas the sectionname. bss babe. π§--Tdata=valueβ same as--section-startwith.dataas the sectionname. data darling. π--Ttext=valueβ same as--section-startwith.textas the sectionname. text time. π--thinlto-cache-dir=valueβ path to ThinLTO cached object file directory. cache palace. π°--thinlto-cache-policy=valueβ pruning policy for the ThinLTO cache. prune it. βοΈ--thinlto-jobs=valueβ number of ThinLTO jobs. work work work. πΌ--threads=Nβ number of threads.all(default) means all of concurrent threads supported.1disables multi-threading. thread squad. π§΅--time-traceβ record time trace. time tracking. β±οΈ--time-trace-file=fileβ write time trace output to file. save the receipts. π§Ύ--time-trace-granularity=valueβ minimum time granularity (in microseconds) traced by time profiler. micro vibes. π¬--traceβ print the names of the input files. spill the tea. β--trace-symbol=symbol,-ysymbol β trace references to symbol. follow the 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 but found. π»--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. glob queen. π--uniqueβ creates a separate output section for every orphan input section. one of a kind. π--unresolved-symbols=valueβ determine how to handle unresolved symbols. mystery solved. π--use-android-relr-tagsβ useSHT_ANDROID_RELR/DT_ANDROID_RELR*tags instead ofSHT_RELR/DT_RELR*. android vibes. π€-vβ display the version number and proceed with linking if object files are specified. version check. β-V,--versionβ display the version number and exit. peace out. βοΈ--verboseβ verbose mode. talkative. π£οΈ--version-script=fileβ read version script from file. scripted. π--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. back it up. π--warn-backrefs-exclude=globβ glob describing an archive (or an object file within--start-lib) which should be ignored for--warn-backrefs. excluded. π«--warn-commonβ warn about duplicate common symbols. duplicate alert. π¨--warn-ifunc-textrelβ warn about using ifunc symbols in conjunction with text relocations. Older versions of glibc library (2.28 and 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. glibc drama. π--warn-unresolved-symbolsβ report unresolved symbols as warnings. warning not error. β οΈ--whole-archiveβ force load of all members in a static library. all in. π―--wrap=symbolβ redirect symbol references to__wrap_symboland__real_symbolreferences to symbol. wrapped up. π-zoption β linker option extensions. the extra sauce. πdead-reloc-in-nonalloc=section_glob=valueβ resolve a relocation in a matched non-SHF_ALLOC section 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. glob galore. π§©execstackβ make the main stack executable. Stack permissions are recorded in thePT_GNU_STACKsegment. stack go brrr. πforce-btiβ force enable AArch64 BTI instruction in PLT, warn if Input ELF file does not haveGNU_PROPERTY_AARCH64_FEATURE_1_BTIproperty. BTI vibes. π‘οΈforce-ibtβ force enable Intel Indirect Branch Tracking in PLT, warn if an input ELF file does not haveGNU_PROPERTY_X86_FEATURE_1_IBTproperty. IBT vibes. π‘οΈglobalβ sets theDF_1_GLOBALflag in the DYNAMIC section. Different loaders can decide how to handle this flag on their own. global queen. πifunc-nopltβ do not emit PLT entries for ifunc symbols. Instead, emit text relocations referencing the resolver. This is an experimental optimization and only suitable for standalone environments where text relocations do not have the usual drawbacks. This option must be combined with the-z notextoption. experimental. π§ͺinitfirstβ sets theDF_1_INITFIRSTflag to indicate the module should be initialized first. first place. π₯
interposeβ sets theDF_1_INTERPOSEflag to tell the runtime linker that this object is an interposer. During symbol resolution, interposers get searched after the application but before other dependencies. periodt.muldefsβ do not error if a symbol is defined multiple times. The first definition will be used. This is 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 to indicate that default library search paths should be ignored.nodeleteβ sets theDF_1_NODELETEflag to indicate that the object cannot be unloaded from a process.nodlopenβ sets theDF_1_NOOPENflag to indicate that 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β allow relocations against read-only segments. Sets theDT_TEXTRELflag in theDYNAMICsection.nowβ set theDF_BIND_NOWflag to indicate that the run-time loader should perform all relocation processing as part of object initialization. By default relocations may be performed on demand.originβ set theDF_ORIGINflag to indicate that the object requires$ORIGINprocessing.pac-pltβ AArch64 only, use pointer authentication in PLT.relβ use REL format for dynamic relocations.relaβ use RELA format for dynamic relocations.retpolinepltβ emit retpoline format PLT entries as a mitigation for CVE-2017-5715.rodynamicβ make the.dynamicsection read-only. TheDT_DEBUGtag will not be emitted.- the overlap trio: these specify whether two adjacent
PT_LOADsegments are allowed to overlap in pages.separate-loadable-segmentsβ disallows overlap.separate-codeβ allows overlap between two executable segments, or two non-executable segments.noseparate-codeβ (default) allows overlap.
shstkβ x86 only, use shadow stack.stack-size=sizeβ set the main thread's stack size to size. The stack size is recorded as the size of thePT_GNU_STACKprogram segment.start-stop-gcβ don't let__start_/__stop_references retain the associated C identifier name sections (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β create aPT_OPENBSD_WXNEEDEDsegment.
β¨ IMPLEMENTATION NOTES β¨
okay so real talk: ld.lld's handling of archive files (the ones with a .a file extension) is different from traditional linkers used on Unix-like systems.
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 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.
With certain archive inputs ld.lld may produce different results compared to traditional linkers. In practice, large bodies of third party software have been linked with ld.lld without material issues.
The --warn-backrefs option may be used to identify a linker invocation that may be incompatible with traditional Unix-like linker behavior.
sourced from Debian, dated May 12, 2019, for LD.LLD(1) β go link something iconic, bestie. πβ¨π¦
π¦ where this page comes from
- debian bookworm: lld-13 1:13.0.1-11+b2 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu jammy: lld-13 1:13.0.1-2ubuntu2 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu jammy: lld-13 1:13.0.1-2ubuntu2.2 Β· 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