The release of the Mold 3.0 linker has been published, which can serve as a faster, transparent replacement for the GNU linker on Linux systems. The project is developed by Rui Ueyama, the author of the LLVM lld linker. A key feature of Mold is its extremely high speed in linking object files, significantly outpacing the GNU gold and LLVM lld linkers (linking in Mold operates at a speed only twice that of simply copying files with the cp utility). The code is written in Rust and distributed under the MIT license.
Reducing linking time significantly enhances the development experience for large projects by decreasing the wait times during the building of executable files while debugging and testing changes. The motivation behind creating Mold stemmed from the frustration of having to wait for the linking to finish after every code change, coupled with the inefficiency of existing linkers on multi-core systems and a desire to explore a fundamentally different linking architecture without resorting to overly complex models, such as incremental linking.
The high performance of linking an executable file from a large number of object files prepared by the compiler in Mold is achieved through the use of faster algorithms, active parallelization of operations across available CPU cores, and the application of more efficient data structures. For example, Mold implements a technique for performing intensive computations concurrently with file copying, anticipatory loading of object files into memory, fast hash tables for symbol resolution, scanning relocation tables in a separate thread, and deduplication of overlapping sections across different files.
The Mold 3.0 branch is noteworthy for rewriting the codebase from C++ (C++20) to Rust. Mold 3.0 can serve as a transparent replacement for Mold 2.42.1, the last release in C++, and supports all previously available options and target architectures. Transitioning to Rust has safeguarded the project from potential issues when dealing with corrupted object files — in situations where the C++ version would crash due to accessing memory areas beyond the buffer, the Rust version halts operation at the boundary check stage. The performance of the Rust implementation is on par with that of the C++ version.
In addition to the migration to Rust, a key objective in developing branch 3.0 was to enhance compatibility with GNU ld and prepare the project for use as the default linker in Linux distributions. The build system has been replaced from CMake with Cargo, and the testing system from ctest with cargo test. The oneTBB library has been removed from dependencies.
Source: opennet.ru
