LD.LLD(1)
β¨ NAME β¨
ld.lld β ELF linker from the LLVM project π
πΈ SYNOPSIS πΈ
ld.lld [options] objfile ...
π DESCRIPTION π
Okay bestie, so a linker is the friend who 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 ultimate group project merge. π
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 cap.
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. π¦
π 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. π
--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 benoneβ No compression.zlibβ The default compression level is 1 (fastest) as the debug info usually compresses well at that level. If you want to compress it more, you can specify-O2to set the compression level to 6.zstdβ The compression level is 5.
--crefβ Output cross reference table. If-Mapis specified, print to the map file.--defsym=symbol=expressionβ Define a symbol alias.expressionmay be another symbol or a linker script expression. For example, β--defsym=foo=barβ or β--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 onAArch64.--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-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-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.--undefined-versionβ Do not report version scripts that refer to 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-warnings,-wβ Suppress warnings and cancel--fatal-warnings.--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β keeps the executable output file around whenever it's still usable. no yeeting a perfectly good binary π--nostdlibβ only searches the directories you literally put on the command line, and that's it.-opath β writes the output executable, library, or object to path. skip it anda.outgets used as the default. classic default behavior fr.-Ovalueβ optimizes output file size. value can be:0β disables string merging.1β enables string merging.2β enables string tail merging. and if--compress-debug-sectionsis given too, it compresses debug sections at compression level6instead of1.
-O1 is the default. periodt.
--oformat=formatβ specifies the format for the output object file. the only supported format isbinary, which produces output with no ELF header at all. minimalism slay β¨--omagic,-Nβ sets the text and data sections to be readable and writable, doesn't page align sections, and links against static libraries.--opt-remarks-filenamefile β writes optimization remarks in YAML format to file.--opt-remarks-passespass-regex β filters optimization remarks by only letting through the passes that match pass-regex.--opt-remarks-with-hotnessβ includes hotness information in the optimization remarks file. π₯ iykyk--orphan-handling=modeβ controls how orphan sections get handled. an orphan section is one that's not specifically mentioned in a linker script π₯Ί mode can be:placeβ places orphan sections in suitable output sections.warnβ places orphan sections as forplace, and also reports a warning.errorβ places orphan sections as forplace, and also reports an error.
place is the default.
--pack-dyn-relocs=formatβ packs dynamic relocations in the given format. format can be:noneβ doesn't pack. dynamic relocations are encoded inSHT_REL(A).androidβ packs dynamic relocations inSHT_ANDROID_REL(A).relrβ packs relative relocations inSHT_RELR, and the rest of the dynamic relocations inSHT_REL(A).android+relrβ packs relative relocations inSHT_RELR, and the rest of the dynamic relocations inSHT_ANDROID_REL(A).
none is the default. and if --use-android-relr-tags is specified, it uses SHT_ANDROID_RELR instead of SHT_RELR.
--pic-veneerβ always generates position independent thunks.--pie,--pic-executableβ creates a position independent executable.--power10-stubs=modeβ whether to use Power10 instructions in call stubs forR_PPC64_REL24_NOTOCand TOC/NOTOC interworking. mode can be:yesβ (default) use.autoβ currently the same asyes.noβ don't use.
--print-gc-sectionsβ lists removed unused sections.--print-icf-sectionsβ lists identical folded sections.--print-mapβ prints a link map to the 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. π bookmarking it--pop-stateβ restores the states saved by--push-state.--relocatable,-rβ creates a relocatable object file.--reproduce=pathβ writes 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. unpack it and you can re-run the linker with the same options and input files. it's giving time capsule π--retain-symbols-file=fileβ retains only the symbols listed in the file.--rpath=value,-Rvalue β adds aDT_RUNPATHto the output.--rsp-quoting=valueβ quoting style for response files. the supported *value*s arewindowsandposix.--script=file,-Tfile β reads the linker script from file. if you give multiple linker scripts, they're processed as if they were concatenated in the order they appeared on the command line.--section-start=section=addressβ sets the address of section.--shared,--Bsharableβ builds a shared object.--shuffle-sections=seedβ shuffles matched sections using the given seed before mapping them to the output sections. if it's-1, it reverses the section order. if it's0, it uses a random seed. π² chaotic but valid--soname=value,-hvalue β setsDT_SONAMEto value.--sort-commonβ this option is ignored for GNU compatibility. bestie it literally does nothing, it's just here so GNU users don't get confused π--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 together in an archive.--strip-all,-sβ strips all symbols. implies--strip-debug.--strip-debug,-Sβ strips debugging information.--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-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 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.all(the default) means all of the concurrent threads supported.1disables multi-threading.--time-traceβ records a time trace. β±οΈ--time-trace-file=fileβ writes 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,-ysymbol β traces references to symbol.--undefined=symbol,-usymbol β if symbol isn't defined after symbol resolution, and there's a static library that contains an object file defining the symbol, it loads the member so the object file gets included in the output file.--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. 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β determines how to handle unresolved symbols.--use-android-relr-tagsβ usesSHT_ANDROID_RELR/DT_ANDROID_RELR*tags instead ofSHT_RELR/DT_RELR*.-v,-Vβ displays the version number and proceeds with linking if object files are specified.--versionβ displays the version number and exits.--verboseβ verbose mode. (yes bestie, that's the entire description π short and sweet)--version-script=fileβ reads a version script from file.--warn-backrefsβ warns about reverse or cyclic dependencies to or between static archives. you can 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) which should be ignored for--warn-backrefs.--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.28and earlier) have a bug that causes the segment that includes ifunc symbols to be marked as not executable when they're relocated. so even though the program compiles and links successfully, it gives a segmentation fault the moment 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 may be linked with an older glibc version. otherwise there's no need to use it, since the default value doesn't give a warning. 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.--whole-archiveβ forces loading of all members in a static library.--why-extract=fileβ prints to a file about why archive members are extracted.--wrap=symbolβ redirects symbol references to__wrap_symbol, and__real_symbolreferences to symbol.-zoption β linker option extensions. the little sub-menu of chaos πdead-reloc-in-nonalloc=section_glob=valueβ resolves a relocation in a matched non-SHF_ALLOCsection that references a discarded symbol to value. it accepts globs, and 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β makes the main stack executable. stack permissions are recorded in thePT_GNU_STACKsegment.bti-report=[none|warning|error]β specifies how to report the missingGNU_PROPERTY_AARCH64_FEATURE_1_BTIproperty.noneis the default, so the linker won't report the missing property; otherwise it'll be reported as a warning or an error.
-z cet-report=[none|warning|error]β how do you wanna be told about a missingGNU_PROPERTY_X86_FEATURE_1_IBTorGNU_PROPERTY_X86_FEATURE_1_SHSTKproperty bestie? πnoneis the default and means the linker justβ¦ won't tell you at all π. Anything else and it gets reported as a warning or as an error. Pick your chaos.-z force-btiβ force-enables the AArch64 BTI instruction in the PLT β¨, and throws a warning if an input ELF file is missing theGNU_PROPERTY_AARCH64_FEATURE_1_BTIproperty. Like, we're doing it anyway, but I am judging you a little. π-z 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.-z globalβ sets theDF_1_GLOBALflag in theDYNAMICsection. Different loaders can decide how to handle this flag on their own β it's giving "you figure it out" energy. π«Ά-z 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 don't have the usual drawbacks. You must combine this with the-z notextoption, no cap. π§ͺ-z initfirstβ sets theDF_1_INITFIRSTflag to say this module should be initialized first. main character energy, literally. π-z 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. Slotted in the middle, as one does. π-z muldefsβ don't error out if a symbol is defined multiple times. The first definition wins. This is a synonym for--allow-multiple-definition. π-z nocombrelocβ disables combining and sorting multiple relocation sections.-z nocopyrelocβ disables the creation of copy relocations.-z nodefaultlibβ sets theDF_1_NODEFLIBflag to say default library search paths should be ignored. Bye bye search path bestie. πΈ-z nodeleteβ sets theDF_1_NODELETEflag to say this object cannot be unloaded from a process. It's here forever. β¨-z nodlopenβ sets theDF_1_NOOPENflag to say this object may not be opened bydlopen(3). Locked. π-z nognustackβ do not emit thePT_GNU_STACKsegment.-z norelroβ don't indicate that portions of the object should be mapped read-only after initial relocation processing. The object will omit thePT_GNU_RELROsegment.-z notextβ allow relocations against read-only segments. Sets theDT_TEXTRELflag in theDYNAMICsection.-z nowβ sets theDF_BIND_NOWflag to tell the run-time loader it should do all relocation processing as part of object initialization. By default, relocations may be performed on demand. Like doing your homework all at once instead of the night before. π-z originβ sets theDF_ORIGINflag to say the object requires$ORIGINprocessing.-z pac-pltβ AArch64 only, use pointer authentication in the PLT. π-z pack-relative-relocsβ similar to-pack-dyn-relocs=relr, but it synthesizes theGLIBC_ABI_DT_RELRversion dependency if there's aGLIBC_2.*version dependency. Heads up: glibcld.sorejects loading a dynamically linked object without theGLIBC_ABI_DT_RELRversion dependency. So yeah, that one matters fr fr. β οΈ-z relβ useRELformat for dynamic relocations.-z relaβ useRELAformat for dynamic relocations.-z retpolinepltβ emit retpoline format PLT entries as a mitigation for CVE-2017-5715. π‘οΈ-z rodynamicβ make the.dynamicsection read-only. Heads up: theDT_DEBUGtag will not be emitted.-z separate-loadable-segments,-z separate-code,-z noseparate-codeβ these three specify whether two adjacentPT_LOADsegments are allowed to overlap in pages.noseparate-codeis the default and allows overlap.separate-codeallows overlap between two executable segments, or between two non-executable segments.separate-loadable-segmentsdisallows overlap entirely. π-z shstkβ x86 only, use shadow stack. π-z 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.-z start-stop-gcβ don't let__start_/__stop_references retain the associated C identifier name sections (this is the default).-z nostart-stop-gcβ let__start_/__stop_references retain the associated C identifier name sections.-z textβ do not allow relocations against read-only segments. This is the default.-z wxneededβ create aPT_OPENBSD_WXNEEDEDsegment.
π« IMPLEMENTATION NOTES π«
okay bestie this next bit is the tea β β 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 better, not worse, just built different. π¦
Traditional linkers maintain a set of undefined symbols during linking. The linker processes each file in the order 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, with its undefined symbols added to the set. And when it hits an archive file, a traditional linker searches the objects contained inside and processes the ones that satisfy symbols in the unresolved set. Very "one pass, in order, no take-backs" of them. π
Handling mutually dependent archives can be awkward with a traditional linker, ngl. Archive files might have to be specified multiple times, or you can use the special command line options --start-group and --end-group to make the linker loop over the files in the group until no new symbols get added to the set. It's giving "keep spinning until it settles". π
ld.lld does it differently: it records all symbols found in objects and archives as it iterates over the 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. Obsessed with that efficiency honestly. β
With certain archive inputs, ld.lld may produce different results compared to traditional linkers. But 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. π«Ά
And if you ever need to hunt down a linker invocation that might be incompatible with traditional Unix-like linker behavior, the --warn-backrefs option is right there for you. iykyk. π
That's the whole page bestie, you made it to the end and you ate. π β¨
This page comes from the Debian build, dated May 12, 2019 β so go forth, link things, and remember: the vibes are immaculate but the flags are exact. ππ
π¦ where this page comes from
- debian bookworm: lld-16 1:16.0.6-15~deb12u1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu noble: lld-16 1:16.0.6-23ubuntu4 Β· 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