One question I have been asked by developers and power users alike, is “how do I safely test gold?”, and slightly down the FAQ list “is there an ebuild for it?”. The answers to these questions are quite difficult to give, and it’s virtually impossible to just give a single answer to them. But I’ll try.
The second question is the one that has to be answered first. As a link editor, gold is not built standalone; it is still built as part of GNU binutils, just like the bfd-based link editor, while it is mostly standalone from the rest of the utilities. For a (little) while, Gentoo used to have an USE flag that could turn on building/installing gold, but then it was dropped, mostly because it was clearly too soon to have it even available. Right now, there is only one version to build a binutils package that uses gold as default link editor: the
EXTRA_ECONF variable has to be set to
--enable-gold=default (without the
=default part it would build and install gold, but it wouldn’t be the preferred link editor —
I could give more hints about how to do this, but I’m not going to do so; if you do not know how to set the variable, you really shouldn’t be playing with gold right now, it is not safe at this level just yet.
With the configure switch I give above, you both build gold and set it as the preferred link editor, not the only one though, as the old bfd editor is also built and installed. So what’s the problem? Doesn’t that mean that it is possible to have both and switch then at runtime? Unfortunately, not so much.
Unfortunately GCC does not use a variable to choose which linker to use, it only looks for three executable names (
ld) in a series of path, starting with the ones listed in
COMPILER_PATH environment variable. On an unmodified Gentoo system, what the compiler will execute is something like this (taken from my laptop):
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld, which is a symlink created directly by the binutils package. Of course you can use custom
COMPILER_PATH values to play with gold, but that’s definitely not something you wish to keep doing for a very long time.
The perfect solution would be to have a tool to select different linker versions, which is what
binutils-config would be supposed to do. Unfortunately it never worked as it was properly intended, and the couple of people who tried implementing
eselect binutils before has shown that it’s not a trivial task to implement multiple binutils versions slotting properly. the same goes for
eselect compiler. I think I have already proposed implementing new, complex
eselect tools as part of GSoC, but it seems like nobody picked it up. I’m afraid that this could still be an option next year.