LD.LLD(1)
π LD.LLD(1) β the ELF linker from the LLVM project π
okay bestie, sit down, hydrate, we're reading a whole linker manual together and honestly? it's giving main character energy. this is the ld.lld page from the General Commands Manual, and we're doing it in four parts because she's long. part one starts now. π
β¨ NAME β¨
ld.lld β the ELF linker, straight outta the LLVM project π¦
β¨ SYNOPSIS β¨
ld.lld [options] objfile ...
like, options first, then all ur object files. slay. π
β¨ DESCRIPTION β¨
so what even is a linker, you ask? a linker takes one or more object, archive, and library files and smushes them all together into one output file β could be an executable, could be a shared library, could be another object file. that's the vibe. π on the way it relocates code and data from the input files and resolves symbol references between them. literally its whole job.
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 those GNU linkers do. no cap, you can just... swap it in. π
right now ld.lld supports these targets: i386, x86-64, ARM, AArch64, LoongArch, PowerPC32, PowerPC64, MIPS32, MIPS64, RISC-V, AMDGPU, Hexagon and SPARC V9. and here's the cute part β ld.lld acts as a Microsoft link.exe-compatible linker if you invoke it as lld-link, and as macOS's ld if you invoke it 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. iconic behaviour tbh.
β¨ OPTIONS β¨
many options have both a single-letter and a long form, because of course they do. π when using the long form options β other than those beginning with the letter o β you may specify them using either one or two dashes preceding the option name. but long options beginning with o need two dashes, because otherwise everyone gets confused with the -o path option. so that's the rule, remember it. π
--allow-multiple-definitionβ do not error if a symbol is defined multiple times. the first definition will be used. first come first served, bestie. π--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. not me being picky about which libs get tagged. π--auxiliary=valueβ set theDT_AUXILIARYfield to the specified name.--Bdynamic,--dyβ link against shared libraries.--Bstatic,--static,--dnβ do not link against shared libraries. (the static life. π)-Bno-symbolicβ don't bind default visibility defined symbols locally for-shared(this is the default).-Bsymbolicβ bind default visibility defined symbols locally for-shared. also sets theDF_SYMBOLICflag. two jobs, one flag. π-Bsymbolic-non-weakβ bind default visibility definedSTB_GLOBALsymbols locally for-shared.-Bsymbolic-functionsβ bind default visibility defined function symbols locally for-shared.-Bsymbolic-non-weak-functionsβ bind default visibility definedSTB_GLOBALfunction symbols locally for-shared.--be8β write a Big Endian ELF File using BE8 format (AArch32 only).--branch-to-branchβ enable the branch-to-branch optimizations: a branch whose target is another branch instruction gets rewritten to point to the latter branch target (AArch64 and X86_64 only). enabled by default at-O2. π§--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. don't use it for ur secrets bestie.--build-idβ synonym for--build-id=sha1.--call-graph-profile-sort=algorithmβalgorithmmay be:noneβ ignore call graph profile.hfsortβ use hfsort.cdsortβ use cdsort (default).
--color-diagnostics=valueβ use colors in diagnostics.valuemay be one ofalways,auto, andnever.autoenables color if and only if output is to a terminal. (we love a conditional glow-up π)--color-diagnosticsβ alias for--color-diagnostics=auto.--compress-debug-sections=valueβ compress DWARF debug sections. the sections remain uncompressed if the compressed content would be larger.valuemay be:noneβ no compression.zlibβ the default compression level is1(fastest) as the debug info usually compresses well at that level.zstdβ use the default compression level in zstd.
--compress-sections=section-glob={none,zlib,zstd}[:level]β compress output sections that match the glob and do not have theSHF_ALLOCflag. matched sections remain uncompressed if the compressed content would be larger. the compression level islevel(if specified) or a default speed-focused level. this is like a generalized--compress-debug-sections. πΈ--crefβ output cross reference table. if-Mapis specified, print to the map file.--debug-namesβ generate a merged.debug_namessection.--default-script=file,-dT fileβ in the absence of--script, read this default linker script.--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. (we're taking the C++ out of the names, it's a whole makeover β¨)--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. nothing gets thrown away here. π«Ά--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.--enable-non-contiguous-regionsβ spill input sections to later matching output sections to avoid memory region overflow. (the overflow is NOT invited to the party π«)--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. (chaos mode: unlocked π)--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. no more "it's just a warning" excuses, bestie. π€--filter=value,-F valueβ set theDT_FILTERfield to the specified value.--fini=symbolβ specify a finalizer function.--force-group-allocationβ only meaningful for-r. section groups are discarded. if two section group members are placed to the same output section, combine their relocations as well.--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 allowslldto 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.
part one done, and there's more coming β don't you dare close the tab π
--no-color-diagnosticsβ bestie, this turns OFF the rainbow in your diagnostics. No colors, just plain text. π--no-demangleβ leaves symbol names in their raw mangled form, no demangling. π--no-dynamic-linkerβ inhibits output of an.interpsection. it just... doesn't go there. β¨--no-fortran-commonβ do not go searching archive members for definitions to overrideCOMMONsymbols. π¦--no-gc-sectionsβ garbage collection of unused sections? disabled. π--no-gnu-uniqueβ disablesSTB_GNU_UNIQUEsymbol binding. periodt. π--no-merge-exidx-entriesβ disables merging of.ARM.exidxentries. πΈ--no-nmagicβ page align sections. that's it, that's the whole thing. β--no-omagicβ does NOT set the text data sections to be writable, and page aligns sections. π--no-relaxβ disables 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 cap. π--undefined-versionβ do not report version scripts that refer to undefined symbols. π«Ά--no-undefinedβ reports unresolved symbols even if the linker is creating a shared library. it's giving strict. π--no-warn-mismatchβ do not reject unknown section types. π--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β retain the executable output file whenever it is still usable. π--nostdlibβ only search directories specified on the command line. no sneaky defaults, iykyk. π-opath β write the output executable, library, or object to path. If you don't specify it,a.outis used as a default. π-Ovalueβ optimize the output file. value may be:0β disable string merging.1β enable string merging.2β enable string tail merging and branch-to-branch optimization.
-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. π--omagic,-Nβ set the text and data sections to be readable and writable, do not page align sections, and 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β controls 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. π€
--package-metadataβ emit a percent-encoded string to the.note.packagesection. For example,%25decodes to a single%. πΈ--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. It prints 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. π--randomize-section-padding=seedβ randomly insert padding between input sections and at the start of each segment using the given seed. Padding is inserted into output sections with names matching the following patterns:.bss,.data,.data.rel.ro,.lbss,.ldata,.lrodata,.ltext,.rodataand.text*. π---relax-gpβ enable global pointer relaxation for RISC-V. (yep, three dashes, that's how it's written, iykyk) π§--relocatable,-rβ create relocatable object file. π--remap-inputs=from-glob=to-fileβ input files matching from-glob are mapped to to-file. Use/dev/nullto ignore an input file. π--remap-inputs-file=fileβ remap input files based on patterns in file. Each line in the remap file is of the formatfrom-glob=to-fileor a comment starting with#. π--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 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. it literally just sits there, no thoughts head empty. π--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. π§΅--fat-lto-objectsβ use the.llvm.ltosection, which contains LLVM bitcode, in fat LTO object files to perform LTO. π--no-fat-lto-objectsβ ignore the.llvm.ltosection in relocatable object files (default). π--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,-Vβ display the version number and proceed with linking if object files are specified. π--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β a glob that says "bestie, ignore this one". It describes an archive (or an object file inside--start-lib) that should be skipped entirely by--warn-backrefs. No drama from that file, periodt.--warn-commonβ yells at you about duplicate common symbols. It's giving "we have that at home already".--warn-ifunc-textrelβ warns when you're usingifuncsymbols together with text relocations. Okay so listen, older glibc (2.28 and earlier) has a bug where the segment holdingifuncsymbols gets marked as not executable once they're relocated. So your program compiles and links all cute and fine, and then the instruction pointer reaches anifuncsymbol and it just segmentation faults. π Use-warn-ifunc-textrelto let lld throw a warning if your code may includeifuncsymbols, may do text relocations, and is being linked with an older glibc. Otherwise? Don't bother, the default value gives no warning. This flag showed up in late 2018, has no counterpart in theldandgoldlinkers, and may be removed in the future. iykyk--warn-unresolved-symbolsβ reports unresolved symbols as warnings instead of making it a whole thing.--whole-archiveβ forces the load of all the members in a static library. No cherry-picking, we take the whole menu. π--why-extract=fileβ prints to a file all about why archive members are being extracted. Receipts, basically. π§Ύ--why-live=globβ for each symbol matching the glob, reports a chain of references that's preventing garbage collection. It's the "why are you still here" of linking. π--wrap=symbolβ redirects references to symbol over to__wrap_symbol, and references to__real_symbolback over to symbol. Chaotic but iconic.
π
-z option π
Linker option extensions. The little -z that could. β¨
dead-reloc-in-nonalloc=section_glob=valueβ resolves a relocation in a matched non-SHF_ALLOCsection that references a discarded symbol, and gives it value. It accepts globs, and if a section matches more than one option, the last option wins (takes precedence). The recommended order is least specific β most specific match. Match your outfit to your section, basically.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 at all; otherwise it'll be reported as a warning or an error.cet-report=[none|warning|error]β specifies how to report the missingGNU_PROPERTY_X86_FEATURE_1_IBTorGNU_PROPERTY_X86_FEATURE_1_SHSTKproperties.noneis the default, linker won't report the missing property; otherwise it's a warning or an error.dynamic-undefined-weakβ makes undefined weak symbols dynamic when the dynamic symbol table is present, if they're referenced from relocatable object files and not forced local by symbol visibility or versioning. They do not get made dynamic whennodynamic-undefined-weakis specified.dynamic-undefined-weakis the default when building a shared object, or when an input shared object is present.pauth-report=[none|warning|error]β specifies how to report the missingGNU_PROPERTY_AARCH64_FEATURE_PAUTHproperty.noneis the default, linker won't report the missing property; otherwise it'll be a warning or an error.force-btiβ force enable AArch64 BTI instruction in PLT, and warn if an input ELF file does not have theGNU_PROPERTY_AARCH64_FEATURE_1_BTIproperty.force-ibtβ force enable Intel Indirect Branch Tracking in PLT, and warn if an input ELF file does not have theGNU_PROPERTY_X86_FEATURE_1_IBTproperty.globalβ sets theDF_1_GLOBALflag in theDYNAMICsection. Different loaders can decide how to handle this flag on their own. Everyone's got their own vibe, fr fr.ifunc-nopltβ do not emit PLT entries forifuncsymbols. 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. Heads up: this option must be combined with the-z notextoption.initfirstβ sets theDF_1_INITFIRSTflag to indicate the module should be initialized first. Main character gets to go first. πinterposeβ set 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.lrodata-after-bssβ places.lrodataafter.bss. Simple as that, bestie.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. It's staying. Forever. π«Ά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.nosectionheaderβ don't generate the section header table.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.pack-relative-relocsβ similar to-pack-dyn-relocs=relr, but it synthesizes theGLIBC_ABI_DT_RELRversion dependency if there is aGLIBC_2.*version dependency. And it has to, because glibcld.sorejects loading a dynamically linked object without theGLIBC_ABI_DT_RELRversion dependency. No pass, no entry.relβ use REL format for dynamic relocations.relaβ use RELA format for dynamic relocations.retpolinepltβ emit retpoline format PLT entries as a mitigation forCVE-2017-5715. Security slay. π‘οΈrodynamicβ make the.dynamicsection read-only. TheDT_DEBUGtag will not be emitted.separate-loadable-segments,separate-code,noseparate-codeβ these specify whether two adjacentPT_LOADsegments are allowed to overlap in pages.noseparate-code(default) allows overlap.separate-codeallows overlap between two executable segments, or two non-executable segments.separate-loadable-segmentsdisallows overlap entirely.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 the size.PT_GNU_STACKprogram segment. (Yes, that's what it says, bestie, I'm just the messenger π)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.nobtcfiβ create aPT_OPENBSD_NOBTCFIsegment.wxneededβ create aPT_OPENBSD_WXNEEDEDsegment.
π ENVIRONMENT VARIABLES π
The vibes your shell can set for you. π¦
LLD_REPRODUCEβ create a reproduce tarball with the specified filename. If--reproduceis specified,--reproducetakes precedence. (Options over env vars, always. π)LLD_VERSIONβld.lldcreates a section named.commentcontaining the LLD version string. The version string can be overridden by this environment variable, which is useful to eliminate differences in the binary caused by LLD version number differences. Same binary, different lore. β¨
π IMPLEMENTATION NOTES π
okay bestie, this is the part where we talk about how ld.lld is built different. specifically? its whole relationship with archive files β you know, the ones with a .a file extension β is not the same as what the traditional linkers on Unix-like systems do. like, same energy, different execution. π¦
π the old-school way (traditional linkers)
so traditional linkers keep a whole set of undefined symbols hanging around while they're linking. the vibe is:
- the linker goes through every file in the exact order it shows up on the command line, and it keeps going until that set of undefined symbols is empty. that's the whole loop.
- the moment it hits an object file, that object gets linked into the output object, and its undefined symbols get tossed into the set. boom, added.
- and when it runs into an archive file? it digs through the objects inside, and processes the ones that satisfy symbols sitting in that unresolved set. β¨
π the mutually dependent archives problem
this is where traditional linkers start acting up. if your archives depend on each other (mutual dependency, the messiest kind of relationship honestly), it gets awkward. your options are:
- specify the archive files multiple times on the command line, or
- use the special command line options
--start-groupand--end-group, which make the linker loop over the files in the group until no new symbols get added to the set.
it's giving "we have to keep going around in circles until nothing changes." π
π how ld.lld does it (main character behavior)
ld.lld said "not me doing all that." instead:
ld.lld records all symbols found in objects and archives as it iterates over command line arguments. so when it 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 looping required. π
β οΈ the caveat, because of course there's a caveat
with certain archive inputs, ld.lld may produce different results compared to traditional linkers. that's just the tea. π
but β and this is the reassuring part β 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're worried about a specific linker invocation that might be incompatible with traditional Unix-like linker behavior? the --warn-backrefs option is right there to help you identify it. use it. it's literally what it's for. π«Ά
and that's the whole page, bestie!! you made it to the end of all four parts, which is genuinely iconic of you. π
this lil manual page is from the Debian packaging, dated Jul 25, 2023, and its name is LD.LLD(1). go forth and link things. slay. πβ¨πΈ
π¦ where this page comes from
- epel 10: lld21 21.1.8-8.el10_3 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 43: lld 21.1.2-1.fc43 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 43: lld 21.1.2-1.fc43 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 43: lld 21.1.8-6.fc43 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 43: lld 21.1.8-6.fc43 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 44: lld21 21.1.8-3.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 44: lld21 21.1.8-5.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- ubuntu questing: lld-21 1:21.1.2-2ubuntu6
- ubuntu resolute: lld-21 1:21.1.8-6ubuntu1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu stonking: lld-21 1:21.1.8-10ubuntu2 Β· 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