LD.LLD(1)

πŸ“¦ version 16.0.6, in debian bookworm, ubuntu noble

✨ 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 set DT_NEEDED for shared libraries if used.
  • --auxiliary=value β€” Set the DT_AUXILIARY field 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 the DF_SYMBOLIC flag.
  • -Bsymbolic-functions β€” Bind default visibility defined function symbols locally for -shared.
  • -Bsymbolic-non-weak-functions β€” Bind default visibility defined STB_GLOBAL function symbols locally for -shared.
  • --build-id=value β€” Generate a build ID note. value may be one of fast, md5, sha1, tree, uuid, 0xhex-string, and none. tree is an alias for sha1. Build-IDs of type fast, md5, sha1, and tree are calculated from the object contents. fast is not intended to be cryptographically secure.
  • --build-id β€” Synonym for --build-id=fast.
  • --color-diagnostics=value β€” Use colors in diagnostics. value may be one of always, auto, and never. auto enables color if and only if output is to a terminal.
  • --color-diagnostics β€” Alias for --color-diagnostics=auto.
  • --compress-debug-sections=value β€” Compress DWARF debug sections. value may be
    • none β€” 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 -O2 to set the compression level to 6.
    • zstd β€” The compression level is 5.
  • --cref β€” Output cross reference table. If -Map is specified, print to the map file.
  • --defsym=symbol=expression β€” Define a symbol alias. expression may be another symbol or a linker script expression. For example, β€˜--defsym=foo=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 type PT_INTERP.
  • --dynamic-list=file β€” Similar to --export-dynamic-symbol-list. When creating a shared object, implies -Bsymbolic but does not set DF_SYMBOLIC
  • --EB β€” Select the big-endian format in the OUTPUT_FORMAT command.
  • --EL β€” Select the little-endian format in the OUTPUT_FORMAT command.
  • --eh-frame-hdr β€” Request creation of .eh_frame_hdr section and PT_GNU_EH_FRAME segment 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 script script_path upon some error, with tag as 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. tag may be missing-lib followed by the name of the missing library. undefined-symbol followed 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-local STV_DEFAULT symbols shouldn't be bound to definitions within the shared object even if they would otherwise be due to -Bsymbolic , -Bsymbolic-functions or --dynamic-list
  • --export-dynamic-symbol-list=file β€” Read a list of dynamic symbol patterns from file. Apply --export-dynamic-symbol on each pattern.
  • --fatal-warnings β€” Treat warnings as errors.
  • --filter=value, -F value β€” Set the DT_FILTER field to the specified value.
  • --fini=symbol β€” Specify a finalizer function.
  • --format=input-format, -b input-format β€” Specify the format of the inputs following this option. input-format may be one of binary, elf, and default. default is a synonym for elf.
  • --gc-sections β€” Enable garbage collection of unused sections.
  • --gdb-index β€” Generate .gdb_index section.
  • --hash-style=value β€” Specify hash style. value may be sysv, gnu, or both. both is the default.
  • --help β€” Print a help message.
  • --icf=all β€” Enable identical code folding.
  • --icf=safe β€” Enable safe identical code folding.
  • --icf=none β€” Disable identical code folding.
  • --ignore-data-address-equality β€” Ignore address equality of data. C/C++ requires each data to have a unique address. This option allows lld to do unsafe optimization that breaks the requirement: create copies of read-only data or merge two or more read-only data that happen to have the same value.
  • --ignore-function-address-equality β€” Ignore address equality of functions. This option allows non-PIC calls to a function with non-default visibility in a shared object. The function may have different addresses within the executable and within the shared object.
  • --image-base=value β€” Set the base address to value.
  • --init=symbol β€” Specify an initializer function.
  • --keep-unique=symbol β€” Do not 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 to file.
  • --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 set DT_NEEDED for 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 .interp section.
  • --no-fortran-common β€” Do not search archive members for definitions to override COMMON symbols.
  • --no-gc-sections β€” Disable garbage collection of unused sections.
  • --no-gnu-unique β€” Disable STB_GNU_UNIQUE symbol binding.
  • --no-merge-exidx-entries β€” Disable merging .ARM.exidx entries.
  • --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 disables R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX GOT 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.
  • -o path β€” writes the output executable, library, or object to path. skip it and a.out gets 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-sections is given too, it compresses debug sections at compression level 6 instead of 1.

-O1 is the default. periodt.

  • --oformat=format β€” specifies the format for the output object file. the only supported format is binary, 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-filename file β€” writes optimization remarks in YAML format to file.
  • --opt-remarks-passes pass-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 for place, and also reports a warning.
    • error β€” places orphan sections as for place, 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 in SHT_REL(A).
    • android β€” packs dynamic relocations in SHT_ANDROID_REL(A).
    • relr β€” packs relative relocations in SHT_RELR, and the rest of the dynamic relocations in SHT_REL(A).
    • android+relr β€” packs relative relocations in SHT_RELR, and the rest of the dynamic relocations in SHT_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 for R_PPC64_REL24_NOTOC and TOC/NOTOC interworking. mode can be:
    • yes β€” (default) use.
    • auto β€” currently the same as yes.
    • 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 called response.txt containing the command line options, and a text file called version.txt containing the output of ld.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, -R value β€” adds a DT_RUNPATH to the output.
  • --rsp-quoting=value β€” quoting style for response files. the supported *value*s are windows and posix.
  • --script=file, -T file β€” 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's 0, it uses a random seed. 🎲 chaotic but valid
  • --soname=value, -h value β€” sets DT_SONAME to 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 β€” interprets R_ARM_TARGET1 as R_ARM_ABS32.
  • --target1-rel β€” interprets R_ARM_TARGET1 as R_ARM_REL32.
  • --target2=type β€” interprets R_ARM_TARGET2 as type, where type is one of rel, abs, or got-rel.
  • --Tbss=value β€” same as --section-start with .bss as the sectionname.
  • --Tdata=value β€” same as --section-start with .data as the sectionname.
  • --Ttext=value β€” same as --section-start with .text as 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. 1 disables 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, -y symbol β€” traces references to symbol.
  • --undefined=symbol, -u symbol β€” 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 β€” uses SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_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.28 and 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-textrel to 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_symbol references to symbol.
  • -z option β€” linker option extensions. the little sub-menu of chaos πŸ“
    • dead-reloc-in-nonalloc=section_glob=value β€” resolves a relocation in a matched non-SHF_ALLOC section 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 the PT_GNU_STACK segment.
    • bti-report=[none|warning|error] β€” specifies how to report the missing GNU_PROPERTY_AARCH64_FEATURE_1_BTI property. none is 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 missing GNU_PROPERTY_X86_FEATURE_1_IBT or GNU_PROPERTY_X86_FEATURE_1_SHSTK property bestie? πŸ’… none is 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 the GNU_PROPERTY_AARCH64_FEATURE_1_BTI property. 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 the GNU_PROPERTY_X86_FEATURE_1_IBT property.
  • -z global β€” sets the DF_1_GLOBAL flag in the DYNAMIC section. 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 notext option, no cap. πŸ§ͺ
  • -z initfirst β€” sets the DF_1_INITFIRST flag to say this module should be initialized first. main character energy, literally. πŸ‘‘
  • -z interpose β€” sets the DF_1_INTERPOSE flag 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 the DF_1_NODEFLIB flag to say default library search paths should be ignored. Bye bye search path bestie. 🌸
  • -z nodelete β€” sets the DF_1_NODELETE flag to say this object cannot be unloaded from a process. It's here forever. ✨
  • -z nodlopen β€” sets the DF_1_NOOPEN flag to say this object may not be opened by dlopen(3). Locked. πŸ”’
  • -z nognustack β€” do not emit the PT_GNU_STACK segment.
  • -z norelro β€” don't indicate that portions of the object should be mapped read-only after initial relocation processing. The object will omit the PT_GNU_RELRO segment.
  • -z notext β€” allow relocations against read-only segments. Sets the DT_TEXTREL flag in the DYNAMIC section.
  • -z now β€” sets the DF_BIND_NOW flag 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 the DF_ORIGIN flag to say the object requires $ORIGIN processing.
  • -z pac-plt β€” AArch64 only, use pointer authentication in the PLT. πŸ’…
  • -z pack-relative-relocs β€” similar to -pack-dyn-relocs=relr, but it synthesizes the GLIBC_ABI_DT_RELR version dependency if there's a GLIBC_2.* version dependency. Heads up: glibc ld.so rejects loading a dynamically linked object without the GLIBC_ABI_DT_RELR version dependency. So yeah, that one matters fr fr. ⚠️
  • -z rel β€” use REL format for dynamic relocations.
  • -z rela β€” use RELA format for dynamic relocations.
  • -z retpolineplt β€” emit retpoline format PLT entries as a mitigation for CVE-2017-5715. πŸ›‘οΈ
  • -z rodynamic β€” make the .dynamic section read-only. Heads up: the DT_DEBUG tag will not be emitted.
  • -z separate-loadable-segments, -z separate-code, -z noseparate-code β€” these three specify whether two adjacent PT_LOAD segments are allowed to overlap in pages. noseparate-code is the default and allows overlap. separate-code allows overlap between two executable segments, or between two non-executable segments. separate-loadable-segments disallows 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 the PT_GNU_STACK program 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 a PT_OPENBSD_WXNEEDED segment.

πŸ’« 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