rui314 / mold
mold: A Modern Linker ðŸ¦
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing rui314/mold in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewmold: A Modern Linker 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 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. 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 ( 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. Installation Binary packages for the following systems are currently available: 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 in this directory. It will detect your Linux distribution and attempt to install the necessary packages. You may need to run it as root. Compile mold You might need to pass a C++20 compiler command name to . In the example above, is passed. If that doesn't work for you, try a specific version of a compiler, such as or . By default, is installed to . You can change the installation location by passing . For other cmake options, see the comments in . If you are not using a recent enough Linux distribution, or if does not work for you for any reason, you can use Podman to build mold in a container. To do so, run in this directory instead of using . The shell script will pull a container image, build mold and auxiliary files inside it, and package them into a single tar file named . 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 ) is indirectly invoked by the compiler driver (typically , , or ), which is in turn indirectly invoked by 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 : • For Clang: pass • For GCC 12.1.0 or later: pass • For GCC before 12.1.0: the option does not accept as a valid argument, so you need to use the option instead. The option tells GCC where to look for external commands like . If you have installed mold with , there should be a directory named (or , depending on your ), and the command should be there. The is actually a symlink to . So, all you need is to pass (or ) to GCC. If you haven't installed to any , you can still pass to clang to use mold. However, GCC does not accept an absolute path as an argument for . If you are using Rust Create in your project directory with the following: where is an absolute path to the mold executable. In the example above, we use as a linker driver since it always accepts the option. If your GCC is recent enough to recognize the option, you may be able to remove the line. If you want to use mold for all projects, add the above snippet to . If you are using Nim Create in your project directory with the following: where must be included in the environment variable. In this example, is used as the linker driver. Use the 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 . If you are using Conan package manager You can configure Conan to download the latest version of 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 to specify an alternative linker. To address this situation, mold has a feature to intercept all invocations of , , , or and redirect them to itself. To use this feature, run (or another build command) as a subcommand of mold as follows: Internally, mold invokes a given command with the environment variable set to its companion shared object file. The shared object file intercepts all function calls to -family functions to replace with if it is , , , or . 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 section of an output file. You can print it out to verify that you are actually using mold. If is present in the section, the file was created by…