Favicon of mold

mold

mold is a fast, parallel drop-in replacement linker for Unix systems, cutting link times for large C, C++, and Rust builds.

mold website screenshot
mold GitHub repository preview

mold is a high-performance linker built to replace the default Unix linker (ld, lld, gold) without changing your build setup. It's aimed at developers working with large C, C++, or Rust codebases where the link step of a build (combining compiled object files into an executable or shared library) eats up noticeable time during edit-compile-rebuild cycles. The project is written by the original author of LLVM lld, and it's been used in production since 2021.

Linking is often the slowest, least parallel part of a build. mold was designed from scratch around pervasive parallelism and efficient data structures to cut that time down, especially for debug builds of large projects where build output can run into gigabytes.

Key features

  • Drop-in compatibility: works as a replacement for existing linkers via a single compiler flag, no build system rewrite needed.
  • Parallel architecture: built from the ground up for multi-core linking rather than retrofitted, which is the main source of its speed advantage.
  • Broad architecture support: x86-64, i386, ARM 32/64, RISC-V 32/64, PowerPC 32/64, s390x, LoongArch 32/64, SPARC64, m68k, and SH-4.
  • mold -run: a mode that intercepts calls to ld, ld.bfd, ld.lld, or ld.gold via LD_PRELOAD, so you can redirect any build command to mold without editing its config.
  • Verifiable output: embeds an identification string in the .comment section of linked binaries so you can confirm mold produced the file.
  • Tested at scale: the test suite covers every linker feature across supported architectures under CI, and releases are checked against a build of roughly 19,000 Gentoo packages to catch regressions.

Ideal use cases

mold fits projects with large object file output where the link step is a measurable fraction of build time: big C++ codebases, browser engines, compilers, game engines, and Rust projects with many crates. It's particularly useful in debug-edit-rebuild loops, where developers relink repeatedly and every second matters, and in CI pipelines where link time adds up across many jobs.

It's less useful for small projects where linking already takes a fraction of a second; the overhead of switching linkers isn't worth it if your total link time is negligible. It also won't help with compile time itself, only the link phase, so projects bottlenecked on compilation rather than linking won't see much benefit. Some linker feature gaps exist in comparison to lld for edge cases (for example, identical code folding behavior differs from the wild linker), so projects relying on specific linker flags should check compatibility first.

Installation

Prebuilt binary packages are available for many Linux distributions (see the Repology badge in the repo), and prebuilt binaries for Linux on x86-64, ARM64, ARM32, RISC-V, PPC64LE, s390x, and LoongArch are attached to each GitHub release.

To build from source, you need Rust 1.95 or later (install via rustup if your system's Rust is older), Git, and a C compiler like GCC or Clang:

git clone https://github.com/rui314/mold.git
cd mold
cargo build --release

The resulting executable is at target/release/mold. To install it system-wide:

sudo ./install-mold.sh

Use sudo PREFIX=/usr ./install-mold.sh to install under a different prefix, or just run target/release/mold directly without installing.

To actually use mold, point your compiler driver at it. For Clang or GCC 12.1.0+, pass -fuse-ld=mold. For older GCC, use -B/usr/local/libexec/mold (or your custom prefix) since -fuse-ld doesn't accept mold as an argument on those versions. For Rust projects, add a rustflags entry in .cargo/config.toml pointing at mold via -C link-arg=-fuse-ld=mold. If you can't easily change compiler flags, run your build through mold -run make (or another build command) to intercept linker calls automatically on Linux and FreeBSD.

Frequently asked questions

Share:

Stars
17.7K
Forks
577
Last commit
5 hours ago
Repository age
6 years
License
MIT
Self-hosted
No
Activity score
79/100
View Repository
Built with:
Ad
Favicon

 

  
 

Similar to mold

Favicon

 

  
 
Favicon

 

  
 
Favicon