# mold — A Modern High-Speed Linker for Linux > A drop-in replacement for Unix linkers that is several times faster than GNU ld and LLVM lld, designed to reduce edit-compile-debug cycle times for large C/C++ and Rust projects. ## Install Save in your project root: # mold — A Modern High-Speed Linker for Linux ## Quick Use ```bash # Ubuntu/Debian sudo apt install mold # Use with any compiler CC="cc -fuse-ld=mold" make ``` ## Introduction mold is a high-speed linker that dramatically reduces the time spent in the link phase of C, C++, and Rust builds. It achieves this through aggressive parallelism and efficient algorithms, making large project rebuilds feel nearly instant. ## What mold Does - Links ELF binaries on Linux several times faster than GNU ld or LLVM lld - Serves as a drop-in replacement requiring only a compiler flag change - Parallelizes all linker phases including symbol resolution, relocation, and output writing - Supports C, C++, Rust, and any language that produces ELF object files - Provides macOS support via a sold (sister project) variant ## Architecture Overview mold splits the linking process into many fine-grained parallel tasks. It memory-maps all input object files and shared libraries simultaneously, resolves symbols using concurrent hash tables, and writes the output file using parallel memcpy operations. The design avoids the sequential bottlenecks present in traditional linkers by treating linking as a data-parallel problem from the ground up. ## Self-Hosting & Configuration - Install via system package manager (apt, dnf, pacman) or build from source with CMake - Requires a Linux system with ELF toolchain; macOS variant is called sold - Enable with `-fuse-ld=mold` flag in GCC or Clang, or set `RUSTFLAGS="-C link-arg=-fuse-ld=mold"` for Rust - No configuration files needed; it respects standard linker script syntax - Compatible with LTO, PGO, split-dwarf, and other advanced compilation modes ## Key Features - Typically 2-10x faster than lld and 10-50x faster than GNU ld on large projects - Full compatibility with existing linker scripts and build systems - Supports `--compress-debug-sections=zstd` for smaller debug info - Incremental-friendly design reduces worst-case linking time - Minimal memory overhead through memory-mapped I/O and copy-on-write techniques ## Comparison with Similar Tools - **GNU ld (bfd)** — sequential and slow; mold is orders of magnitude faster - **GNU gold** — faster than ld but still largely sequential; mold parallelizes more aggressively - **LLVM lld** — good performance; mold is typically 2-5x faster on large link jobs - **Apple ld (ld-prime)** — macOS only; mold targets Linux ELF with sold for macOS - **Wild (Rust linker)** — experimental; mold is production-ready with broad adoption ## FAQ **Q: Does mold produce identical binaries to other linkers?** A: The output is ABI-compatible but not byte-identical due to different section ordering and alignment choices. **Q: Can I use mold with CMake projects?** A: Yes. Set `CMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold"` or use `add_link_options(-fuse-ld=mold)`. **Q: Does it support cross-compilation?** A: mold supports multiple ELF architectures including x86-64, ARM64, RISC-V, and others. **Q: Is mold safe for production builds?** A: Yes. It is used in production at multiple large companies and passes the binutils and LLVM test suites. ## Sources - https://github.com/rui314/mold - https://github.com/rui314/mold/blob/main/docs/mold.md --- Source: https://tokrepo.com/en/workflows/asset-d13a2d0f Author: AI Open Source