This Time Self-Hosted
dark mode light mode Search

Gold readiness obstacle #3: side-by-side selection

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 — ld).

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 (real-ld, collect-ld and 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.

Comments 4
  1. All you have to do to switch linkers on the fly are the following commands:(for gold)ln -f /usr/x86_64-pc-linux-gnu/binutils-bin/2.21.51.0.9/ld.gold /usr/x86_64-pc-linux-gnu/binutils-bin/2.21.51.0.9/ld(for old bfd linker)ln -f /usr/x86_64-pc-linux-gnu/binutils-bin/2.21.51.0.9/ld.bfd /usr/x86_64-pc-linux-gnu/binutils-bin/2.21.51.0.9/ldAs soon as you run one of them gcc picks up the new linker immediately. I use gold as my default linker for over a year now andthere a very few problems (~5% of all ebuilds fail to link because the bfd linker is sometimes more permissive).

  2. Hi,this work is very interesting to me as a software developer. So please continue! 🙂

  3. What I did was to modify the ebuild to install a “redirector”, based on environment variables it switched linkker between bfd and gold.then you mess with /etc/portage/env and set which packege need to fallback to bfd

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.