Skip to content

mold - Modern High-Performance Linker Cheatsheet

mold - Modern High-Performance Linker Cheatsheet

mold (Modern Linker) is a drop-in replacement for GNU ld, gold, and LLVM lld that is designed from the ground up to use all your CPU cores. Linking is often the serialized tail of an otherwise-parallel build — you compile 200 files across 16 cores, then wait on one core to link. mold parallelizes that step, frequently reducing link times by an order of magnitude, which is most noticeable in edit-compile-run loops on large C, C++, and Rust codebases.

Installation

PlatformCommand
Debian/Ubuntusudo apt install mold
Fedorasudo dnf install mold
Arch Linuxsudo pacman -S mold
macOS (Homebrew)brew install mold
From sourcebuild from the rui314/mold repo
Verifymold --version

Using mold (three ways)

MethodHow
Wrappermold -run cargo build / mold -run make
Compiler flag-fuse-ld=mold (GCC 12+/Clang)
SymlinkPoint ld at mold (system-wide)
# Easiest: wrap any build command
mold -run make -j$(nproc)
mold -run cargo build --release

Rust Configuration

# ~/.cargo/config.toml or project .cargo/config.toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
ApproachNote
link-arg=-fuse-ld=moldStandard, requires clang or GCC 12+
mold -run cargo buildNo config changes needed
Per-target sectionKeeps other platforms unaffected

C/C++ Configuration

# Direct compiler flag
gcc -fuse-ld=mold main.c -o main
clang++ -fuse-ld=mold app.cpp -o app

# CMake
cmake -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold" ..

# Makefile
LDFLAGS += -fuse-ld=mold

Verifying mold Was Used

# Check the linker recorded in the binary's comment section
readelf -p .comment ./my-binary | grep -i mold

# Or run with mold's stats
mold -run cargo build 2>&1 | tail

Useful Options

OptionEffect
--threads=NLimit worker threads
-run CMDWrap a build command
--perfPrint performance breakdown
--statsEmit link statistics
--gc-sectionsRemove unused sections
--icf=allIdentical code folding (smaller binaries)
# See where link time goes
mold --perf -run cargo build --release

When mold Helps Most

SituationBenefit
Large binaries with many objectsLargest absolute savings
Frequent incremental rebuildsBiggest quality-of-life gain
Debug builds (large symbol tables)Very noticeable
Many CPU cores availableScales with cores
Tiny projectsMarginal — link was already fast

Licensing & Platform Notes

NoteDetail
LicenseMIT (modern versions)
LinuxFully supported, primary target
macOSSupported; Apple’s own linker also improved
WindowsNot the primary target

mold vs Other Linkers

LinkerRelative speedNote
GNU ldBaseline (slowest)Default on many systems
goldFaster than ldLargely superseded
lld (LLVM)Much fasterGood default, well supported
moldFastestBest for large parallel links

Combine with sccache for the full win: sccache avoids recompiling, mold speeds up the link that remains.

Resources