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
| Platform | Command |
|---|
| Debian/Ubuntu | sudo apt install mold |
| Fedora | sudo dnf install mold |
| Arch Linux | sudo pacman -S mold |
| macOS (Homebrew) | brew install mold |
| From source | build from the rui314/mold repo |
| Verify | mold --version |
Using mold (three ways)
| Method | How |
|---|
| Wrapper | mold -run cargo build / mold -run make |
| Compiler flag | -fuse-ld=mold (GCC 12+/Clang) |
| Symlink | Point 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"]
| Approach | Note |
|---|
link-arg=-fuse-ld=mold | Standard, requires clang or GCC 12+ |
mold -run cargo build | No config changes needed |
| Per-target section | Keeps 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
| Option | Effect |
|---|
--threads=N | Limit worker threads |
-run CMD | Wrap a build command |
--perf | Print performance breakdown |
--stats | Emit link statistics |
--gc-sections | Remove unused sections |
--icf=all | Identical code folding (smaller binaries) |
# See where link time goes
mold --perf -run cargo build --release
When mold Helps Most
| Situation | Benefit |
|---|
| Large binaries with many objects | Largest absolute savings |
| Frequent incremental rebuilds | Biggest quality-of-life gain |
| Debug builds (large symbol tables) | Very noticeable |
| Many CPU cores available | Scales with cores |
| Tiny projects | Marginal — link was already fast |
| Note | Detail |
|---|
| License | MIT (modern versions) |
| Linux | Fully supported, primary target |
| macOS | Supported; Apple’s own linker also improved |
| Windows | Not the primary target |
mold vs Other Linkers
| Linker | Relative speed | Note |
|---|
| GNU ld | Baseline (slowest) | Default on many systems |
| gold | Faster than ld | Largely superseded |
| lld (LLVM) | Much faster | Good default, well supported |
| mold | Fastest | Best for large parallel links |
Combine with sccache for the full win: sccache avoids recompiling, mold speeds up the link that remains.
Resources