mold is a linker that aims to provide drop-in compatibility with existing Unix linkers. It is many times faster than sys-devel/lld and GNU gold. Its speed is achieved through the usage of optimized data structures and parallelization.
mold is in the Gentoo package repository and can be installed for all users with Emerge.
emerge --ask sys-devel/mold
A patch to GCC that allows it to invoke mold as a linker has landed in the master branch and is expected to be a part of GCC 12. In the meantime, the patch can be placed in /etc/portage/patches to use it with GCC 11:
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 \
-fuse-ld=mold can then be set in the make.conf file so that mold is used to link all packages:
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-fuse-ld=mold"
Package fails to build using mold
# mold does not support linker scripts; it cannot be used to link the kernel sys-kernel/vanilla-kernel no-mold
- Gold — a linker intended as a replacement for the ld.bfd linker.
- Why is mold so fast?, GitHub. Retrieved on January 8, 2022