diff --git a/packages/toolchain/lang/gcc/patches/gcc-Support-fuse-ld-bfd-and-fuse-ld-gold.patch b/packages/toolchain/lang/gcc/patches/gcc-Support-fuse-ld-bfd-and-fuse-ld-gold.patch new file mode 100644 index 0000000000..47033f1ba1 --- /dev/null +++ b/packages/toolchain/lang/gcc/patches/gcc-Support-fuse-ld-bfd-and-fuse-ld-gold.patch @@ -0,0 +1,323 @@ +From 18514bb58339ccee148545fd2a61f9dba1beabd8 Mon Sep 17 00:00:00 2001 +From: Stefan Saraev +Date: Wed, 15 May 2013 21:41:47 +0300 +Subject: [PATCH] gcc: Support -fuse-ld=bfd and -fuse-ld=gold + +this is a (partial) backport of the following patches +http://gcc.gnu.org/git/?p=gcc.git;a=patch;h=71f006b89ca312590ac63b99c9d85c0ca116fa94 +http://gcc.gnu.org/git/?p=gcc.git;a=patch;h=eadecd281f2d8bc957c4a613b67d27aeb7497412 +http://gcc.gnu.org/git/?p=gcc.git;a=patch;h=61f41b94c58c64e7334d97df57d6467cb1c7b70e +http://gcc.gnu.org/git/?p=gcc.git;a=patch;h=99d5fe2dc7fe91aa2471ae80315c9a9a60e43dc4 +--- + gcc/collect2.c | 68 ++++++++++++++++++++++++++++++++++++--------------- + gcc/common.opt | 8 ++++++ + gcc/config.in | 2 +- + gcc/configure | 12 ++++++-- + gcc/configure.ac | 12 ++++++-- + gcc/doc/invoke.texi | 8 +++++- + gcc/gcc.c | 3 +- + gcc/opts.c | 2 + + 8 files changed, 86 insertions(+), 29 deletions(-) + +diff --git a/gcc/collect2.c b/gcc/collect2.c +index 748a3f4..e7e1887 100644 +--- a/gcc/collect2.c ++++ b/gcc/collect2.c +@@ -1020,8 +1020,21 @@ maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, + int + main (int argc, char **argv) + { +- static const char *const ld_suffix = "ld"; +- static const char *const plugin_ld_suffix = PLUGIN_LD; ++ enum linker_select ++ { ++ USE_DEFAULT_LD, ++ USE_PLUGIN_LD, ++ USE_GOLD_LD, ++ USE_BFD_LD, ++ USE_LD_MAX ++ } selected_linker = USE_DEFAULT_LD; ++ static const char *const ld_suffixes[USE_LD_MAX] = ++ { ++ "ld", ++ PLUGIN_LD_SUFFIX, ++ "ld.gold", ++ "ld.bfd" ++ }; + static const char *const real_ld_suffix = "real-ld"; + static const char *const collect_ld_suffix = "collect-ld"; + static const char *const nm_suffix = "nm"; +@@ -1032,16 +1045,13 @@ main (int argc, char **argv) + static const char *const strip_suffix = "strip"; + static const char *const gstrip_suffix = "gstrip"; + ++ const char *full_ld_suffixes[USE_LD_MAX]; + #ifdef CROSS_DIRECTORY_STRUCTURE + /* If we look for a program in the compiler directories, we just use + the short name, since these directories are already system-specific. + But it we look for a program in the system directories, we need to + qualify the program name with the target machine. */ + +- const char *const full_ld_suffix = +- concat(target_machine, "-", ld_suffix, NULL); +- const char *const full_plugin_ld_suffix = +- concat(target_machine, "-", plugin_ld_suffix, NULL); + const char *const full_nm_suffix = + concat (target_machine, "-", nm_suffix, NULL); + const char *const full_gnm_suffix = +@@ -1055,13 +1065,11 @@ main (int argc, char **argv) + const char *const full_gstrip_suffix = + concat (target_machine, "-", gstrip_suffix, NULL); + #else +- const char *const full_ld_suffix = 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; + #ifdef LDD_SUFFIX + const char *const full_ldd_suffix = ldd_suffix; + #endif ++ const char *const full_nm_suffix = nm_suffix; ++ const char *const full_gnm_suffix = gnm_suffix; + const char *const full_strip_suffix = strip_suffix; + const char *const full_gstrip_suffix = gstrip_suffix; + #endif /* CROSS_DIRECTORY_STRUCTURE */ +@@ -1078,6 +1086,7 @@ main (int argc, char **argv) + char **ld1_argv; + const char **ld1; + bool use_plugin = false; ++ bool use_collect_ld = false; + + /* 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 +@@ -1097,6 +1106,15 @@ main (int argc, char **argv) + int first_file; + int num_c_args; + char **old_argv; ++ int i; ++ ++ for (i = 0; i < USE_LD_MAX; i++) ++ full_ld_suffixes[i] ++#ifdef CROSS_DIRECTORY_STRUCTURE ++ = concat (target_machine, "-", ld_suffixes[i], NULL); ++#else ++ = ld_suffixes[i]; ++#endif + + p = argv[0] + strlen (argv[0]); + while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])) +@@ -1158,7 +1176,6 @@ main (int argc, char **argv) + are called. We also look for the -flto or -flto-partition=none flag to know + what LTO mode we are in. */ + { +- int i; + bool no_partition = false; + + for (i = 1; argv[i] != NULL; i ++) +@@ -1176,7 +1193,14 @@ main (int argc, char **argv) + { + use_plugin = true; + lto_mode = LTO_MODE_NONE; ++ if (selected_linker == USE_DEFAULT_LD) ++ selected_linker = USE_PLUGIN_LD; + } ++ else if (strcmp (argv[i], "-fuse-ld=bfd") == 0) ++ selected_linker = USE_BFD_LD; ++ else if (strcmp (argv[i], "-fuse-ld=gold") == 0) ++ selected_linker = USE_GOLD_LD; ++ + #ifdef COLLECT_EXPORT_LIST + /* since -brtl, -bexport, -b64 are not position dependent + also check for them here */ +@@ -1272,21 +1296,18 @@ main (int argc, char **argv) + ld_file_name = find_a_file (&cpath, real_ld_suffix); + /* Likewise for `collect-ld'. */ + if (ld_file_name == 0) +- ld_file_name = find_a_file (&cpath, collect_ld_suffix); ++ { ++ ld_file_name = find_a_file (&cpath, collect_ld_suffix); ++ use_collect_ld = ld_file_name != 0; ++ } + /* 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); ++ ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker]); + /* 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); ++ ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker]); + + #ifdef REAL_NM_FILE_NAME + nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME); +@@ -1443,6 +1464,13 @@ main (int argc, char **argv) + "configuration"); + #endif + } ++ else if (!use_collect_ld ++ && strncmp (arg, "-fuse-ld=", 9) == 0) ++ { ++ /* Do not pass -fuse-ld={bfd|gold} to the linker. */ ++ ld1--; ++ ld2--; ++ } + #ifdef TARGET_AIX_VERSION + else + { +diff --git a/gcc/common.opt b/gcc/common.opt +index e72d8cf..2e938f1 100644 +--- a/gcc/common.opt ++++ b/gcc/common.opt +@@ -2089,6 +2089,14 @@ funwind-tables + Common Report Var(flag_unwind_tables) Optimization + Just generate unwind tables for exception handling + ++fuse-ld=bfd ++Common Negative(fuse-ld=gold) ++Use the bfd linker instead of the default linker ++ ++fuse-ld=gold ++Common Negative(fuse-ld=bfd) ++Use the gold linker instead of the default linker ++ + fuse-linker-plugin + Common Undocumented + +diff --git a/gcc/config.in b/gcc/config.in +index 2e632b2..b391b62 100644 +--- a/gcc/config.in ++++ b/gcc/config.in +@@ -1700,7 +1700,7 @@ + + /* Specify plugin linker */ + #ifndef USED_FOR_TARGET +-#undef PLUGIN_LD ++#undef PLUGIN_LD_SUFFIX + #endif + + +diff --git a/gcc/configure b/gcc/configure +index 91adc79..3480292 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -21597,20 +21597,26 @@ fi + fi + + ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld +-PLUGIN_LD=`basename $gcc_cv_ld` ++PLUGIN_LD_SUFFIX=`basename $gcc_cv_ld | sed -e "s,$target_alias-,,"` ++# if the PLUGIN_LD is set ld-new, just have it as ld ++# as that is the installed named. ++if test x$PLUGIN_LD_SUFFIX = xld-new \ ++ || test x$PLUGIN_LD_SUFFIX = xcollect-ld ; then ++ PLUGIN_LD_SUFFIX=ld ++fi + + # Check whether --with-plugin-ld was given. + if test "${with_plugin_ld+set}" = set; then : + withval=$with_plugin_ld; if test x"$withval" != x; then + ORIGINAL_PLUGIN_LD_FOR_TARGET="$withval" +- PLUGIN_LD="$withval" ++ PLUGIN_LD_SUFFIX=`echo $withval | sed -e "s,$target_alias-,,"` + fi + fi + + + + cat >>confdefs.h <<_ACEOF +-#define PLUGIN_LD "$PLUGIN_LD" ++#define PLUGIN_LD_SUFFIX "$PLUGIN_LD_SUFFIX" + _ACEOF + + +diff --git a/gcc/configure.ac b/gcc/configure.ac +index 1d41895..0063a3d 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -2051,15 +2051,21 @@ else + fi]) + + ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld +-PLUGIN_LD=`basename $gcc_cv_ld` ++PLUGIN_LD_SUFFIX=`basename $gcc_cv_ld | sed -e "s,$target_alias-,,"` ++# if the PLUGIN_LD is set ld-new, just have it as ld ++# as that is the installed named. ++if test x$PLUGIN_LD_SUFFIX = xld-new \ ++ || test x$PLUGIN_LD_SUFFIX = xcollect-ld ; then ++ PLUGIN_LD_SUFFIX=ld ++fi + AC_ARG_WITH(plugin-ld, + [AS_HELP_STRING([[--with-plugin-ld=[ARG]]], [specify the plugin linker])], + [if test x"$withval" != x; then + ORIGINAL_PLUGIN_LD_FOR_TARGET="$withval" +- PLUGIN_LD="$withval" ++ PLUGIN_LD_SUFFIX=`echo $withval | sed -e "s,$target_alias-,,"` + fi]) + AC_SUBST(ORIGINAL_PLUGIN_LD_FOR_TARGET) +-AC_DEFINE_UNQUOTED(PLUGIN_LD, "$PLUGIN_LD", [Specify plugin linker]) ++AC_DEFINE_UNQUOTED(PLUGIN_LD_SUFFIX, "$PLUGIN_LD_SUFFIX", [Specify plugin linker]) + + # Check to see if we are using gold instead of ld + AC_MSG_CHECKING(whether we are using gold) +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index f989952..ee33b03 100644 +--- a/gcc/doc/invoke.texi ++++ b/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 -fwpa -fuse-ld=@var{linker} -fuse-linker-plugin @gol + --param @var{name}=@var{value} + -O -O0 -O1 -O2 -O3 -Os -Ofast} + +@@ -8042,6 +8042,12 @@ the comparison operation before register allocation is complete. + + Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}. + ++@item -fuse-ld=bfd ++Use the @command{bfd} linker instead of the default linker. ++ ++@item -fuse-ld=gold ++Use the @command{gold} linker instead of the default linker. ++ + @item -fcprop-registers + @opindex fcprop-registers + After register allocation and post-register allocation instruction splitting, +diff --git a/gcc/gcc.c b/gcc/gcc.c +index 939dcc8..a6da5c9 100644 +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -672,7 +672,8 @@ proper position among the other output files. */ + LINK_PLUGIN_SPEC \ + "%{flto|flto=*:%max_errors = value; + break; + ++ case OPT_fuse_ld_bfd: ++ case OPT_fuse_ld_gold: + case OPT_fuse_linker_plugin: + /* No-op. Used by the driver and passed to us because it starts with f.*/ + break; +-- +1.7.2.5 +