If one has both ld and gold installed, gcc gives little help in letting someone choose one or the other for a particular link job. (Systemwide relinking a la alternatives(1), or forcing creation of a temporary -B directory, are not convenient.) Please consider adding an option to the driver, akin to -Wl... to allow overriding of the ld binary being invoked. Perhaps: gcc -Wl=/bin/ld.gold (and similar options for -Wa=, -Wp= could make sense).
http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00402.html
While this report seems to be just talking about switching between ld.bfd and gold, I'd appreciate it if the linker switching could be done more generically, to support more linkers besides just those two. For example, on my current system (darwin), my copy of gcc is configured to use the ld64 installed by my package manager by default. Besides this linker, I also have several other linkers to choose between: * the system ld64, which is an older version than the default ld64 installed by my package manager * several other versions of ld64, each with a version suffix appended to the name of its binary (i.e. "ld-97", "ld-127", "ld-136", and "ld-latest") * the old cctools ld, installed as "ld_classic" * the GNU binutils/bfd ld, installed with binaries prefixed with the letter "g" (so "gld" and "gld.bfd") My case is probably a little extreme, as I doubt the average user will have this many linkers installed, but it still serves as an example of the variety of linkers that exist out there. Oh, and also, while I'm here, I figure I might as well add a personal example of a practical effect that this issue can have: today, I was running into an error codesigning the copy of gdb that I just built, because the linker that my copy of gcc used generated load commands that were newer than what my system codesigning utilities understood. I tried wrangling the codesigning stuff in a few different ways, but it would have been easier if I could have just told gcc to use the system linker instead of the one it had been configured with...
Dup. *** This bug has been marked as a duplicate of bug 55470 ***
I posted a patch https://gcc.gnu.org/ml/gcc-patches/2020-02/msg00510.html to make -fuse-ld=linker generic (absolute path or ld.linker)