From Gentoo Wiki
Jump to: navigation, search

gold is a new linker intended as a replacement for the ld.bfd linker.

The two installed linkers are available directly as ld.bfd and respectively. Additionally, the default linker is also installed as ld - and this binary is used by compilers.


Gold can be enabled by setting the gold USE flag for sys-devel/binutils. Additionally, setting default-gold will make the default linker.

FILE /etc/portage/package.use/gold
# enable gold and set it as default
sys-devel/binutils      gold default-gold

After setting the USE flags, re-install binutils:

root #emerge --ask --changed-use --deep --oneshot --verbose sys-devel/binutils


Switching the default linker

The easy way

The sys-devel/binutils-config package can be used to set the default:

root #binutils-config --linker
* Setting default linker to for x86_64-pc-linux-gnu-2.32 ...                            [ ok ]

If using crossdev, the linker for a cross-compile toolchain can be switched by additionally providing the CHOST. For example, to switch the arm64 linker back to ld.bfd, run:

root #binutils-config --linker ld.bfd aarch64-unknown-linux-gnu
 * Setting default linker to ld.bfd for aarch64-unknown-linux-gnu-2.32 ...                      [ ok ]

The hard way (manually)

The default linker can be changed immediately by linking ld to in the binutils directory.

user $readlink -f /usr/bin/ld

Hard link:

root #ln -f /usr/x86_64-pc-linux-gnu/binutils-bin/2.22/ /usr/x86_64-pc-linux-gnu/binutils-bin/2.22/ld

Symbolic link:

root #ln -sf /usr/x86_64-pc-linux-gnu/binutils-bin/2.22/ld