Convert Figma logo to code with AI

rui314 logomold

mold: A Modern Linker 🦠

16,961
550
16,961
184

Top Related Projects

6,416

A Small C Compiler

11,858

A small C compiler

1,949

A Small C Compiler

Quick Overview

mold is a high-performance linker for ELF, Mach-O, and PE executables. It is designed to be a drop-in replacement for the GNU linker (ld) and the LLVM linker (lld), providing faster build times and smaller binary sizes.

Pros

  • Fast Linking: mold is designed to be significantly faster than traditional linkers, with benchmarks showing up to 10x faster linking times.
  • Smaller Binary Sizes: mold can produce smaller executable files compared to other linkers, reducing the overall size of the final build.
  • Cross-Platform: mold supports multiple executable formats (ELF, Mach-O, PE) and can be used on various operating systems, including Linux, macOS, and Windows.
  • Compatibility: mold aims to be a drop-in replacement for existing linkers, allowing for easy integration into existing build systems.

Cons

  • Limited Documentation: The project's documentation is relatively sparse, which may make it challenging for new users to get started.
  • Experimental Status: As a relatively new project, mold is still considered experimental and may not have the same level of maturity and stability as more established linkers.
  • Limited Ecosystem: Since mold is a relatively new project, the ecosystem of tools and libraries that integrate with it may be more limited compared to other linkers.
  • Potential Compatibility Issues: While mold aims to be a drop-in replacement, there may be some compatibility issues or edge cases that users need to be aware of when transitioning from other linkers.

Code Examples

N/A (mold is a linker, not a code library)

Getting Started

N/A (mold is a linker, not a code library)

Competitor Comparisons

6,416

A Small C Compiler

Pros of 8cc

  • 8cc is a small and simple C compiler, making it a good learning resource for understanding compiler internals.
  • The codebase is well-documented and easy to navigate, making it a good starting point for those interested in compiler development.
  • 8cc supports a wide range of target architectures, including x86, ARM, and RISC-V.

Cons of 8cc

  • 8cc is primarily focused on being a learning tool and may not be suitable for large-scale production use.
  • The compiler does not support advanced language features like C++, which may limit its usefulness for some projects.
  • The development of 8cc appears to be less active compared to mold, with fewer recent commits and updates.

Code Comparison

Here's a brief comparison of the code structure between 8cc and mold:

8cc (main.c):

int main(int argc, char **argv) {
    if (argc < 2) {
        fprintf(stderr, "usage: %s <file>\n", argv[0]);
        return 1;
    }
    return compile(argv[1]);
}

mold (main.cpp):

int main(int argc, char **argv) {
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <object-file>...\n", argv[0]);
        return 1;
    }
    return link(argc - 1, argv + 1);
}

As you can see, the main function in 8cc is more focused on the compilation process, while the main function in mold is focused on the linking process.

11,858

A small C compiler

Pros of chibicc

  • chibicc is a self-contained, single-file C compiler, making it easy to understand and modify.
  • chibicc supports a wide range of C language features, including structs, functions, and pointers.
  • chibicc has a simple and straightforward codebase, making it a good learning resource for those interested in compiler design.

Cons of chibicc

  • chibicc is primarily focused on being a learning resource, and may not be as optimized or feature-rich as other C compilers.
  • chibicc has a limited set of target architectures, primarily focusing on x86-64.
  • chibicc may not be suitable for large-scale, production-ready projects due to its limited feature set and optimization capabilities.

Code Comparison

Here's a brief comparison of the code structure between chibicc and mold:

chibicc (main.c):

int main(int argc, char **argv) {
    if (argc != 2) {
        fprintf(stderr, "usage: chibicc <source>\n");
        return 1;
    }

    // Parse the input file
    user_input = argv[1];
    token = tokenize();
    program();

    // Traverse the AST and generate assembly
    codegen();
    return 0;
}

mold (main.cpp):

int main(int argc, char **argv) {
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <object files or archives>\n", argv[0]);
        return 1;
    }

    // Initialize the linker
    LdDriver ld;
    ld.parseCommandLine(argc, argv);
    ld.run();
    return 0;
}

As you can see, the main functions of the two projects have a similar structure, but the implementation details and the overall scope of the projects are quite different.

1,949

A Small C Compiler

Pros of 9cc

  • 9cc is a simple and lightweight C compiler, making it a good choice for learning and understanding the fundamentals of compiler design.
  • The codebase is well-documented and easy to navigate, making it a valuable resource for those interested in compiler development.
  • 9cc supports a subset of the C language, which can be useful for specific projects or educational purposes.

Cons of 9cc

  • 9cc has a more limited feature set compared to mold, as it only supports a subset of the C language.
  • The performance of 9cc may not be as optimized as mold, as it is a simpler and more lightweight compiler.
  • 9cc may not be suitable for large-scale or complex projects that require a more robust and feature-rich compiler.

Code Comparison

9cc (5 lines):

int main() {
    printf("Hello, world!\n");
    return 0;
}

mold (5 lines):

int main() {
    printf("Hello, world!\n");
    return 0;
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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:

  • AMD Ryzen Threadripper 7980X (64 cores) running Ubuntu 24.04
  • Apple M1 Ultra (16 performance cores and 4 efficiency cores) running Fedora Asahi Remix 42; the benchmark is restricted to the performance cores

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)lldwildmoldwild/moldlld/mold
Blender 5.2 (2.46 GiB)4.72s1.98s0.86s2.3x5.5x
Chromium 145 (4.51 GiB)16.64s3.98s1.65s2.4x10.1x
Chromium 145 ARM64 (4.76 GiB)20.91sN/A1.83sN/A11.4x
Clang 21 (4.19 GiB)6.19s3.71s1.34s2.8x4.6x
ClickHouse 26.1 (5.58 GiB)6.62s4.40s0.98s4.5x6.7x
Firefox 149 (2.37 GiB)5.11sN/A0.78sN/A6.5x
Firefox 149 ARM64 (2.43 GiB)6.40sN/A0.93sN/A6.9x
Godot 4.6 (1.01 GiB)1.77s1.08s0.46s2.3x3.8x
LibreOffice 26.2 (0.98 GiB)3.46s1.41s0.44s3.2x7.9x
PyTorch 2.9 (3.51 GiB)4.35s2.48s0.80s3.1x5.4x
TensorFlow 2.21 (9.55 GiB)50.73sN/A3.15sN/A16.1x

AMD Ryzen Threadripper 7980X, release builds

Program (output size)lldwildmoldwild/moldlld/mold
Blender 5.2 (0.24 GiB)0.85s0.30s0.20s1.5x4.2x
Chromium 145 (0.58 GiB)6.48sN/A0.64sN/A10.2x
Chromium 145 ARM64 (0.60 GiB)7.91sN/A0.73sN/A10.8x
Clang 21 (0.21 GiB)0.53s0.23s0.11s2.2x5.0x
ClickHouse 26.1 (1.23 GiB)3.18s2.07s0.41s5.0x7.7x
Firefox 149 (0.22 GiB)1.01s0.41s0.21s2.0x4.9x
Godot 4.6 (0.15 GiB)0.44s0.21s0.08s2.7x5.8x
LibreOffice 26.2 (0.19 GiB)1.13s0.57s0.19s3.0x6.0x
PyTorch 2.9 (0.31 GiB)0.68s0.32s0.15s2.2x4.7x
TensorFlow 2.21 (0.73 GiB)9.62sN/A0.70sN/A13.7x

Apple M1 Ultra, debug builds

Program (output size)lldwildmoldwild/moldlld/mold
Blender 5.2 (2.46 GiB)3.21s1.81s1.56s1.2x2.1x
Chromium 145 (4.51 GiB)9.54s3.49s2.22s1.6x4.3x
Chromium 145 ARM64 (4.76 GiB)12.67sN/A2.31sN/A5.5x
Clang 21 (4.19 GiB)4.40s2.78s2.96s0.9x1.5x
ClickHouse 26.1 (5.58 GiB)4.92s3.50s1.71s2.1x2.9x
Firefox 149 (2.37 GiB)3.21sN/A1.12sN/A2.9x
Firefox 149 ARM64 (2.43 GiB)4.13sN/A1.12sN/A3.7x
Godot 4.6 (1.01 GiB)1.12s0.81s0.62s1.3x1.8x
LibreOffice 26.2 (0.98 GiB)2.08s0.94s0.63s1.5x3.3x
PyTorch 2.9 (3.51 GiB)3.07s2.10s1.45s1.4x2.1x
TensorFlow 2.21 (9.55 GiB)43.68sN/A4.43sN/A9.9x

Apple M1 Ultra, release builds

Program (output size)lldwildmoldwild/moldlld/mold
Blender 5.2 (0.24 GiB)0.56s0.20s0.25s0.8x2.3x
Chromium 145 (0.58 GiB)4.25sN/A0.78sN/A5.5x
Chromium 145 ARM64 (0.60 GiB)5.17sN/A0.91sN/A5.7x
Clang 21 (0.21 GiB)0.30s0.15s0.14s1.0x2.1x
ClickHouse 26.1 (1.23 GiB)1.94s0.95s0.55s1.7x3.5x
Firefox 149 (0.22 GiB)0.56s0.23s0.20s1.1x2.7x
Godot 4.6 (0.15 GiB)0.26s0.11s0.11s1.0x2.3x
LibreOffice 26.2 (0.19 GiB)0.62s0.30s0.23s1.3x2.7x
PyTorch 2.9 (0.31 GiB)0.43s0.22s0.17s1.3x2.5x
TensorFlow 2.21 (0.73 GiB)8.07sN/A0.68sN/A11.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