RFA/RFC: Enable both gold and ld in a single toolchain
Nick Clifton
nickc@redhat.com
Thu Mar 4 19:26:00 GMT 2010
Hi Guys,
I have created a patch (attached) that enables both GOLD and LD to be
built and used in a single toolchain. This allows easy comparison of
the two linkers with just a single command line switch to choose
between them.
I suspect that the patch may not be approved, but I wanted to
contribute it in case anyone else was interested in this facility.
In order to build both linkers it is necessary to run the top level
configure script with the switch:
--enable-gold=both
Then once the linkers are built/installed you can add:
-Luse-gold
to a gcc command line to use the GOLD linker. Otherwise the LD linker
(aka gld) will be used.
There is one special caveat though. When installing the two linkers
it is necessary to install gold before ld as otherwise the ld linker
will be overwritten. Ie run:
make ... install-gold install-ld ...
The choice of -Luse-gold as the switch to select the gold linker is a
hack. One of the requirements for programs and scripts that sit
between gcc and the linker, (such as collect2 and collect-ld), is that
gcc must continue to work if they are not there and the linker is
invoked directly. Thus any options that are intended for the
intermediate programs/scripts must be disguised in some fashion.
Collect2 uses environment variables to get its options but this is,
IMHO, heinous. So instead I chose to use the -L switch. This can
take an arbitrary text argument and it will not cause the linker to
complain if the argument is not recognised or the so called library
search path does not actually exist. In theory it could break a link
if there really is a sub-directory of the current directory called
"use-gold" and this directory contains subtly invalid binaries, but
this is very unlikely to happen.
Comments welcome, and if the gcc maintainers feel that this feature is
actually wanted in the mainstream sources I will happy to apply my
patch and maintain it in the future.
Tested with i686-pc-linux-gnu, sparc-elf and arm-eabi toolchains, and
an x86 bootstrap. (That is bootstrapping without gold enabled, just
to make sure that I did not break anything).
Cheers
Nick
./ChangeLog
2010-03-04 Nick Clifton <nickc@redhat.com>
* configure.ac (--enable-gold): Accept a value of "both". If
this value is given then configure both ld and gold.
* configure: Regenerate.
gcc/ChangeLog
2010-03-04 Nick Clifton <nickc@redhat.com>
* configure.ac (gcc_cv_gold_srcdir): New cached variable -
contains the location of the gold sources.
(ORIGINAL_GOLD_FOR_TARGET): New substituted variable - contains
the name of the locally built gold executable.
* configure: Regenerate.
* collect2.c (main): Detect the -Luse-gold switch and select the
gold linker, if found.
* exec-tool.in: Detect the -Luse-gold switch and select the gold
linker, if found. Add support for -v switch. Report problems
locating linker executable.
gold/ChangeLog
2010-03-04 Nick Clifton <nickc@redhat.com>
* Makefile.am (install-exec-local): Also install the executable
as a binary named 'gold'.
* Makefile.in: Regenerate.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gold-and-ld.patch
Type: text/x-patch
Size: 10368 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20100304/81b68d2c/attachment.bin>
More information about the Gcc-patches
mailing list