1
# DP: Enable both gold and ld in a single toolchain.
2
# DP: New option -fuse-ld=ld.bfd, -fuse-ld=gold.
4
--- a/src/gcc/doc/invoke.texi
5
+++ b/srcgcc/doc/invoke.texi
7
-funit-at-a-time -funroll-all-loops -funroll-loops @gol
8
-funsafe-loop-optimizations -funsafe-math-optimizations -funswitch-loops @gol
9
-fvariable-expansion-in-unroller -fvect-cost-model -fvpt -fweb @gol
10
--fwhole-program -fwpa -fuse-linker-plugin @gol
11
+-fwhole-program -fwpa -fuse-ld -fuse-linker-plugin @gol
12
--param @var{name}=@var{value}
13
-O -O0 -O1 -O2 -O3 -Os -Ofast}
15
@@ -7689,6 +7689,16 @@
16
Enabled by default when LTO support in GCC is enabled and GCC was compiled
17
with linker supporting plugins (GNU ld or @code{gold}).
20
+Use the @command{gold} linker instead of the default linker.
21
+This option is only necessary if GCC has been configured with
22
+@option{--enable-gold} and @option{--enable-ld=default}.
25
+Use the @command{ld.bfd} linker instead of the default linker.
26
+This option is only necessary if GCC has been configured with
27
+@option{--enable-gold} and @option{--enable-ld}.
29
@item -fcprop-registers
30
@opindex fcprop-registers
31
After register allocation and post-register allocation instruction splitting,
35
}"PLUGIN_COND_CLOSE" \
36
%{flto|flto=*:%<fcompare-debug*} \
37
%{flto} %{flto=*} %l " LINK_PIE_SPEC \
38
+ "%{fuse-ld=gold:%{fuse-ld=bfd:%e-fuse-ld=gold and -fuse-ld=bfd may not be used together}} \
39
+ %{fuse-ld=gold:-use-gold} \
40
+ %{fuse-ld=bfd:-use-ld}" \
41
"%X %{o*} %{e*} %{N} %{n} %{r}\
42
%{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}}\
43
%{static:} %{L*} %(mfwrap) %(link_libgcc) %o\
47
dc->max_errors = value;
51
case OPT_fuse_linker_plugin:
52
- /* No-op. Used by the driver and passed to us because it starts with f.*/
53
+ /* No-op. Used by the driver and passed to us because it starts with f. */
57
--- a/src/gcc/configure.ac
58
+++ b/srcgcc/configure.ac
59
@@ -1937,6 +1937,17 @@
60
AC_PATH_PROG(gcc_cv_ld, $LD_FOR_TARGET)
63
+gcc_cv_ld_gold_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/gold
65
+AS_VAR_SET_IF(gcc_cv_gold,, [
66
+if test -f $gcc_cv_ld_gold_srcdir/configure.ac \
67
+ && test -f ../gold/Makefile \
68
+ && test x$build = x$host; then
69
+ gcc_cv_gold=../gold/ld-new$build_exeext
74
ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld
75
PLUGIN_LD=`basename $gcc_cv_ld`
76
AC_ARG_WITH(plugin-ld,
78
*) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;;
81
+ORIGINAL_GOLD_FOR_TARGET=$gcc_cv_gold
82
+AC_SUBST(ORIGINAL_GOLD_FOR_TARGET)
84
AC_MSG_CHECKING(what linker to use)
85
if test "$gcc_cv_ld" = ../ld/ld-new$build_exeext; then
86
# Single tree build which includes ld. We want to prefer it
87
--- a/src/gcc/exec-tool.in
88
+++ b/srcgcc/exec-tool.in
92
-# Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
93
+# Copyright (C) 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
94
# This file is part of GCC.
96
# GCC is free software; you can redistribute it and/or modify
99
ORIGINAL_AS_FOR_TARGET="@ORIGINAL_AS_FOR_TARGET@"
100
ORIGINAL_LD_FOR_TARGET="@ORIGINAL_LD_FOR_TARGET@"
101
+ORIGINAL_GOLD_FOR_TARGET="@ORIGINAL_GOLD_FOR_TARGET@"
102
ORIGINAL_PLUGIN_LD_FOR_TARGET="@ORIGINAL_PLUGIN_LD_FOR_TARGET@"
103
ORIGINAL_NM_FOR_TARGET="@ORIGINAL_NM_FOR_TARGET@"
105
fast_install=@enable_fast_install@
109
invoked=`basename "$0"`
115
- # when using a linker plugin, gcc will always pass '-plugin' as the
116
- # first or second option to the linker.
117
- if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then
118
- original=$ORIGINAL_PLUGIN_LD_FOR_TARGET
120
- original=$ORIGINAL_LD_FOR_TARGET
122
+ # Look for the a command line option
123
+ # specifying the linker to be used.
126
+ original=$ORIGINAL_GOLD_FOR_TARGET
129
+ *\ -use-ld\ * | *\ -use-ld.bfd\ *)
130
+ original=$ORIGINAL_LD_FOR_TARGET
134
+ original=$ORIGINAL_PLUGIN_LD_FOR_TARGET
138
+ original=$ORIGINAL_LD_FOR_TARGET
143
+ # If the selected linker has not been configured then
144
+ # try using the others, in the order PLUGIN-LD, LD, GOLD.
145
+ if test x"$original" = x; then
146
+ if test x"$ORIGINAL_PLUGIN_LD_FOR_TARGET" != x; then
147
+ original=$ORIGINAL_PLUGIN_LD_FOR_TARGET
149
+ elif test x"$ORIGINAL_LD_FOR_TARGET" != x; then
150
+ original=$ORIGINAL_LD_FOR_TARGET
152
+ elif test x"$ORIGINAL_GOLD_FOR_TARGET" != x; then
153
+ original=$ORIGINAL_GOLD_FOR_TARGET
155
+ # Otherwise do nothing - the case statement below
156
+ # will issue an error message for us.
165
scriptdir=`cd "$tdir" && pwd`
167
if test -x $scriptdir/../$dir/$prog; then
168
- test "$fast_install" = yes || exec $scriptdir/../$dir/$prog ${1+"$@"}
169
+ if test "$fast_install" = yes; then
170
+ # If libtool did everything it needs to do, there's a fast path.
171
+ lt_prog=$scriptdir/../$dir/$objdir/lt-$prog
173
- # if libtool did everything it needs to do, there's a fast path
174
- lt_prog=$scriptdir/../$dir/$objdir/lt-$prog
175
- test -x $lt_prog && exec $lt_prog ${1+"$@"}
177
- # libtool has not relinked ld-new yet, but we cannot just use the
178
- # previous stage (because then the relinking would just never happen!).
179
- # So we take extra care to use prev-ld/ld-new *on recursive calls*.
180
- eval LT_RCU="\${LT_RCU_$id}"
181
- test x"$LT_RCU" = x"1" && exec $scriptdir/../prev-$dir/$prog ${1+"$@"}
185
- $scriptdir/../$dir/$prog ${1+"$@"}
189
+ if test -x $lt_prog; then
192
+ # Libtool has not relinked ld-new yet, but we cannot just use the
193
+ # previous stage (because then the relinking would just never happen!).
194
+ # So we take extra care to use prev-ld/ld-new *on recursive calls*.
195
+ eval LT_RCU="\${LT_RCU_$id}"
196
+ if test x"$LT_RCU" = x"1"; then
197
+ original=$scriptdir/../prev-$dir/$prog
203
+ echo "$invoked $version"
204
+ echo $scriptdir/../$dir/$prog $*
207
+ $scriptdir/../$dir/$prog ${1+"$@"}
213
+ original=$scriptdir/../$dir/$prog
216
- exec $scriptdir/../prev-$dir/$prog ${1+"$@"}
217
+ original=$scriptdir/../prev-$dir/$prog
221
- exec $original ${1+"$@"}
223
+ echo "$invoked: executable not configured"
228
+# If -v has been used then display our version number
229
+# and then echo the command we are about to invoke.
232
+ echo "$invoked $version"
237
+if test -x $original; then
238
+ exec "$original" ${1+"$@"}
240
+ echo "$invoked: unable to locate executable: $original"
243
--- a/src/gcc/common.opt
244
+++ b/srcgcc/common.opt
245
@@ -1998,6 +1998,9 @@
246
Common Report Var(flag_unwind_tables) Optimization
247
Just generate unwind tables for exception handling
250
+Common Joined Undocumented
255
--- a/src/gcc/collect2.c
256
+++ b/srcgcc/collect2.c
257
@@ -1075,17 +1075,19 @@
259
main (int argc, char **argv)
261
- static const char *const ld_suffix = "ld";
262
- static const char *const plugin_ld_suffix = PLUGIN_LD;
263
- static const char *const real_ld_suffix = "real-ld";
264
+ static const char *const ld_suffix = "ld";
265
+ static const char *const gold_suffix = "gold";
266
+ static const char *const bfd_ld_suffix = "ld.bfd";
267
+ static const char *const plugin_ld_suffix = PLUGIN_LD;
268
+ static const char *const real_ld_suffix = "real-ld";
269
static const char *const collect_ld_suffix = "collect-ld";
270
- static const char *const nm_suffix = "nm";
271
- static const char *const gnm_suffix = "gnm";
272
+ static const char *const nm_suffix = "nm";
273
+ static const char *const gnm_suffix = "gnm";
275
- static const char *const ldd_suffix = LDD_SUFFIX;
276
+ static const char *const ldd_suffix = LDD_SUFFIX;
278
- static const char *const strip_suffix = "strip";
279
- static const char *const gstrip_suffix = "gstrip";
280
+ static const char *const strip_suffix = "strip";
281
+ static const char *const gstrip_suffix = "gstrip";
283
#ifdef CROSS_DIRECTORY_STRUCTURE
284
/* If we look for a program in the compiler directories, we just use
285
@@ -1095,6 +1097,10 @@
287
const char *const full_ld_suffix =
288
concat(target_machine, "-", ld_suffix, NULL);
289
+ const char *const full_gold_suffix =
290
+ concat (target_machine, "-", gold_suffix, NULL);
291
+ const char *const full_bfd_ld_suffix =
292
+ concat (target_machine, "-", bfd_ld_suffix, NULL);
293
const char *const full_plugin_ld_suffix =
294
concat(target_machine, "-", plugin_ld_suffix, NULL);
295
const char *const full_nm_suffix =
296
@@ -1110,15 +1116,17 @@
297
const char *const full_gstrip_suffix =
298
concat (target_machine, "-", gstrip_suffix, NULL);
300
- const char *const full_ld_suffix = ld_suffix;
301
+ const char *const full_ld_suffix = ld_suffix;
302
+ const char *const full_gold_suffix = gold_suffix;
303
+ const char *const full_bfd_ld_suffix = bfd_ld_suffix;
304
const char *const full_plugin_ld_suffix = plugin_ld_suffix;
305
- const char *const full_nm_suffix = nm_suffix;
306
- const char *const full_gnm_suffix = gnm_suffix;
307
+ const char *const full_nm_suffix = nm_suffix;
308
+ const char *const full_gnm_suffix = gnm_suffix;
310
- const char *const full_ldd_suffix = ldd_suffix;
311
+ const char *const full_ldd_suffix = ldd_suffix;
313
- const char *const full_strip_suffix = strip_suffix;
314
- const char *const full_gstrip_suffix = gstrip_suffix;
315
+ const char *const full_strip_suffix = strip_suffix;
316
+ const char *const full_gstrip_suffix = gstrip_suffix;
317
#endif /* CROSS_DIRECTORY_STRUCTURE */
320
@@ -1132,7 +1140,13 @@
324
- bool use_plugin = false;
331
+ } selected_linker = DFLT_LINKER;
333
/* The kinds of symbols we will have to consider when scanning the
334
outcome of a first pass link. This is ALL to start with, then might
335
@@ -1209,15 +1223,21 @@
336
else if (! strcmp (argv[i], "-flto-partition=none"))
338
else if ((! strncmp (argv[i], "-flto=", 6)
339
- || ! strcmp (argv[i], "-flto")) && ! use_plugin)
340
+ || ! strcmp (argv[i], "-flto"))
341
+ && selected_linker != PLUGIN_LINKER)
342
lto_mode = LTO_MODE_WHOPR;
343
else if (!strncmp (argv[i], "-fno-lto", 8))
344
lto_mode = LTO_MODE_NONE;
345
else if (! strcmp (argv[i], "-plugin"))
348
+ selected_linker = PLUGIN_LINKER;
349
lto_mode = LTO_MODE_NONE;
351
+ else if (! strcmp (argv[i], "-use-gold"))
352
+ selected_linker = GOLD_LINKER;
353
+ else if (! strcmp (argv[i], "-use-ld"))
354
+ selected_linker = BFD_LINKER;
356
#ifdef COLLECT_EXPORT_LIST
357
/* since -brtl, -bexport, -b64 are not position dependent
358
also check for them here */
359
@@ -1299,36 +1319,109 @@
360
/* Try to discover a valid linker/nm/strip to use. */
362
/* Maybe we know the right file to use (if not cross). */
364
+ ld_file_name = NULL;
365
#ifdef DEFAULT_LINKER
366
if (access (DEFAULT_LINKER, X_OK) == 0)
367
ld_file_name = DEFAULT_LINKER;
368
- if (ld_file_name == 0)
369
+ if (ld_file_name == NULL)
371
#ifdef REAL_LD_FILE_NAME
372
ld_file_name = find_a_file (&path, REAL_LD_FILE_NAME);
373
- if (ld_file_name == 0)
374
+ if (ld_file_name == NULL)
376
/* Search the (target-specific) compiler dirs for ld'. */
377
ld_file_name = find_a_file (&cpath, real_ld_suffix);
378
/* Likewise for `collect-ld'. */
379
- if (ld_file_name == 0)
380
+ if (ld_file_name == NULL)
381
ld_file_name = find_a_file (&cpath, collect_ld_suffix);
382
/* Search the compiler directories for `ld'. We have protection against
383
recursive calls in find_a_file. */
384
- if (ld_file_name == 0)
385
- ld_file_name = find_a_file (&cpath,
389
+ if (ld_file_name == NULL)
390
+ switch (selected_linker)
394
+ ld_file_name = find_a_file (&cpath, ld_suffix);
396
+ case PLUGIN_LINKER:
397
+ ld_file_name = find_a_file (&cpath, plugin_ld_suffix);
400
+ ld_file_name = find_a_file (&cpath, gold_suffix);
403
+ ld_file_name = find_a_file (&cpath, bfd_ld_suffix);
406
/* Search the ordinary system bin directories
407
for `ld' (if native linking) or `TARGET-ld' (if cross). */
408
- if (ld_file_name == 0)
409
- ld_file_name = find_a_file (&path,
411
- ? full_plugin_ld_suffix
413
+ if (ld_file_name == NULL)
414
+ switch (selected_linker)
418
+ ld_file_name = find_a_file (&path, full_ld_suffix);
420
+ case PLUGIN_LINKER:
421
+ ld_file_name = find_a_file (&path, full_plugin_ld_suffix);
424
+ ld_file_name = find_a_file (&path, full_gold_suffix);
427
+ ld_file_name = find_a_file (&path, full_bfd_ld_suffix);
430
+ /* If we failed to find a plugin-capable linker, try the ordinary one. */
431
+ if (ld_file_name == NULL && selected_linker == PLUGIN_LINKER)
432
+ ld_file_name = find_a_file (&cpath, ld_suffix);
434
+ if ((vflag || debug) && ld_file_name == NULL)
436
+ struct prefix_list * p;
439
+ notice ("collect2: warning: unable to find linker.\n");
441
+#ifdef DEFAULT_LINKER
442
+ notice (" Searched for this absolute executable:\n");
443
+ notice (" %s\n", DEFAULT_LINKER);
446
+ notice (" Searched in these paths:\n");
447
+ for (p = cpath.plist; p != NULL; p = p->next)
448
+ notice (" %s\n", p->prefix);
449
+ notice (" For these executables:\n");
450
+ notice (" %s\n", real_ld_suffix);
451
+ notice (" %s\n", collect_ld_suffix);
452
+ switch (selected_linker)
455
+ case DFLT_LINKER: s = ld_suffix; break;
456
+ case PLUGIN_LINKER: s = plugin_ld_suffix; break;
457
+ case GOLD_LINKER: s = gold_suffix; break;
458
+ case BFD_LINKER: s = bfd_ld_suffix; break;
460
+ notice (" %s\n", s);
462
+ notice (" And searched in these paths:\n");
463
+ for (p = path.plist; p != NULL; p = p->next)
464
+ notice (" %s\n", p->prefix);
465
+ notice (" For these executables:\n");
466
+#ifdef REAL_LD_FILE_NAME
467
+ notice (" %s\n", REAL_LD_FILE_NAME);
469
+ switch (selected_linker)
472
+ case DFLT_LINKER: s = full_ld_suffix; break;
473
+ case PLUGIN_LINKER: s = full_plugin_ld_suffix; break;
474
+ case GOLD_LINKER: s = full_gold_suffix; break;
475
+ case BFD_LINKER: s = full_bfd_ld_suffix; break;
477
+ notice (" %s\n", s);
480
#ifdef REAL_NM_FILE_NAME
481
nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME);
482
if (nm_file_name == 0)