1 http://patchwork.ozlabs.org/patch/102292/
2 http://codereview.appspot.com/4664051/
3 http://sourceware.org/ml/binutils/2011-01/msg00178.html
4 http://anonscm.debian.org/viewvc/gcccvs/branches/sid/gcc-4.6/debian/patches/gold-and-ld.diff
6 Index: gcc/doc/invoke.texi
7 ===================================================================
8 --- gcc/doc/invoke.texi (revision 175346)
9 +++ gcc/doc/invoke.texi (working copy)
11 -funit-at-a-time -funroll-all-loops -funroll-loops @gol
12 -funsafe-loop-optimizations -funsafe-math-optimizations -funswitch-loops @gol
13 -fvariable-expansion-in-unroller -fvect-cost-model -fvpt -fweb @gol
14 --fwhole-program -fwpa -fuse-linker-plugin @gol
15 +-fwhole-program -fwpa -fuse-ld -fuse-linker-plugin @gol
16 --param @var{name}=@var{value}
17 -O -O0 -O1 -O2 -O3 -Os -Ofast}
19 @@ -8017,6 +8017,16 @@
21 Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}.
24 +Use the @command{gold} linker instead of the default linker.
25 +This option is only necessary if GCC has been configured with
26 +@option{--enable-gold} and @option{--enable-ld=default}.
29 +Use the @command{ld.bfd} linker instead of the default linker.
30 +This option is only necessary if GCC has been configured with
31 +@option{--enable-gold} and @option{--enable-ld}.
33 @item -fcprop-registers
34 @opindex fcprop-registers
35 After register allocation and post-register allocation instruction splitting,
37 ===================================================================
38 --- gcc/configure (revision 175346)
39 +++ gcc/configure (working copy)
42 ORIGINAL_NM_FOR_TARGET
44 +ORIGINAL_GOLD_FOR_TARGET
45 ORIGINAL_LD_FOR_TARGET
46 ORIGINAL_PLUGIN_LD_FOR_TARGET
48 @@ -21131,6 +21132,21 @@
52 +gcc_cv_ld_gold_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/gold
54 +if test "${gcc_cv_gold+set}" = set; then :
58 +if test -f $gcc_cv_ld_gold_srcdir/configure.ac \
59 + && test -f ../gold/Makefile \
60 + && test x$build = x$host; then
61 + gcc_cv_gold=../gold/ld-new$build_exeext
67 ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld
68 PLUGIN_LD=`basename $gcc_cv_ld`
70 @@ -21170,6 +21186,9 @@
74 +ORIGINAL_GOLD_FOR_TARGET=$gcc_cv_gold
77 { $as_echo "$as_me:${as_lineno-$LINENO}: checking what linker to use" >&5
78 $as_echo_n "checking what linker to use... " >&6; }
79 if test "$gcc_cv_ld" = ../ld/ld-new$build_exeext; then
81 ===================================================================
82 --- gcc/gcc.c (revision 175346)
83 +++ gcc/gcc.c (working copy)
85 }"PLUGIN_COND_CLOSE" \
86 %{flto|flto=*:%<fcompare-debug*} \
87 %{flto} %{flto=*} %l " LINK_PIE_SPEC \
88 + "%{fuse-ld=gold:%{fuse-ld=bfd:%e-fuse-ld=gold and -fuse-ld=bfd may not be used together}} \
89 + %{fuse-ld=gold:-use-gold} \
90 + %{fuse-ld=bfd:-use-ld}" \
91 "%X %{o*} %{e*} %{N} %{n} %{r}\
92 %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}}\
93 %{static:} %{L*} %(mfwrap) %(link_libgcc) %o\
95 ===================================================================
96 --- gcc/opts.c (revision 175346)
97 +++ gcc/opts.c (working copy)
99 dc->max_errors = value;
103 case OPT_fuse_linker_plugin:
104 - /* No-op. Used by the driver and passed to us because it starts with f.*/
105 + /* No-op. Used by the driver and passed to us because it starts with f. */
108 case OPT_Wuninitialized:
109 Index: gcc/configure.ac
110 ===================================================================
111 --- gcc/configure.ac (revision 175346)
112 +++ gcc/configure.ac (working copy)
113 @@ -1974,6 +1974,17 @@
114 AC_PATH_PROG(gcc_cv_ld, $LD_FOR_TARGET)
117 +gcc_cv_ld_gold_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/gold
119 +AS_VAR_SET_IF(gcc_cv_gold,, [
120 +if test -f $gcc_cv_ld_gold_srcdir/configure.ac \
121 + && test -f ../gold/Makefile \
122 + && test x$build = x$host; then
123 + gcc_cv_gold=../gold/ld-new$build_exeext
128 ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld
129 PLUGIN_LD=`basename $gcc_cv_ld`
130 AC_ARG_WITH(plugin-ld,
131 @@ -2003,6 +2014,9 @@
132 *) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;;
135 +ORIGINAL_GOLD_FOR_TARGET=$gcc_cv_gold
136 +AC_SUBST(ORIGINAL_GOLD_FOR_TARGET)
138 AC_MSG_CHECKING(what linker to use)
139 if test "$gcc_cv_ld" = ../ld/ld-new$build_exeext; then
140 # Single tree build which includes ld. We want to prefer it
141 Index: gcc/exec-tool.in
142 ===================================================================
143 --- gcc/exec-tool.in (revision 175346)
144 +++ gcc/exec-tool.in (working copy)
148 -# Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
149 +# Copyright (C) 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
150 # This file is part of GCC.
152 # GCC is free software; you can redistribute it and/or modify
155 ORIGINAL_AS_FOR_TARGET="@ORIGINAL_AS_FOR_TARGET@"
156 ORIGINAL_LD_FOR_TARGET="@ORIGINAL_LD_FOR_TARGET@"
157 +ORIGINAL_GOLD_FOR_TARGET="@ORIGINAL_GOLD_FOR_TARGET@"
158 ORIGINAL_PLUGIN_LD_FOR_TARGET="@ORIGINAL_PLUGIN_LD_FOR_TARGET@"
159 ORIGINAL_NM_FOR_TARGET="@ORIGINAL_NM_FOR_TARGET@"
161 fast_install=@enable_fast_install@
165 invoked=`basename "$0"`
171 - # when using a linker plugin, gcc will always pass '-plugin' as the
172 - # first or second option to the linker.
173 - if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then
174 - original=$ORIGINAL_PLUGIN_LD_FOR_TARGET
176 - original=$ORIGINAL_LD_FOR_TARGET
178 + # Look for the a command line option
179 + # specifying the linker to be used.
182 + original=$ORIGINAL_GOLD_FOR_TARGET
185 + *\ -use-ld\ * | *\ -use-ld.bfd\ *)
186 + original=$ORIGINAL_LD_FOR_TARGET
190 + original=$ORIGINAL_PLUGIN_LD_FOR_TARGET
194 + original=$ORIGINAL_LD_FOR_TARGET
199 + # If the selected linker has not been configured then
200 + # try using the others, in the order PLUGIN-LD, LD, GOLD.
201 + if test x"$original" = x; then
202 + if test x"$ORIGINAL_PLUGIN_LD_FOR_TARGET" != x; then
203 + original=$ORIGINAL_PLUGIN_LD_FOR_TARGET
205 + elif test x"$ORIGINAL_LD_FOR_TARGET" != x; then
206 + original=$ORIGINAL_LD_FOR_TARGET
208 + elif test x"$ORIGINAL_GOLD_FOR_TARGET" != x; then
209 + original=$ORIGINAL_GOLD_FOR_TARGET
211 + # Otherwise do nothing - the case statement below
212 + # will issue an error message for us.
221 scriptdir=`cd "$tdir" && pwd`
223 if test -x $scriptdir/../$dir/$prog; then
224 - test "$fast_install" = yes || exec $scriptdir/../$dir/$prog ${1+"$@"}
225 + if test "$fast_install" = yes; then
226 + # If libtool did everything it needs to do, there's a fast path.
227 + lt_prog=$scriptdir/../$dir/$objdir/lt-$prog
229 - # if libtool did everything it needs to do, there's a fast path
230 - lt_prog=$scriptdir/../$dir/$objdir/lt-$prog
231 - test -x $lt_prog && exec $lt_prog ${1+"$@"}
233 - # libtool has not relinked ld-new yet, but we cannot just use the
234 - # previous stage (because then the relinking would just never happen!).
235 - # So we take extra care to use prev-ld/ld-new *on recursive calls*.
236 - eval LT_RCU="\${LT_RCU_$id}"
237 - test x"$LT_RCU" = x"1" && exec $scriptdir/../prev-$dir/$prog ${1+"$@"}
241 - $scriptdir/../$dir/$prog ${1+"$@"}
245 + if test -x $lt_prog; then
248 + # Libtool has not relinked ld-new yet, but we cannot just use the
249 + # previous stage (because then the relinking would just never happen!).
250 + # So we take extra care to use prev-ld/ld-new *on recursive calls*.
251 + eval LT_RCU="\${LT_RCU_$id}"
252 + if test x"$LT_RCU" = x"1"; then
253 + original=$scriptdir/../prev-$dir/$prog
259 + echo "$invoked $version"
260 + echo $scriptdir/../$dir/$prog $*
263 + $scriptdir/../$dir/$prog ${1+"$@"}
269 + original=$scriptdir/../$dir/$prog
272 - exec $scriptdir/../prev-$dir/$prog ${1+"$@"}
273 + original=$scriptdir/../prev-$dir/$prog
277 - exec $original ${1+"$@"}
279 + echo "$invoked: executable not configured"
284 +# If -v has been used then display our version number
285 +# and then echo the command we are about to invoke.
288 + echo "$invoked $version"
293 +if test -x $original; then
294 + exec "$original" ${1+"$@"}
296 + echo "$invoked: unable to locate executable: $original"
299 Index: gcc/common.opt
300 ===================================================================
301 --- gcc/common.opt (revision 175346)
302 +++ gcc/common.opt (working copy)
303 @@ -2138,6 +2138,9 @@
304 Common Report Var(flag_unwind_tables) Optimization
305 Just generate unwind tables for exception handling
308 +Common Joined Undocumented
313 Index: gcc/collect2.c
314 ===================================================================
315 --- gcc/collect2.c (revision 175346)
316 +++ gcc/collect2.c (working copy)
317 @@ -1075,17 +1075,19 @@
319 main (int argc, char **argv)
321 - static const char *const ld_suffix = "ld";
322 - static const char *const plugin_ld_suffix = PLUGIN_LD;
323 - static const char *const real_ld_suffix = "real-ld";
324 + static const char *const ld_suffix = "ld";
325 + static const char *const gold_suffix = "ld.gold";
326 + static const char *const bfd_ld_suffix = "ld.bfd";
327 + static const char *const plugin_ld_suffix = PLUGIN_LD;
328 + static const char *const real_ld_suffix = "real-ld";
329 static const char *const collect_ld_suffix = "collect-ld";
330 - static const char *const nm_suffix = "nm";
331 - static const char *const gnm_suffix = "gnm";
332 + static const char *const nm_suffix = "nm";
333 + static const char *const gnm_suffix = "gnm";
335 - static const char *const ldd_suffix = LDD_SUFFIX;
336 + static const char *const ldd_suffix = LDD_SUFFIX;
338 - static const char *const strip_suffix = "strip";
339 - static const char *const gstrip_suffix = "gstrip";
340 + static const char *const strip_suffix = "strip";
341 + static const char *const gstrip_suffix = "gstrip";
343 #ifdef CROSS_DIRECTORY_STRUCTURE
344 /* If we look for a program in the compiler directories, we just use
345 @@ -1095,6 +1097,10 @@
347 const char *const full_ld_suffix =
348 concat(target_machine, "-", ld_suffix, NULL);
349 + const char *const full_gold_suffix =
350 + concat (target_machine, "-", gold_suffix, NULL);
351 + const char *const full_bfd_ld_suffix =
352 + concat (target_machine, "-", bfd_ld_suffix, NULL);
353 const char *const full_plugin_ld_suffix =
354 concat(target_machine, "-", plugin_ld_suffix, NULL);
355 const char *const full_nm_suffix =
356 @@ -1110,15 +1116,17 @@
357 const char *const full_gstrip_suffix =
358 concat (target_machine, "-", gstrip_suffix, NULL);
360 - const char *const full_ld_suffix = ld_suffix;
361 + const char *const full_ld_suffix = ld_suffix;
362 + const char *const full_gold_suffix = gold_suffix;
363 + const char *const full_bfd_ld_suffix = bfd_ld_suffix;
364 const char *const full_plugin_ld_suffix = plugin_ld_suffix;
365 - const char *const full_nm_suffix = nm_suffix;
366 - const char *const full_gnm_suffix = gnm_suffix;
367 + const char *const full_nm_suffix = nm_suffix;
368 + const char *const full_gnm_suffix = gnm_suffix;
370 - const char *const full_ldd_suffix = ldd_suffix;
371 + const char *const full_ldd_suffix = ldd_suffix;
373 - const char *const full_strip_suffix = strip_suffix;
374 - const char *const full_gstrip_suffix = gstrip_suffix;
375 + const char *const full_strip_suffix = strip_suffix;
376 + const char *const full_gstrip_suffix = gstrip_suffix;
377 #endif /* CROSS_DIRECTORY_STRUCTURE */
380 @@ -1132,7 +1140,13 @@
384 - bool use_plugin = false;
391 + } selected_linker = DFLT_LINKER;
393 /* The kinds of symbols we will have to consider when scanning the
394 outcome of a first pass link. This is ALL to start with, then might
395 @@ -1209,15 +1223,21 @@
396 else if (! strcmp (argv[i], "-flto-partition=none"))
398 else if ((! strncmp (argv[i], "-flto=", 6)
399 - || ! strcmp (argv[i], "-flto")) && ! use_plugin)
400 + || ! strcmp (argv[i], "-flto"))
401 + && selected_linker != PLUGIN_LINKER)
402 lto_mode = LTO_MODE_WHOPR;
403 else if (!strncmp (argv[i], "-fno-lto", 8))
404 lto_mode = LTO_MODE_NONE;
405 else if (! strcmp (argv[i], "-plugin"))
408 + selected_linker = PLUGIN_LINKER;
409 lto_mode = LTO_MODE_NONE;
411 + else if (! strcmp (argv[i], "-use-gold"))
412 + selected_linker = GOLD_LINKER;
413 + else if (! strcmp (argv[i], "-use-ld"))
414 + selected_linker = BFD_LINKER;
416 #ifdef COLLECT_EXPORT_LIST
417 /* since -brtl, -bexport, -b64 are not position dependent
418 also check for them here */
419 @@ -1299,36 +1319,109 @@
420 /* Try to discover a valid linker/nm/strip to use. */
422 /* Maybe we know the right file to use (if not cross). */
424 + ld_file_name = NULL;
425 #ifdef DEFAULT_LINKER
426 if (access (DEFAULT_LINKER, X_OK) == 0)
427 ld_file_name = DEFAULT_LINKER;
428 - if (ld_file_name == 0)
429 + if (ld_file_name == NULL)
431 #ifdef REAL_LD_FILE_NAME
432 ld_file_name = find_a_file (&path, REAL_LD_FILE_NAME);
433 - if (ld_file_name == 0)
434 + if (ld_file_name == NULL)
436 /* Search the (target-specific) compiler dirs for ld'. */
437 ld_file_name = find_a_file (&cpath, real_ld_suffix);
438 /* Likewise for `collect-ld'. */
439 - if (ld_file_name == 0)
440 + if (ld_file_name == NULL)
441 ld_file_name = find_a_file (&cpath, collect_ld_suffix);
442 /* Search the compiler directories for `ld'. We have protection against
443 recursive calls in find_a_file. */
444 - if (ld_file_name == 0)
445 - ld_file_name = find_a_file (&cpath,
449 + if (ld_file_name == NULL)
450 + switch (selected_linker)
454 + ld_file_name = find_a_file (&cpath, ld_suffix);
456 + case PLUGIN_LINKER:
457 + ld_file_name = find_a_file (&cpath, plugin_ld_suffix);
460 + ld_file_name = find_a_file (&cpath, gold_suffix);
463 + ld_file_name = find_a_file (&cpath, bfd_ld_suffix);
466 /* Search the ordinary system bin directories
467 for `ld' (if native linking) or `TARGET-ld' (if cross). */
468 - if (ld_file_name == 0)
469 - ld_file_name = find_a_file (&path,
471 - ? full_plugin_ld_suffix
473 + if (ld_file_name == NULL)
474 + switch (selected_linker)
478 + ld_file_name = find_a_file (&path, full_ld_suffix);
480 + case PLUGIN_LINKER:
481 + ld_file_name = find_a_file (&path, full_plugin_ld_suffix);
484 + ld_file_name = find_a_file (&path, full_gold_suffix);
487 + ld_file_name = find_a_file (&path, full_bfd_ld_suffix);
490 + /* If we failed to find a plugin-capable linker, try the ordinary one. */
491 + if (ld_file_name == NULL && selected_linker == PLUGIN_LINKER)
492 + ld_file_name = find_a_file (&cpath, ld_suffix);
494 + if ((vflag || debug) && ld_file_name == NULL)
496 + struct prefix_list * p;
499 + notice ("collect2: warning: unable to find linker.\n");
501 +#ifdef DEFAULT_LINKER
502 + notice (" Searched for this absolute executable:\n");
503 + notice (" %s\n", DEFAULT_LINKER);
506 + notice (" Searched in these paths:\n");
507 + for (p = cpath.plist; p != NULL; p = p->next)
508 + notice (" %s\n", p->prefix);
509 + notice (" For these executables:\n");
510 + notice (" %s\n", real_ld_suffix);
511 + notice (" %s\n", collect_ld_suffix);
512 + switch (selected_linker)
515 + case DFLT_LINKER: s = ld_suffix; break;
516 + case PLUGIN_LINKER: s = plugin_ld_suffix; break;
517 + case GOLD_LINKER: s = gold_suffix; break;
518 + case BFD_LINKER: s = bfd_ld_suffix; break;
520 + notice (" %s\n", s);
522 + notice (" And searched in these paths:\n");
523 + for (p = path.plist; p != NULL; p = p->next)
524 + notice (" %s\n", p->prefix);
525 + notice (" For these executables:\n");
526 +#ifdef REAL_LD_FILE_NAME
527 + notice (" %s\n", REAL_LD_FILE_NAME);
529 + switch (selected_linker)
532 + case DFLT_LINKER: s = full_ld_suffix; break;
533 + case PLUGIN_LINKER: s = full_plugin_ld_suffix; break;
534 + case GOLD_LINKER: s = full_gold_suffix; break;
535 + case BFD_LINKER: s = full_bfd_ld_suffix; break;
537 + notice (" %s\n", s);
540 #ifdef REAL_NM_FILE_NAME
541 nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME);
542 if (nm_file_name == 0)