mold README

The project's README from github.com/rui314/mold. As one markdown file: README.md.

mold: A Modern Linker

mold is a high-performance drop-in replacement for existing Unix linkers, designed to speed up builds. In our August 2026 benchmarks, it links 4.9x faster than LLVM lld and 1.9x faster than wild at the median; see Benchmark for the full results.

mold is written by the original developer of LLVM lld, the linker that Android, Chrome, FreeBSD, PlayStation, Nintendo Switch, and other production systems are built with. mold started as an effort to build an even faster linker from scratch, free of the architectural limits its author had run into while optimizing lld. It has been in production use since 2021, and today it is the default linker of many large open-source projects and is used internally by many companies.

mold supports x86-64, i386, ARM 32/64, RISC-V 32/64, PowerPC 32/64, s390x, LoongArch 32/64, SPARC64, m68k, and SH-4.

Why does linking speed matter?

If you are using a compiled language such as C, C++, or Rust, a build consists of two phases. In the first phase, a compiler compiles source files into object files (.o files). In the second phase, a linker takes all object files and combines them into a single executable or shared library file.

The second phase can be time-consuming if your build output is large. mold can speed up this process, saving you time and preventing distractions while waiting for a lengthy build to finish. The difference is most noticeable during rapid debug-edit-rebuild cycles.

Benchmark

Here is a performance comparison of lld, wild, and mold when linking nine large programs on two machines:

The Threadripper represents many-core workstation and server processors, and the M1 Ultra represents high-performance desktop processors.

All three linkers were built from source in release configuration as of 2026-08-28 and ran with their default options. Times are wall-clock times as seen by the caller, the median of three runs after a warm-up. The ARM64 rows are the ARM64 builds of the same programs. The benchmark suite, including all linker inputs, is available on Zenodo.

AMD Ryzen Threadripper 7980X, debug builds

Program (output size) lld wild mold wild/mold lld/mold
Blender 5.2 (2.46 GiB) 4.72s 1.98s 0.86s 2.3x 5.5x
Chromium 145 (4.51 GiB) 16.64s 3.98s 1.65s 2.4x 10.1x
Chromium 145 ARM64 (4.76 GiB) 20.91s N/A 1.83s N/A 11.4x
Clang 21 (4.19 GiB) 6.19s 3.71s 1.34s 2.8x 4.6x
ClickHouse 26.1 (5.58 GiB) 6.62s 4.40s 0.98s 4.5x 6.7x
Firefox 149 (2.37 GiB) 5.11s N/A 0.78s N/A 6.5x
Firefox 149 ARM64 (2.43 GiB) 6.40s N/A 0.93s N/A 6.9x
Godot 4.6 (1.01 GiB) 1.77s 1.08s 0.46s 2.3x 3.8x
LibreOffice 26.2 (0.98 GiB) 3.46s 1.41s 0.44s 3.2x 7.9x
PyTorch 2.9 (3.51 GiB) 4.35s 2.48s 0.80s 3.1x 5.4x
TensorFlow 2.21 (9.55 GiB) 50.73s N/A 3.15s N/A 16.1x

AMD Ryzen Threadripper 7980X, release builds

Program (output size) lld wild mold wild/mold lld/mold
Blender 5.2 (0.24 GiB) 0.85s 0.30s 0.20s 1.5x 4.2x
Chromium 145 (0.58 GiB) 6.48s N/A 0.64s N/A 10.2x
Chromium 145 ARM64 (0.60 GiB) 7.91s N/A 0.73s N/A 10.8x
Clang 21 (0.21 GiB) 0.53s 0.23s 0.11s 2.2x 5.0x
ClickHouse 26.1 (1.23 GiB) 3.18s 2.07s 0.41s 5.0x 7.7x
Firefox 149 (0.22 GiB) 1.01s 0.41s 0.21s 2.0x 4.9x
Godot 4.6 (0.15 GiB) 0.44s 0.21s 0.08s 2.7x 5.8x
LibreOffice 26.2 (0.19 GiB) 1.13s 0.57s 0.19s 3.0x 6.0x
PyTorch 2.9 (0.31 GiB) 0.68s 0.32s 0.15s 2.2x 4.7x
TensorFlow 2.21 (0.73 GiB) 9.62s N/A 0.70s N/A 13.7x

Apple M1 Ultra, debug builds

Program (output size) lld wild mold wild/mold lld/mold
Blender 5.2 (2.46 GiB) 3.21s 1.81s 1.56s 1.2x 2.1x
Chromium 145 (4.51 GiB) 9.54s 3.49s 2.22s 1.6x 4.3x
Chromium 145 ARM64 (4.76 GiB) 12.67s N/A 2.31s N/A 5.5x
Clang 21 (4.19 GiB) 4.40s 2.78s 2.96s 0.9x 1.5x
ClickHouse 26.1 (5.58 GiB) 4.92s 3.50s 1.71s 2.1x 2.9x
Firefox 149 (2.37 GiB) 3.21s N/A 1.12s N/A 2.9x
Firefox 149 ARM64 (2.43 GiB) 4.13s N/A 1.12s N/A 3.7x
Godot 4.6 (1.01 GiB) 1.12s 0.81s 0.62s 1.3x 1.8x
LibreOffice 26.2 (0.98 GiB) 2.08s 0.94s 0.63s 1.5x 3.3x
PyTorch 2.9 (3.51 GiB) 3.07s 2.10s 1.45s 1.4x 2.1x
TensorFlow 2.21 (9.55 GiB) 43.68s N/A 4.43s N/A 9.9x

Apple M1 Ultra, release builds

Program (output size) lld wild mold wild/mold lld/mold
Blender 5.2 (0.24 GiB) 0.56s 0.20s 0.25s 0.8x 2.3x
Chromium 145 (0.58 GiB) 4.25s N/A 0.78s N/A 5.5x
Chromium 145 ARM64 (0.60 GiB) 5.17s N/A 0.91s N/A 5.7x
Clang 21 (0.21 GiB) 0.30s 0.15s 0.14s 1.0x 2.1x
ClickHouse 26.1 (1.23 GiB) 1.94s 0.95s 0.55s 1.7x 3.5x
Firefox 149 (0.22 GiB) 0.56s 0.23s 0.20s 1.1x 2.7x
Godot 4.6 (0.15 GiB) 0.26s 0.11s 0.11s 1.0x 2.3x
LibreOffice 26.2 (0.19 GiB) 0.62s 0.30s 0.23s 1.3x 2.7x
PyTorch 2.9 (0.31 GiB) 0.43s 0.22s 0.17s 1.3x 2.5x
TensorFlow 2.21 (0.73 GiB) 8.07s N/A 0.68s N/A 11.9x

N/A indicates that the linker cannot link that program. wild's Chromium release links are also marked N/A because wild does not implement --icf=all and links without identical code folding.

Why is mold so fast?

mold owes its speed to pervasive parallelism and to efficient data structures and algorithms. For details, read our paper "mold: A Massively Parallel Linker" (ASPLOS 2027), available at https://arxiv.org/abs/2608.23228.

Installation

Binary packages for the following systems are currently available:

Packaging status

Prebuilt binaries for Linux on x86-64, ARM64, ARM32, RISC-V, PPC64LE, s390x, and LoongArch are also attached to each GitHub release.

How to Build

mold is written in C++20, so if you build mold yourself, you will need a recent version of a C++ compiler and a C++ standard library. We recommend GCC 10.2 or Clang 16.0.0 (or later) and libstdc++ 10 or libc++ 7 (or later).

Install Dependencies

To install build dependencies, run ./install-build-deps.sh in this directory. It will detect your Linux distribution and attempt to install the necessary packages.

Compile mold

git clone --branch stable https://github.com/rui314/mold.git
cd mold
sudo ./install-build-deps.sh
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ -B build
cmake --build build -j$(nproc)
sudo cmake --build build --target install

You might need to pass a C++20 compiler command name to cmake. In the example above, c++ is passed. If that doesn't work for you, try a specific version of a compiler, such as g++-10 or clang++-12.

By default, mold is installed to /usr/local/bin. You can change the installation location by passing -DCMAKE_INSTALL_PREFIX=<directory>. For other cmake options, see the comments in CMakeLists.txt.

If you are not using a recent enough Linux distribution, or if cmake does not work for you for any reason, you can use Podman to build mold in a container. To do so, run ./dist.sh in this directory instead of using cmake. The shell script will pull a container image, build mold and auxiliary files inside it, and package them into a single tar file named dist/mold-$version-$arch-linux.tar.gz. You can extract the tar file anywhere and use the mold executable in it.

How to use

A classic way to use mold

On Unix, the linker command (usually /usr/bin/ld) is indirectly invoked by the compiler driver (typically cc, gcc, or clang), which is in turn indirectly invoked by make or other build system commands.

If you can specify an additional command line option for your compiler driver by modifying the build system's config files, add one of the following flags to use mold instead of /usr/bin/ld:

  • For Clang: pass -fuse-ld=mold

  • For GCC 12.1.0 or later: pass -fuse-ld=mold

  • For GCC before 12.1.0: the -fuse-ld option does not accept mold as a valid argument, so you need to use the -B option instead. The -B option tells GCC where to look for external commands like ld.

    If you have installed mold with make install, there should be a directory named /usr/libexec/mold (or /usr/local/libexec/mold, depending on your $PREFIX), and the ld command should be there. The ld is actually a symlink to mold. So, all you need is to pass -B/usr/libexec/mold (or -B/usr/local/libexec/mold) to GCC.

If you haven't installed ld.mold to any $PATH, you can still pass -fuse-ld=/absolute/path/to/mold to clang to use mold. However, GCC does not accept an absolute path as an argument for -fuse-ld.

If you are using Rust

Create .cargo/config.toml in your project directory with the following:

[target.'cfg(target_os = "linux")']
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"]

where /path/to/mold is an absolute path to the mold executable. In the example above, we use clang as a linker driver since it always accepts the -fuse-ld option. If your GCC is recent enough to recognize the option, you may be able to remove the linker = "clang" line.

[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

If you want to use mold for all projects, add the above snippet to ~/.cargo/config.toml.

If you are using Nim

Create config.nims in your project directory with the following:

when findExe("mold").len > 0 and defined(linux):
  switch("passL", "-fuse-ld=mold")

where mold must be included in the PATH environment variable. In this example, gcc is used as the linker driver. Use the -fuse-ld option if your GCC is recent enough to recognize this option.

If you want to use mold for all projects, add the above snippet to ~/.config/config.nims.

If you are using Conan package manager

You can configure Conan to download the latest version of mold and use it as the linker when building your dependencies and projects from source. Please see the instructions here.

mold -run

It is sometimes very hard to pass an appropriate command line option to cc to specify an alternative linker. To address this situation, mold has a feature to intercept all invocations of ld, ld.bfd, ld.lld, or ld.gold and redirect them to itself. To use this feature, run make (or another build command) as a subcommand of mold as follows:

mold -run make <make-options-if-any>

Internally, mold invokes a given command with the LD_PRELOAD environment variable set to its companion shared object file. The shared object file intercepts all function calls to exec(3)-family functions to replace argv[0] with mold if it is ld, ld.bf, ld.gold, or ld.lld.

GitHub Actions

You can use our setup-mold GitHub Action to speed up GitHub-hosted continuous builds. Although GitHub Actions run on a 4 core machine, mold is still significantly faster than the default GNU linker, especially when linking large programs.

Verify that you are using mold

mold leaves its identification string in the .comment section of an output file. You can print it out to verify that you are actually using mold.

$ readelf -p .comment <executable-file>

String dump of section '.comment':
  [     0]  GCC: (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
  [    2b]  mold 9a1679b47d9b22012ec7dfbda97c8983956716f7

If mold is present in the .comment section, the file was created by mold.

Online manual

Since mold is a drop-in replacement, you should be able to use it without reading its manual. However, if you need it, mold's man page is available online. You can read the same manual by running man mold.

Stability

mold has been developed in the open since 2020 and has more than 140 contributors. Its test suite, which covers every linker feature, runs in CI for all supported target CPU architectures, natively or under QEMU, and under ASAN and TSAN. Before each release, we try to build all of Gentoo Linux's roughly 19,000 packages with mold, using GNU ld as a control, to find regressions before they reach a release.

Sponsors

mold is free to use, but keeping it maintained is continuous work: supporting new architectures and toolchain features, keeping up with the projects that depend on it, and making it faster. That work is funded by sponsors. If mold saves you or your company time, please consider becoming a GitHub sponsor.

We thank everyone who sponsors the project. In particular, we'd like to acknowledge the following people and organizations who have sponsored $128/month or more:

Corporate sponsors

Mercury

Cybozu

Emerge Tools

Individual sponsors

mold (rui314/mold)

Searching Database…

17.7K ·GitHub
这是什么?mold 是一个高性能的 Unix 链接器替代品,可以直接替换系统默认的链接器,它只为一件事而生:让大型 C、C++ 和 Rust 项目的链接环节快上好几倍。
它是个编译器吗,还是说它到底做什么?它不是编译器。编译器把源代码编译成目标文件之后,链接器再把这些目标文件合并成最终的可执行文件或共享库;mold 就是把默认的 ld 换成一个快得多的链接器。
怎么把我的项目切换到用它?安装一个二进制软件包,或者从 GitHub release 下载预编译的二进制文件,然后给 Clang 或 GCC 12.1+ 传入 -fuse-ld=mold;老版本 GCC 可以用 -B/usr/libexec/mold,或者用 mold -run make 来运行构建。
哪些语言和构建工具能配合它使用?凡是走 Unix 链接器的都可以:配合 GCC 或 Clang 的 C 和 C++,通过 .cargo/config.toml 使用的 Rust,还有 Nim 以及用 Conan 管理的构建;另外还有一个官方的 setup-mold GitHub Action 可用于 CI。
小项目用它能感觉到明显差别吗?提速效果和输出大小成正比:对生成几个 GB 大小的二进制文件的大型构建最有用,而且在频繁的「改代码—调试—重新构建」循环里感受最明显,一次性发布构建就没那么明显。
它只能跑在 Linux 上,还是别的系统也行?它替换的是 /usr/bin/ld,所以只在 Unix 系统上可用:官方发布的预编译二进制文件覆盖 x86-64、ARM64、ARM32、RISC-V、PPC64LE、s390x 和 LoongArch 架构的 Linux。
它能为哪些 CPU 架构链接二进制文件?x86-64、i386、ARM 32/64、RISC-V 32/64、PowerPC 32/64、s390x、LoongArch 32/64、SPARC64、m68k 和 SH-4——对交叉编译到嵌入式和老旧平台来说足够全面了。
它为什么比传统链接器快这么多?速度来自全面的并行化,再加上高效的数据结构和算法;具体设计在团队的 ASPLOS 2027 论文《mold: A Massively Parallel Linker》里有描述。
我怎么确认我的二进制文件确实是用 mold 链接的?mold 会在每个输出文件的 .comment 段里写入一个标识字符串——把那个段打印出来,如果里面出现了 mold,就说明这个文件是 mold 生成的。
What are similar projects?nx, ripgrep, CalcKernel, bazel, nub, turborepo, ninja, gcc
Creator
rui314
Size
37.3 MB
Stars
17.7K
Age
6y
Commits · 90 Days