From 00e287bea815b3c2a55447d91b3911a4bb014072 Mon Sep 17 00:00:00 2001 From: Andrew Hsieh Date: Tue, 9 Oct 2012 18:53:36 +0800 Subject: [4.7] Add -fuse-ld= Google ref 54218-p2 2011-06-27 Doug Kwan Google ref 41164-p2 Backport upstream patch under review. 2011-01-19 NNick Clifton Matthias Klose * 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 -use-gold and -use-ld switches and select the appropriate linker, if found. If a linker cannot be found and collect2 is executing in verbose mode then report the search paths examined. * exec-tool.in: Detect the -use-gold and -use-ld switches and select the appropriate linker, if found. Add support for -v switch. Report problems locating linker executable. * gcc.c (LINK_COMMAND_SPEC): Translate -fuse-ld=gold into -use-gold and -fuse-ld=bfd into -use-ld. * common.opt: Add fuse-ld=gold and fuse-ld=bfd. * opts.c (comman_handle_option): Ignore -fuse-ld=gold and -fuse-ld=bfd. * doc/invoke.texi: Document the new options. Change-Id: I659dd3f53b8ee23667fec0d7d77efc90155cdf43 --- gcc-4.7/gcc/collect2.c | 115 ++++++++++++++++++++++++++++++++++++++----- gcc-4.7/gcc/common.opt | 3 ++ gcc-4.7/gcc/configure | 19 ++++++++ gcc-4.7/gcc/configure.ac | 14 ++++++ gcc-4.7/gcc/doc/invoke.texi | 12 ++++- gcc-4.7/gcc/exec-tool.in | 116 +++++++++++++++++++++++++++++++++----------- gcc-4.7/gcc/gcc.c | 3 ++ gcc-4.7/gcc/opts.c | 1 + 8 files changed, 243 insertions(+), 40 deletions(-) diff --git a/gcc-4.7/gcc/collect2.c b/gcc-4.7/gcc/collect2.c index a44b2e7bc..7429309ac 100644 --- a/gcc-4.7/gcc/collect2.c +++ b/gcc-4.7/gcc/collect2.c @@ -1021,6 +1021,8 @@ int main (int argc, char **argv) { static const char *const ld_suffix = "ld"; + static const char *const gold_suffix = "ld.gold"; + static const char *const bfd_ld_suffix = "ld.bfd"; static const char *const plugin_ld_suffix = PLUGIN_LD; static const char *const real_ld_suffix = "real-ld"; static const char *const collect_ld_suffix = "collect-ld"; @@ -1040,6 +1042,10 @@ main (int argc, char **argv) const char *const full_ld_suffix = concat(target_machine, "-", ld_suffix, NULL); + const char *const full_gold_suffix = + concat (target_machine, "-", gold_suffix, NULL); + const char *const full_bfd_ld_suffix = + concat (target_machine, "-", bfd_ld_suffix, NULL); const char *const full_plugin_ld_suffix = concat(target_machine, "-", plugin_ld_suffix, NULL); const char *const full_nm_suffix = @@ -1056,6 +1062,8 @@ main (int argc, char **argv) concat (target_machine, "-", gstrip_suffix, NULL); #else const char *const full_ld_suffix = ld_suffix; + const char *const full_gold_suffix = gold_suffix; + const char *const full_bfd_ld_suffix = bfd_ld_suffix; const char *const full_plugin_ld_suffix = plugin_ld_suffix; const char *const full_nm_suffix = nm_suffix; const char *const full_gnm_suffix = gnm_suffix; @@ -1077,7 +1085,13 @@ main (int argc, char **argv) const char **c_ptr; char **ld1_argv; const char **ld1; - bool use_plugin = false; + enum linker_select + { + DFLT_LINKER, + PLUGIN_LINKER, + GOLD_LINKER, + BFD_LINKER + } selected_linker = DFLT_LINKER; /* The kinds of symbols we will have to consider when scanning the outcome of a first pass link. This is ALL to start with, then might @@ -1168,15 +1182,21 @@ main (int argc, char **argv) else if (! strcmp (argv[i], "-flto-partition=none")) no_partition = true; else if ((! strncmp (argv[i], "-flto=", 6) - || ! strcmp (argv[i], "-flto")) && ! use_plugin) + || ! strcmp (argv[i], "-flto")) + && selected_linker != PLUGIN_LINKER) lto_mode = LTO_MODE_WHOPR; else if (!strncmp (argv[i], "-fno-lto", 8)) lto_mode = LTO_MODE_NONE; else if (! strcmp (argv[i], "-plugin")) { - use_plugin = true; + selected_linker = PLUGIN_LINKER; lto_mode = LTO_MODE_NONE; } + else if (! strcmp (argv[i], "-use-gold")) + selected_linker = GOLD_LINKER; + else if (! strcmp (argv[i], "-use-ld")) + selected_linker = BFD_LINKER; + #ifdef COLLECT_EXPORT_LIST /* since -brtl, -bexport, -b64 are not position dependent also check for them here */ @@ -1276,17 +1296,90 @@ main (int argc, char **argv) /* Search the compiler directories for `ld'. We have protection against recursive calls in find_a_file. */ if (ld_file_name == 0) - ld_file_name = find_a_file (&cpath, - use_plugin - ? plugin_ld_suffix - : ld_suffix); + switch (selected_linker) + { + default: + case DFLT_LINKER: + ld_file_name = find_a_file (&cpath, ld_suffix); + break; + case PLUGIN_LINKER: + ld_file_name = find_a_file (&cpath, plugin_ld_suffix); + break; + case GOLD_LINKER: + ld_file_name = find_a_file (&cpath, gold_suffix); + break; + case BFD_LINKER: + ld_file_name = find_a_file (&cpath, bfd_ld_suffix); + break; + } /* Search the ordinary system bin directories for `ld' (if native linking) or `TARGET-ld' (if cross). */ if (ld_file_name == 0) - ld_file_name = find_a_file (&path, - use_plugin - ? full_plugin_ld_suffix - : full_ld_suffix); + switch (selected_linker) + { + default: + case DFLT_LINKER: + ld_file_name = find_a_file (&path, full_ld_suffix); + break; + case PLUGIN_LINKER: + ld_file_name = find_a_file (&path, full_plugin_ld_suffix); + break; + case GOLD_LINKER: + ld_file_name = find_a_file (&path, full_gold_suffix); + break; + case BFD_LINKER: + ld_file_name = find_a_file (&path, full_bfd_ld_suffix); + break; + } + /* If we failed to find a plugin-capable linker, try the ordinary one. */ + if (ld_file_name == 0 && selected_linker == PLUGIN_LINKER) + ld_file_name = find_a_file (&cpath, ld_suffix); + + if ((vflag || debug) && ld_file_name == 0) + { + struct prefix_list * p; + const char * s; + + notice ("collect2: warning: unable to find linker.\n"); + +#ifdef DEFAULT_LINKER + notice (" Searched for this absolute executable:\n"); + notice (" %s\n", DEFAULT_LINKER); +#endif + + notice (" Searched in these paths:\n"); + for (p = cpath.plist; p != NULL; p = p->next) + notice (" %s\n", p->prefix); + notice (" For these executables:\n"); + notice (" %s\n", real_ld_suffix); + notice (" %s\n", collect_ld_suffix); + switch (selected_linker) + { + default: + case DFLT_LINKER: s = ld_suffix; break; + case PLUGIN_LINKER: s = plugin_ld_suffix; break; + case GOLD_LINKER: s = gold_suffix; break; + case BFD_LINKER: s = bfd_ld_suffix; break; + } + notice (" %s\n", s); + + notice (" And searched in these paths:\n"); + for (p = path.plist; p != NULL; p = p->next) + notice (" %s\n", p->prefix); + notice (" For these executables:\n"); +#ifdef REAL_LD_FILE_NAME + notice (" %s\n", REAL_LD_FILE_NAME); +#endif + switch (selected_linker) + { + default: + case DFLT_LINKER: s = full_ld_suffix; break; + case PLUGIN_LINKER: s = full_plugin_ld_suffix; break; + case GOLD_LINKER: s = full_gold_suffix; break; + case BFD_LINKER: s = full_bfd_ld_suffix; break; + } + notice (" %s\n", s); + } #ifdef REAL_NM_FILE_NAME nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME); diff --git a/gcc-4.7/gcc/common.opt b/gcc-4.7/gcc/common.opt index 033fbe026..ba1cf5ba8 100644 --- a/gcc-4.7/gcc/common.opt +++ b/gcc-4.7/gcc/common.opt @@ -2086,6 +2086,9 @@ funwind-tables Common Report Var(flag_unwind_tables) Optimization Just generate unwind tables for exception handling +fuse-ld= +Common Joined Undocumented + fuse-linker-plugin Common Undocumented diff --git a/gcc-4.7/gcc/configure b/gcc-4.7/gcc/configure index 52cc6b6f0..593e816a6 100755 --- a/gcc-4.7/gcc/configure +++ b/gcc-4.7/gcc/configure @@ -681,6 +681,7 @@ gcc_cv_readelf gcc_cv_objdump ORIGINAL_NM_FOR_TARGET gcc_cv_nm +ORIGINAL_GOLD_FOR_TARGET ORIGINAL_LD_FOR_TARGET ORIGINAL_PLUGIN_LD_FOR_TARGET gcc_cv_ld @@ -21560,6 +21561,21 @@ fi fi fi +gcc_cv_ld_gold_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/gold + +if test "${gcc_cv_gold+set}" = set; then : + +else + +if test -f $gcc_cv_ld_gold_srcdir/configure.ac \ + && test -f ../gold/Makefile \ + && test x$build = x$host; then + gcc_cv_gold=../gold/ld-new$build_exeext +else + gcc_cv_gold='' +fi +fi + ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld PLUGIN_LD=`basename $gcc_cv_ld` @@ -21599,6 +21615,9 @@ case "$ORIGINAL_LD_FOR_TARGET" in ;; esac +ORIGINAL_GOLD_FOR_TARGET=$gcc_cv_gold + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking what linker to use" >&5 $as_echo_n "checking what linker to use... " >&6; } if test "$gcc_cv_ld" = ../ld/ld-new$build_exeext \ diff --git a/gcc-4.7/gcc/configure.ac b/gcc-4.7/gcc/configure.ac index 2d1876f3a..0d23c5ef2 100644 --- a/gcc-4.7/gcc/configure.ac +++ b/gcc-4.7/gcc/configure.ac @@ -2024,6 +2024,17 @@ else AC_PATH_PROG(gcc_cv_ld, $LD_FOR_TARGET) fi]) +gcc_cv_ld_gold_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/gold + +AS_VAR_SET_IF(gcc_cv_gold,, [ +if test -f $gcc_cv_ld_gold_srcdir/configure.ac \ + && test -f ../gold/Makefile \ + && test x$build = x$host; then + gcc_cv_gold=../gold/ld-new$build_exeext +else + gcc_cv_gold='' +fi]) + ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld PLUGIN_LD=`basename $gcc_cv_ld` AC_ARG_WITH(plugin-ld, @@ -2053,6 +2064,9 @@ case "$ORIGINAL_LD_FOR_TARGET" in *) AC_CONFIG_FILES(collect-ld:exec-tool.in, [chmod +x collect-ld]) ;; esac +ORIGINAL_GOLD_FOR_TARGET=$gcc_cv_gold +AC_SUBST(ORIGINAL_GOLD_FOR_TARGET) + AC_MSG_CHECKING(what linker to use) if test "$gcc_cv_ld" = ../ld/ld-new$build_exeext \ || test "$gcc_cv_ld" = ../gold/ld-new$build_exeext; then diff --git a/gcc-4.7/gcc/doc/invoke.texi b/gcc-4.7/gcc/doc/invoke.texi index 8fcebf3a8..506264b3d 100644 --- a/gcc-4.7/gcc/doc/invoke.texi +++ b/gcc-4.7/gcc/doc/invoke.texi @@ -415,7 +415,7 @@ Objective-C and Objective-C++ Dialects}. -funit-at-a-time -funroll-all-loops -funroll-loops @gol -funsafe-loop-optimizations -funsafe-math-optimizations -funswitch-loops @gol -fvariable-expansion-in-unroller -fvect-cost-model -fvpt -fweb @gol --fwhole-program -fwpa -fuse-linker-plugin @gol +-fwhole-program -fuse-ld -fwpa -fuse-linker-plugin @gol --param @var{name}=@var{value} -O -O0 -O1 -O2 -O3 -Os -Ofast} @@ -8038,6 +8038,16 @@ the comparison operation before register allocation is complete. Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. +@item -fuse-ld=gold +Use the @command{gold} linker instead of the default linker. +This option is only necessary if GCC has been configured with +@option{--enable-gold} and @option{--enable-ld=default}. + +@item -fuse-ld=bfd +Use the @command{ld.bfd} linker instead of the default linker. +This option is only necessary if GCC has been configured with +@option{--enable-gold} and @option{--enable-ld}. + @item -fcprop-registers @opindex fcprop-registers After register allocation and post-register allocation instruction splitting, diff --git a/gcc-4.7/gcc/exec-tool.in b/gcc-4.7/gcc/exec-tool.in index 8a1077573..f19a251e8 100644 --- a/gcc-4.7/gcc/exec-tool.in +++ b/gcc-4.7/gcc/exec-tool.in @@ -21,11 +21,13 @@ ORIGINAL_AS_FOR_TARGET="@ORIGINAL_AS_FOR_TARGET@" ORIGINAL_LD_FOR_TARGET="@ORIGINAL_LD_FOR_TARGET@" +ORIGINAL_GOLD_FOR_TARGET="@ORIGINAL_GOLD_FOR_TARGET@" ORIGINAL_PLUGIN_LD_FOR_TARGET="@ORIGINAL_PLUGIN_LD_FOR_TARGET@" ORIGINAL_NM_FOR_TARGET="@ORIGINAL_NM_FOR_TARGET@" exeext=@host_exeext@ fast_install=@enable_fast_install@ objdir=@objdir@ +version="1.1" invoked=`basename "$0"` id=$invoked @@ -36,15 +38,44 @@ case "$invoked" in dir=gas ;; collect-ld) - # when using a linker plugin, gcc will always pass '-plugin' as the - # first or second option to the linker. - if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then - original=$ORIGINAL_PLUGIN_LD_FOR_TARGET - else - original=$ORIGINAL_LD_FOR_TARGET - fi prog=ld-new$exeext - dir=ld + # Look for the a command line option + # specifying the linker to be used. + case " $* " in + *\ -use-gold\ *) + original=$ORIGINAL_GOLD_FOR_TARGET + dir=gold + ;; + *\ -use-ld\ * | *\ -use-ld.bfd\ *) + original=$ORIGINAL_LD_FOR_TARGET + dir=ld + ;; + *\ -plugin\ *) + original=$ORIGINAL_PLUGIN_LD_FOR_TARGET + dir=ld + ;; + *) + original=$ORIGINAL_LD_FOR_TARGET + dir=ld + ;; + esac + + # If the selected linker has not been configured then + # try using the others, in the order PLUGIN-LD, LD, GOLD. + if test x"$original" = x; then + if test x"$ORIGINAL_PLUGIN_LD_FOR_TARGET" != x; then + original=$ORIGINAL_PLUGIN_LD_FOR_TARGET + dir=ld + elif test x"$ORIGINAL_LD_FOR_TARGET" != x; then + original=$ORIGINAL_LD_FOR_TARGET + dir=ld + elif test x"$ORIGINAL_GOLD_FOR_TARGET" != x; then + original=$ORIGINAL_GOLD_FOR_TARGET + dir=gold + # Otherwise do nothing - the case statement below + # will issue an error message for us. + fi + fi id=ld ;; nm) @@ -61,29 +92,58 @@ case "$original" in scriptdir=`cd "$tdir" && pwd` if test -x $scriptdir/../$dir/$prog; then - test "$fast_install" = yes || exec $scriptdir/../$dir/$prog ${1+"$@"} - - # if libtool did everything it needs to do, there's a fast path - lt_prog=$scriptdir/../$dir/$objdir/lt-$prog - test -x $lt_prog && exec $lt_prog ${1+"$@"} - - # libtool has not relinked ld-new yet, but we cannot just use the - # previous stage (because then the relinking would just never happen!). - # So we take extra care to use prev-ld/ld-new *on recursive calls*. - eval LT_RCU="\${LT_RCU_$id}" - test x"$LT_RCU" = x"1" && exec $scriptdir/../prev-$dir/$prog ${1+"$@"} - - eval LT_RCU_$id=1 - export LT_RCU_$id - $scriptdir/../$dir/$prog ${1+"$@"} - result=$? - exit $result + if test "$fast_install" = yes; then + # If libtool did everything it needs to do, there's a fast path. + lt_prog=$scriptdir/../$dir/$objdir/lt-$prog + if test -x $lt_prog; then + original=$lt_prog + else + # Libtool has not relinked ld-new yet, but we cannot just use the + # previous stage (because then the relinking would just never happen!). + # So we take extra care to use prev-ld/ld-new *on recursive calls*. + eval LT_RCU="\${LT_RCU_$id}" + if test x"$LT_RCU" = x"1"; then + original=$scriptdir/../prev-$dir/$prog + else + eval LT_RCU_$id=1 + export LT_RCU_$id + case " $* " in + *\ -v\ *) + echo "$invoked $version" + echo $scriptdir/../$dir/$prog $* + ;; + esac + $scriptdir/../$dir/$prog ${1+"$@"} + result=$? + exit $result + fi + fi + else + original=$scriptdir/../$dir/$prog + fi else - exec $scriptdir/../prev-$dir/$prog ${1+"$@"} + original=$scriptdir/../prev-$dir/$prog fi ;; - *) - exec $original ${1+"$@"} + "") + echo "$invoked: executable not configured" + exit 1 ;; esac + +# If -v has been used then display our version number +# and then echo the command we are about to invoke. +case " $* " in + *\ -v\ *) + echo "$invoked $version" + echo $original $* + ;; +esac + +if test -x $original; then + exec "$original" ${1+"$@"} +else + echo "$invoked: unable to locate executable: $original" + exit 1 +fi diff --git a/gcc-4.7/gcc/gcc.c b/gcc-4.7/gcc/gcc.c index cc6a08eb0..c07041d55 100644 --- a/gcc-4.7/gcc/gcc.c +++ b/gcc-4.7/gcc/gcc.c @@ -671,6 +671,9 @@ proper position among the other output files. */ LINK_PLUGIN_SPEC \ "%{flto|flto=*:%max_errors = value; break; + case OPT_fuse_ld_: case OPT_fuse_linker_plugin: /* No-op. Used by the driver and passed to us because it starts with f.*/ break; -- cgit v1.2.3