mold is a linker that aims to provide drop-in compatibility with existing Unix linkers. It is many times faster than the BFD linker from GNU's binutils and slightly faster than LLVM's LLD linker in some use cases. Its speed is achieved through the usage of optimized data structures and parallelization. mold is still in the early stages of development and as features are added to be on par with the other linkers, this could affect the speedy nature of mold.
LTO (Link-time optimization) support has been added to mold-1.1.1. Older versions of the linker lacks LTO support and possibly other features traditional linkers provide for their respective compilers.
The mold linker is in the Gentoo package repository and can be installed using the following command:
emerge --ask sys-devel/mold
GCC 12+ and clang support adding
-fuse-ld=mold to LDFLAGS in the make.conf file so that mold is used to link all packages:
LDFLAGS="-fuse-ld=mold -Wl,-O1 -Wl,--as-needed"
As of 2022-09-15, the following patch does not apply cleanly to gcc 11.3.1_p20220909.
A patch that allows GCC 11 to invoke mold as a linker is also available. The patch can be placed in /etc/portage/patches:
mkdir -p /etc/portage/patches/sys-devel/gcc-11.2.1_p20211127
curl -Lo /etc/portage/patches/sys-devel/gcc-11.2.1_p20211127/fuse-ld-mold.patch \
Package fails to build using mold
Some packages do not build with mold (see bug #830404 for a list). An environment can be created to selectively disable it for some packages:
# mold does not support linker scripts; it cannot be used to link the kernel sys-kernel/vanilla-kernel no-mold
Known packages to fail
- sys-app/sandbox (bug #830748)
- sys-libs/glibc (bug #860900)
- Gold — a linker intended as a replacement for the ld.bfd linker.
- ↑ Why is mold so fast?, GitHub. Retrieved on January 8, 2022
- ↑ Why isn't ld.lld faster? LLD developer, maskray's blog December 12, 2021
- ↑ Support LTO linker plugin #181, GitHub. Retrieved on January 31, 2022