Rui Ueyama, the author of the LLVM lld linker and the chibicc compiler, has introduced the first stable release of the new high-performance linker Mold, which significantly outpaces GNU gold and LLVM lld in object file linking speed. The project is deemed ready for production use and can serve as a faster drop-in replacement for the GNU linker on Linux systems. Future significant releases will focus on bringing support for the macOS platform, after which work will commence on adapting Mold for Windows.
Mold is written in C++ (C++20) and is distributed under the AGPLv3 license, which is compatible with GPLv3 but not GPLv2, as it requires changes made during the development of web services to be shared. This choice stems from a desire to secure funding for development — the author is willing to sell rights to the code for re-licensing under a permissive license such as MIT or offer a separate commercial license for those who do not agree with AGPL.
Mold supports all the features of the GNU linker and boasts very high performance — linking is performed at a speed that is only twice as slow as simply copying files with the cp utility. For instance, building Chrome 96 (with code size of 1.89 GB) takes 53 seconds with GNU gold, 11.7 seconds with LLVM lld, while Mold completes it in just 2.2 seconds (26 times faster than GNU gold). For linking Clang 13 (3.18 GB), GNU gold requires 64 seconds, LLVM lld takes 5.8 seconds, whereas Mold does it in 2.9 seconds. When linking Firefox 89 (1.64 GB), GNU gold needs 32.9 seconds, LLVM lld takes 6.8 seconds, and Mold finishes it in 1.4 seconds.

Reducing linking time greatly enhances the development experience for large projects by minimizing waiting times during executable file generation while debugging and testing changes. The motivation behind creating Mold arose from frustration over having to wait for linking to complete after every code modification, coupled with the inefficiency of existing linkers on multi-core systems and the desire to experiment with a fundamentally different linking architecture without resorting to overly complex models like incremental linking.
High performance in the executable file linking 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 the technique of performing intensive computations simultaneously with file copying, preloading object files into memory, using fast hash tables for symbol resolution, scanning relocation tables in a separate thread, and deduplicating repeating sections across different files.
Source: opennet.ru
