From Gentoo Wiki
Jump to:navigation Jump to:search

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.[1]



mold is in the Gentoo package repository and can be installed for all users with Emerge.

root #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:

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 \

-fuse-ld=mold can then be set in the make.conf file so that mold is used to link all packages:

FILE /etc/portage/make.conf
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-fuse-ld=mold"


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:

FILE /etc/portage/package.env/no-mold
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
FILE /etc/portage/package.env
# mold does not support linker scripts; it cannot be used to link the kernel
sys-kernel/vanilla-kernel no-mold

See also

  • Gold — a linker intended as a replacement for the ld.bfd linker.


  1. Why is mold so fast?, GitHub. Retrieved on January 8, 2022