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 set DT_NEEDED for shared libraries if used. not me being picky about which libs get tagged. πŸ’…
  • --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. (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 the DF_SYMBOLIC flag. two jobs, one flag. πŸ‘‘
  • -Bsymbolic-non-weak β€” bind default visibility defined STB_GLOBAL symbols locally for -shared.
  • -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.
  • --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. 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. don't use it for ur secrets bestie.
  • --build-id β€” synonym for --build-id=sha1.
  • --call-graph-profile-sort=algorithm β€” algorithm may be:
    • none β€” ignore call graph profile.
    • hfsort β€” use hfsort.
    • cdsort β€” use cdsort (default).
  • --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. (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. value may be:
    • none β€” no compression.
    • zlib β€” the default compression level is 1 (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 the SHF_ALLOC flag. matched sections remain uncompressed if the compressed content would be larger. the compression level is level (if specified) or a default speed-focused level. this is like a generalized --compress-debug-sections. 🌸
  • --cref β€” output cross reference table. if -Map is specified, print to the map file.
  • --debug-names β€” generate a merged .debug_names section.
  • --default-script=file, -dT file β€” in the absence of --script, read this default linker script.
  • --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. (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 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.
  • --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 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. no more "it's just a warning" excuses, bestie. 😀
  • --filter=value, -F value β€” set the DT_FILTER field 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-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.

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 .interp section. it just... doesn't go there. ✨
  • --no-fortran-common β€” do not go searching archive members for definitions to override COMMON symbols. πŸ¦‹
  • --no-gc-sections β€” garbage collection of unused sections? disabled. πŸ’€
  • --no-gnu-unique β€” disables STB_GNU_UNIQUE symbol binding. periodt. πŸ’…
  • --no-merge-exidx-entries β€” disables merging of .ARM.exidx entries. 🌸
  • --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 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. 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. πŸ‘‘
  • -o path β€” write the output executable, library, or object to path. If you don't specify it, a.out is 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 is binary, 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-filename file β€” write optimization remarks in YAML format to file. πŸ“
  • --opt-remarks-passes pass-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 for place and also report a warning.
    • error β€” place orphan sections as for place and 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 in SHT_REL(A).
    • android β€” pack dynamic relocations in SHT_ANDROID_REL(A).
    • relr β€” pack relative relocations in SHT_RELR, and the rest of dynamic relocations in SHT_REL(A).
    • android+relr β€” pack relative relocations in SHT_RELR, and the rest of dynamic relocations in SHT_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.package section. For example, %25 decodes 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 for R_PPC64_REL24_NOTOC and TOC/NOTOC interworking. mode may be:
    • yes β€” (default) use.
    • auto β€” currently the same as yes.
    • 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, .rodata and .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/null to 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 format from-glob=to-file or 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 called response.txt containing the command line options and a text file called version.txt containing the output of ld.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, -R value β€” add a DT_RUNPATH to the output. πŸ”₯
  • --rsp-quoting=value β€” quoting style for response files. The supported values are windows and posix. πŸ’…
  • --script=file, -T file β€” 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. If 0, use a random seed. πŸ”€
  • --soname=value, -h value β€” set DT_SONAME to 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 β€” interpret R_ARM_TARGET1 as R_ARM_ABS32. πŸ¦‹
  • --target1-rel β€” interpret R_ARM_TARGET1 as R_ARM_REL32. πŸ¦‹
  • --target2=type β€” interpret 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 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. 1 disables multi-threading. 🧡
  • --fat-lto-objects β€” use the .llvm.lto section, which contains LLVM bitcode, in fat LTO object files to perform LTO. πŸ”
  • --no-fat-lto-objects β€” ignore the .llvm.lto section 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, -y symbol β€” trace references to symbol. πŸ”
  • --undefined=symbol, -u symbol β€” 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 β€” use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_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 using ifunc symbols together with text relocations. Okay so listen, older glibc (2.28 and earlier) has a bug where the segment holding ifunc symbols 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 an ifunc symbol and it just segmentation faults. πŸ’€ Use -warn-ifunc-textrel to let lld throw a warning if your code may include ifunc symbols, 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 the ld and gold linkers, 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_symbol back 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_ALLOC section 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 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 at all; otherwise it'll be reported as a warning or an error.
  • cet-report=[none|warning|error] β€” specifies how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT or GNU_PROPERTY_X86_FEATURE_1_SHSTK properties. none is 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 when nodynamic-undefined-weak is specified. dynamic-undefined-weak is 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 missing GNU_PROPERTY_AARCH64_FEATURE_PAUTH property. none is 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 the GNU_PROPERTY_AARCH64_FEATURE_1_BTI property.
  • force-ibt β€” force enable Intel Indirect Branch Tracking in PLT, and warn if an input ELF file does not have the GNU_PROPERTY_X86_FEATURE_1_IBT property.
  • global β€” sets the DF_1_GLOBAL flag in the DYNAMIC section. 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 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. Heads up: this option must be combined with the -z notext option.
  • initfirst β€” sets the DF_1_INITFIRST flag to indicate the module should be initialized first. Main character gets to go first. πŸ‘‘
  • interpose β€” set the DF_1_INTERPOSE flag 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 .lrodata after .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 the DF_1_NODEFLIB flag to indicate that default library search paths should be ignored.
  • nodelete β€” sets the DF_1_NODELETE flag to indicate that the object cannot be unloaded from a process. It's staying. Forever. 🫢
  • nodlopen β€” sets the DF_1_NOOPEN flag to indicate that the object may not be opened by dlopen(3).
  • nognustack β€” do not emit the PT_GNU_STACK segment.
  • norelro β€” do not indicate that portions of the object should be mapped read-only after initial relocation processing. The object will omit the PT_GNU_RELRO segment.
  • nosectionheader β€” don't generate the section header table.
  • notext β€” allow relocations against read-only segments. Sets the DT_TEXTREL flag in the DYNAMIC section.
  • now β€” set the DF_BIND_NOW flag 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 the DF_ORIGIN flag to indicate that the object requires $ORIGIN processing.
  • pac-plt β€” AArch64 only, use pointer authentication in PLT.
  • pack-relative-relocs β€” similar to -pack-dyn-relocs=relr, but it synthesizes the GLIBC_ABI_DT_RELR version dependency if there is a GLIBC_2.* version dependency. And it has to, because glibc ld.so rejects loading a dynamically linked object without the GLIBC_ABI_DT_RELR version 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 for CVE-2017-5715. Security slay. πŸ›‘οΈ
  • rodynamic β€” make the .dynamic section read-only. The DT_DEBUG tag will not be emitted.
  • separate-loadable-segments, separate-code, noseparate-code β€” these specify whether two adjacent PT_LOAD segments are allowed to overlap in pages. noseparate-code (default) allows overlap. separate-code allows overlap between two executable segments, or two non-executable segments. separate-loadable-segments disallows 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_STACK program 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 a PT_OPENBSD_NOBTCFI segment.
  • wxneeded β€” create a PT_OPENBSD_WXNEEDED segment.

🌈 ENVIRONMENT VARIABLES 🌈

The vibes your shell can set for you. πŸ¦‹

  • LLD_REPRODUCE β€” create a reproduce tarball with the specified filename. If --reproduce is specified, --reproduce takes precedence. (Options over env vars, always. πŸ‘‘)
  • LLD_VERSION β€” ld.lld creates a section named .comment containing 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-group and --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