mold
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.[1] mold is still in the early stages of development and as features are added to be on par with the other linkers[2], this could affect the speedy nature of mold.
LTO (Link-time optimization) support has been added since mold-1.1.1.
Installation
Emerge
The mold linker is in the Gentoo package repository and can be installed using the following command:
root #
emerge --ask sys-devel/mold
Usage
GCC 12+ & Clang
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="${LDFLAGS} -fuse-ld=mold"
GCC 11
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:
root #
mkdir -p /etc/portage/patches/sys-devel/gcc-11.2.1_p20211127
root #
curl -Lo /etc/portage/patches/sys-devel/gcc-11.2.1_p20211127/fuse-ld-mold.patch \
https://gist.github.com/00-matt/dda791a36318bafb68576b8576b1d283/raw/fuse-ld-mold.patch
Troubleshooting
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:
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
# 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-libs/glibc (bug #860900)
A Mold tracker also exists on bugs.gentoo.org - bug #830404
See also
- Gold — a linker intended as a replacement for the ld.bfd linker.
References
- ↑ 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