Published release of the Mold 3.0 linker, which can be used as a faster transparent replacement for the GNU linker on Linux systems. The project is developed by Rui Ueyama, author of the LLVM lld linker. A key feature of Mold is the very high speed of linking object files, noticeably ahead of the GNU gold and LLVM lld linkers (linking in Mold is performed at a speed only half as fast as simply copying files with the cp utility). The code is written in Rust and distributed under the MIT license.
Reducing build time can significantly improve the convenience of developing large projects by reducing the wait in the process of generating executable files when debugging and testing changes. The motivation for creating Mold was the irritation of having to wait for linking to complete after each change to the code, as well as the low efficiency of existing linkers on multi-core systems and the desire to try a fundamentally different linking architecture without resorting to overly complicated models such as incremental linking.
High performance of linking an executable file from a large number of compiler-prepared object files in Mold is achieved by using faster algorithms, actively parallelizing operations between available CPU cores and using more efficient data structures. For example, Mold implements the technique of performing intensive calculations simultaneously with copying files, pre-loading object files into memory, using fast hash tables when resolving characters, scanning relocation tables in a separate thread, and deduplicating merged sections that are repeated in different files.
The Mold 3.0 branch is notable for rewriting the code base from C++ (C++20) to the Rust language. Mold 3.0 can be used as a transparent replacement for Mold 2.42.1, the latest C++ release, and supports all previously available options and target architectures. The transition to Rust made it possible to protect the project from potential problems when processing damaged object files – in situations where the C++ version crashed due to accessing memory areas outside the buffer, the Rust version stops working at the bounds checking stage.
The performance of the Rust implementation is on par with the C++ version.
In addition to the migration to Rust, a key goal in the development of the 3.0 branch was to increase compatibility with GNU ld and prepare the project for use as the default linker in Linux distributions. The build system was changed from CMake to Cargo, and the test system from ctest to cargo test. The library oneTBB is excluded from dependencies.