LD.LLD(1)
π NAME π
okay bestie, meet ld.lld β the ELF linker from the LLVM project. This is ld.lld(1), and she's here to link your stuff. π
β¨ SYNOPSIS β¨
ld.lld [options] objfile ...
π DESCRIPTION π
So a linker? It's giving matchmaker but for object files. It takes one or more object, archive, and library files and smooshes them into one output file β could be an executable, a shared library, or another object file. Along the way it relocates code and data from the input files and resolves symbol references between them. Slay. π«Ά
ld.lld is a drop-in replacement for the GNU BFD and gold linkers. She accepts most of the same command line arguments and linker scripts as GNU linkers. No cap.
Right now ld.lld supports these targets: i386, x86-64, ARM, AArch64, PowerPC32, PowerPC64, MIPS32, MIPS64, RISC-V, AMDGPU, Hexagon and SPARC V9. If you invoke her as lld-link, she acts as a Microsoft link.exe-compatible linker, and if you invoke her as ld.ld64, she acts as macOS's ld. And here's the iconic part: 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. Periodt. π
π OPTIONS π
okay so many options have both a single-letter and long form. When 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.--Bsymbolicβ bind defined symbols locally.--Bsymbolic-functionsβ bind defined function symbols locally.--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 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.--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.--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.--fatal-warningsβ treat warnings as errors. π--filter=value,-F valueβ set theDT_FILTERfield to the specifiedvalue.--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 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-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β only search directories specified on the command line.-o pathβ write the output executable, library, or object topath. If not specified,a.outis used as a default.-Ovalueβ optimize output file size.valuemay 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β tells the linker what format the output object file should be. literally only one option on the menu:binary, which spits out output with no ELF header at all. that's it bestie, that's the whole list π--omagic,-Nβ makes the text and data sections readable AND writable π«Ά, skips page-aligning the sections, and links against static libraries. chaotic but iconic.--opt-remarks-filename fileβ writes optimization remarks out in YAML format into file β¨--opt-remarks-passes pass-regexβ filters those optimization remarks so only the passes matching pass-regex get through. gatekeeping, but make it productive πΈ--opt-remarks-with-hotnessβ adds hotness info into the optimization remarks file π₯ (yes, actual hotness, it's giving profile data)--orphan-handling=modeβ controls what happens to orphan sections. an orphan section is one that nobody bothered to mention in the linker script π abandoned fr. mode can be:placeβ places orphan sections into suitable output sections. this is the default.warnβ does whatplacedoes, and also throws a warning.errorβ does whatplacedoes, and also throws an error.
--pack-dyn-relocs=formatβ packs dynamic relocations in the given format. format can be:noneβ don't pack. dynamic relocations get encoded inSHT_REL(A).androidβ packs dynamic relocations intoSHT_ANDROID_REL(A).relrβ packs relative relocations intoSHT_RELR, and the rest of the dynamic relocations intoSHT_REL(A).android+relrβ packs relative relocations intoSHT_RELR, and the rest of the dynamic relocations intoSHT_ANDROID_REL(A).
none is the default. and heads up: if --use-android-relr-tags is specified, it uses SHT_ANDROID_RELR instead of SHT_RELR π
--pic-veneerβ always generates position independent thunks. no cap.--pie,--pic-executableβ creates a position independent executable π¦--print-gc-sectionsβ lists out the unused sections that got removed. exposing them, honestly--print-icf-sectionsβ lists the identical folded sections β¨--print-mapβ prints a link map straight to standard output π--print-archive-stats=fileβ writes archive usage statistics to the specified file. it prints the numbers of members and fetched members for each archive π--push-stateβ saves the current state of--as-needed,--static, and--whole-archive. a little save point, we love to see it π--pop-stateβ undoes whatever--push-statedid. rewind time bestie--relocatable,-rβ creates a relocatable object file π--reproduce=pathβ writes a tar file to path that contains all the input files you'd need to reproduce the link, plus a text file calledresponse.txtwith the command line options, plus a text file calledversion.txtcontaining the output ofld.lld --version. once you unpack that archive you can re-run the linker with the exact same options and input files. time capsule energy fr π°οΈ--retain-symbols-file=fileβ retains ONLY the symbols listed in file. everyone else, goodbye π--rpath=value,-R valueβ adds aDT_RUNPATHto the output π--rsp-quoting=valueβ sets the quoting style for response files. the supported values arewindowsandposix.--script=file,-T fileβ reads the linker script from file. if you hand it multiple linker scripts, they get processed as if they were concatenated in the order they appeared on the command line π--section-start=section=addressβ sets the address of a section.--shared,--Bsharableβ builds a shared object π«Ά--shuffle-sections=seedβ shuffles input sections using the given seed. if it's0, it uses a random seed π² gambling but for linkers--soname=value,-h valueβ setsDT_SONAMEto value.--sort-commonβ this option is ignored for GNU compatibility. it's just there for the vibes, doing absolutely nothing π--sort-section=valueβ specifies the sections sorting rule when a linkerscript is used.--start-libβ starts a grouping of objects that should be treated as if they were all together in an archive π¦--strip-all,-sβ strips all symbols. bye bye everything π--strip-debug,-Sβ strips debugging information. keeps the rest, just not the debug tea π΅--symbol-ordering-file=fileβ lays out sections in the order specified by file π--sysroot=valueβ sets the system root.--target1-absβ interpretsR_ARM_TARGET1asR_ARM_ABS32.--target1-relβ interpretsR_ARM_TARGET1asR_ARM_REL32.--target2=typeβ interpretsR_ARM_TARGET2as type, where type is one ofrel,abs, orgot-rel.--Tbss=valueβ same as--section-startbut with.bssas the sectionname.--Tdata=valueβ same as--section-startbut with.dataas the sectionname.--Ttext=valueβ same as--section-startbut with.textas the sectionname.--thinlto-cache-dir=valueβ path to the 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.allis the default and means all the concurrent threads supported.1disables multi-threading entirely π§΅ multitasking queen vs. one girl doing everything--time-traceβ records a time trace β±οΈ--time-trace-file=fileβ writes the time trace output to file.--time-trace-granularity=valueβ minimum time granularity (in microseconds) traced by the time profiler π°οΈ--traceβ prints the names of the input files.--trace-symbol=symbol,-y symbolβ traces references to symbol π--undefined=symbol,-u symbolβ if symbol isn't defined after symbol resolution, and there's a static library containing an object file that defines the symbol, it loads that member so the object file gets included in the output file. dragging it out of the archive by name π--undefined-glob=patternβ a synonym for--undefined, except it takes a glob pattern. in a glob pattern,*matches zero or more characters,?matches any single character, and[...]matches the characters within the brackets. every symbol matching a given pattern gets handled as if it were passed as an argument to--undefinedπ--uniqueβ creates a separate output section for every orphan input section. no sharing, everyone gets their own room πͺ--unresolved-symbols=valueβ determines how unresolved symbols get handled π€·--use-android-relr-tagsβ usesSHT_ANDROID_RELR/DT_ANDROID_RELR*tags instead ofSHT_RELR/DT_RELR*.-vβ displays the version number and then proceeds with linking if object files are specified. shows up AND does the work π-V,--versionβ displays the version number and exits. no linking, just the flex π--verboseβ verbose mode π£οΈ--version-script=fileβ reads the version script from file.--warn-backrefsβ warns about reverse or cyclic dependencies to or between static archives. you'd use this to make sure the linker invocation stays compatible with traditional Unix-like linkers π--warn-backrefs-exclude=globβ a glob describing an archive (or an object file within--start-lib) that should be ignored for--warn-backrefs. a lil do-not-warn list--warn-commonβ warns about duplicate common symbols π―--warn-ifunc-textrelβ warns about using ifunc symbols together with text relocations. older versions of the glibc library (2.28 and earlier) have a bug that marks the segment containing ifunc symbols as not executable when they get relocated. so even though the program compiles and links just fine, it gives a segmentation fault when the instruction pointer reaches an ifunc symbol π. use-warn-ifunc-textrelto let lld give you a warning if the code may include ifunc symbols, may do text relocations, and gets linked with an older glibc version. otherwise there's no need to use it, since the default value doesn't warn. this flag was introduced in late 2018, has no counterpart in the ld and gold linkers, and may be removed in the future β οΈ--warn-unresolved-symbolsβ reports unresolved symbols as warnings instead of errors.--whole-archiveβ forces loading of all members in a static library π nobody gets left out--wrap=symbolβ redirects references to__wrap_symboland__real_symbolreferences to symbol π-z optionβ linker option extensions β¨ these are the little extras:dead-reloc-in-nonalloc=section_glob=valueβ resolves a relocation in a matched non-SHF_ALLOCsection that references a discarded symbol to value. accepts globs. if a section matches more than one option, the last option wins. the recommended move is ordering them from least specific to most specific match πexecstackβ makes the main stack executable. stack permissions get recorded in thePT_GNU_STACKsegment β οΈforce-btiβ force-enables the AArch64 BTI instruction in the PLT, and warns if an input ELF file doesn't have theGNU_PROPERTY_AARCH64_FEATURE_1_BTIproperty.force-ibtβ force-enables Intel Indirect Branch Tracking in the PLT, and warns if an input ELF file doesn't have theGNU_PROPERTY_X86_FEATURE_1_IBTproperty.globalβ sets theDF_1_GLOBALflag in the DYNAMIC section. different loaders can decide how to handle this flag on their own π€·ifunc-nopltβ does not emit PLT entries for ifunc symbols. instead, it emits text relocations referencing the resolver. this is an experimental optimization and only suitable for standalone environments where text relocations don't have the usual drawbacks. it must be combined with the-z notextoption β οΈinitfirstβ sets theDF_1_INITFIRSTflag to indicate the module should be initialized first π₯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.muldefsβ doesn't error if a symbol is defined multiple times. the first definition gets used. this is a synonym for--allow-multiple-definition.nocombrelocβ disables combining and sorting multiple relocation sections π«
nocopyrelocβ turns off the creation of copy relocations. bye bestie, no copy relocs for you πnodefaultlibβ sets theDF_1_NODEFLIBflag, which basically says "ignore the default library search paths, we're not doing that today." π«nodeleteβ sets theDF_1_NODELETEflag, so the object can't be unloaded from a process. it's staying, it lives here now πnodlopenβ sets theDF_1_NOOPENflag, meaning the object may not be opened bydlopen(3). sorry, doors closed πͺnognustackβ don't emit thePT_GNU_STACKsegment. it's just not giving segment today β¨norelroβ do not indicate that portions of the object should be mapped read-only after the initial relocation processing. the object will omit thePT_GNU_RELROsegment. lowkey a choice but ok π«£notextβ allow relocations against read-only segments. sets theDT_TEXTRELflag in theDYNAMICsection. πnowβ sets theDF_BIND_NOWflag, telling the run-time loader to do all the relocation processing as part of object initialization. by default, relocations may be performed on demand instead (very "we'll get to it when we get to it" energy, no shade).originβ sets theDF_ORIGINflag, so the object requires$ORIGINprocessing. π±pac-pltβ AArch64 only bestie, use pointer authentication in PLT. πrelβ useRELformat for dynamic relocations.relaβ useRELAformat for dynamic relocations.retpolinepltβ emit retpoline format PLT entries as a mitigation for CVE-2017-5715. protection era, we love to see it π‘οΈrodynamicβ makes the.dynamicsection read-only. heads up: 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. like, are we sharing the page or not?? πnoseparate-code(the default) β allows overlap.separate-codeβ allows overlap between two executable segments, or between two non-executable segments.separate-loadable-segmentsβ disallows overlap. hard boundary, no touching π§
shstkβ x86 only, use shadow stack. β¨stack-size=sizeβ set the main thread's stack size to size. it gets recorded as the size of thePT_GNU_STACKprogram segment. πtextβ do not allow relocations against read-only segments. this is the default, so if you did nothing, congrats, you already have it πwxneededβ create aPT_OPENBSD_WXNEEDEDsegment. π
π IMPLEMENTATION NOTES π
okay so this part is important and honestly kind of iconic, because ld.lld's handling of archive files (the ones with a .a file extension) is different from the traditional linkers used on Unix-like systems. not wrong, just different. main character behavior.
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 that set of undefined symbols becomes empty. an object file gets linked into the output object when it's encountered, and its undefined symbols get added to the set. then, 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 can be lowkey awkward with a traditional linker, ngl. archive files may have to be specified multiple times, or you can use the special command line options --start-group and --end-group to have the linker loop over the files in the group until no new symbols are added to the set. π
ld.lld does it differently: it records all symbols found in objects and archives as it iterates over command line arguments. and 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. no waiting, no second pass, just slay β¨
β οΈ With certain archive inputs, ld.lld may produce different results compared to traditional linkers. that's a real thing, bestie, don't @ me.
In practice, large bodies of third party software have been linked with ld.lld without material issues. so like, it's fine. it's fine!! π
The --warn-backrefs option may be used to identify a linker invocation that may be incompatible with traditional Unix-like linker behavior. use it, it's your little detective π
and that's the whole page, bestie!! π this one came from the Debian folks, dated May 12, 2019 β so if you're reading this in the future, yes, it's vintage, and vintage is always in π thanks for reading all three parts, you ate that fr fr ππ π¦
π¦ where this page comes from
- ubuntu jammy: lld-12 1:12.0.1-19ubuntu3 Β· 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