mold is a faster drop-in replacement for existing Unix linkers. It is several times quicker than the LLVM lld linker, the second-fastest open-source linker, which I initially developed a few years ago. mold aims to enhance developer productivity by minimizing build time, particularly in rapid debug-edit-rebuild cycles.
Here is a performance comparison of GNU ld, GNU gold, LLVM lld, and mold when linking final debuginfo-enabled executables for major large programs on a simulated 16-core, 32-thread machine.
Program (linker output size) | GNU ld | GNU gold | LLVM lld | mold |
---|---|---|---|---|
MySQL 8.3 (0.47 GiB) | 10.84s | 7.47s | 1.64s | 0.46s |
Clang 19 (1.56 GiB) | 42.07s | 33.13s | 5.20s | 1.35s |
Chromium 124 (1.35 GiB) | N/A | 27.40s | 6.10s | 1.52s |
mold is so fast that it is only 2x slower than the cp
command on the same
machine. If you find that mold is not faster than other linkers, feel
free to file a bug report.
mold supports x86-64, i386, ARM64, ARM32, 64-bit/32-bit little/big-endian RISC-V, 32-bit PowerPC, 64-bit big-endian PowerPC ELFv1, 64-bit little-endian PowerPC ELFv2, s390x, 64-bit/32-bit LoongArch, SPARC64, m68k, and SH-4.
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.
Binary packages for the following systems are currently available:
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 12.0.0 (or later) and libstdc++ 10 or libc++ 7 (or later).
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. You may need to run it as root.
git clone --branch stable https://github.com/rui314/mold.git
cd mold
./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 Docker to build mold in a Docker
environment. To do so, run ./dist.sh
in this directory instead of using
cmake
. The shell script will pull a Docker image, build mold and auxiliary
files inside it, and package them into a single tar file named
mold-$version-$arch-linux.tar.gz
. You can extract the tar file anywhere and
use the mold executable within it.
One reason is that it utilizes faster algorithms and more efficient data structures compared to other linkers. Another reason is that mold is highly parallelized.
Here is a side-by-side comparison of per-core CPU usage for lld (left) and mold (right), linking the same program, a Chromium executable.
As you can see, mold uses all available cores throughout its execution and finishes quickly. In contrast, lld fails to utilize available cores most of the time. In this demo, the maximum parallelism is artificially capped at 16, so that the bars fit in the GIF.
For details, please see the design notes.
It is taken for granted nowadays that compiler toolchains can be easily installed and used for free, and people may not think too much about the individuals behind these "free tools". mold supports many projects, but it is essentially a one-person project. This situation is similar to the one depicted in the following xkcd illustration.
If you think that the "Nebraska guy" should be rewarded, please consider becoming our GitHub sponsor!
We thank everyone who sponsors our project. In particular, we'd like to acknowledge the following people and organizations who have sponsored $128/month or more: