public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
@ 2020-02-10  0:02 Fangrui Song via gcc-patches
  2020-02-13 17:59 ` Fangrui Song via gcc-patches
  2020-03-11 12:55 ` [PATCH] " Martin Liška
  0 siblings, 2 replies; 44+ messages in thread
From: Fangrui Song via gcc-patches @ 2020-02-10  0:02 UTC (permalink / raw)
  To: gcc-patches

	PR driver/93645
	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
---
 gcc/ChangeLog       |  8 ++++++
 gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
 gcc/common.opt      | 14 ++--------
 gcc/doc/invoke.texi | 15 +++-------
 gcc/gcc.c           | 14 ++++------
 gcc/opts.c          |  4 +--
 6 files changed, 57 insertions(+), 65 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index feb2d066d0b..6bcec12d841 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2020-02-09  Fangrui Song  <maskray@google.com>
+
+	PR driver/93645
+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
+	* gcc.c (driver_handle_option): Likewise.
+	* collect2.c (main): Likewise.
+
 2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
 
 	* recog.c: Move pass_split_before_sched2 code in front of
diff --git a/gcc/collect2.c b/gcc/collect2.c
index 502d629141c..a3ef525a93b 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -859,18 +859,12 @@ main (int argc, char **argv)
     {
       USE_DEFAULT_LD,
       USE_PLUGIN_LD,
-      USE_GOLD_LD,
-      USE_BFD_LD,
-      USE_LLD_LD,
-      USE_LD_MAX
+      USE_LD
     } selected_linker = USE_DEFAULT_LD;
-  static const char *const ld_suffixes[USE_LD_MAX] =
+  static const char *const ld_suffixes[USE_LD] =
     {
       "ld",
-      PLUGIN_LD_SUFFIX,
-      "ld.gold",
-      "ld.bfd",
-      "ld.lld"
+      PLUGIN_LD_SUFFIX
     };
   static const char *const real_ld_suffix = "real-ld";
   static const char *const collect_ld_suffix = "collect-ld";
@@ -882,7 +876,7 @@ 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];
+  const char *full_ld_suffixes[USE_LD];
 #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.
@@ -924,6 +918,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *use_ld = NULL;
 
   /* 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
@@ -948,7 +943,7 @@ main (int argc, char **argv)
 #endif
   int i;
 
-  for (i = 0; i < USE_LD_MAX; i++)
+  for (i = 0; i < USE_LD; i++)
     full_ld_suffixes[i]
 #ifdef CROSS_DIRECTORY_STRUCTURE
       = concat (target_machine, "-", ld_suffixes[i], NULL);
@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
 	    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;
-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
-	  selected_linker = USE_LLD_LD;
+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
+	  {
+	    use_ld = argv[i] + 9;
+	    selected_linker = USE_LD;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
   /* Maybe we know the right file to use (if not cross).  */
   ld_file_name = 0;
 #ifdef DEFAULT_LINKER
-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
-      selected_linker == USE_LLD_LD)
+  if (!ld_file_name && selected_linker == USE_LD)
     {
       char *linker_name;
 # ifdef HOST_EXECUTABLE_SUFFIX
@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
 	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
 	    {
 	      default_linker[len] = '\0';
-	      linker_name = concat (default_linker,
-				    &ld_suffixes[selected_linker][2],
+	      linker_name = concat (default_linker, ".", use_ld,
 				    HOST_EXECUTABLE_SUFFIX, NULL);
 	    }
 	}
       if (linker_name == NULL)
 # endif
-      linker_name = concat (DEFAULT_LINKER,
-			    &ld_suffixes[selected_linker][2],
+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
 			    NULL);
       if (access (linker_name, X_OK) == 0)
 	ld_file_name = linker_name;
@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
       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, ld_suffixes[selected_linker], X_OK);
-  /* 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, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker != USE_LD) {
+    /* Search the compiler directories for `ld'.  We have protection against
+       recursive calls in find_a_file.  */
+    if (!ld_file_name)
+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
+    /* Search the ordinary system bin directories
+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
+    if (!ld_file_name)
+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
+    ld_file_name = use_ld;
+  } else {
+    const char *linker_name = concat("ld.", use_ld, NULL);
+    if (!ld_file_name)
+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
+    if (!ld_file_name) {
+#ifdef CROSS_DIRECTORY_STRUCTURE
+	linker_name = concat(target_machine, "-", linker_name, NULL);
+#endif
+	ld_file_name = find_a_file(&path, linker_name, X_OK);
+    }
+  }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
diff --git a/gcc/common.opt b/gcc/common.opt
index 5692cd04374..a76ed6434bb 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2859,17 +2859,9 @@ funwind-tables
 Common Report Var(flag_unwind_tables) Optimization
 Just generate unwind tables for exception handling.
 
-fuse-ld=bfd
-Common Driver Negative(fuse-ld=gold)
-Use the bfd linker instead of the default linker.
-
-fuse-ld=gold
-Common Driver Negative(fuse-ld=bfd)
-Use the gold linker instead of the default linker.
-
-fuse-ld=lld
-Common Driver Negative(fuse-ld=lld)
-Use the lld LLVM linker instead of the default linker.
+fuse-ld=
+Common Driver Joined
+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
 
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 35b341e759f..c2dd410c88f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
 recommended to link such objects into static library instead. Alternatively it
 is possible to use H.J. Lu's binutils with support for mixed objects.
 
-@item -fuse-ld=bfd
-@opindex fuse-ld=bfd
-Use the @command{bfd} linker instead of the default linker.
-
-@item -fuse-ld=gold
-@opindex fuse-ld=gold
-Use the @command{gold} linker instead of the default linker.
-
-@item -fuse-ld=lld
-@opindex fuse-ld=lld
-Use the LLVM @command{lld} linker instead of the default linker.
+@item -fuse-ld=@var{linker}
+@opindex fuse-ld=linker
+If @var{linker} is an absolute path, use it instead of the default linker;
+otherwise use @command{ld.@var{linker}}.
 
 @cindex Libraries
 @item -l@var{library}
diff --git a/gcc/gcc.c b/gcc/gcc.c
index effc384f3ef..f9a6f10502d 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
       do_save = false;
       break;
 
-    case OPT_fuse_ld_bfd:
-       use_ld = ".bfd";
-       break;
-
-    case OPT_fuse_ld_gold:
-       use_ld = ".gold";
+    case OPT_fuse_ld_:
+       use_ld = arg;
        break;
 
     case OPT_fcompare_debug_second:
@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
 	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
 		{
 		  default_linker[len] = '\0';
-		  ld = concat (default_linker, use_ld,
+		  ld = concat (default_linker, ".", use_ld,
 			       HOST_EXECUTABLE_SUFFIX, NULL);
 		}
 	    }
 	  if (ld == NULL)
 # endif
-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
 	  if (access (ld, X_OK) == 0)
 	    {
 	      printf ("%s\n", ld);
 	      return (0);
 	    }
 #endif
-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
 	}
       char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
       printf ("%s\n", (newname ? newname : print_prog_name));
diff --git a/gcc/opts.c b/gcc/opts.c
index 7affeb41a96..f50d365d517 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
       dc->max_errors = value;
       break;
 
-    case OPT_fuse_ld_bfd:
-    case OPT_fuse_ld_gold:
-    case OPT_fuse_ld_lld:
+    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;
-- 
2.25.0

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-02-10  0:02 [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Fangrui Song via gcc-patches
@ 2020-02-13 17:59 ` Fangrui Song via gcc-patches
  2020-02-24 23:02   ` Fangrui Song via gcc-patches
  2020-03-11 12:55 ` [PATCH] " Martin Liška
  1 sibling, 1 reply; 44+ messages in thread
From: Fangrui Song via gcc-patches @ 2020-02-13 17:59 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu

On 2020-02-09, Fangrui Song wrote:
>	PR driver/93645
>	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>	* gcc.c (driver_handle_option): Likewise.
>	* collect2.c (main): Likewise.
>---
> gcc/ChangeLog       |  8 ++++++
> gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
> gcc/common.opt      | 14 ++--------
> gcc/doc/invoke.texi | 15 +++-------
> gcc/gcc.c           | 14 ++++------
> gcc/opts.c          |  4 +--
> 6 files changed, 57 insertions(+), 65 deletions(-)
>
>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>index feb2d066d0b..6bcec12d841 100644
>--- a/gcc/ChangeLog
>+++ b/gcc/ChangeLog
>@@ -1,3 +1,11 @@
>+2020-02-09  Fangrui Song  <maskray@google.com>
>+
>+	PR driver/93645
>+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>+	* gcc.c (driver_handle_option): Likewise.
>+	* collect2.c (main): Likewise.
>+
> 2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>
> 	* recog.c: Move pass_split_before_sched2 code in front of
>diff --git a/gcc/collect2.c b/gcc/collect2.c
>index 502d629141c..a3ef525a93b 100644
>--- a/gcc/collect2.c
>+++ b/gcc/collect2.c
>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>     {
>       USE_DEFAULT_LD,
>       USE_PLUGIN_LD,
>-      USE_GOLD_LD,
>-      USE_BFD_LD,
>-      USE_LLD_LD,
>-      USE_LD_MAX
>+      USE_LD
>     } selected_linker = USE_DEFAULT_LD;
>-  static const char *const ld_suffixes[USE_LD_MAX] =
>+  static const char *const ld_suffixes[USE_LD] =
>     {
>       "ld",
>-      PLUGIN_LD_SUFFIX,
>-      "ld.gold",
>-      "ld.bfd",
>-      "ld.lld"
>+      PLUGIN_LD_SUFFIX
>     };
>   static const char *const real_ld_suffix = "real-ld";
>   static const char *const collect_ld_suffix = "collect-ld";
>@@ -882,7 +876,7 @@ 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];
>+  const char *full_ld_suffixes[USE_LD];
> #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.
>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>   const char **ld1;
>   bool use_plugin = false;
>   bool use_collect_ld = false;
>+  const char *use_ld = NULL;
>
>   /* 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
>@@ -948,7 +943,7 @@ main (int argc, char **argv)
> #endif
>   int i;
>
>-  for (i = 0; i < USE_LD_MAX; i++)
>+  for (i = 0; i < USE_LD; i++)
>     full_ld_suffixes[i]
> #ifdef CROSS_DIRECTORY_STRUCTURE
>       = concat (target_machine, "-", ld_suffixes[i], NULL);
>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
> 	    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;
>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>-	  selected_linker = USE_LLD_LD;
>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>+	  {
>+	    use_ld = argv[i] + 9;
>+	    selected_linker = USE_LD;
>+	  }
> 	else if (strncmp (argv[i], "-o", 2) == 0)
> 	  {
> 	    /* Parse the output filename if it's given so that we can make
>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>   /* Maybe we know the right file to use (if not cross).  */
>   ld_file_name = 0;
> #ifdef DEFAULT_LINKER
>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>-      selected_linker == USE_LLD_LD)
>+  if (!ld_file_name && selected_linker == USE_LD)
>     {
>       char *linker_name;
> # ifdef HOST_EXECUTABLE_SUFFIX
>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
> 	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
> 	    {
> 	      default_linker[len] = '\0';
>-	      linker_name = concat (default_linker,
>-				    &ld_suffixes[selected_linker][2],
>+	      linker_name = concat (default_linker, ".", use_ld,
> 				    HOST_EXECUTABLE_SUFFIX, NULL);
> 	    }
> 	}
>       if (linker_name == NULL)
> # endif
>-      linker_name = concat (DEFAULT_LINKER,
>-			    &ld_suffixes[selected_linker][2],
>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
> 			    NULL);
>       if (access (linker_name, X_OK) == 0)
> 	ld_file_name = linker_name;
>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>       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, ld_suffixes[selected_linker], X_OK);
>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>+  if (selected_linker != USE_LD) {
>+    /* Search the compiler directories for `ld'.  We have protection against
>+       recursive calls in find_a_file.  */
>+    if (!ld_file_name)
>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>+    /* Search the ordinary system bin directories
>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>+    if (!ld_file_name)
>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>+    ld_file_name = use_ld;
>+  } else {
>+    const char *linker_name = concat("ld.", use_ld, NULL);
>+    if (!ld_file_name)
>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>+    if (!ld_file_name) {
>+#ifdef CROSS_DIRECTORY_STRUCTURE
>+	linker_name = concat(target_machine, "-", linker_name, NULL);
>+#endif
>+	ld_file_name = find_a_file(&path, linker_name, X_OK);
>+    }
>+  }
>
> #ifdef REAL_NM_FILE_NAME
>   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>diff --git a/gcc/common.opt b/gcc/common.opt
>index 5692cd04374..a76ed6434bb 100644
>--- a/gcc/common.opt
>+++ b/gcc/common.opt
>@@ -2859,17 +2859,9 @@ funwind-tables
> Common Report Var(flag_unwind_tables) Optimization
> Just generate unwind tables for exception handling.
>
>-fuse-ld=bfd
>-Common Driver Negative(fuse-ld=gold)
>-Use the bfd linker instead of the default linker.
>-
>-fuse-ld=gold
>-Common Driver Negative(fuse-ld=bfd)
>-Use the gold linker instead of the default linker.
>-
>-fuse-ld=lld
>-Common Driver Negative(fuse-ld=lld)
>-Use the lld LLVM linker instead of the default linker.
>+fuse-ld=
>+Common Driver Joined
>+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>
> fuse-linker-plugin
> Common Undocumented Var(flag_use_linker_plugin)
>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>index 35b341e759f..c2dd410c88f 100644
>--- a/gcc/doc/invoke.texi
>+++ b/gcc/doc/invoke.texi
>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
> recommended to link such objects into static library instead. Alternatively it
> is possible to use H.J. Lu's binutils with support for mixed objects.
>
>-@item -fuse-ld=bfd
>-@opindex fuse-ld=bfd
>-Use the @command{bfd} linker instead of the default linker.
>-
>-@item -fuse-ld=gold
>-@opindex fuse-ld=gold
>-Use the @command{gold} linker instead of the default linker.
>-
>-@item -fuse-ld=lld
>-@opindex fuse-ld=lld
>-Use the LLVM @command{lld} linker instead of the default linker.
>+@item -fuse-ld=@var{linker}
>+@opindex fuse-ld=linker
>+If @var{linker} is an absolute path, use it instead of the default linker;
>+otherwise use @command{ld.@var{linker}}.
>
> @cindex Libraries
> @item -l@var{library}
>diff --git a/gcc/gcc.c b/gcc/gcc.c
>index effc384f3ef..f9a6f10502d 100644
>--- a/gcc/gcc.c
>+++ b/gcc/gcc.c
>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>       do_save = false;
>       break;
>
>-    case OPT_fuse_ld_bfd:
>-       use_ld = ".bfd";
>-       break;
>-
>-    case OPT_fuse_ld_gold:
>-       use_ld = ".gold";
>+    case OPT_fuse_ld_:
>+       use_ld = arg;
>        break;
>
>     case OPT_fcompare_debug_second:
>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
> 	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
> 		{
> 		  default_linker[len] = '\0';
>-		  ld = concat (default_linker, use_ld,
>+		  ld = concat (default_linker, ".", use_ld,
> 			       HOST_EXECUTABLE_SUFFIX, NULL);
> 		}
> 	    }
> 	  if (ld == NULL)
> # endif
>-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
>+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
> 	  if (access (ld, X_OK) == 0)
> 	    {
> 	      printf ("%s\n", ld);
> 	      return (0);
> 	    }
> #endif
>-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
>+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
> 	}
>       char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>       printf ("%s\n", (newname ? newname : print_prog_name));
>diff --git a/gcc/opts.c b/gcc/opts.c
>index 7affeb41a96..f50d365d517 100644
>--- a/gcc/opts.c
>+++ b/gcc/opts.c
>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>       dc->max_errors = value;
>       break;
>
>-    case OPT_fuse_ld_bfd:
>-    case OPT_fuse_ld_gold:
>-    case OPT_fuse_ld_lld:
>+    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;
>-- 
>2.25.0

Friendly ping:)

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-02-13 17:59 ` Fangrui Song via gcc-patches
@ 2020-02-24 23:02   ` Fangrui Song via gcc-patches
  2020-03-10 17:19     ` [PING^3][PATCH] " Fangrui Song
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song via gcc-patches @ 2020-02-24 23:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Martin Liska

On 2020-02-13, Fangrui Song wrote:
>On 2020-02-09, Fangrui Song wrote:
>>	PR driver/93645
>>	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>	* gcc.c (driver_handle_option): Likewise.
>>	* collect2.c (main): Likewise.
>>---
>>gcc/ChangeLog       |  8 ++++++
>>gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>gcc/common.opt      | 14 ++--------
>>gcc/doc/invoke.texi | 15 +++-------
>>gcc/gcc.c           | 14 ++++------
>>gcc/opts.c          |  4 +--
>>6 files changed, 57 insertions(+), 65 deletions(-)
>>
>>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>index feb2d066d0b..6bcec12d841 100644
>>--- a/gcc/ChangeLog
>>+++ b/gcc/ChangeLog
>>@@ -1,3 +1,11 @@
>>+2020-02-09  Fangrui Song  <maskray@google.com>
>>+
>>+	PR driver/93645
>>+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>+	* gcc.c (driver_handle_option): Likewise.
>>+	* collect2.c (main): Likewise.
>>+
>>2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>
>>	* recog.c: Move pass_split_before_sched2 code in front of
>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>index 502d629141c..a3ef525a93b 100644
>>--- a/gcc/collect2.c
>>+++ b/gcc/collect2.c
>>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>>    {
>>      USE_DEFAULT_LD,
>>      USE_PLUGIN_LD,
>>-      USE_GOLD_LD,
>>-      USE_BFD_LD,
>>-      USE_LLD_LD,
>>-      USE_LD_MAX
>>+      USE_LD
>>    } selected_linker = USE_DEFAULT_LD;
>>-  static const char *const ld_suffixes[USE_LD_MAX] =
>>+  static const char *const ld_suffixes[USE_LD] =
>>    {
>>      "ld",
>>-      PLUGIN_LD_SUFFIX,
>>-      "ld.gold",
>>-      "ld.bfd",
>>-      "ld.lld"
>>+      PLUGIN_LD_SUFFIX
>>    };
>>  static const char *const real_ld_suffix = "real-ld";
>>  static const char *const collect_ld_suffix = "collect-ld";
>>@@ -882,7 +876,7 @@ 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];
>>+  const char *full_ld_suffixes[USE_LD];
>>#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.
>>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>>  const char **ld1;
>>  bool use_plugin = false;
>>  bool use_collect_ld = false;
>>+  const char *use_ld = NULL;
>>
>>  /* 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
>>@@ -948,7 +943,7 @@ main (int argc, char **argv)
>>#endif
>>  int i;
>>
>>-  for (i = 0; i < USE_LD_MAX; i++)
>>+  for (i = 0; i < USE_LD; i++)
>>    full_ld_suffixes[i]
>>#ifdef CROSS_DIRECTORY_STRUCTURE
>>      = concat (target_machine, "-", ld_suffixes[i], NULL);
>>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>	    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;
>>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>-	  selected_linker = USE_LLD_LD;
>>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>+	  {
>>+	    use_ld = argv[i] + 9;
>>+	    selected_linker = USE_LD;
>>+	  }
>>	else if (strncmp (argv[i], "-o", 2) == 0)
>>	  {
>>	    /* Parse the output filename if it's given so that we can make
>>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>  /* Maybe we know the right file to use (if not cross).  */
>>  ld_file_name = 0;
>>#ifdef DEFAULT_LINKER
>>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>-      selected_linker == USE_LLD_LD)
>>+  if (!ld_file_name && selected_linker == USE_LD)
>>    {
>>      char *linker_name;
>># ifdef HOST_EXECUTABLE_SUFFIX
>>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>	    {
>>	      default_linker[len] = '\0';
>>-	      linker_name = concat (default_linker,
>>-				    &ld_suffixes[selected_linker][2],
>>+	      linker_name = concat (default_linker, ".", use_ld,
>>				    HOST_EXECUTABLE_SUFFIX, NULL);
>>	    }
>>	}
>>      if (linker_name == NULL)
>># endif
>>-      linker_name = concat (DEFAULT_LINKER,
>>-			    &ld_suffixes[selected_linker][2],
>>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>			    NULL);
>>      if (access (linker_name, X_OK) == 0)
>>	ld_file_name = linker_name;
>>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>      ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>      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, ld_suffixes[selected_linker], X_OK);
>>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>+  if (selected_linker != USE_LD) {
>>+    /* Search the compiler directories for `ld'.  We have protection against
>>+       recursive calls in find_a_file.  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>+    /* Search the ordinary system bin directories
>>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>+    ld_file_name = use_ld;
>>+  } else {
>>+    const char *linker_name = concat("ld.", use_ld, NULL);
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>+    if (!ld_file_name) {
>>+#ifdef CROSS_DIRECTORY_STRUCTURE
>>+	linker_name = concat(target_machine, "-", linker_name, NULL);
>>+#endif
>>+	ld_file_name = find_a_file(&path, linker_name, X_OK);
>>+    }
>>+  }
>>
>>#ifdef REAL_NM_FILE_NAME
>>  nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>diff --git a/gcc/common.opt b/gcc/common.opt
>>index 5692cd04374..a76ed6434bb 100644
>>--- a/gcc/common.opt
>>+++ b/gcc/common.opt
>>@@ -2859,17 +2859,9 @@ funwind-tables
>>Common Report Var(flag_unwind_tables) Optimization
>>Just generate unwind tables for exception handling.
>>
>>-fuse-ld=bfd
>>-Common Driver Negative(fuse-ld=gold)
>>-Use the bfd linker instead of the default linker.
>>-
>>-fuse-ld=gold
>>-Common Driver Negative(fuse-ld=bfd)
>>-Use the gold linker instead of the default linker.
>>-
>>-fuse-ld=lld
>>-Common Driver Negative(fuse-ld=lld)
>>-Use the lld LLVM linker instead of the default linker.
>>+fuse-ld=
>>+Common Driver Joined
>>+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>>
>>fuse-linker-plugin
>>Common Undocumented Var(flag_use_linker_plugin)
>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>index 35b341e759f..c2dd410c88f 100644
>>--- a/gcc/doc/invoke.texi
>>+++ b/gcc/doc/invoke.texi
>>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>recommended to link such objects into static library instead. Alternatively it
>>is possible to use H.J. Lu's binutils with support for mixed objects.
>>
>>-@item -fuse-ld=bfd
>>-@opindex fuse-ld=bfd
>>-Use the @command{bfd} linker instead of the default linker.
>>-
>>-@item -fuse-ld=gold
>>-@opindex fuse-ld=gold
>>-Use the @command{gold} linker instead of the default linker.
>>-
>>-@item -fuse-ld=lld
>>-@opindex fuse-ld=lld
>>-Use the LLVM @command{lld} linker instead of the default linker.
>>+@item -fuse-ld=@var{linker}
>>+@opindex fuse-ld=linker
>>+If @var{linker} is an absolute path, use it instead of the default linker;
>>+otherwise use @command{ld.@var{linker}}.
>>
>>@cindex Libraries
>>@item -l@var{library}
>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>index effc384f3ef..f9a6f10502d 100644
>>--- a/gcc/gcc.c
>>+++ b/gcc/gcc.c
>>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>      do_save = false;
>>      break;
>>
>>-    case OPT_fuse_ld_bfd:
>>-       use_ld = ".bfd";
>>-       break;
>>-
>>-    case OPT_fuse_ld_gold:
>>-       use_ld = ".gold";
>>+    case OPT_fuse_ld_:
>>+       use_ld = arg;
>>       break;
>>
>>    case OPT_fcompare_debug_second:
>>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>		{
>>		  default_linker[len] = '\0';
>>-		  ld = concat (default_linker, use_ld,
>>+		  ld = concat (default_linker, ".", use_ld,
>>			       HOST_EXECUTABLE_SUFFIX, NULL);
>>		}
>>	    }
>>	  if (ld == NULL)
>># endif
>>-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>	  if (access (ld, X_OK) == 0)
>>	    {
>>	      printf ("%s\n", ld);
>>	      return (0);
>>	    }
>>#endif
>>-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
>>+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>>	}
>>      char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>      printf ("%s\n", (newname ? newname : print_prog_name));
>>diff --git a/gcc/opts.c b/gcc/opts.c
>>index 7affeb41a96..f50d365d517 100644
>>--- a/gcc/opts.c
>>+++ b/gcc/opts.c
>>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>      dc->max_errors = value;
>>      break;
>>
>>-    case OPT_fuse_ld_bfd:
>>-    case OPT_fuse_ld_gold:
>>-    case OPT_fuse_ld_lld:
>>+    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;
>>-- 
>>2.25.0
>
>Friendly ping:)

Patch ping https://gcc.gnu.org/ml/gcc-patches/2020-02/msg00510.html

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PING^3][PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-02-24 23:02   ` Fangrui Song via gcc-patches
@ 2020-03-10 17:19     ` Fangrui Song
  0 siblings, 0 replies; 44+ messages in thread
From: Fangrui Song @ 2020-03-10 17:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Martin Liska

On 2020-02-24, Fangrui Song wrote:
>On 2020-02-13, Fangrui Song wrote:
>>On 2020-02-09, Fangrui Song wrote:
>>>	PR driver/93645
>>>	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>>	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>>	* gcc.c (driver_handle_option): Likewise.
>>>	* collect2.c (main): Likewise.
>>>---
>>>gcc/ChangeLog       |  8 ++++++
>>>gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>>gcc/common.opt      | 14 ++--------
>>>gcc/doc/invoke.texi | 15 +++-------
>>>gcc/gcc.c           | 14 ++++------
>>>gcc/opts.c          |  4 +--
>>>6 files changed, 57 insertions(+), 65 deletions(-)
>>>
>>>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>>index feb2d066d0b..6bcec12d841 100644
>>>--- a/gcc/ChangeLog
>>>+++ b/gcc/ChangeLog
>>>@@ -1,3 +1,11 @@
>>>+2020-02-09  Fangrui Song  <maskray@google.com>
>>>+
>>>+	PR driver/93645
>>>+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>>+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>>+	* gcc.c (driver_handle_option): Likewise.
>>>+	* collect2.c (main): Likewise.
>>>+
>>>2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>>
>>>	* recog.c: Move pass_split_before_sched2 code in front of
>>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>>index 502d629141c..a3ef525a93b 100644
>>>--- a/gcc/collect2.c
>>>+++ b/gcc/collect2.c
>>>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>>>   {
>>>     USE_DEFAULT_LD,
>>>     USE_PLUGIN_LD,
>>>-      USE_GOLD_LD,
>>>-      USE_BFD_LD,
>>>-      USE_LLD_LD,
>>>-      USE_LD_MAX
>>>+      USE_LD
>>>   } selected_linker = USE_DEFAULT_LD;
>>>-  static const char *const ld_suffixes[USE_LD_MAX] =
>>>+  static const char *const ld_suffixes[USE_LD] =
>>>   {
>>>     "ld",
>>>-      PLUGIN_LD_SUFFIX,
>>>-      "ld.gold",
>>>-      "ld.bfd",
>>>-      "ld.lld"
>>>+      PLUGIN_LD_SUFFIX
>>>   };
>>> static const char *const real_ld_suffix = "real-ld";
>>> static const char *const collect_ld_suffix = "collect-ld";
>>>@@ -882,7 +876,7 @@ 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];
>>>+  const char *full_ld_suffixes[USE_LD];
>>>#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.
>>>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>>> const char **ld1;
>>> bool use_plugin = false;
>>> bool use_collect_ld = false;
>>>+  const char *use_ld = NULL;
>>>
>>> /* 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
>>>@@ -948,7 +943,7 @@ main (int argc, char **argv)
>>>#endif
>>> int i;
>>>
>>>-  for (i = 0; i < USE_LD_MAX; i++)
>>>+  for (i = 0; i < USE_LD; i++)
>>>   full_ld_suffixes[i]
>>>#ifdef CROSS_DIRECTORY_STRUCTURE
>>>     = concat (target_machine, "-", ld_suffixes[i], NULL);
>>>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>>	    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;
>>>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>>-	  selected_linker = USE_LLD_LD;
>>>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>>+	  {
>>>+	    use_ld = argv[i] + 9;
>>>+	    selected_linker = USE_LD;
>>>+	  }
>>>	else if (strncmp (argv[i], "-o", 2) == 0)
>>>	  {
>>>	    /* Parse the output filename if it's given so that we can make
>>>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>> /* Maybe we know the right file to use (if not cross).  */
>>> ld_file_name = 0;
>>>#ifdef DEFAULT_LINKER
>>>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>>-      selected_linker == USE_LLD_LD)
>>>+  if (!ld_file_name && selected_linker == USE_LD)
>>>   {
>>>     char *linker_name;
>>># ifdef HOST_EXECUTABLE_SUFFIX
>>>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>>	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>	    {
>>>	      default_linker[len] = '\0';
>>>-	      linker_name = concat (default_linker,
>>>-				    &ld_suffixes[selected_linker][2],
>>>+	      linker_name = concat (default_linker, ".", use_ld,
>>>				    HOST_EXECUTABLE_SUFFIX, NULL);
>>>	    }
>>>	}
>>>     if (linker_name == NULL)
>>># endif
>>>-      linker_name = concat (DEFAULT_LINKER,
>>>-			    &ld_suffixes[selected_linker][2],
>>>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>>			    NULL);
>>>     if (access (linker_name, X_OK) == 0)
>>>	ld_file_name = linker_name;
>>>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>>     ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>>     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, ld_suffixes[selected_linker], X_OK);
>>>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>>+  if (selected_linker != USE_LD) {
>>>+    /* Search the compiler directories for `ld'.  We have protection against
>>>+       recursive calls in find_a_file.  */
>>>+    if (!ld_file_name)
>>>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>>+    /* Search the ordinary system bin directories
>>>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>>+    if (!ld_file_name)
>>>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>>+    ld_file_name = use_ld;
>>>+  } else {
>>>+    const char *linker_name = concat("ld.", use_ld, NULL);
>>>+    if (!ld_file_name)
>>>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>>+    if (!ld_file_name) {
>>>+#ifdef CROSS_DIRECTORY_STRUCTURE
>>>+	linker_name = concat(target_machine, "-", linker_name, NULL);
>>>+#endif
>>>+	ld_file_name = find_a_file(&path, linker_name, X_OK);
>>>+    }
>>>+  }
>>>
>>>#ifdef REAL_NM_FILE_NAME
>>> nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>>diff --git a/gcc/common.opt b/gcc/common.opt
>>>index 5692cd04374..a76ed6434bb 100644
>>>--- a/gcc/common.opt
>>>+++ b/gcc/common.opt
>>>@@ -2859,17 +2859,9 @@ funwind-tables
>>>Common Report Var(flag_unwind_tables) Optimization
>>>Just generate unwind tables for exception handling.
>>>
>>>-fuse-ld=bfd
>>>-Common Driver Negative(fuse-ld=gold)
>>>-Use the bfd linker instead of the default linker.
>>>-
>>>-fuse-ld=gold
>>>-Common Driver Negative(fuse-ld=bfd)
>>>-Use the gold linker instead of the default linker.
>>>-
>>>-fuse-ld=lld
>>>-Common Driver Negative(fuse-ld=lld)
>>>-Use the lld LLVM linker instead of the default linker.
>>>+fuse-ld=
>>>+Common Driver Joined
>>>+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>>>
>>>fuse-linker-plugin
>>>Common Undocumented Var(flag_use_linker_plugin)
>>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>>index 35b341e759f..c2dd410c88f 100644
>>>--- a/gcc/doc/invoke.texi
>>>+++ b/gcc/doc/invoke.texi
>>>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>>recommended to link such objects into static library instead. Alternatively it
>>>is possible to use H.J. Lu's binutils with support for mixed objects.
>>>
>>>-@item -fuse-ld=bfd
>>>-@opindex fuse-ld=bfd
>>>-Use the @command{bfd} linker instead of the default linker.
>>>-
>>>-@item -fuse-ld=gold
>>>-@opindex fuse-ld=gold
>>>-Use the @command{gold} linker instead of the default linker.
>>>-
>>>-@item -fuse-ld=lld
>>>-@opindex fuse-ld=lld
>>>-Use the LLVM @command{lld} linker instead of the default linker.
>>>+@item -fuse-ld=@var{linker}
>>>+@opindex fuse-ld=linker
>>>+If @var{linker} is an absolute path, use it instead of the default linker;
>>>+otherwise use @command{ld.@var{linker}}.
>>>
>>>@cindex Libraries
>>>@item -l@var{library}
>>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>>index effc384f3ef..f9a6f10502d 100644
>>>--- a/gcc/gcc.c
>>>+++ b/gcc/gcc.c
>>>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>>     do_save = false;
>>>     break;
>>>
>>>-    case OPT_fuse_ld_bfd:
>>>-       use_ld = ".bfd";
>>>-       break;
>>>-
>>>-    case OPT_fuse_ld_gold:
>>>-       use_ld = ".gold";
>>>+    case OPT_fuse_ld_:
>>>+       use_ld = arg;
>>>      break;
>>>
>>>   case OPT_fcompare_debug_second:
>>>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>>	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>		{
>>>		  default_linker[len] = '\0';
>>>-		  ld = concat (default_linker, use_ld,
>>>+		  ld = concat (default_linker, ".", use_ld,
>>>			       HOST_EXECUTABLE_SUFFIX, NULL);
>>>		}
>>>	    }
>>>	  if (ld == NULL)
>>># endif
>>>-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>>+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>>	  if (access (ld, X_OK) == 0)
>>>	    {
>>>	      printf ("%s\n", ld);
>>>	      return (0);
>>>	    }
>>>#endif
>>>-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
>>>+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>>>	}
>>>     char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>>     printf ("%s\n", (newname ? newname : print_prog_name));
>>>diff --git a/gcc/opts.c b/gcc/opts.c
>>>index 7affeb41a96..f50d365d517 100644
>>>--- a/gcc/opts.c
>>>+++ b/gcc/opts.c
>>>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>>     dc->max_errors = value;
>>>     break;
>>>
>>>-    case OPT_fuse_ld_bfd:
>>>-    case OPT_fuse_ld_gold:
>>>-    case OPT_fuse_ld_lld:
>>>+    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;
>>>-- 
>>>2.25.0
>>
>>Friendly ping:)
>
>Patch ping https://gcc.gnu.org/ml/gcc-patches/2020-02/msg00510.html

Friendly ping https://gcc.gnu.org/ml/gcc-patches/2020-02/msg00510.html

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-02-10  0:02 [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Fangrui Song via gcc-patches
  2020-02-13 17:59 ` Fangrui Song via gcc-patches
@ 2020-03-11 12:55 ` Martin Liška
  2020-04-05 22:32   ` Fangrui Song
  1 sibling, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-03-11 12:55 UTC (permalink / raw)
  To: Fangrui Song, gcc-patches

On 2/10/20 1:02 AM, Fangrui Song via gcc-patches wrote:

Hello.

Thank you for the patch. You haven't received a review because we are right now
in stage4 of the development cycle:
https://gcc.gnu.org/develop.html#stage4

Anyway, I'm going to provide a review (even though I'm not maintainer of that).

Can you please describe your test-case why you need such option? When using
a different ld, I typically export PATH=/path/to/binutils and then run configure
and make.

I noticed not ideal error message:

$ gcc -fuse-ld=pes /tmp/foo.c
collect2: fatal error: cannot find ‘ld’
compilation terminated.

while clang prints:

$clang -fuse-ld=pes /tmp/foo.c
clang-9.0: error: invalid linker name in argument '-fuse-ld=pes'

The rest of the patch is comment inline...

> 	PR driver/93645
> 	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
> 	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
> 	* gcc.c (driver_handle_option): Likewise.
> 	* collect2.c (main): Likewise.
> ---
>   gcc/ChangeLog       |  8 ++++++
>   gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>   gcc/common.opt      | 14 ++--------
>   gcc/doc/invoke.texi | 15 +++-------
>   gcc/gcc.c           | 14 ++++------
>   gcc/opts.c          |  4 +--
>   6 files changed, 57 insertions(+), 65 deletions(-)
> 
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index feb2d066d0b..6bcec12d841 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,11 @@
> +2020-02-09  Fangrui Song  <maskray@google.com>
> +
> +	PR driver/93645
> +	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
> +	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
> +	* gcc.c (driver_handle_option): Likewise.
> +	* collect2.c (main): Likewise.
> +
>   2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>   
>   	* recog.c: Move pass_split_before_sched2 code in front of
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index 502d629141c..a3ef525a93b 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -859,18 +859,12 @@ main (int argc, char **argv)
>       {
>         USE_DEFAULT_LD,
>         USE_PLUGIN_LD,
> -      USE_GOLD_LD,
> -      USE_BFD_LD,
> -      USE_LLD_LD,
> -      USE_LD_MAX
> +      USE_LD
>       } selected_linker = USE_DEFAULT_LD;
> -  static const char *const ld_suffixes[USE_LD_MAX] =
> +  static const char *const ld_suffixes[USE_LD] =
>       {
>         "ld",
> -      PLUGIN_LD_SUFFIX,
> -      "ld.gold",
> -      "ld.bfd",
> -      "ld.lld"
> +      PLUGIN_LD_SUFFIX
>       };
>     static const char *const real_ld_suffix = "real-ld";
>     static const char *const collect_ld_suffix = "collect-ld";
> @@ -882,7 +876,7 @@ 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];
> +  const char *full_ld_suffixes[USE_LD];
>   #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.
> @@ -924,6 +918,7 @@ main (int argc, char **argv)
>     const char **ld1;
>     bool use_plugin = false;
>     bool use_collect_ld = false;
> +  const char *use_ld = NULL;
>   
>     /* 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
> @@ -948,7 +943,7 @@ main (int argc, char **argv)
>   #endif
>     int i;
>   
> -  for (i = 0; i < USE_LD_MAX; i++)
> +  for (i = 0; i < USE_LD; i++)
>       full_ld_suffixes[i]
>   #ifdef CROSS_DIRECTORY_STRUCTURE
>         = concat (target_machine, "-", ld_suffixes[i], NULL);
> @@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>   	    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;
> -	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
> -	  selected_linker = USE_LLD_LD;
> +	else if (!strncmp (argv[i], "-fuse-ld=", 9))
> +	  {
> +	    use_ld = argv[i] + 9;
> +	    selected_linker = USE_LD;
> +	  }
>   	else if (strncmp (argv[i], "-o", 2) == 0)
>   	  {
>   	    /* Parse the output filename if it's given so that we can make
> @@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>     /* Maybe we know the right file to use (if not cross).  */
>     ld_file_name = 0;
>   #ifdef DEFAULT_LINKER
> -  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
> -      selected_linker == USE_LLD_LD)
> +  if (!ld_file_name && selected_linker == USE_LD)
>       {
>         char *linker_name;
>   # ifdef HOST_EXECUTABLE_SUFFIX
> @@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>   	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>   	    {
>   	      default_linker[len] = '\0';
> -	      linker_name = concat (default_linker,
> -				    &ld_suffixes[selected_linker][2],
> +	      linker_name = concat (default_linker, ".", use_ld,
>   				    HOST_EXECUTABLE_SUFFIX, NULL);
>   	    }
>   	}
>         if (linker_name == NULL)
>   # endif
> -      linker_name = concat (DEFAULT_LINKER,
> -			    &ld_suffixes[selected_linker][2],
> +      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>   			    NULL);
>         if (access (linker_name, X_OK) == 0)
>   	ld_file_name = linker_name;
> @@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>         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, ld_suffixes[selected_linker], X_OK);
> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
> +  if (selected_linker != USE_LD) {
> +    /* Search the compiler directories for `ld'.  We have protection against
> +       recursive calls in find_a_file.  */
> +    if (!ld_file_name)
> +      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
> +    /* Search the ordinary system bin directories
> +       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
> +    if (!ld_file_name)
> +      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
> +  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
> +    ld_file_name = use_ld;
> +  } else {
> +    const char *linker_name = concat("ld.", use_ld, NULL);

This leads to strange searches like:

$ strace -f -s512 gcc -fuse-ld=/x/y/z/pes /tmp/foo.c 2>&1 | grep pes
...
[pid 24295] stat("/home/marxin/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
[pid 24295] stat("/usr/local/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)

Moreover, before the patch we only searched for suffixes 'ld.bfd', 'ld.gold' and 'ld.gold'. Now it
searches also for:

$ strace ... gcc -fuse-ld=xyz
...
[pid 24893] stat("/home/marxin/bin/ld.xyz", 0x7fffffffd200) = -1 ENOENT (No such file or directory)

> +    if (!ld_file_name)
> +      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
> +    if (!ld_file_name) {
> +#ifdef CROSS_DIRECTORY_STRUCTURE
> +	linker_name = concat(target_machine, "-", linker_name, NULL);
> +#endif
> +	ld_file_name = find_a_file(&path, linker_name, X_OK);
> +    }
> +  }
>   
>   #ifdef REAL_NM_FILE_NAME
>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 5692cd04374..a76ed6434bb 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2859,17 +2859,9 @@ funwind-tables
>   Common Report Var(flag_unwind_tables) Optimization
>   Just generate unwind tables for exception handling.
>   
> -fuse-ld=bfd
> -Common Driver Negative(fuse-ld=gold)
> -Use the bfd linker instead of the default linker.
> -
> -fuse-ld=gold
> -Common Driver Negative(fuse-ld=bfd)
> -Use the gold linker instead of the default linker.
> -
> -fuse-ld=lld
> -Common Driver Negative(fuse-ld=lld)
> -Use the lld LLVM linker instead of the default linker.
> +fuse-ld=
> +Common Driver Joined
> +-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>   
>   fuse-linker-plugin
>   Common Undocumented Var(flag_use_linker_plugin)
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 35b341e759f..c2dd410c88f 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>   recommended to link such objects into static library instead. Alternatively it
>   is possible to use H.J. Lu's binutils with support for mixed objects.
>   
> -@item -fuse-ld=bfd
> -@opindex fuse-ld=bfd
> -Use the @command{bfd} linker instead of the default linker.
> -
> -@item -fuse-ld=gold
> -@opindex fuse-ld=gold
> -Use the @command{gold} linker instead of the default linker.
> -
> -@item -fuse-ld=lld
> -@opindex fuse-ld=lld
> -Use the LLVM @command{lld} linker instead of the default linker.
> +@item -fuse-ld=@var{linker}
> +@opindex fuse-ld=linker
> +If @var{linker} is an absolute path, use it instead of the default linker;
> +otherwise use @command{ld.@var{linker}}.

You should somehow mention the special values bfd,gold and ldd.

>   
>   @cindex Libraries
>   @item -l@var{library}
> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index effc384f3ef..f9a6f10502d 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>         do_save = false;
>         break;
>   
> -    case OPT_fuse_ld_bfd:
> -       use_ld = ".bfd";
> -       break;
> -
> -    case OPT_fuse_ld_gold:
> -       use_ld = ".gold";
> +    case OPT_fuse_ld_:
> +       use_ld = arg;
>          break;
>   
>       case OPT_fcompare_debug_second:
> @@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>   	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>   		{
>   		  default_linker[len] = '\0';
> -		  ld = concat (default_linker, use_ld,
> +		  ld = concat (default_linker, ".", use_ld,
>   			       HOST_EXECUTABLE_SUFFIX, NULL);
>   		}
>   	    }
>   	  if (ld == NULL)
>   # endif
> -	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
> +	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>   	  if (access (ld, X_OK) == 0)
>   	    {
>   	      printf ("%s\n", ld);
>   	      return (0);
>   	    }
>   #endif
> -	  print_prog_name = concat (print_prog_name, use_ld, NULL);
> +	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);

In gcc.c you will probably have similar issues.

>   	}
>         char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>         printf ("%s\n", (newname ? newname : print_prog_name));
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 7affeb41a96..f50d365d517 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>         dc->max_errors = value;
>         break;
>   
> -    case OPT_fuse_ld_bfd:
> -    case OPT_fuse_ld_gold:
> -    case OPT_fuse_ld_lld:
> +    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;
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-03-11 12:55 ` [PATCH] " Martin Liška
@ 2020-04-05 22:32   ` Fangrui Song
  2020-04-06  7:18     ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2020-04-05 22:32 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

On 2020-03-11, Martin Liška wrote:
>On 2/10/20 1:02 AM, Fangrui Song via gcc-patches wrote:
>
>Hello.
>
>Thank you for the patch. You haven't received a review because we are right now
>in stage4 of the development cycle:
>https://gcc.gnu.org/develop.html#stage4

Thanks for the review!
According to https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543028.html "GCC 10.0 Status Report (2020-04-01)",
I guess GCC is not open for a new development cycle yet.
I will just answer a few questions instead of uploading a new patch.

>Anyway, I'm going to provide a review (even though I'm not maintainer of that).
>
>Can you please describe your test-case why you need such option? When using
>a different ld, I typically export PATH=/path/to/binutils and then run configure
>and make.

I would hope -fuse-ld=ld.bfd and -fuse-ld=ld.gold were used instead of
-fuse-ld=bfd and -fuse-ld=gold, then it would be more natural to have
-fuse-ld=/abs/path/to/ld . https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55470

-fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=lld are hard-coded in numerous
places. It is too late to change that.

One idea is to make

-fuse-ld=bfd
-fuse-ld=gold
-fuse-ld=lld

special. For any other value, e.g. -fuse-ld=foo or -fuse-ld=/abs/path, just searches the
executable named "foo" (instead of "ld.foo") or /abs/path .

Does the scheme sound good? If it is agreed, I can make a similar change to clang.

>I noticed not ideal error message:
>
>$ gcc -fuse-ld=pes /tmp/foo.c
>collect2: fatal error: cannot find ‘ld’
>compilation terminated.
>
>while clang prints:
>
>$clang -fuse-ld=pes /tmp/foo.c
>clang-9.0: error: invalid linker name in argument '-fuse-ld=pes'
>
>The rest of the patch is comment inline...

Thanks for all the comments.

>>	PR driver/93645
>>	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>	* gcc.c (driver_handle_option): Likewise.
>>	* collect2.c (main): Likewise.
>>---
>>  gcc/ChangeLog       |  8 ++++++
>>  gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>  gcc/common.opt      | 14 ++--------
>>  gcc/doc/invoke.texi | 15 +++-------
>>  gcc/gcc.c           | 14 ++++------
>>  gcc/opts.c          |  4 +--
>>  6 files changed, 57 insertions(+), 65 deletions(-)
>>
>>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>index feb2d066d0b..6bcec12d841 100644
>>--- a/gcc/ChangeLog
>>+++ b/gcc/ChangeLog
>>@@ -1,3 +1,11 @@
>>+2020-02-09  Fangrui Song  <maskray@google.com>
>>+
>>+	PR driver/93645
>>+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>+	* gcc.c (driver_handle_option): Likewise.
>>+	* collect2.c (main): Likewise.
>>+
>>  2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>  	* recog.c: Move pass_split_before_sched2 code in front of
>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>index 502d629141c..a3ef525a93b 100644
>>--- a/gcc/collect2.c
>>+++ b/gcc/collect2.c
>>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>>      {
>>        USE_DEFAULT_LD,
>>        USE_PLUGIN_LD,
>>-      USE_GOLD_LD,
>>-      USE_BFD_LD,
>>-      USE_LLD_LD,
>>-      USE_LD_MAX
>>+      USE_LD
>>      } selected_linker = USE_DEFAULT_LD;
>>-  static const char *const ld_suffixes[USE_LD_MAX] =
>>+  static const char *const ld_suffixes[USE_LD] =
>>      {
>>        "ld",
>>-      PLUGIN_LD_SUFFIX,
>>-      "ld.gold",
>>-      "ld.bfd",
>>-      "ld.lld"
>>+      PLUGIN_LD_SUFFIX
>>      };
>>    static const char *const real_ld_suffix = "real-ld";
>>    static const char *const collect_ld_suffix = "collect-ld";
>>@@ -882,7 +876,7 @@ 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];
>>+  const char *full_ld_suffixes[USE_LD];
>>  #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.
>>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>>    const char **ld1;
>>    bool use_plugin = false;
>>    bool use_collect_ld = false;
>>+  const char *use_ld = NULL;
>>    /* 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
>>@@ -948,7 +943,7 @@ main (int argc, char **argv)
>>  #endif
>>    int i;
>>-  for (i = 0; i < USE_LD_MAX; i++)
>>+  for (i = 0; i < USE_LD; i++)
>>      full_ld_suffixes[i]
>>  #ifdef CROSS_DIRECTORY_STRUCTURE
>>        = concat (target_machine, "-", ld_suffixes[i], NULL);
>>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>  	    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;
>>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>-	  selected_linker = USE_LLD_LD;
>>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>+	  {
>>+	    use_ld = argv[i] + 9;
>>+	    selected_linker = USE_LD;
>>+	  }
>>  	else if (strncmp (argv[i], "-o", 2) == 0)
>>  	  {
>>  	    /* Parse the output filename if it's given so that we can make
>>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>    /* Maybe we know the right file to use (if not cross).  */
>>    ld_file_name = 0;
>>  #ifdef DEFAULT_LINKER
>>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>-      selected_linker == USE_LLD_LD)
>>+  if (!ld_file_name && selected_linker == USE_LD)
>>      {
>>        char *linker_name;
>>  # ifdef HOST_EXECUTABLE_SUFFIX
>>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>  	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>  	    {
>>  	      default_linker[len] = '\0';
>>-	      linker_name = concat (default_linker,
>>-				    &ld_suffixes[selected_linker][2],
>>+	      linker_name = concat (default_linker, ".", use_ld,
>>  				    HOST_EXECUTABLE_SUFFIX, NULL);
>>  	    }
>>  	}
>>        if (linker_name == NULL)
>>  # endif
>>-      linker_name = concat (DEFAULT_LINKER,
>>-			    &ld_suffixes[selected_linker][2],
>>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>  			    NULL);
>>        if (access (linker_name, X_OK) == 0)
>>  	ld_file_name = linker_name;
>>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>        ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>        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, ld_suffixes[selected_linker], X_OK);
>>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>+  if (selected_linker != USE_LD) {
>>+    /* Search the compiler directories for `ld'.  We have protection against
>>+       recursive calls in find_a_file.  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>+    /* Search the ordinary system bin directories
>>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>+    ld_file_name = use_ld;
>>+  } else {
>>+    const char *linker_name = concat("ld.", use_ld, NULL);
>
>This leads to strange searches like:
>
>$ strace -f -s512 gcc -fuse-ld=/x/y/z/pes /tmp/foo.c 2>&1 | grep pes
>...
>[pid 24295] stat("/home/marxin/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>[pid 24295] stat("/usr/local/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>
>Moreover, before the patch we only searched for suffixes 'ld.bfd', 'ld.gold' and 'ld.gold'. Now it
>searches also for:
>
>$ strace ... gcc -fuse-ld=xyz
>...
>[pid 24893] stat("/home/marxin/bin/ld.xyz", 0x7fffffffd200) = -1 ENOENT (No such file or directory)
>
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>+    if (!ld_file_name) {
>>+#ifdef CROSS_DIRECTORY_STRUCTURE
>>+	linker_name = concat(target_machine, "-", linker_name, NULL);
>>+#endif
>>+	ld_file_name = find_a_file(&path, linker_name, X_OK);
>>+    }
>>+  }
>>  #ifdef REAL_NM_FILE_NAME
>>    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>diff --git a/gcc/common.opt b/gcc/common.opt
>>index 5692cd04374..a76ed6434bb 100644
>>--- a/gcc/common.opt
>>+++ b/gcc/common.opt
>>@@ -2859,17 +2859,9 @@ funwind-tables
>>  Common Report Var(flag_unwind_tables) Optimization
>>  Just generate unwind tables for exception handling.
>>-fuse-ld=bfd
>>-Common Driver Negative(fuse-ld=gold)
>>-Use the bfd linker instead of the default linker.
>>-
>>-fuse-ld=gold
>>-Common Driver Negative(fuse-ld=bfd)
>>-Use the gold linker instead of the default linker.
>>-
>>-fuse-ld=lld
>>-Common Driver Negative(fuse-ld=lld)
>>-Use the lld LLVM linker instead of the default linker.
>>+fuse-ld=
>>+Common Driver Joined
>>+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>>  fuse-linker-plugin
>>  Common Undocumented Var(flag_use_linker_plugin)
>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>index 35b341e759f..c2dd410c88f 100644
>>--- a/gcc/doc/invoke.texi
>>+++ b/gcc/doc/invoke.texi
>>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>  recommended to link such objects into static library instead. Alternatively it
>>  is possible to use H.J. Lu's binutils with support for mixed objects.
>>-@item -fuse-ld=bfd
>>-@opindex fuse-ld=bfd
>>-Use the @command{bfd} linker instead of the default linker.
>>-
>>-@item -fuse-ld=gold
>>-@opindex fuse-ld=gold
>>-Use the @command{gold} linker instead of the default linker.
>>-
>>-@item -fuse-ld=lld
>>-@opindex fuse-ld=lld
>>-Use the LLVM @command{lld} linker instead of the default linker.
>>+@item -fuse-ld=@var{linker}
>>+@opindex fuse-ld=linker
>>+If @var{linker} is an absolute path, use it instead of the default linker;
>>+otherwise use @command{ld.@var{linker}}.
>
>You should somehow mention the special values bfd,gold and ldd.
>>  @cindex Libraries
>>  @item -l@var{library}
>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>index effc384f3ef..f9a6f10502d 100644
>>--- a/gcc/gcc.c
>>+++ b/gcc/gcc.c
>>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>        do_save = false;
>>        break;
>>-    case OPT_fuse_ld_bfd:
>>-       use_ld = ".bfd";
>>-       break;
>>-
>>-    case OPT_fuse_ld_gold:
>>-       use_ld = ".gold";
>>+    case OPT_fuse_ld_:
>>+       use_ld = arg;
>>         break;
>>      case OPT_fcompare_debug_second:
>>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>  	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>  		{
>>  		  default_linker[len] = '\0';
>>-		  ld = concat (default_linker, use_ld,
>>+		  ld = concat (default_linker, ".", use_ld,
>>  			       HOST_EXECUTABLE_SUFFIX, NULL);
>>  		}
>>  	    }
>>  	  if (ld == NULL)
>>  # endif
>>-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>  	  if (access (ld, X_OK) == 0)
>>  	    {
>>  	      printf ("%s\n", ld);
>>  	      return (0);
>>  	    }
>>  #endif
>>-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
>>+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>
>In gcc.c you will probably have similar issues.
>
>>  	}
>>        char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>        printf ("%s\n", (newname ? newname : print_prog_name));
>>diff --git a/gcc/opts.c b/gcc/opts.c
>>index 7affeb41a96..f50d365d517 100644
>>--- a/gcc/opts.c
>>+++ b/gcc/opts.c
>>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>        dc->max_errors = value;
>>        break;
>>-    case OPT_fuse_ld_bfd:
>>-    case OPT_fuse_ld_gold:
>>-    case OPT_fuse_ld_lld:
>>+    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;
>>
>

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-04-05 22:32   ` Fangrui Song
@ 2020-04-06  7:18     ` Martin Liška
  2020-05-19 19:21       ` [PATCH] Add -fuse-ld= to specify an arbitrary executable as the linker Fangrui Song
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-04-06  7:18 UTC (permalink / raw)
  To: Fangrui Song; +Cc: gcc-patches

On 4/6/20 12:32 AM, Fangrui Song wrote:
> On 2020-03-11, Martin Liška wrote:
>> On 2/10/20 1:02 AM, Fangrui Song via gcc-patches wrote:
>>
>> Hello.
>>
>> Thank you for the patch. You haven't received a review because we are right now
>> in stage4 of the development cycle:
>> https://gcc.gnu.org/develop.html#stage4
> 
> Thanks for the review!
> According to https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543028.html "GCC 10.0 Status Report (2020-04-01)",
> I guess GCC is not open for a new development cycle yet.

Yes, it's not opened, but I expect to be opened in 3 weeks from now.

> I will just answer a few questions instead of uploading a new patch.

Sure, but don't hesitate to send a patch. It can sit here and wait for next stage1 ;)

> 
>> Anyway, I'm going to provide a review (even though I'm not maintainer of that).
>>
>> Can you please describe your test-case why you need such option? When using
>> a different ld, I typically export PATH=/path/to/binutils and then run configure
>> and make.
> 
> I would hope -fuse-ld=ld.bfd and -fuse-ld=ld.gold were used instead of
> -fuse-ld=bfd and -fuse-ld=gold, then it would be more natural to have
> -fuse-ld=/abs/path/to/ld . https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55470

Well, problem with that is that the option values are used and we want to preserve
backward compatibility of options (if possible). I mean we can't just rename
-fuse-ld=bfd to -fuse-ld=ld.bfd.

> 
> -fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=lld are hard-coded in numerous
> places. It is too late to change that.
> 
> One idea is to make
> 
> -fuse-ld=bfd
> -fuse-ld=gold
> -fuse-ld=lld
> 
> special. For any other value, e.g. -fuse-ld=foo or -fuse-ld=/abs/path, just searches the
> executable named "foo" (instead of "ld.foo") or /abs/path .

Yes, that seems feasible to me.

> 
> Does the scheme sound good? If it is agreed, I can make a similar change to clang.

Yes, please send a patch and we can make another round of review process.

Thanks,
Martin

> 
>> I noticed not ideal error message:
>>
>> $ gcc -fuse-ld=pes /tmp/foo.c
>> collect2: fatal error: cannot find ‘ld’
>> compilation terminated.
>>
>> while clang prints:
>>
>> $clang -fuse-ld=pes /tmp/foo.c
>> clang-9.0: error: invalid linker name in argument '-fuse-ld=pes'
>>
>> The rest of the patch is comment inline...
> 
> Thanks for all the comments.
> 
>>>     PR driver/93645
>>>     * common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>>     * opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>>     * gcc.c (driver_handle_option): Likewise.
>>>     * collect2.c (main): Likewise.
>>> ---
>>>  gcc/ChangeLog       |  8 ++++++
>>>  gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>>  gcc/common.opt      | 14 ++--------
>>>  gcc/doc/invoke.texi | 15 +++-------
>>>  gcc/gcc.c           | 14 ++++------
>>>  gcc/opts.c          |  4 +--
>>>  6 files changed, 57 insertions(+), 65 deletions(-)
>>>
>>> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>> index feb2d066d0b..6bcec12d841 100644
>>> --- a/gcc/ChangeLog
>>> +++ b/gcc/ChangeLog
>>> @@ -1,3 +1,11 @@
>>> +2020-02-09  Fangrui Song  <maskray@google.com>
>>> +
>>> +    PR driver/93645
>>> +    * common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>> +    * opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>> +    * gcc.c (driver_handle_option): Likewise.
>>> +    * collect2.c (main): Likewise.
>>> +
>>>  2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>>      * recog.c: Move pass_split_before_sched2 code in front of
>>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>>> index 502d629141c..a3ef525a93b 100644
>>> --- a/gcc/collect2.c
>>> +++ b/gcc/collect2.c
>>> @@ -859,18 +859,12 @@ main (int argc, char **argv)
>>>      {
>>>        USE_DEFAULT_LD,
>>>        USE_PLUGIN_LD,
>>> -      USE_GOLD_LD,
>>> -      USE_BFD_LD,
>>> -      USE_LLD_LD,
>>> -      USE_LD_MAX
>>> +      USE_LD
>>>      } selected_linker = USE_DEFAULT_LD;
>>> -  static const char *const ld_suffixes[USE_LD_MAX] =
>>> +  static const char *const ld_suffixes[USE_LD] =
>>>      {
>>>        "ld",
>>> -      PLUGIN_LD_SUFFIX,
>>> -      "ld.gold",
>>> -      "ld.bfd",
>>> -      "ld.lld"
>>> +      PLUGIN_LD_SUFFIX
>>>      };
>>>    static const char *const real_ld_suffix = "real-ld";
>>>    static const char *const collect_ld_suffix = "collect-ld";
>>> @@ -882,7 +876,7 @@ 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];
>>> +  const char *full_ld_suffixes[USE_LD];
>>>  #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.
>>> @@ -924,6 +918,7 @@ main (int argc, char **argv)
>>>    const char **ld1;
>>>    bool use_plugin = false;
>>>    bool use_collect_ld = false;
>>> +  const char *use_ld = NULL;
>>>    /* 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
>>> @@ -948,7 +943,7 @@ main (int argc, char **argv)
>>>  #endif
>>>    int i;
>>> -  for (i = 0; i < USE_LD_MAX; i++)
>>> +  for (i = 0; i < USE_LD; i++)
>>>      full_ld_suffixes[i]
>>>  #ifdef CROSS_DIRECTORY_STRUCTURE
>>>        = concat (target_machine, "-", ld_suffixes[i], NULL);
>>> @@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>>          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;
>>> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>> -      selected_linker = USE_LLD_LD;
>>> +    else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>> +      {
>>> +        use_ld = argv[i] + 9;
>>> +        selected_linker = USE_LD;
>>> +      }
>>>      else if (strncmp (argv[i], "-o", 2) == 0)
>>>        {
>>>          /* Parse the output filename if it's given so that we can make
>>> @@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>>    /* Maybe we know the right file to use (if not cross).  */
>>>    ld_file_name = 0;
>>>  #ifdef DEFAULT_LINKER
>>> -  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>> -      selected_linker == USE_LLD_LD)
>>> +  if (!ld_file_name && selected_linker == USE_LD)
>>>      {
>>>        char *linker_name;
>>>  # ifdef HOST_EXECUTABLE_SUFFIX
>>> @@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>>        if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>          {
>>>            default_linker[len] = '\0';
>>> -          linker_name = concat (default_linker,
>>> -                    &ld_suffixes[selected_linker][2],
>>> +          linker_name = concat (default_linker, ".", use_ld,
>>>                      HOST_EXECUTABLE_SUFFIX, NULL);
>>>          }
>>>      }
>>>        if (linker_name == NULL)
>>>  # endif
>>> -      linker_name = concat (DEFAULT_LINKER,
>>> -                &ld_suffixes[selected_linker][2],
>>> +      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>>                  NULL);
>>>        if (access (linker_name, X_OK) == 0)
>>>      ld_file_name = linker_name;
>>> @@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>>        ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>>        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, ld_suffixes[selected_linker], X_OK);
>>> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>> +  if (selected_linker != USE_LD) {
>>> +    /* Search the compiler directories for `ld'.  We have protection against
>>> +       recursive calls in find_a_file.  */
>>> +    if (!ld_file_name)
>>> +      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>> +    /* Search the ordinary system bin directories
>>> +       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>> +    if (!ld_file_name)
>>> +      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>> +  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>> +    ld_file_name = use_ld;
>>> +  } else {
>>> +    const char *linker_name = concat("ld.", use_ld, NULL);
>>
>> This leads to strange searches like:
>>
>> $ strace -f -s512 gcc -fuse-ld=/x/y/z/pes /tmp/foo.c 2>&1 | grep pes
>> ...
>> [pid 24295] stat("/home/marxin/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>> [pid 24295] stat("/usr/local/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>>
>> Moreover, before the patch we only searched for suffixes 'ld.bfd', 'ld.gold' and 'ld.gold'. Now it
>> searches also for:
>>
>> $ strace ... gcc -fuse-ld=xyz
>> ...
>> [pid 24893] stat("/home/marxin/bin/ld.xyz", 0x7fffffffd200) = -1 ENOENT (No such file or directory)
>>
>>> +    if (!ld_file_name)
>>> +      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>> +    if (!ld_file_name) {
>>> +#ifdef CROSS_DIRECTORY_STRUCTURE
>>> +    linker_name = concat(target_machine, "-", linker_name, NULL);
>>> +#endif
>>> +    ld_file_name = find_a_file(&path, linker_name, X_OK);
>>> +    }
>>> +  }
>>>  #ifdef REAL_NM_FILE_NAME
>>>    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>> diff --git a/gcc/common.opt b/gcc/common.opt
>>> index 5692cd04374..a76ed6434bb 100644
>>> --- a/gcc/common.opt
>>> +++ b/gcc/common.opt
>>> @@ -2859,17 +2859,9 @@ funwind-tables
>>>  Common Report Var(flag_unwind_tables) Optimization
>>>  Just generate unwind tables for exception handling.
>>> -fuse-ld=bfd
>>> -Common Driver Negative(fuse-ld=gold)
>>> -Use the bfd linker instead of the default linker.
>>> -
>>> -fuse-ld=gold
>>> -Common Driver Negative(fuse-ld=bfd)
>>> -Use the gold linker instead of the default linker.
>>> -
>>> -fuse-ld=lld
>>> -Common Driver Negative(fuse-ld=lld)
>>> -Use the lld LLVM linker instead of the default linker.
>>> +fuse-ld=
>>> +Common Driver Joined
>>> +-fuse-ld=[bfd|gold|lld|<absolute path>]    Use the specified linker.
>>>  fuse-linker-plugin
>>>  Common Undocumented Var(flag_use_linker_plugin)
>>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>> index 35b341e759f..c2dd410c88f 100644
>>> --- a/gcc/doc/invoke.texi
>>> +++ b/gcc/doc/invoke.texi
>>> @@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>>  recommended to link such objects into static library instead. Alternatively it
>>>  is possible to use H.J. Lu's binutils with support for mixed objects.
>>> -@item -fuse-ld=bfd
>>> -@opindex fuse-ld=bfd
>>> -Use the @command{bfd} linker instead of the default linker.
>>> -
>>> -@item -fuse-ld=gold
>>> -@opindex fuse-ld=gold
>>> -Use the @command{gold} linker instead of the default linker.
>>> -
>>> -@item -fuse-ld=lld
>>> -@opindex fuse-ld=lld
>>> -Use the LLVM @command{lld} linker instead of the default linker.
>>> +@item -fuse-ld=@var{linker}
>>> +@opindex fuse-ld=linker
>>> +If @var{linker} is an absolute path, use it instead of the default linker;
>>> +otherwise use @command{ld.@var{linker}}.
>>
>> You should somehow mention the special values bfd,gold and ldd.
>>>  @cindex Libraries
>>>  @item -l@var{library}
>>> diff --git a/gcc/gcc.c b/gcc/gcc.c
>>> index effc384f3ef..f9a6f10502d 100644
>>> --- a/gcc/gcc.c
>>> +++ b/gcc/gcc.c
>>> @@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>>        do_save = false;
>>>        break;
>>> -    case OPT_fuse_ld_bfd:
>>> -       use_ld = ".bfd";
>>> -       break;
>>> -
>>> -    case OPT_fuse_ld_gold:
>>> -       use_ld = ".gold";
>>> +    case OPT_fuse_ld_:
>>> +       use_ld = arg;
>>>         break;
>>>      case OPT_fcompare_debug_second:
>>> @@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>>            if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>          {
>>>            default_linker[len] = '\0';
>>> -          ld = concat (default_linker, use_ld,
>>> +          ld = concat (default_linker, ".", use_ld,
>>>                     HOST_EXECUTABLE_SUFFIX, NULL);
>>>          }
>>>          }
>>>        if (ld == NULL)
>>>  # endif
>>> -      ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>> +      ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>>        if (access (ld, X_OK) == 0)
>>>          {
>>>            printf ("%s\n", ld);
>>>            return (0);
>>>          }
>>>  #endif
>>> -      print_prog_name = concat (print_prog_name, use_ld, NULL);
>>> +      print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>>
>> In gcc.c you will probably have similar issues.
>>
>>>      }
>>>        char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>>        printf ("%s\n", (newname ? newname : print_prog_name));
>>> diff --git a/gcc/opts.c b/gcc/opts.c
>>> index 7affeb41a96..f50d365d517 100644
>>> --- a/gcc/opts.c
>>> +++ b/gcc/opts.c
>>> @@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>>        dc->max_errors = value;
>>>        break;
>>> -    case OPT_fuse_ld_bfd:
>>> -    case OPT_fuse_ld_gold:
>>> -    case OPT_fuse_ld_lld:
>>> +    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;
>>>
>>


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-04-06  7:18     ` Martin Liška
@ 2020-05-19 19:21       ` Fangrui Song
  2020-05-20 13:45         ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2020-05-19 19:21 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 15093 bytes --]


On 2020-04-06, Martin Liška wrote:
>On 4/6/20 12:32 AM, Fangrui Song wrote:
>>On 2020-03-11, Martin Liška wrote:
>>>On 2/10/20 1:02 AM, Fangrui Song via gcc-patches wrote:
>>>
>>>Hello.
>>>
>>>Thank you for the patch. You haven't received a review because we are right now
>>>in stage4 of the development cycle:
>>>https://gcc.gnu.org/develop.html#stage4
>>
>>Thanks for the review!
>>According to https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543028.html "GCC 10.0 Status Report (2020-04-01)",
>>I guess GCC is not open for a new development cycle yet.
>
>Yes, it's not opened, but I expect to be opened in 3 weeks from now.
>
>>I will just answer a few questions instead of uploading a new patch.
>
>Sure, but don't hesitate to send a patch. It can sit here and wait for next stage1 ;)

Thank you! I got around and updated the patch.

Tested locally with -fuse-ld=~/Stable/bin/ld.lld and -fuse-ld=~/Dev/binutils-gdb/Debug/ld/ld-new

>>
>>>Anyway, I'm going to provide a review (even though I'm not maintainer of that).
>>>
>>>Can you please describe your test-case why you need such option? When using
>>>a different ld, I typically export PATH=/path/to/binutils and then run configure
>>>and make.
>>
>>I would hope -fuse-ld=ld.bfd and -fuse-ld=ld.gold were used instead of
>>-fuse-ld=bfd and -fuse-ld=gold, then it would be more natural to have
>>-fuse-ld=/abs/path/to/ld . https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55470
>
>Well, problem with that is that the option values are used and we want to preserve
>backward compatibility of options (if possible). I mean we can't just rename
>-fuse-ld=bfd to -fuse-ld=ld.bfd.
>
>>
>>-fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=lld are hard-coded in numerous
>>places. It is too late to change that.
>>
>>One idea is to make
>>
>>-fuse-ld=bfd
>>-fuse-ld=gold
>>-fuse-ld=lld
>>
>>special. For any other value, e.g. -fuse-ld=foo or -fuse-ld=/abs/path, just searches the
>>executable named "foo" (instead of "ld.foo") or /abs/path .
>
>Yes, that seems feasible to me.
>
>>
>>Does the scheme sound good? If it is agreed, I can make a similar change to clang.
>
>Yes, please send a patch and we can make another round of review process.
>
>Thanks,
>Martin
>
>>
>>>I noticed not ideal error message:
>>>
>>>$ gcc -fuse-ld=pes /tmp/foo.c
>>>collect2: fatal error: cannot find ‘ld’
>>>compilation terminated.
>>>
>>>while clang prints:
>>>
>>>$clang -fuse-ld=pes /tmp/foo.c
>>>clang-9.0: error: invalid linker name in argument '-fuse-ld=pes'
>>>
>>>The rest of the patch is comment inline...
>>
>>Thanks for all the comments.
>>
>>>>    PR driver/93645
>>>>    * common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>>>    * opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>>>    * gcc.c (driver_handle_option): Likewise.
>>>>    * collect2.c (main): Likewise.
>>>>---
>>>> gcc/ChangeLog       |  8 ++++++
>>>> gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>>> gcc/common.opt      | 14 ++--------
>>>> gcc/doc/invoke.texi | 15 +++-------
>>>> gcc/gcc.c           | 14 ++++------
>>>> gcc/opts.c          |  4 +--
>>>> 6 files changed, 57 insertions(+), 65 deletions(-)
>>>>
>>>>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>>>index feb2d066d0b..6bcec12d841 100644
>>>>--- a/gcc/ChangeLog
>>>>+++ b/gcc/ChangeLog
>>>>@@ -1,3 +1,11 @@
>>>>+2020-02-09  Fangrui Song  <maskray@google.com>
>>>>+
>>>>+    PR driver/93645
>>>>+    * common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>>>+    * opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>>>+    * gcc.c (driver_handle_option): Likewise.
>>>>+    * collect2.c (main): Likewise.
>>>>+
>>>> 2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>>>     * recog.c: Move pass_split_before_sched2 code in front of
>>>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>>>index 502d629141c..a3ef525a93b 100644
>>>>--- a/gcc/collect2.c
>>>>+++ b/gcc/collect2.c
>>>>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>>>>     {
>>>>       USE_DEFAULT_LD,
>>>>       USE_PLUGIN_LD,
>>>>-      USE_GOLD_LD,
>>>>-      USE_BFD_LD,
>>>>-      USE_LLD_LD,
>>>>-      USE_LD_MAX
>>>>+      USE_LD
>>>>     } selected_linker = USE_DEFAULT_LD;
>>>>-  static const char *const ld_suffixes[USE_LD_MAX] =
>>>>+  static const char *const ld_suffixes[USE_LD] =
>>>>     {
>>>>       "ld",
>>>>-      PLUGIN_LD_SUFFIX,
>>>>-      "ld.gold",
>>>>-      "ld.bfd",
>>>>-      "ld.lld"
>>>>+      PLUGIN_LD_SUFFIX
>>>>     };
>>>>   static const char *const real_ld_suffix = "real-ld";
>>>>   static const char *const collect_ld_suffix = "collect-ld";
>>>>@@ -882,7 +876,7 @@ 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];
>>>>+  const char *full_ld_suffixes[USE_LD];
>>>> #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.
>>>>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>>>>   const char **ld1;
>>>>   bool use_plugin = false;
>>>>   bool use_collect_ld = false;
>>>>+  const char *use_ld = NULL;
>>>>   /* 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
>>>>@@ -948,7 +943,7 @@ main (int argc, char **argv)
>>>> #endif
>>>>   int i;
>>>>-  for (i = 0; i < USE_LD_MAX; i++)
>>>>+  for (i = 0; i < USE_LD; i++)
>>>>     full_ld_suffixes[i]
>>>> #ifdef CROSS_DIRECTORY_STRUCTURE
>>>>       = concat (target_machine, "-", ld_suffixes[i], NULL);
>>>>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>>>         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;
>>>>-    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>>>-      selected_linker = USE_LLD_LD;
>>>>+    else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>>>+      {
>>>>+        use_ld = argv[i] + 9;
>>>>+        selected_linker = USE_LD;
>>>>+      }
>>>>     else if (strncmp (argv[i], "-o", 2) == 0)
>>>>       {
>>>>         /* Parse the output filename if it's given so that we can make
>>>>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>>>   /* Maybe we know the right file to use (if not cross).  */
>>>>   ld_file_name = 0;
>>>> #ifdef DEFAULT_LINKER
>>>>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>>>-      selected_linker == USE_LLD_LD)
>>>>+  if (!ld_file_name && selected_linker == USE_LD)
>>>>     {
>>>>       char *linker_name;
>>>> # ifdef HOST_EXECUTABLE_SUFFIX
>>>>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>>>       if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>>         {
>>>>           default_linker[len] = '\0';
>>>>-          linker_name = concat (default_linker,
>>>>-                    &ld_suffixes[selected_linker][2],
>>>>+          linker_name = concat (default_linker, ".", use_ld,
>>>>                     HOST_EXECUTABLE_SUFFIX, NULL);
>>>>         }
>>>>     }

This piece of code (added by commit b78e932d513b7d3373bc5e1aab456dda737d07d0 PR driver/59321) is a bit complex.
The new patch does not touch it.

>>>>       if (linker_name == NULL)
>>>> # endif
>>>>-      linker_name = concat (DEFAULT_LINKER,
>>>>-                &ld_suffixes[selected_linker][2],
>>>>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>>>                 NULL);
>>>>       if (access (linker_name, X_OK) == 0)
>>>>     ld_file_name = linker_name;
>>>>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>>>       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>>>       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, ld_suffixes[selected_linker], X_OK);
>>>>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>>>+  if (selected_linker != USE_LD) {
>>>>+    /* Search the compiler directories for `ld'.  We have protection against
>>>>+       recursive calls in find_a_file.  */
>>>>+    if (!ld_file_name)
>>>>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>>>+    /* Search the ordinary system bin directories
>>>>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>>>+    if (!ld_file_name)
>>>>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>>>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>>>+    ld_file_name = use_ld;
>>>>+  } else {
>>>>+    const char *linker_name = concat("ld.", use_ld, NULL);
>>>
>>>This leads to strange searches like:
>>>
>>>$ strace -f -s512 gcc -fuse-ld=/x/y/z/pes /tmp/foo.c 2>&1 | grep pes
>>>...
>>>[pid 24295] stat("/home/marxin/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>>>[pid 24295] stat("/usr/local/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>>>
>>>Moreover, before the patch we only searched for suffixes 'ld.bfd', 'ld.gold' and 'ld.gold'. Now it
>>>searches also for:
>>>
>>>$ strace ... gcc -fuse-ld=xyz
>>>...
>>>[pid 24893] stat("/home/marxin/bin/ld.xyz", 0x7fffffffd200) = -1 ENOENT (No such file or directory)
>>>
>>>>+    if (!ld_file_name)
>>>>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>>>+    if (!ld_file_name) {
>>>>+#ifdef CROSS_DIRECTORY_STRUCTURE
>>>>+    linker_name = concat(target_machine, "-", linker_name, NULL);
>>>>+#endif
>>>>+    ld_file_name = find_a_file(&path, linker_name, X_OK);
>>>>+    }
>>>>+  }
>>>> #ifdef REAL_NM_FILE_NAME
>>>>   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>>>diff --git a/gcc/common.opt b/gcc/common.opt
>>>>index 5692cd04374..a76ed6434bb 100644
>>>>--- a/gcc/common.opt
>>>>+++ b/gcc/common.opt
>>>>@@ -2859,17 +2859,9 @@ funwind-tables
>>>> Common Report Var(flag_unwind_tables) Optimization
>>>> Just generate unwind tables for exception handling.
>>>>-fuse-ld=bfd
>>>>-Common Driver Negative(fuse-ld=gold)
>>>>-Use the bfd linker instead of the default linker.
>>>>-
>>>>-fuse-ld=gold
>>>>-Common Driver Negative(fuse-ld=bfd)
>>>>-Use the gold linker instead of the default linker.
>>>>-
>>>>-fuse-ld=lld
>>>>-Common Driver Negative(fuse-ld=lld)
>>>>-Use the lld LLVM linker instead of the default linker.
>>>>+fuse-ld=
>>>>+Common Driver Joined
>>>>+-fuse-ld=[bfd|gold|lld|<absolute path>]    Use the specified linker.
>>>> fuse-linker-plugin
>>>> Common Undocumented Var(flag_use_linker_plugin)
>>>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>>>index 35b341e759f..c2dd410c88f 100644
>>>>--- a/gcc/doc/invoke.texi
>>>>+++ b/gcc/doc/invoke.texi
>>>>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>>> recommended to link such objects into static library instead. Alternatively it
>>>> is possible to use H.J. Lu's binutils with support for mixed objects.
>>>>-@item -fuse-ld=bfd
>>>>-@opindex fuse-ld=bfd
>>>>-Use the @command{bfd} linker instead of the default linker.
>>>>-
>>>>-@item -fuse-ld=gold
>>>>-@opindex fuse-ld=gold
>>>>-Use the @command{gold} linker instead of the default linker.
>>>>-
>>>>-@item -fuse-ld=lld
>>>>-@opindex fuse-ld=lld
>>>>-Use the LLVM @command{lld} linker instead of the default linker.
>>>>+@item -fuse-ld=@var{linker}
>>>>+@opindex fuse-ld=linker
>>>>+If @var{linker} is an absolute path, use it instead of the default linker;
>>>>+otherwise use @command{ld.@var{linker}}.
>>>
>>>You should somehow mention the special values bfd,gold and ldd.
>>>> @cindex Libraries
>>>> @item -l@var{library}
>>>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>>>index effc384f3ef..f9a6f10502d 100644
>>>>--- a/gcc/gcc.c
>>>>+++ b/gcc/gcc.c
>>>>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>>>       do_save = false;
>>>>       break;
>>>>-    case OPT_fuse_ld_bfd:
>>>>-       use_ld = ".bfd";
>>>>-       break;
>>>>-
>>>>-    case OPT_fuse_ld_gold:
>>>>-       use_ld = ".gold";
>>>>+    case OPT_fuse_ld_:
>>>>+       use_ld = arg;
>>>>        break;
>>>>     case OPT_fcompare_debug_second:
>>>>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>>>           if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>>         {
>>>>           default_linker[len] = '\0';
>>>>-          ld = concat (default_linker, use_ld,
>>>>+          ld = concat (default_linker, ".", use_ld,
>>>>                    HOST_EXECUTABLE_SUFFIX, NULL);
>>>>         }
>>>>         }
>>>>       if (ld == NULL)
>>>> # endif
>>>>-      ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>>>+      ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>>>       if (access (ld, X_OK) == 0)
>>>>         {
>>>>           printf ("%s\n", ld);
>>>>           return (0);
>>>>         }
>>>> #endif
>>>>-      print_prog_name = concat (print_prog_name, use_ld, NULL);
>>>>+      print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>>>
>>>In gcc.c you will probably have similar issues.
>>>
>>>>     }
>>>>       char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>>>       printf ("%s\n", (newname ? newname : print_prog_name));
>>>>diff --git a/gcc/opts.c b/gcc/opts.c
>>>>index 7affeb41a96..f50d365d517 100644
>>>>--- a/gcc/opts.c
>>>>+++ b/gcc/opts.c
>>>>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>>>       dc->max_errors = value;
>>>>       break;
>>>>-    case OPT_fuse_ld_bfd:
>>>>-    case OPT_fuse_ld_gold:
>>>>-    case OPT_fuse_ld_lld:
>>>>+    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;
>>>>
>>>
>

[-- Attachment #2: 0001-Add-fuse-ld-to-specify-an-arbitrary-executable-as-th.patch --]
[-- Type: text/x-diff, Size: 6173 bytes --]

From 72049b927b6cee8c3acb2d56b2a403d9f0946807 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Tue, 19 May 2020 12:21:26 -0700
Subject: [PATCH] Add -fuse-ld= to specify an arbitrary executable as the
 linker

The value can be either an absolute path or a relative path.
Unlike -fuse-ld={bfd,gold,lld}, -fuse-ld= does not add a prefix `ld.`

	PR driver/93645
	* common.opt (-fuse-ld=): Add -fuse-ld=.
	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
	* doc/invoke.texi: Document -fuse-ld=.
---
 gcc/ChangeLog       |  9 +++++++++
 gcc/collect2.c      | 34 ++++++++++++++++++++++------------
 gcc/common.opt      |  4 ++++
 gcc/doc/invoke.texi |  4 ++++
 gcc/opts.c          |  1 +
 5 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 703b6349516..19506bf0884 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2020-05-19  Fangrui Song  <maskray@google.com>
+
+	PR driver/93645
+	* common.opt (-fuse-ld=): Add -fuse-ld=.
+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
+	* gcc.c (driver_handle_option): Likewise.
+	* collect2.c (main): Likewise.
+	* doc/invoke.texi: Document -fuse-ld=.
+
 2020-05-19  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
 	* doc/sourcebuild.texi: Document new short_eq_int, ptr_eq_short,
diff --git a/gcc/collect2.c b/gcc/collect2.c
index f8a5ce45994..e04892cb91f 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -782,15 +782,16 @@ main (int argc, char **argv)
       USE_GOLD_LD,
       USE_BFD_LD,
       USE_LLD_LD,
+      USE_LD,
       USE_LD_MAX
     } selected_linker = USE_DEFAULT_LD;
-  static const char *const ld_suffixes[USE_LD_MAX] =
+  static const char *const ld_suffixes[USE_LD] =
     {
       "ld",
       PLUGIN_LD_SUFFIX,
       "ld.gold",
       "ld.bfd",
-      "ld.lld"
+      "ld.lld",
     };
   static const char *const real_ld_suffix = "real-ld";
   static const char *const collect_ld_suffix = "collect-ld";
@@ -802,7 +803,7 @@ 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];
+  const char *full_ld_suffixes[USE_LD];
 #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.
@@ -844,6 +845,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *use_ld = NULL;
 
   /* 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
@@ -868,7 +870,7 @@ main (int argc, char **argv)
 #endif
   int i;
 
-  for (i = 0; i < USE_LD_MAX; i++)
+  for (i = 0; i < USE_LD; i++)
     full_ld_suffixes[i]
 #ifdef CROSS_DIRECTORY_STRUCTURE
       = concat (target_machine, "-", ld_suffixes[i], NULL);
@@ -967,6 +969,11 @@ main (int argc, char **argv)
 	  selected_linker = USE_GOLD_LD;
 	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
 	  selected_linker = USE_LLD_LD;
+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
+	  {
+	    use_ld = argv[i] + 9;
+	    selected_linker = USE_LD;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1119,12 +1126,16 @@ 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, ld_suffixes[selected_linker], X_OK);
-  /* 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, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker == USE_LD) {
+    ld_file_name = find_a_file (&cpath, use_ld, X_OK);
+  } else {
+    if (ld_file_name == 0)
+      ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
+    /* 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, full_ld_suffixes[selected_linker], X_OK);
+  }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
@@ -1296,8 +1307,7 @@ main (int argc, char **argv)
 			 "configuration");
 #endif
 		}
-	      else if (!use_collect_ld
-		       && strncmp (arg, "-fuse-ld=", 9) == 0)
+	      else if (strncmp (arg, "-fuse-ld=", 9) == 0)
 		{
 		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
 		  ld1--;
diff --git a/gcc/common.opt b/gcc/common.opt
index 4464049fc1f..6408d042d8c 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2908,6 +2908,10 @@ fuse-ld=lld
 Common Driver Negative(fuse-ld=lld)
 Use the lld LLVM linker instead of the default linker.
 
+fuse-ld=
+Common Driver Joined
+Use the specified executable instead of the default linker.
+
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7217e27151d..30a2fc4fa53 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14304,6 +14304,10 @@ Use the @command{gold} linker instead of the default linker.
 @opindex fuse-ld=lld
 Use the LLVM @command{lld} linker instead of the default linker.
 
+@item -fuse-ld=@var{linker}
+@opindex fuse-ld=linker
+Use the specified executable named @var{linker} instead of the default linker.
+
 @cindex Libraries
 @item -l@var{library}
 @itemx -l @var{library}
diff --git a/gcc/opts.c b/gcc/opts.c
index ec3ca0720f9..522a196ab0f 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2785,6 +2785,7 @@ common_handle_option (struct gcc_options *opts,
     case OPT_fuse_ld_bfd:
     case OPT_fuse_ld_gold:
     case OPT_fuse_ld_lld:
+    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;
-- 
2.26.2.761.g0e0b3e54be-goog


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-05-19 19:21       ` [PATCH] Add -fuse-ld= to specify an arbitrary executable as the linker Fangrui Song
@ 2020-05-20 13:45         ` Martin Liška
  2020-05-20 23:52           ` [PATCH v2] " Fangrui Song
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-05-20 13:45 UTC (permalink / raw)
  To: Fangrui Song; +Cc: gcc-patches

Hello.
  
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index f8a5ce45994..e04892cb91f 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -782,15 +782,16 @@ main (int argc, char **argv)
>        USE_GOLD_LD,
>        USE_BFD_LD,
>        USE_LLD_LD,
> +      USE_LD,

I wouldn't add a new constant.

>        USE_LD_MAX
>      } selected_linker = USE_DEFAULT_LD;
> -  static const char *const ld_suffixes[USE_LD_MAX] =
> +  static const char *const ld_suffixes[USE_LD] =
>      {
>        "ld",
>        PLUGIN_LD_SUFFIX,
>        "ld.gold",
>        "ld.bfd",
> -      "ld.lld"
> +      "ld.lld",

Not needed change.

>      };
>    static const char *const real_ld_suffix = "real-ld";
>    static const char *const collect_ld_suffix = "collect-ld";
> @@ -802,7 +803,7 @@ 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];
> +  const char *full_ld_suffixes[USE_LD];
>  #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.
> @@ -844,6 +845,7 @@ main (int argc, char **argv)
>    const char **ld1;
>    bool use_plugin = false;
>    bool use_collect_ld = false;
> +  const char *use_ld = NULL;
>  
>    /* 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
> @@ -868,7 +870,7 @@ main (int argc, char **argv)
>  #endif
>    int i;
>  
> -  for (i = 0; i < USE_LD_MAX; i++)
> +  for (i = 0; i < USE_LD; i++)
>      full_ld_suffixes[i]
>  #ifdef CROSS_DIRECTORY_STRUCTURE
>        = concat (target_machine, "-", ld_suffixes[i], NULL);
> @@ -967,6 +969,11 @@ main (int argc, char **argv)
>  	  selected_linker = USE_GOLD_LD;
>  	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>  	  selected_linker = USE_LLD_LD;
> +	else if (!strncmp (argv[i], "-fuse-ld=", 9))
> +	  {
> +	    use_ld = argv[i] + 9;
> +	    selected_linker = USE_LD;

Here you can selected_linker = USE_LD_MAX.

> +	  }
>  	else if (strncmp (argv[i], "-o", 2) == 0)
>  	  {
>  	    /* Parse the output filename if it's given so that we can make
> @@ -1119,12 +1126,16 @@ 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, ld_suffixes[selected_linker], X_OK);
> -  /* 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, full_ld_suffixes[selected_linker], X_OK);

Here you can check either for selected_linker == USE_LD_MAX or for use_ld != NULL.

> +  if (selected_linker == USE_LD) {
> +    ld_file_name = find_a_file (&cpath, use_ld, X_OK);
> +  } else {

Bad coding style (braces should be at a separate line) and you don't need the {} here.

> +    if (ld_file_name == 0)
> +      ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
> +    /* 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, full_ld_suffixes[selected_linker], X_OK);
> +  }
>  
>  #ifdef REAL_NM_FILE_NAME
>    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
> @@ -1296,8 +1307,7 @@ main (int argc, char **argv)
>  			 "configuration");
>  #endif
>  		}
> -	      else if (!use_collect_ld
> -		       && strncmp (arg, "-fuse-ld=", 9) == 0)
> +	      else if (strncmp (arg, "-fuse-ld=", 9) == 0)

Why did you change this logic here? Note that it also affects e.g. -fuse-ld=gold here.

Martin

>  		{
>  		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
>  		  ld1--;
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 4464049fc1f..6408d042d8c 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2908,6 +2908,10 @@ fuse-ld=lld
>  Common Driver Negative(fuse-ld=lld)
>  Use the lld LLVM linker instead of the default linker.
>  
> +fuse-ld=
> +Common Driver Joined
> +Use the specified executable instead of the default linker.
> +
>  fuse-linker-plugin
>  Common Undocumented Var(flag_use_linker_plugin)
>  
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 7217e27151d..30a2fc4fa53 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -14304,6 +14304,10 @@ Use the @command{gold} linker instead of the default linker.
>  @opindex fuse-ld=lld
>  Use the LLVM @command{lld} linker instead of the default linker.
>  
> +@item -fuse-ld=@var{linker}
> +@opindex fuse-ld=linker
> +Use the specified executable named @var{linker} instead of the default linker.
> +
>  @cindex Libraries
>  @item -l@var{library}
>  @itemx -l @var{library}
> diff --git a/gcc/opts.c b/gcc/opts.c
> index ec3ca0720f9..522a196ab0f 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -2785,6 +2785,7 @@ common_handle_option (struct gcc_options *opts,
>      case OPT_fuse_ld_bfd:
>      case OPT_fuse_ld_gold:
>      case OPT_fuse_ld_lld:
> +    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;


  #ifdef REAL_NM_FILE_NAME
    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
@@ -1296,8 +1307,7 @@ main (int argc, char **argv)
  			 "configuration");
  #endif
  		}
-	      else if (!use_collect_ld
-		       && strncmp (arg, "-fuse-ld=", 9) == 0)
+	      else if (strncmp (arg, "-fuse-ld=", 9) == 0)
  		{
  		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
  		  ld1--;
diff --git a/gcc/common.opt b/gcc/common.opt
index 4464049fc1f..6408d042d8c 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2908,6 +2908,10 @@ fuse-ld=lld
  Common Driver Negative(fuse-ld=lld)
  Use the lld LLVM linker instead of the default linker.
  
+fuse-ld=
+Common Driver Joined
+Use the specified executable instead of the default linker.
+
  fuse-linker-plugin
  Common Undocumented Var(flag_use_linker_plugin)
  
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7217e27151d..30a2fc4fa53 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14304,6 +14304,10 @@ Use the @command{gold} linker instead of the default linker.
  @opindex fuse-ld=lld
  Use the LLVM @command{lld} linker instead of the default linker.
  
+@item -fuse-ld=@var{linker}
+@opindex fuse-ld=linker
+Use the specified executable named @var{linker} instead of the default linker.
+
  @cindex Libraries
  @item -l@var{library}
  @itemx -l @var{library}
diff --git a/gcc/opts.c b/gcc/opts.c
index ec3ca0720f9..522a196ab0f 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2785,6 +2785,7 @@ common_handle_option (struct gcc_options *opts,
      case OPT_fuse_ld_bfd:
      case OPT_fuse_ld_gold:
      case OPT_fuse_ld_lld:
+    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;


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v2] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-05-20 13:45         ` Martin Liška
@ 2020-05-20 23:52           ` Fangrui Song
  2020-05-21  8:43             ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2020-05-20 23:52 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 8034 bytes --]

On 2020-05-20, Martin Liška wrote:
>Hello.

Thanks for review. Sent PATCH v2.

>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>index f8a5ce45994..e04892cb91f 100644
>>--- a/gcc/collect2.c
>>+++ b/gcc/collect2.c
>>@@ -782,15 +782,16 @@ main (int argc, char **argv)
>>       USE_GOLD_LD,
>>       USE_BFD_LD,
>>       USE_LLD_LD,
>>+      USE_LD,
>
>I wouldn't add a new constant.
>
>>       USE_LD_MAX
>>     } selected_linker = USE_DEFAULT_LD;
>>-  static const char *const ld_suffixes[USE_LD_MAX] =
>>+  static const char *const ld_suffixes[USE_LD] =
>>     {
>>       "ld",
>>       PLUGIN_LD_SUFFIX,
>>       "ld.gold",
>>       "ld.bfd",
>>-      "ld.lld"
>>+      "ld.lld",
>
>Not needed change.
>
>>     };
>>   static const char *const real_ld_suffix = "real-ld";
>>   static const char *const collect_ld_suffix = "collect-ld";
>>@@ -802,7 +803,7 @@ 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];
>>+  const char *full_ld_suffixes[USE_LD];
>> #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.
>>@@ -844,6 +845,7 @@ main (int argc, char **argv)
>>   const char **ld1;
>>   bool use_plugin = false;
>>   bool use_collect_ld = false;
>>+  const char *use_ld = NULL;
>>   /* 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
>>@@ -868,7 +870,7 @@ main (int argc, char **argv)
>> #endif
>>   int i;
>>-  for (i = 0; i < USE_LD_MAX; i++)
>>+  for (i = 0; i < USE_LD; i++)
>>     full_ld_suffixes[i]
>> #ifdef CROSS_DIRECTORY_STRUCTURE
>>       = concat (target_machine, "-", ld_suffixes[i], NULL);
>>@@ -967,6 +969,11 @@ main (int argc, char **argv)
>> 	  selected_linker = USE_GOLD_LD;
>> 	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>> 	  selected_linker = USE_LLD_LD;
>>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>+	  {
>>+	    use_ld = argv[i] + 9;
>>+	    selected_linker = USE_LD;
>
>Here you can selected_linker = USE_LD_MAX.
>
>>+	  }
>> 	else if (strncmp (argv[i], "-o", 2) == 0)
>> 	  {
>> 	    /* Parse the output filename if it's given so that we can make
>>@@ -1119,12 +1126,16 @@ 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, ld_suffixes[selected_linker], X_OK);
>>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>
>Here you can check either for selected_linker == USE_LD_MAX or for use_ld != NULL.

v2 changes to use `path` (PATH) instead. It probably makes more sense.
-fuse-ld=ld.lld -> find a program named ld.lld in PATH.
find_a_file with cpath can unlikely return a result.

Additionally, full_ld_suffixes[selected_linker] does not make sense for
a non-BFD-non-gold linker. (So the existing behavior regarding
-fuse-ld=lld may be strange. I don't intend to change the behavior, though).

>>+  if (selected_linker == USE_LD) {
>>+    ld_file_name = find_a_file (&cpath, use_ld, X_OK);
>>+  } else {
>
>Bad coding style (braces should be at a separate line) and you don't need the {} here.
>
>>+    if (ld_file_name == 0)
>>+      ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>>+    /* 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, full_ld_suffixes[selected_linker], X_OK);
>>+  }
>> #ifdef REAL_NM_FILE_NAME
>>   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>@@ -1296,8 +1307,7 @@ main (int argc, char **argv)
>> 			 "configuration");
>> #endif
>> 		}
>>-	      else if (!use_collect_ld
>>-		       && strncmp (arg, "-fuse-ld=", 9) == 0)
>>+	      else if (strncmp (arg, "-fuse-ld=", 9) == 0)
>
>Why did you change this logic here? Note that it also affects e.g. -fuse-ld=gold here.
>
>Martin

Thanks. I noted that the program Debug/gcc/collect-ld is not updated for
-fuse-ld=lld. configure.ac has a problem that if my ld in PATH is
actually /usr/local/bin/ld -> lld, 

ORIGINAL_LD_BFD_FOR_TARGET
and
ORIGINAL_LD_GOLD_FOR_TARGET

can point to non-existent /usr/local/bin/ld.{bfd,gold}

The above issues motivated me to touch this line in PATCH v2.
Dropped in PATCH v2.

>> 		{
>> 		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
>> 		  ld1--;
>>diff --git a/gcc/common.opt b/gcc/common.opt
>>index 4464049fc1f..6408d042d8c 100644
>>--- a/gcc/common.opt
>>+++ b/gcc/common.opt
>>@@ -2908,6 +2908,10 @@ fuse-ld=lld
>> Common Driver Negative(fuse-ld=lld)
>> Use the lld LLVM linker instead of the default linker.
>>+fuse-ld=
>>+Common Driver Joined
>>+Use the specified executable instead of the default linker.
>>+
>> fuse-linker-plugin
>> Common Undocumented Var(flag_use_linker_plugin)
>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>index 7217e27151d..30a2fc4fa53 100644
>>--- a/gcc/doc/invoke.texi
>>+++ b/gcc/doc/invoke.texi
>>@@ -14304,6 +14304,10 @@ Use the @command{gold} linker instead of the default linker.
>> @opindex fuse-ld=lld
>> Use the LLVM @command{lld} linker instead of the default linker.
>>+@item -fuse-ld=@var{linker}
>>+@opindex fuse-ld=linker
>>+Use the specified executable named @var{linker} instead of the default linker.
>>+
>> @cindex Libraries
>> @item -l@var{library}
>> @itemx -l @var{library}
>>diff --git a/gcc/opts.c b/gcc/opts.c
>>index ec3ca0720f9..522a196ab0f 100644
>>--- a/gcc/opts.c
>>+++ b/gcc/opts.c
>>@@ -2785,6 +2785,7 @@ common_handle_option (struct gcc_options *opts,
>>     case OPT_fuse_ld_bfd:
>>     case OPT_fuse_ld_gold:
>>     case OPT_fuse_ld_lld:
>>+    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;
>
>
> #ifdef REAL_NM_FILE_NAME
>   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>@@ -1296,8 +1307,7 @@ main (int argc, char **argv)
> 			 "configuration");
> #endif
> 		}
>-	      else if (!use_collect_ld
>-		       && strncmp (arg, "-fuse-ld=", 9) == 0)
>+	      else if (strncmp (arg, "-fuse-ld=", 9) == 0)
> 		{
> 		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
> 		  ld1--;
>diff --git a/gcc/common.opt b/gcc/common.opt
>index 4464049fc1f..6408d042d8c 100644
>--- a/gcc/common.opt
>+++ b/gcc/common.opt
>@@ -2908,6 +2908,10 @@ fuse-ld=lld
> Common Driver Negative(fuse-ld=lld)
> Use the lld LLVM linker instead of the default linker.
>+fuse-ld=
>+Common Driver Joined
>+Use the specified executable instead of the default linker.
>+
> fuse-linker-plugin
> Common Undocumented Var(flag_use_linker_plugin)
>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>index 7217e27151d..30a2fc4fa53 100644
>--- a/gcc/doc/invoke.texi
>+++ b/gcc/doc/invoke.texi
>@@ -14304,6 +14304,10 @@ Use the @command{gold} linker instead of the default linker.
> @opindex fuse-ld=lld
> Use the LLVM @command{lld} linker instead of the default linker.
>+@item -fuse-ld=@var{linker}
>+@opindex fuse-ld=linker
>+Use the specified executable named @var{linker} instead of the default linker.
>+
> @cindex Libraries
> @item -l@var{library}
> @itemx -l @var{library}
>diff --git a/gcc/opts.c b/gcc/opts.c
>index ec3ca0720f9..522a196ab0f 100644
>--- a/gcc/opts.c
>+++ b/gcc/opts.c
>@@ -2785,6 +2785,7 @@ common_handle_option (struct gcc_options *opts,
>     case OPT_fuse_ld_bfd:
>     case OPT_fuse_ld_gold:
>     case OPT_fuse_ld_lld:
>+    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;
>

[-- Attachment #2: 0001-Add-fuse-ld-to-specify-an-arbitrary-executable-as-th.patch --]
[-- Type: text/x-diff, Size: 4381 bytes --]

From 4050d91468ba2b358037818f8d5945bdd643e112 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Tue, 19 May 2020 12:21:26 -0700
Subject: [PATCH] Add -fuse-ld= to specify an arbitrary executable as the
 linker

The value can be either a relative path (relative to a PATH directory)
or an absolute path.  Unlike -fuse-ld={bfd,gold,lld}, -fuse-ld= does not
add a prefix `ld.`

	PR driver/93645
	* common.opt (-fuse-ld=): Add -fuse-ld=.
	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
	* doc/invoke.texi: Document -fuse-ld=.
---
 gcc/collect2.c      | 30 ++++++++++++++++++++++--------
 gcc/common.opt      |  4 ++++
 gcc/doc/invoke.texi |  4 ++++
 gcc/opts.c          |  1 +
 4 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index f8a5ce45994..707cd2581e9 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -844,6 +844,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *use_ld = NULL;
 
   /* 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
@@ -967,6 +968,11 @@ main (int argc, char **argv)
 	  selected_linker = USE_GOLD_LD;
 	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
 	  selected_linker = USE_LLD_LD;
+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
+	  {
+	    use_ld = argv[i] + 9;
+	    selected_linker = USE_LD_MAX;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1117,14 +1123,22 @@ main (int argc, char **argv)
       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
       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, ld_suffixes[selected_linker], X_OK);
-  /* 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, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker == USE_LD_MAX)
+    {
+      ld_file_name = find_a_file (&path, use_ld, X_OK);
+    }
+  else
+    {
+      /* 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, ld_suffixes[selected_linker], X_OK);
+      /* 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, full_ld_suffixes[selected_linker], X_OK);
+  }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
diff --git a/gcc/common.opt b/gcc/common.opt
index 4464049fc1f..6408d042d8c 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2908,6 +2908,10 @@ fuse-ld=lld
 Common Driver Negative(fuse-ld=lld)
 Use the lld LLVM linker instead of the default linker.
 
+fuse-ld=
+Common Driver Joined
+Use the specified executable instead of the default linker.
+
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7217e27151d..30a2fc4fa53 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14304,6 +14304,10 @@ Use the @command{gold} linker instead of the default linker.
 @opindex fuse-ld=lld
 Use the LLVM @command{lld} linker instead of the default linker.
 
+@item -fuse-ld=@var{linker}
+@opindex fuse-ld=linker
+Use the specified executable named @var{linker} instead of the default linker.
+
 @cindex Libraries
 @item -l@var{library}
 @itemx -l @var{library}
diff --git a/gcc/opts.c b/gcc/opts.c
index ec3ca0720f9..522a196ab0f 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2785,6 +2785,7 @@ common_handle_option (struct gcc_options *opts,
     case OPT_fuse_ld_bfd:
     case OPT_fuse_ld_gold:
     case OPT_fuse_ld_lld:
+    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;
-- 
2.26.2.761.g0e0b3e54be-goog


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-05-20 23:52           ` [PATCH v2] " Fangrui Song
@ 2020-05-21  8:43             ` Martin Liška
  2020-05-22  4:42               ` [PATCH v3] " Fangrui Song
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-05-21  8:43 UTC (permalink / raw)
  To: Fangrui Song; +Cc: gcc-patches

On 5/21/20 1:52 AM, Fangrui Song wrote:
> The above issues motivated me to touch this line in PATCH v2.
> Dropped in PATCH v2.

Thank you for the updated patch.
The patch is fine except coding style issues:

$ ./contrib/check_GNU_style.py /tmp/0001-Add-fuse-ld-to-specify-an-arbitrary-executable-as-th.patch
=== ERROR type #1: blocks of 8 spaces should be replaced with tabs (4 error(s)) ===
gcc/collect2.c:1135:0:████████ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
gcc/collect2.c:1137:0:████████ for `ld' (if native linking) or `TARGET-ld' (if cross).  */
gcc/collect2.c:1139:0:████████ld_file_name =
gcc/collect2.c:1140:0:████████    find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);

=== ERROR type #2: there should be exactly one space between function name and parenthesis (2 error(s)) ===
gcc/collect2.c:1135:34:        ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
gcc/collect2.c:1140:23:            find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);

=== ERROR type #3: trailing operator (1 error(s)) ===
gcc/collect2.c:1139:21:        ld_file_name =

Note that I can't approve the patch, please wait for a reviewer that can approve it.

Martin

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v3] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-05-21  8:43             ` Martin Liška
@ 2020-05-22  4:42               ` Fangrui Song
  2020-05-25  9:57                 ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2020-05-22  4:42 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1685 bytes --]

On 2020-05-21, Martin Liška wrote:
>On 5/21/20 1:52 AM, Fangrui Song wrote:
>>The above issues motivated me to touch this line in PATCH v2.
>>Dropped in PATCH v2.
>
>Thank you for the updated patch.
>The patch is fine except coding style issues:
>
>$ ./contrib/check_GNU_style.py /tmp/0001-Add-fuse-ld-to-specify-an-arbitrary-executable-as-th.patch
>=== ERROR type #1: blocks of 8 spaces should be replaced with tabs (4 error(s)) ===
>gcc/collect2.c:1135:0:████████ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>gcc/collect2.c:1137:0:████████ for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>gcc/collect2.c:1139:0:████████ld_file_name =
>gcc/collect2.c:1140:0:████████    find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>
>=== ERROR type #2: there should be exactly one space between function name and parenthesis (2 error(s)) ===
>gcc/collect2.c:1135:34:        ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>gcc/collect2.c:1140:23:            find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);

Thank you. I did not know ./contrib/check_GNU_style.py

PATCH v3 fixes the above style issues and checks both cpath and path
which appears to make more sense (and compatible with clang).

>=== ERROR type #3: trailing operator (1 error(s)) ===
>gcc/collect2.c:1139:21:        ld_file_name =

but I can't fix this one because joining two lines will break the 80-column rule.
>
>Note that I can't approve the patch, please wait for a reviewer that can approve it.
>
>Martin

I'll wait for a reviewer to approve and apply it.

[-- Attachment #2: 0001-Add-fuse-ld-to-specify-an-arbitrary-executable-as-th.patch --]
[-- Type: text/x-diff, Size: 4473 bytes --]

From 1fea80498891db3fef831bd65f231603951e5f14 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Tue, 19 May 2020 12:21:26 -0700
Subject: [PATCH] Add -fuse-ld= to specify an arbitrary executable as the
 linker

The value can be either a relative path (relative to a COMPILER_PATH
directory or a PATH directory) or an absolute path.  Unlike
-fuse-ld={bfd,gold,lld}, -fuse-ld= does not add a prefix `ld.`

	PR driver/93645
	* common.opt (-fuse-ld=): Add -fuse-ld=.
	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
	* doc/invoke.texi: Document -fuse-ld=.
---
 gcc/collect2.c      | 32 ++++++++++++++++++++++++--------
 gcc/common.opt      |  4 ++++
 gcc/doc/invoke.texi |  4 ++++
 gcc/opts.c          |  1 +
 4 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index f8a5ce45994..cc57a20e08b 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -844,6 +844,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *use_ld = NULL;
 
   /* 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
@@ -967,6 +968,11 @@ main (int argc, char **argv)
 	  selected_linker = USE_GOLD_LD;
 	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
 	  selected_linker = USE_LLD_LD;
+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
+	  {
+	    use_ld = argv[i] + 9;
+	    selected_linker = USE_LD_MAX;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1117,14 +1123,24 @@ main (int argc, char **argv)
       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
       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, ld_suffixes[selected_linker], X_OK);
-  /* 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, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker == USE_LD_MAX)
+    {
+      ld_file_name = find_a_file (&cpath, use_ld, X_OK);
+      if (ld_file_name == 0)
+	ld_file_name = find_a_file (&path, use_ld, X_OK);
+    }
+  else
+    {
+      /* 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, ld_suffixes[selected_linker], X_OK);
+      /* 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, full_ld_suffixes[selected_linker], X_OK);
+    }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
diff --git a/gcc/common.opt b/gcc/common.opt
index 4464049fc1f..6408d042d8c 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2908,6 +2908,10 @@ fuse-ld=lld
 Common Driver Negative(fuse-ld=lld)
 Use the lld LLVM linker instead of the default linker.
 
+fuse-ld=
+Common Driver Joined
+Use the specified executable instead of the default linker.
+
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7217e27151d..30a2fc4fa53 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14304,6 +14304,10 @@ Use the @command{gold} linker instead of the default linker.
 @opindex fuse-ld=lld
 Use the LLVM @command{lld} linker instead of the default linker.
 
+@item -fuse-ld=@var{linker}
+@opindex fuse-ld=linker
+Use the specified executable named @var{linker} instead of the default linker.
+
 @cindex Libraries
 @item -l@var{library}
 @itemx -l @var{library}
diff --git a/gcc/opts.c b/gcc/opts.c
index ec3ca0720f9..522a196ab0f 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2785,6 +2785,7 @@ common_handle_option (struct gcc_options *opts,
     case OPT_fuse_ld_bfd:
     case OPT_fuse_ld_gold:
     case OPT_fuse_ld_lld:
+    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;
-- 
2.27.0.rc0.183.gde8f92d652-goog


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-05-22  4:42               ` [PATCH v3] " Fangrui Song
@ 2020-05-25  9:57                 ` Martin Liška
  2020-05-29  1:10                   ` Fangrui Song
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-05-25  9:57 UTC (permalink / raw)
  To: Fangrui Song; +Cc: gcc-patches

On 5/22/20 6:42 AM, Fangrui Song wrote:
> but I can't fix this one because joining two lines will break the 80-column rule.

What about this:

diff --git a/gcc/collect2.c b/gcc/collect2.c
index cc57a20e08b..e5b54b080f7 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -1138,8 +1138,8 @@ main (int argc, char **argv)
        /* 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, full_ld_suffixes[selected_linker], X_OK);
+	ld_file_name
+	  = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
      }
  
  #ifdef REAL_NM_FILE_NAME

Apart from that, the patch is fine.

Martin

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-05-25  9:57                 ` Martin Liška
@ 2020-05-29  1:10                   ` Fangrui Song
  2020-06-30 12:51                     ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2020-05-29  1:10 UTC (permalink / raw)
  To: Martin Liška, jakub, rguenther; +Cc: gcc-patches

On 2020-05-25, Martin Liška wrote:
>On 5/22/20 6:42 AM, Fangrui Song wrote:
>>but I can't fix this one because joining two lines will break the 80-column rule.
>
>What about this:
>
>diff --git a/gcc/collect2.c b/gcc/collect2.c
>index cc57a20e08b..e5b54b080f7 100644
>--- a/gcc/collect2.c
>+++ b/gcc/collect2.c
>@@ -1138,8 +1138,8 @@ main (int argc, char **argv)
>       /* 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, full_ld_suffixes[selected_linker], X_OK);
>+	ld_file_name
>+	  = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>     }
> #ifdef REAL_NM_FILE_NAME
>
>Apart from that, the patch is fine.
>
>Martin

Adding people who may be able to approve and commit on my behalf.

This formatting issue seems small enough. Hopefully a maintainer can do
it for me.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-05-29  1:10                   ` Fangrui Song
@ 2020-06-30 12:51                     ` Martin Liška
  2020-06-30 15:32                       ` Fāng-ruì Sòng
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-06-30 12:51 UTC (permalink / raw)
  To: Fangrui Song, jakub, rguenther; +Cc: gcc-patches

PING^1

On 5/29/20 3:10 AM, Fangrui Song wrote:
> On 2020-05-25, Martin Liška wrote:
>> On 5/22/20 6:42 AM, Fangrui Song wrote:
>>> but I can't fix this one because joining two lines will break the 80-column rule.
>>
>> What about this:
>>
>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>> index cc57a20e08b..e5b54b080f7 100644
>> --- a/gcc/collect2.c
>> +++ b/gcc/collect2.c
>> @@ -1138,8 +1138,8 @@ main (int argc, char **argv)
>>       /* 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, full_ld_suffixes[selected_linker], X_OK);
>> +    ld_file_name
>> +      = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>>     }
>> #ifdef REAL_NM_FILE_NAME
>>
>> Apart from that, the patch is fine.
>>
>> Martin
> 
> Adding people who may be able to approve and commit on my behalf.
> 
> This formatting issue seems small enough. Hopefully a maintainer can do
> it for me.


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-06-30 12:51                     ` Martin Liška
@ 2020-06-30 15:32                       ` Fāng-ruì Sòng
  2020-07-01  7:13                         ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fāng-ruì Sòng @ 2020-06-30 15:32 UTC (permalink / raw)
  To: Martin Liška; +Cc: jakub, Richard Biener, GCC Patches

There is some concern about clang's -fuse-ld=path
http://lists.llvm.org/pipermail/cfe-dev/2020-June/065710.html and use
of COMPILER_PATH vs PATH.
Shall we introduce another option like -fld-path=path (PATH is used,
COMPILER_PATH is not used)?

On Tue, Jun 30, 2020 at 6:04 AM Martin Liška <mliska@suse.cz> wrote:
>
> PING^1
>
> On 5/29/20 3:10 AM, Fangrui Song wrote:
> > On 2020-05-25, Martin Liška wrote:
> >> On 5/22/20 6:42 AM, Fangrui Song wrote:
> >>> but I can't fix this one because joining two lines will break the 80-column rule.
> >>
> >> What about this:
> >>
> >> diff --git a/gcc/collect2.c b/gcc/collect2.c
> >> index cc57a20e08b..e5b54b080f7 100644
> >> --- a/gcc/collect2.c
> >> +++ b/gcc/collect2.c
> >> @@ -1138,8 +1138,8 @@ main (int argc, char **argv)
> >>       /* 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, full_ld_suffixes[selected_linker], X_OK);
> >> +    ld_file_name
> >> +      = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
> >>     }
> >> #ifdef REAL_NM_FILE_NAME
> >>
> >> Apart from that, the patch is fine.
> >>
> >> Martin
> >
> > Adding people who may be able to approve and commit on my behalf.
> >
> > This formatting issue seems small enough. Hopefully a maintainer can do
> > it for me.
>


-- 
宋方睿

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-06-30 15:32                       ` Fāng-ruì Sòng
@ 2020-07-01  7:13                         ` Martin Liška
  2020-07-02  4:59                           ` Fāng-ruì Sòng
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-07-01  7:13 UTC (permalink / raw)
  To: Fāng-ruì Sòng; +Cc: jakub, Richard Biener, GCC Patches

On 6/30/20 5:32 PM, Fāng-ruì Sòng wrote:
> There is some concern about clang's -fuse-ld=path
> http://lists.llvm.org/pipermail/cfe-dev/2020-June/065710.html and use
> of COMPILER_PATH vs PATH.
> Shall we introduce another option like -fld-path=path (PATH is used,
> COMPILER_PATH is not used)?

I would recommend first landing a patch to LLVM and then we can do
a corresponding change to GCC.

Martin

> 
> On Tue, Jun 30, 2020 at 6:04 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> PING^1
>>
>> On 5/29/20 3:10 AM, Fangrui Song wrote:
>>> On 2020-05-25, Martin Liška wrote:
>>>> On 5/22/20 6:42 AM, Fangrui Song wrote:
>>>>> but I can't fix this one because joining two lines will break the 80-column rule.
>>>>
>>>> What about this:
>>>>
>>>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>>>> index cc57a20e08b..e5b54b080f7 100644
>>>> --- a/gcc/collect2.c
>>>> +++ b/gcc/collect2.c
>>>> @@ -1138,8 +1138,8 @@ main (int argc, char **argv)
>>>>        /* 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, full_ld_suffixes[selected_linker], X_OK);
>>>> +    ld_file_name
>>>> +      = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>>>>      }
>>>> #ifdef REAL_NM_FILE_NAME
>>>>
>>>> Apart from that, the patch is fine.
>>>>
>>>> Martin
>>>
>>> Adding people who may be able to approve and commit on my behalf.
>>>
>>> This formatting issue seems small enough. Hopefully a maintainer can do
>>> it for me.
>>
> 
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add -fuse-ld= to specify an arbitrary executable as the linker
  2020-07-01  7:13                         ` Martin Liška
@ 2020-07-02  4:59                           ` Fāng-ruì Sòng
  2020-07-02 19:34                             ` [PATCH] Add -fld-path= " Fāng-ruì Sòng
  0 siblings, 1 reply; 44+ messages in thread
From: Fāng-ruì Sòng @ 2020-07-02  4:59 UTC (permalink / raw)
  To: Martin Liška; +Cc: jakub, Richard Biener, GCC Patches

On 2020-07-01, Martin Liška wrote:
>On 6/30/20 5:32 PM, Fāng-ruì Sòng wrote:
>>There is some concern about clang's -fuse-ld=path
>>http://lists.llvm.org/pipermail/cfe-dev/2020-June/065710.html and use
>>of COMPILER_PATH vs PATH.
>>Shall we introduce another option like -fld-path=path (PATH is used,
>>COMPILER_PATH is not used)?
>
>I would recommend first landing a patch to LLVM and then we can do
>a corresponding change to GCC.
>
>Martin

Thank a lot for you welcoming words! This is what I intend to add for clang: https://reviews.llvm.org/D83015

I'll create a GCC patch superseding this one later.

>>
>>On Tue, Jun 30, 2020 at 6:04 AM Martin Liška <mliska@suse.cz> wrote:
>>>
>>>PING^1
>>>
>>>On 5/29/20 3:10 AM, Fangrui Song wrote:
>>>>On 2020-05-25, Martin Liška wrote:
>>>>>On 5/22/20 6:42 AM, Fangrui Song wrote:
>>>>>>but I can't fix this one because joining two lines will break the 80-column rule.
>>>>>
>>>>>What about this:
>>>>>
>>>>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>>>>index cc57a20e08b..e5b54b080f7 100644
>>>>>--- a/gcc/collect2.c
>>>>>+++ b/gcc/collect2.c
>>>>>@@ -1138,8 +1138,8 @@ main (int argc, char **argv)
>>>>>       /* 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, full_ld_suffixes[selected_linker], X_OK);
>>>>>+    ld_file_name
>>>>>+      = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>>>>>     }
>>>>>#ifdef REAL_NM_FILE_NAME
>>>>>
>>>>>Apart from that, the patch is fine.
>>>>>
>>>>>Martin
>>>>
>>>>Adding people who may be able to approve and commit on my behalf.
>>>>
>>>>This formatting issue seems small enough. Hopefully a maintainer can do
>>>>it for me.
>>>
>>
>>
>

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH] Add -fld-path= to specify an arbitrary executable as the linker
  2020-07-02  4:59                           ` Fāng-ruì Sòng
@ 2020-07-02 19:34                             ` Fāng-ruì Sòng
  2020-07-03 13:06                               ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fāng-ruì Sòng @ 2020-07-02 19:34 UTC (permalink / raw)
  To: Martin Liška; +Cc: jakub, Richard Biener, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]

On 2020-07-01, Fāng-ruì Sòng wrote:
>On 2020-07-01, Martin Liška wrote:
>>On 6/30/20 5:32 PM, Fāng-ruì Sòng wrote:
>>>There is some concern about clang's -fuse-ld=path
>>>http://lists.llvm.org/pipermail/cfe-dev/2020-June/065710.html and use
>>>of COMPILER_PATH vs PATH.
>>>Shall we introduce another option like -fld-path=path (PATH is used,
>>>COMPILER_PATH is not used)?
>>
>>I would recommend first landing a patch to LLVM and then we can do
>>a corresponding change to GCC.
>>
>>Martin
>
>Thank a lot for you welcoming words! This is what I intend to add for clang: https://reviews.llvm.org/D83015
>
>I'll create a GCC patch superseding this one later.

Attached the new patch.

[-- Attachment #2: 0001-Add-fld-path-to-specify-an-arbitrary-executable-as-t.patch --]
[-- Type: text/x-diff, Size: 6460 bytes --]

From e7f86cdcaf03e4ddb98d0df9d07894d9ffb7d91a Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Thu, 2 Jul 2020 12:26:09 -0700
Subject: [PATCH] Add -fld-path= to specify an arbitrary executable as the
 linker

The value can be either a relative path (relative to a COMPILER_PATH
directory or a PATH directory) or an absolute path. -fld-path=
complements -fuse-ld={bfd,gold,lld} which specifies the linker flavor.

	PR driver/93645
	* common.opt (-fld-path=): Add -fld-path=
	* opts.c (common_handle_option): Handle OPT_fld_path_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
	* doc/invoke.texi: Document -fld-path=.
---
 gcc/collect2.c      | 57 ++++++++++++++++++++++++++++++++-------------
 gcc/common.opt      |  4 ++++
 gcc/doc/invoke.texi |  6 +++++
 gcc/gcc.c           |  2 +-
 gcc/opts.c          |  1 +
 5 files changed, 53 insertions(+), 17 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index f8a5ce45994..efa652f7f82 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -844,6 +844,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *ld_path = NULL;
 
   /* 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
@@ -961,12 +962,21 @@ main (int argc, char **argv)
 	    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;
-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
-	  selected_linker = USE_LLD_LD;
+	else if (strncmp (argv[i], "-fuse-ld=bfd", 9) == 0
+		 && selected_linker != USE_LD_MAX)
+	  {
+	    if (strcmp (argv[i] + 9, "bfd") == 0)
+	      selected_linker = USE_BFD_LD;
+	    else if (strcmp (argv[i] + 9, "gold") == 0)
+	      selected_linker = USE_GOLD_LD;
+	    else if (strcmp (argv[i] + 9, "lld") == 0)
+	      selected_linker = USE_LLD_LD;
+	  }
+	else if (strncmp (argv[i], "-fld-path=", 10) == 0)
+	  {
+	    ld_path = argv[i] + 10;
+	    selected_linker = USE_LD_MAX;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1117,14 +1127,27 @@ main (int argc, char **argv)
       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
       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, ld_suffixes[selected_linker], X_OK);
-  /* 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, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker == USE_LD_MAX)
+    {
+      /* If -fld-path= does not contain a slash, search for the command using
+	 the PATH environment variable.  */
+      if (lbasename (ld_path) == ld_path)
+	ld_file_name = find_a_file (&path, ld_path, X_OK);
+      else if (file_exists (ld_path))
+	ld_file_name = ld_path;
+    }
+  else
+    {
+      /* 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, ld_suffixes[selected_linker], X_OK);
+      /* 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, full_ld_suffixes[selected_linker], X_OK);
+    }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
@@ -1297,9 +1320,11 @@ main (int argc, char **argv)
 #endif
 		}
 	      else if (!use_collect_ld
-		       && strncmp (arg, "-fuse-ld=", 9) == 0)
+		       && (strncmp (arg, "-fuse-ld=", 9) == 0 ||
+			   strncmp (arg, "-fld-path=", 10) == 0))
 		{
-		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
+		  /* Do not pass -fuse-ld={bfd|gold|lld} or -fld-path= to the
+		     linker. */
 		  ld1--;
 		  ld2--;
 		}
diff --git a/gcc/common.opt b/gcc/common.opt
index df8af365d1b..d5dfbb5c9c6 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2919,6 +2919,10 @@ fuse-ld=lld
 Common Driver Negative(fuse-ld=lld)
 Use the lld LLVM linker instead of the default linker.
 
+fld-path=
+Common Driver Joined
+Use the specified executable instead of the default linker.
+
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e21d8a5217b..bfb6222f96b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14651,6 +14651,12 @@ Use the @command{gold} linker instead of the default linker.
 @opindex fuse-ld=lld
 Use the LLVM @command{lld} linker instead of the default linker.
 
+@item -fld-path=@var{linker}
+@opindex fld-path=linker
+Use the specified executable named @var{linker} instead of the default linker.
+If @var{linker} does not contain any slash character, the linker will be
+searched for using @env{PATH}.  This option overrides @option{-fuse-ld=}.
+
 @cindex Libraries
 @item -l@var{library}
 @itemx -l @var{library}
diff --git a/gcc/gcc.c b/gcc/gcc.c
index c0eb3c10cfd..a57a3d0aec4 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1077,7 +1077,7 @@ proper position among the other output files.  */
     LINK_PLUGIN_SPEC \
    "%{flto|flto=*:%<fcompare-debug*} \
     %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
-   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
+   "%{fuse-ld=*:-fuse-ld=%*} %{fld-path=*:-fld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
    "%X %{o*} %{e*} %{N} %{n} %{r}\
     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
     %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
diff --git a/gcc/opts.c b/gcc/opts.c
index 340d99434b3..c4507d53abc 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2750,6 +2750,7 @@ common_handle_option (struct gcc_options *opts,
     case OPT_fuse_ld_bfd:
     case OPT_fuse_ld_gold:
     case OPT_fuse_ld_lld:
+    case OPT_fld_path_:
     case OPT_fuse_linker_plugin:
       /* No-op. Used by the driver and passed to us because it starts with f.*/
       break;
-- 
2.27.0.383.g050319c2ae-goog


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Add -fld-path= to specify an arbitrary executable as the linker
  2020-07-02 19:34                             ` [PATCH] Add -fld-path= " Fāng-ruì Sòng
@ 2020-07-03 13:06                               ` Martin Liška
  2020-07-03 17:18                                 ` Fāng-ruì Sòng
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-07-03 13:06 UTC (permalink / raw)
  To: Fāng-ruì Sòng; +Cc: jakub, Richard Biener, GCC Patches

On 7/2/20 9:34 PM, Fāng-ruì Sòng wrote:
> On 2020-07-01, Fāng-ruì Sòng wrote:
>> On 2020-07-01, Martin Liška wrote:
>>> On 6/30/20 5:32 PM, Fāng-ruì Sòng wrote:
>>>> There is some concern about clang's -fuse-ld=path
>>>> http://lists.llvm.org/pipermail/cfe-dev/2020-June/065710.html and use
>>>> of COMPILER_PATH vs PATH.
>>>> Shall we introduce another option like -fld-path=path (PATH is used,
>>>> COMPILER_PATH is not used)?
>>>
>>> I would recommend first landing a patch to LLVM and then we can do
>>> a corresponding change to GCC.
>>>
>>> Martin
>>
>> Thank a lot for you welcoming words! This is what I intend to add for clang: https://reviews.llvm.org/D83015
>>
>> I'll create a GCC patch superseding this one later.
> 
> Attached the new patch.

Thank you for the update patch:

> From e7f86cdcaf03e4ddb98d0df9d07894d9ffb7d91a Mon Sep 17 00:00:00 2001
> From: Fangrui Song <maskray@google.com>
> Date: Thu, 2 Jul 2020 12:26:09 -0700
> Subject: [PATCH] Add -fld-path= to specify an arbitrary executable as the
>  linker
> 
> The value can be either a relative path (relative to a COMPILER_PATH
> directory or a PATH directory) or an absolute path. -fld-path=
> complements -fuse-ld={bfd,gold,lld} which specifies the linker flavor.
> 
> 	PR driver/93645
> 	* common.opt (-fld-path=): Add -fld-path=
> 	* opts.c (common_handle_option): Handle OPT_fld_path_.
> 	* gcc.c (driver_handle_option): Likewise.
> 	* collect2.c (main): Likewise.
> 	* doc/invoke.texi: Document -fld-path=.
> ---
>  gcc/collect2.c      | 57 ++++++++++++++++++++++++++++++++-------------
>  gcc/common.opt      |  4 ++++
>  gcc/doc/invoke.texi |  6 +++++
>  gcc/gcc.c           |  2 +-
>  gcc/opts.c          |  1 +
>  5 files changed, 53 insertions(+), 17 deletions(-)
> 
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index f8a5ce45994..efa652f7f82 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -844,6 +844,7 @@ main (int argc, char **argv)
>    const char **ld1;
>    bool use_plugin = false;
>    bool use_collect_ld = false;
> +  const char *ld_path = NULL;
>  
>    /* 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
> @@ -961,12 +962,21 @@ main (int argc, char **argv)
>  	    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;
> -	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
> -	  selected_linker = USE_LLD_LD;
> +	else if (strncmp (argv[i], "-fuse-ld=bfd", 9) == 0
> +		 && selected_linker != USE_LD_MAX)
> +	  {

This does not seem correct to me. You match -fuse-ld=bfd and then
test other option values in the following block.

> +	    if (strcmp (argv[i] + 9, "bfd") == 0)
> +	      selected_linker = USE_BFD_LD;
> +	    else if (strcmp (argv[i] + 9, "gold") == 0)
> +	      selected_linker = USE_GOLD_LD;
> +	    else if (strcmp (argv[i] + 9, "lld") == 0)
> +	      selected_linker = USE_LLD_LD;
> +	  }
> +	else if (strncmp (argv[i], "-fld-path=", 10) == 0)
> +	  {
> +	    ld_path = argv[i] + 10;
> +	    selected_linker = USE_LD_MAX;
> +	  }
>  	else if (strncmp (argv[i], "-o", 2) == 0)
>  	  {
>  	    /* Parse the output filename if it's given so that we can make
> @@ -1117,14 +1127,27 @@ main (int argc, char **argv)
>        ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>        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, ld_suffixes[selected_linker], X_OK);
> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
> +  if (selected_linker == USE_LD_MAX)
> +    {
> +      /* If -fld-path= does not contain a slash, search for the command using
> +	 the PATH environment variable.  */

We also support file systems like Windows where the comment about a slash will be misleading.
You can just mention relative vs. absolute path.

> +      if (lbasename (ld_path) == ld_path)

Does it really return the same pointer? Maybe strcmp can be needed?

> +	ld_file_name = find_a_file (&path, ld_path, X_OK);
> +      else if (file_exists (ld_path))
> +	ld_file_name = ld_path;
> +    }
> +  else
> +    {
> +      /* 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, ld_suffixes[selected_linker], X_OK);
> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
> +    }
>  
>  #ifdef REAL_NM_FILE_NAME
>    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
> @@ -1297,9 +1320,11 @@ main (int argc, char **argv)
>  #endif
>  		}
>  	      else if (!use_collect_ld
> -		       && strncmp (arg, "-fuse-ld=", 9) == 0)
> +		       && (strncmp (arg, "-fuse-ld=", 9) == 0 ||
> +			   strncmp (arg, "-fld-path=", 10) == 0))
>  		{
> -		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
> +		  /* Do not pass -fuse-ld={bfd|gold|lld} or -fld-path= to the
> +		     linker. */
>  		  ld1--;
>  		  ld2--;
>  		}
> diff --git a/gcc/common.opt b/gcc/common.opt
> index df8af365d1b..d5dfbb5c9c6 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2919,6 +2919,10 @@ fuse-ld=lld
>  Common Driver Negative(fuse-ld=lld)
>  Use the lld LLVM linker instead of the default linker.
>  
> +fld-path=
> +Common Driver Joined
> +Use the specified executable instead of the default linker.
> +
>  fuse-linker-plugin
>  Common Undocumented Var(flag_use_linker_plugin)
>  
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index e21d8a5217b..bfb6222f96b 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -14651,6 +14651,12 @@ Use the @command{gold} linker instead of the default linker.
>  @opindex fuse-ld=lld
>  Use the LLVM @command{lld} linker instead of the default linker.
>  
> +@item -fld-path=@var{linker}
> +@opindex fld-path=linker
> +Use the specified executable named @var{linker} instead of the default linker.
> +If @var{linker} does not contain any slash character, the linker will be
> +searched for using @env{PATH}.  This option overrides @option{-fuse-ld=}.

The slash comment applies here as well.

Martin

> +
>  @cindex Libraries
>  @item -l@var{library}
>  @itemx -l @var{library}
> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index c0eb3c10cfd..a57a3d0aec4 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>      LINK_PLUGIN_SPEC \
>     "%{flto|flto=*:%<fcompare-debug*} \
>      %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
> +   "%{fuse-ld=*:-fuse-ld=%*} %{fld-path=*:-fld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>     "%X %{o*} %{e*} %{N} %{n} %{r}\
>      %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>      %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 340d99434b3..c4507d53abc 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -2750,6 +2750,7 @@ common_handle_option (struct gcc_options *opts,
>      case OPT_fuse_ld_bfd:
>      case OPT_fuse_ld_gold:
>      case OPT_fuse_ld_lld:
> +    case OPT_fld_path_:
>      case OPT_fuse_linker_plugin:
>        /* No-op. Used by the driver and passed to us because it starts with f.*/
>        break;
> -- 
> 2.27.0.383.g050319c2ae-goog
> 

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Add -fld-path= to specify an arbitrary executable as the linker
  2020-07-03 13:06                               ` Martin Liška
@ 2020-07-03 17:18                                 ` Fāng-ruì Sòng
  2020-07-07 10:16                                   ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fāng-ruì Sòng @ 2020-07-03 17:18 UTC (permalink / raw)
  To: Martin Liška; +Cc: jakub, Richard Biener, GCC Patches


On 2020-07-03, Martin Liška wrote:
>On 7/2/20 9:34 PM, Fāng-ruì Sòng wrote:
>>On 2020-07-01, Fāng-ruì Sòng wrote:
>>>On 2020-07-01, Martin Liška wrote:
>>>>On 6/30/20 5:32 PM, Fāng-ruì Sòng wrote:
>>>>>There is some concern about clang's -fuse-ld=path
>>>>>http://lists.llvm.org/pipermail/cfe-dev/2020-June/065710.html and use
>>>>>of COMPILER_PATH vs PATH.
>>>>>Shall we introduce another option like -fld-path=path (PATH is used,
>>>>>COMPILER_PATH is not used)?
>>>>
>>>>I would recommend first landing a patch to LLVM and then we can do
>>>>a corresponding change to GCC.
>>>>
>>>>Martin
>>>
>>>Thank a lot for you welcoming words! This is what I intend to add for clang: https://reviews.llvm.org/D83015
>>>
>>>I'll create a GCC patch superseding this one later.
>>
>>Attached the new patch.
>
>Thank you for the update patch:
>
>From e7f86cdcaf03e4ddb98d0df9d07894d9ffb7d91a Mon Sep 17 00:00:00 2001
>>From: Fangrui Song <maskray@google.com>
>>Date: Thu, 2 Jul 2020 12:26:09 -0700
>>Subject: [PATCH] Add -fld-path= to specify an arbitrary executable as the
>> linker
>>
>>The value can be either a relative path (relative to a COMPILER_PATH
>>directory or a PATH directory) or an absolute path. -fld-path=
>>complements -fuse-ld={bfd,gold,lld} which specifies the linker flavor.
>>
>>	PR driver/93645
>>	* common.opt (-fld-path=): Add -fld-path=
>>	* opts.c (common_handle_option): Handle OPT_fld_path_.
>>	* gcc.c (driver_handle_option): Likewise.
>>	* collect2.c (main): Likewise.
>>	* doc/invoke.texi: Document -fld-path=.
>>---
>> gcc/collect2.c      | 57 ++++++++++++++++++++++++++++++++-------------
>> gcc/common.opt      |  4 ++++
>> gcc/doc/invoke.texi |  6 +++++
>> gcc/gcc.c           |  2 +-
>> gcc/opts.c          |  1 +
>> 5 files changed, 53 insertions(+), 17 deletions(-)
>>
>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>index f8a5ce45994..efa652f7f82 100644
>>--- a/gcc/collect2.c
>>+++ b/gcc/collect2.c
>>@@ -844,6 +844,7 @@ main (int argc, char **argv)
>>   const char **ld1;
>>   bool use_plugin = false;
>>   bool use_collect_ld = false;
>>+  const char *ld_path = NULL;
>>   /* 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
>>@@ -961,12 +962,21 @@ main (int argc, char **argv)
>> 	    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;
>>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>-	  selected_linker = USE_LLD_LD;
>>+	else if (strncmp (argv[i], "-fuse-ld=bfd", 9) == 0
>>+		 && selected_linker != USE_LD_MAX)
>>+	  {
>
>This does not seem correct to me. You match -fuse-ld=bfd and then
>test other option values in the following block.

This is correct but I probably should use:

- strncmp (argv[i], "-fuse-ld=bfd", 9) == 0
+ strncmp (argv[i], "-fuse-ld=", 9) == 0


>>+	    if (strcmp (argv[i] + 9, "bfd") == 0)
>>+	      selected_linker = USE_BFD_LD;
>>+	    else if (strcmp (argv[i] + 9, "gold") == 0)
>>+	      selected_linker = USE_GOLD_LD;
>>+	    else if (strcmp (argv[i] + 9, "lld") == 0)
>>+	      selected_linker = USE_LLD_LD;
>>+	  }
>>+	else if (strncmp (argv[i], "-fld-path=", 10) == 0)
>>+	  {
>>+	    ld_path = argv[i] + 10;
>>+	    selected_linker = USE_LD_MAX;
>>+	  }
>> 	else if (strncmp (argv[i], "-o", 2) == 0)
>> 	  {
>> 	    /* Parse the output filename if it's given so that we can make
>>@@ -1117,14 +1127,27 @@ main (int argc, char **argv)
>>       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>       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, ld_suffixes[selected_linker], X_OK);
>>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>+  if (selected_linker == USE_LD_MAX)
>>+    {
>>+      /* If -fld-path= does not contain a slash, search for the command using
>>+	 the PATH environment variable.  */
>
>We also support file systems like Windows where the comment about a slash will be misleading.
>You can just mention relative vs. absolute path.

The behavior is modeled after
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html Command Search and Execution

   e.  Otherwise, the command shall be searched for using the PATH environment variable as described in XBD Environment Variables :

is performed if "the command name does not contain any <slash> characters".

For your suggestion, I think 'word' can mean a relative path as well, along with 'rel\path' and 'rel/path'.

Should I say 

   If -fld-path= does not contain a path component separator (e.g. slash), search for the command using

?

>>+      if (lbasename (ld_path) == ld_path)
>
>Does it really return the same pointer? Maybe strcmp can be needed?

lbasename returns a const char * referencing a place of the string. 

lto-wrapper.s has a similar use case:

1542:  if (!dumppfx || lbasename (dumppfx) == dumppfx)

>>+	ld_file_name = find_a_file (&path, ld_path, X_OK);
>>+      else if (file_exists (ld_path))
>>+	ld_file_name = ld_path;
>>+    }
>>+  else
>>+    {
>>+      /* 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, ld_suffixes[selected_linker], X_OK);
>>+      /* 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, full_ld_suffixes[selected_linker], X_OK);
>>+    }
>> #ifdef REAL_NM_FILE_NAME
>>   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>@@ -1297,9 +1320,11 @@ main (int argc, char **argv)
>> #endif
>> 		}
>> 	      else if (!use_collect_ld
>>-		       && strncmp (arg, "-fuse-ld=", 9) == 0)
>>+		       && (strncmp (arg, "-fuse-ld=", 9) == 0 ||
>>+			   strncmp (arg, "-fld-path=", 10) == 0))
>> 		{
>>-		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
>>+		  /* Do not pass -fuse-ld={bfd|gold|lld} or -fld-path= to the
>>+		     linker. */
>> 		  ld1--;
>> 		  ld2--;
>> 		}
>>diff --git a/gcc/common.opt b/gcc/common.opt
>>index df8af365d1b..d5dfbb5c9c6 100644
>>--- a/gcc/common.opt
>>+++ b/gcc/common.opt
>>@@ -2919,6 +2919,10 @@ fuse-ld=lld
>> Common Driver Negative(fuse-ld=lld)
>> Use the lld LLVM linker instead of the default linker.
>>+fld-path=
>>+Common Driver Joined
>>+Use the specified executable instead of the default linker.
>>+
>> fuse-linker-plugin
>> Common Undocumented Var(flag_use_linker_plugin)
>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>index e21d8a5217b..bfb6222f96b 100644
>>--- a/gcc/doc/invoke.texi
>>+++ b/gcc/doc/invoke.texi
>>@@ -14651,6 +14651,12 @@ Use the @command{gold} linker instead of the default linker.
>> @opindex fuse-ld=lld
>> Use the LLVM @command{lld} linker instead of the default linker.
>>+@item -fld-path=@var{linker}
>>+@opindex fld-path=linker
>>+Use the specified executable named @var{linker} instead of the default linker.
>>+If @var{linker} does not contain any slash character, the linker will be
>>+searched for using @env{PATH}.  This option overrides @option{-fuse-ld=}.
>
>The slash comment applies here as well.
>
>Martin

Ack. Will update when I get a clarification regarding the previous comment.

>>+
>> @cindex Libraries
>> @item -l@var{library}
>> @itemx -l @var{library}
>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>index c0eb3c10cfd..a57a3d0aec4 100644
>>--- a/gcc/gcc.c
>>+++ b/gcc/gcc.c
>>@@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>>     LINK_PLUGIN_SPEC \
>>    "%{flto|flto=*:%<fcompare-debug*} \
>>     %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
>>-   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>+   "%{fuse-ld=*:-fuse-ld=%*} %{fld-path=*:-fld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>    "%X %{o*} %{e*} %{N} %{n} %{r}\
>>     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>>     %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
>>diff --git a/gcc/opts.c b/gcc/opts.c
>>index 340d99434b3..c4507d53abc 100644
>>--- a/gcc/opts.c
>>+++ b/gcc/opts.c
>>@@ -2750,6 +2750,7 @@ common_handle_option (struct gcc_options *opts,
>>     case OPT_fuse_ld_bfd:
>>     case OPT_fuse_ld_gold:
>>     case OPT_fuse_ld_lld:
>>+    case OPT_fld_path_:
>>     case OPT_fuse_linker_plugin:
>>       /* No-op. Used by the driver and passed to us because it starts with f.*/
>>       break;
>>-- 
>>2.27.0.383.g050319c2ae-goog
>>

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Add -fld-path= to specify an arbitrary executable as the linker
  2020-07-03 17:18                                 ` Fāng-ruì Sòng
@ 2020-07-07 10:16                                   ` Martin Liška
  2020-07-21  4:07                                     ` [PATCH v2] Add --ld-path= " Fangrui Song
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2020-07-07 10:16 UTC (permalink / raw)
  To: Fāng-ruì Sòng; +Cc: jakub, Richard Biener, GCC Patches

On 7/3/20 7:18 PM, Fāng-ruì Sòng wrote:
> 
> On 2020-07-03, Martin Liška wrote:
>> On 7/2/20 9:34 PM, Fāng-ruì Sòng wrote:
>>> On 2020-07-01, Fāng-ruì Sòng wrote:
>>>> On 2020-07-01, Martin Liška wrote:
>>>>> On 6/30/20 5:32 PM, Fāng-ruì Sòng wrote:
>>>>>> There is some concern about clang's -fuse-ld=path
>>>>>> http://lists.llvm.org/pipermail/cfe-dev/2020-June/065710.html and use
>>>>>> of COMPILER_PATH vs PATH.
>>>>>> Shall we introduce another option like -fld-path=path (PATH is used,
>>>>>> COMPILER_PATH is not used)?
>>>>>
>>>>> I would recommend first landing a patch to LLVM and then we can do
>>>>> a corresponding change to GCC.
>>>>>
>>>>> Martin
>>>>
>>>> Thank a lot for you welcoming words! This is what I intend to add for clang: https://reviews.llvm.org/D83015
>>>>
>>>> I'll create a GCC patch superseding this one later.
>>>
>>> Attached the new patch.
>>
>> Thank you for the update patch:
>>
>>> From e7f86cdcaf03e4ddb98d0df9d07894d9ffb7d91a Mon Sep 17 00:00:00 2001
>>> From: Fangrui Song <maskray@google.com>
>>> Date: Thu, 2 Jul 2020 12:26:09 -0700
>>> Subject: [PATCH] Add -fld-path= to specify an arbitrary executable as the
>>> linker
>>>
>>> The value can be either a relative path (relative to a COMPILER_PATH
>>> directory or a PATH directory) or an absolute path. -fld-path=
>>> complements -fuse-ld={bfd,gold,lld} which specifies the linker flavor.
>>>
>>>     PR driver/93645
>>>     * common.opt (-fld-path=): Add -fld-path=
>>>     * opts.c (common_handle_option): Handle OPT_fld_path_.
>>>     * gcc.c (driver_handle_option): Likewise.
>>>     * collect2.c (main): Likewise.
>>>     * doc/invoke.texi: Document -fld-path=.
>>> ---
>>> gcc/collect2.c      | 57 ++++++++++++++++++++++++++++++++-------------
>>> gcc/common.opt      |  4 ++++
>>> gcc/doc/invoke.texi |  6 +++++
>>> gcc/gcc.c           |  2 +-
>>> gcc/opts.c          |  1 +
>>> 5 files changed, 53 insertions(+), 17 deletions(-)
>>>
>>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>>> index f8a5ce45994..efa652f7f82 100644
>>> --- a/gcc/collect2.c
>>> +++ b/gcc/collect2.c
>>> @@ -844,6 +844,7 @@ main (int argc, char **argv)
>>>   const char **ld1;
>>>   bool use_plugin = false;
>>>   bool use_collect_ld = false;
>>> +  const char *ld_path = NULL;
>>>   /* 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
>>> @@ -961,12 +962,21 @@ main (int argc, char **argv)
>>>         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;
>>> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>> -      selected_linker = USE_LLD_LD;
>>> +    else if (strncmp (argv[i], "-fuse-ld=bfd", 9) == 0
>>> +         && selected_linker != USE_LD_MAX)
>>> +      {
>>
>> This does not seem correct to me. You match -fuse-ld=bfd and then
>> test other option values in the following block.
> 
> This is correct but I probably should use:
> 
> - strncmp (argv[i], "-fuse-ld=bfd", 9) == 0
> + strncmp (argv[i], "-fuse-ld=", 9) == 0

Yes, that would be much better.

> 
> 
>>> +        if (strcmp (argv[i] + 9, "bfd") == 0)
>>> +          selected_linker = USE_BFD_LD;
>>> +        else if (strcmp (argv[i] + 9, "gold") == 0)
>>> +          selected_linker = USE_GOLD_LD;
>>> +        else if (strcmp (argv[i] + 9, "lld") == 0)
>>> +          selected_linker = USE_LLD_LD;
>>> +      }
>>> +    else if (strncmp (argv[i], "-fld-path=", 10) == 0)
>>> +      {
>>> +        ld_path = argv[i] + 10;
>>> +        selected_linker = USE_LD_MAX;
>>> +      }
>>>     else if (strncmp (argv[i], "-o", 2) == 0)
>>>       {
>>>         /* Parse the output filename if it's given so that we can make
>>> @@ -1117,14 +1127,27 @@ main (int argc, char **argv)
>>>       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>>       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, ld_suffixes[selected_linker], X_OK);
>>> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>> +  if (selected_linker == USE_LD_MAX)
>>> +    {
>>> +      /* If -fld-path= does not contain a slash, search for the command using
>>> +     the PATH environment variable.  */
>>
>> We also support file systems like Windows where the comment about a slash will be misleading.
>> You can just mention relative vs. absolute path.
> 
> The behavior is modeled after
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html Command Search and Execution
> 
>    e.  Otherwise, the command shall be searched for using the PATH environment variable as described in XBD Environment Variables :
> 
> is performed if "the command name does not contain any <slash> characters".
> 
> For your suggestion, I think 'word' can mean a relative path as well, along with 'rel\path' and 'rel/path'.
> 
> Should I say
>    If -fld-path= does not contain a path component separator (e.g. slash), search for the command using
> 
> ?

Seems file to me.

> 
>>> +      if (lbasename (ld_path) == ld_path)
>>
>> Does it really return the same pointer? Maybe strcmp can be needed?
> 
> lbasename returns a const char * referencing a place of the string.
> lto-wrapper.s has a similar use case:

Fine then.

> 
> 1542:  if (!dumppfx || lbasename (dumppfx) == dumppfx)
> 
>>> +    ld_file_name = find_a_file (&path, ld_path, X_OK);
>>> +      else if (file_exists (ld_path))
>>> +    ld_file_name = ld_path;
>>> +    }
>>> +  else
>>> +    {
>>> +      /* 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, ld_suffixes[selected_linker], X_OK);
>>> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
>>> +    }
>>> #ifdef REAL_NM_FILE_NAME
>>>   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>> @@ -1297,9 +1320,11 @@ main (int argc, char **argv)
>>> #endif
>>>         }
>>>           else if (!use_collect_ld
>>> -               && strncmp (arg, "-fuse-ld=", 9) == 0)
>>> +               && (strncmp (arg, "-fuse-ld=", 9) == 0 ||
>>> +               strncmp (arg, "-fld-path=", 10) == 0))
>>>         {
>>> -          /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
>>> +          /* Do not pass -fuse-ld={bfd|gold|lld} or -fld-path= to the
>>> +             linker. */
>>>           ld1--;
>>>           ld2--;
>>>         }
>>> diff --git a/gcc/common.opt b/gcc/common.opt
>>> index df8af365d1b..d5dfbb5c9c6 100644
>>> --- a/gcc/common.opt
>>> +++ b/gcc/common.opt
>>> @@ -2919,6 +2919,10 @@ fuse-ld=lld
>>> Common Driver Negative(fuse-ld=lld)
>>> Use the lld LLVM linker instead of the default linker.
>>> +fld-path=
>>> +Common Driver Joined
>>> +Use the specified executable instead of the default linker.
>>> +
>>> fuse-linker-plugin
>>> Common Undocumented Var(flag_use_linker_plugin)
>>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>> index e21d8a5217b..bfb6222f96b 100644
>>> --- a/gcc/doc/invoke.texi
>>> +++ b/gcc/doc/invoke.texi
>>> @@ -14651,6 +14651,12 @@ Use the @command{gold} linker instead of the default linker.
>>> @opindex fuse-ld=lld
>>> Use the LLVM @command{lld} linker instead of the default linker.
>>> +@item -fld-path=@var{linker}
>>> +@opindex fld-path=linker
>>> +Use the specified executable named @var{linker} instead of the default linker.
>>> +If @var{linker} does not contain any slash character, the linker will be
>>> +searched for using @env{PATH}.  This option overrides @option{-fuse-ld=}.
>>
>> The slash comment applies here as well.
>>
>> Martin
> 
> Ack. Will update when I get a clarification regarding the previous comment.

Thanks,
Martin

> 
>>> +
>>> @cindex Libraries
>>> @item -l@var{library}
>>> @itemx -l @var{library}
>>> diff --git a/gcc/gcc.c b/gcc/gcc.c
>>> index c0eb3c10cfd..a57a3d0aec4 100644
>>> --- a/gcc/gcc.c
>>> +++ b/gcc/gcc.c
>>> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>>>     LINK_PLUGIN_SPEC \
>>>    "%{flto|flto=*:%<fcompare-debug*} \
>>>     %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
>>> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>> +   "%{fuse-ld=*:-fuse-ld=%*} %{fld-path=*:-fld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>>    "%X %{o*} %{e*} %{N} %{n} %{r}\
>>>     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>>>     %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
>>> diff --git a/gcc/opts.c b/gcc/opts.c
>>> index 340d99434b3..c4507d53abc 100644
>>> --- a/gcc/opts.c
>>> +++ b/gcc/opts.c
>>> @@ -2750,6 +2750,7 @@ common_handle_option (struct gcc_options *opts,
>>>     case OPT_fuse_ld_bfd:
>>>     case OPT_fuse_ld_gold:
>>>     case OPT_fuse_ld_lld:
>>> +    case OPT_fld_path_:
>>>     case OPT_fuse_linker_plugin:
>>>       /* No-op. Used by the driver and passed to us because it starts with f.*/
>>>       break;
>>> -- 
>>> 2.27.0.383.g050319c2ae-goog
>>>


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-07 10:16                                   ` Martin Liška
@ 2020-07-21  4:07                                     ` Fangrui Song
  2020-07-23 10:17                                       ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2020-07-21  4:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: Martin Liška, jakub, Richard Biener, Fangrui Song

If the value does not contain any path component separator (e.g. a
slash), the linker will be searched for using COMPILER_PATH followed by
PATH. Otherwise, it is either an absolute path or a path relative to the
current working directory.

--ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
future, we want to make dfferent linker option decisions we can let
-fuse-ld= represent the linker flavor and --ld-path= the linker path.

	PR driver/93645
	* common.opt (--ld-path=): Add --ld-path=
	* opts.c (common_handle_option): Handle OPT__ld_path_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
	* doc/invoke.texi: Document --ld-path=.

---
Changes in v2:
* Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
  The option does not affect code generation and is not a language feature,
  -f* is not suitable. Additionally, clang has other similar --*-path=
  options, e.g. --cuda-path=.
---
 gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
 gcc/common.opt      |  4 +++
 gcc/doc/invoke.texi |  9 +++++++
 gcc/gcc.c           |  2 +-
 gcc/opts.c          |  1 +
 5 files changed, 64 insertions(+), 15 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index f8a5ce45994..caa1b96ab52 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -844,6 +844,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *ld_path = NULL;
 
   /* 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
@@ -961,12 +962,21 @@ main (int argc, char **argv)
 	    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;
-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
-	  selected_linker = USE_LLD_LD;
+	else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
+		 && selected_linker != USE_LD_MAX)
+	  {
+	    if (strcmp (argv[i] + 9, "bfd") == 0)
+	      selected_linker = USE_BFD_LD;
+	    else if (strcmp (argv[i] + 9, "gold") == 0)
+	      selected_linker = USE_GOLD_LD;
+	    else if (strcmp (argv[i] + 9, "lld") == 0)
+	      selected_linker = USE_LLD_LD;
+	  }
+	else if (strncmp (argv[i], "--ld-path=", 10) == 0)
+	  {
+	    ld_path = argv[i] + 10;
+	    selected_linker = USE_LD_MAX;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1117,14 +1127,34 @@ main (int argc, char **argv)
       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
       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, ld_suffixes[selected_linker], X_OK);
-  /* 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, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker == USE_LD_MAX)
+    {
+      /* If --ld-path= does not contain a path component separator, search for
+	 the command using cpath, then using path.  Otherwise find the linker
+	 relative to the current working directory.  */
+      if (lbasename (ld_path) == ld_path)
+	{
+	  ld_file_name = find_a_file (&cpath, ld_path, X_OK);
+	  if (ld_file_name == 0)
+	    ld_file_name = find_a_file (&path, ld_path, X_OK);
+	}
+      else if (file_exists (ld_path))
+	{
+	  ld_file_name = ld_path;
+	}
+    }
+  else
+    {
+      /* 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, ld_suffixes[selected_linker], X_OK);
+      /* 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, full_ld_suffixes[selected_linker], X_OK);
+    }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
@@ -1461,6 +1491,11 @@ main (int argc, char **argv)
 		  ld2--;
 #endif
 		}
+	      else if (strncmp (arg, "--ld-path=", 10) == 0)
+		{
+		  ld1--;
+		  ld2--;
+		}
 	      else if (strncmp (arg, "--sysroot=", 10) == 0)
 		target_system_root = arg + 10;
 	      else if (strcmp (arg, "--version") == 0)
diff --git a/gcc/common.opt b/gcc/common.opt
index a3893a4725e..5adbd8c18a3 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2940,6 +2940,10 @@ fuse-ld=lld
 Common Driver Negative(fuse-ld=lld)
 Use the lld LLVM linker instead of the default linker.
 
+-ld-path=
+Common Driver Joined
+Use the specified executable instead of the default linker.
+
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ba18e05fb1a..e185e40ffac 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
 @opindex fuse-ld=lld
 Use the LLVM @command{lld} linker instead of the default linker.
 
+@item --ld-path=@var{linker}
+@opindex -ld-path=linker
+Use the specified executable named @var{linker} instead of the default linker.
+If @var{linker} does not contain any path component separator (e.g. a slash),
+the linker will be searched for using @env{COMPILER_PATH} followed by
+@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
+current working directory.  If @option{-fuse-ld=} is also specified, the linker
+path is specified by @option{--ld-path=}.
+
 @cindex Libraries
 @item -l@var{library}
 @itemx -l @var{library}
diff --git a/gcc/gcc.c b/gcc/gcc.c
index c0eb3c10cfd..05fa5375f06 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1077,7 +1077,7 @@ proper position among the other output files.  */
     LINK_PLUGIN_SPEC \
    "%{flto|flto=*:%<fcompare-debug*} \
     %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
-   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
+   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
    "%X %{o*} %{e*} %{N} %{n} %{r}\
     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
     %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
diff --git a/gcc/opts.c b/gcc/opts.c
index 499eb900643..5cbf9b85549 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
       dc->max_errors = value;
       break;
 
+    case OPT__ld_path_:
     case OPT_fuse_ld_bfd:
     case OPT_fuse_ld_gold:
     case OPT_fuse_ld_lld:
-- 
2.28.0.rc0.105.gf9edc3c819-goog


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-21  4:07                                     ` [PATCH v2] Add --ld-path= " Fangrui Song
@ 2020-07-23 10:17                                       ` Martin Liška
  2020-07-25  5:59                                         ` [PATCH v3] " Fangrui Song
  2020-12-04 13:45                                         ` [PATCH v2] " Martin Liška
  0 siblings, 2 replies; 44+ messages in thread
From: Martin Liška @ 2020-07-23 10:17 UTC (permalink / raw)
  To: Fangrui Song, gcc-patches; +Cc: jakub, Richard Biener

On 7/21/20 6:07 AM, Fangrui Song wrote:
> If the value does not contain any path component separator (e.g. a
> slash), the linker will be searched for using COMPILER_PATH followed by
> PATH. Otherwise, it is either an absolute path or a path relative to the
> current working directory.
> 
> --ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
> future, we want to make dfferent linker option decisions we can let
> -fuse-ld= represent the linker flavor and --ld-path= the linker path.

Hello.

I have just few nits:

=== ERROR type #3: trailing operator (1 error(s)) ===
gcc/collect2.c:1155:14:	ld_file_name =

> 
> 	PR driver/93645
> 	* common.opt (--ld-path=): Add --ld-path=
> 	* opts.c (common_handle_option): Handle OPT__ld_path_.
> 	* gcc.c (driver_handle_option): Likewise.
> 	* collect2.c (main): Likewise.
> 	* doc/invoke.texi: Document --ld-path=.
> 
> ---
> Changes in v2:
> * Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
>    The option does not affect code generation and is not a language feature,
>    -f* is not suitable. Additionally, clang has other similar --*-path=
>    options, e.g. --cuda-path=.
> ---
>   gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
>   gcc/common.opt      |  4 +++
>   gcc/doc/invoke.texi |  9 +++++++
>   gcc/gcc.c           |  2 +-
>   gcc/opts.c          |  1 +
>   5 files changed, 64 insertions(+), 15 deletions(-)
> 
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index f8a5ce45994..caa1b96ab52 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -844,6 +844,7 @@ main (int argc, char **argv)
>     const char **ld1;
>     bool use_plugin = false;
>     bool use_collect_ld = false;
> +  const char *ld_path = NULL;
>   
>     /* 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
> @@ -961,12 +962,21 @@ main (int argc, char **argv)
>   	    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;
> -	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
> -	  selected_linker = USE_LLD_LD;
> +	else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
> +		 && selected_linker != USE_LD_MAX)
> +	  {
> +	    if (strcmp (argv[i] + 9, "bfd") == 0)
> +	      selected_linker = USE_BFD_LD;
> +	    else if (strcmp (argv[i] + 9, "gold") == 0)
> +	      selected_linker = USE_GOLD_LD;
> +	    else if (strcmp (argv[i] + 9, "lld") == 0)
> +	      selected_linker = USE_LLD_LD;
> +	  }
> +	else if (strncmp (argv[i], "--ld-path=", 10) == 0)
> +	  {
> +	    ld_path = argv[i] + 10;
> +	    selected_linker = USE_LD_MAX;
> +	  }
>   	else if (strncmp (argv[i], "-o", 2) == 0)
>   	  {
>   	    /* Parse the output filename if it's given so that we can make
> @@ -1117,14 +1127,34 @@ main (int argc, char **argv)
>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>         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, ld_suffixes[selected_linker], X_OK);
> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
> +  if (selected_linker == USE_LD_MAX)
> +    {
> +      /* If --ld-path= does not contain a path component separator, search for
> +	 the command using cpath, then using path.  Otherwise find the linker
> +	 relative to the current working directory.  */
> +      if (lbasename (ld_path) == ld_path)
> +	{
> +	  ld_file_name = find_a_file (&cpath, ld_path, X_OK);
> +	  if (ld_file_name == 0)
> +	    ld_file_name = find_a_file (&path, ld_path, X_OK);
> +	}
> +      else if (file_exists (ld_path))
> +	{

^^^ these braces are not needed.

> +	  ld_file_name = ld_path;
> +	}
> +    }
> +  else
> +    {
> +      /* Search the compiler directories for `ld'.  We have protection against
> +	 recursive calls in find_a_file.  */
> +      if (ld_file_name == 0)

I would prefer '== NULL'.

> +	ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
> +    }
>   
>   #ifdef REAL_NM_FILE_NAME
>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
> @@ -1461,6 +1491,11 @@ main (int argc, char **argv)
>   		  ld2--;
>   #endif
>   		}
> +	      else if (strncmp (arg, "--ld-path=", 10) == 0)
> +		{
> +		  ld1--;
> +		  ld2--;
> +		}

Can you please explain more this change?

Thank you,
Martin

>   	      else if (strncmp (arg, "--sysroot=", 10) == 0)
>   		target_system_root = arg + 10;
>   	      else if (strcmp (arg, "--version") == 0)
> diff --git a/gcc/common.opt b/gcc/common.opt
> index a3893a4725e..5adbd8c18a3 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2940,6 +2940,10 @@ fuse-ld=lld
>   Common Driver Negative(fuse-ld=lld)
>   Use the lld LLVM linker instead of the default linker.
>   
> +-ld-path=
> +Common Driver Joined
> +Use the specified executable instead of the default linker.
> +
>   fuse-linker-plugin
>   Common Undocumented Var(flag_use_linker_plugin)
>   
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index ba18e05fb1a..e185e40ffac 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
>   @opindex fuse-ld=lld
>   Use the LLVM @command{lld} linker instead of the default linker.
>   
> +@item --ld-path=@var{linker}
> +@opindex -ld-path=linker
> +Use the specified executable named @var{linker} instead of the default linker.
> +If @var{linker} does not contain any path component separator (e.g. a slash),
> +the linker will be searched for using @env{COMPILER_PATH} followed by
> +@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
> +current working directory.  If @option{-fuse-ld=} is also specified, the linker
> +path is specified by @option{--ld-path=}.
> +
>   @cindex Libraries
>   @item -l@var{library}
>   @itemx -l @var{library}
> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index c0eb3c10cfd..05fa5375f06 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>       LINK_PLUGIN_SPEC \
>      "%{flto|flto=*:%<fcompare-debug*} \
>       %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
> +   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>      "%X %{o*} %{e*} %{N} %{n} %{r}\
>       %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>       %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 499eb900643..5cbf9b85549 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
>         dc->max_errors = value;
>         break;
>   
> +    case OPT__ld_path_:
>       case OPT_fuse_ld_bfd:
>       case OPT_fuse_ld_gold:
>       case OPT_fuse_ld_lld:
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v3] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-23 10:17                                       ` Martin Liška
@ 2020-07-25  5:59                                         ` Fangrui Song
  2020-07-25  7:09                                           ` Andreas Schwab
  2020-12-04 13:45                                         ` [PATCH v2] " Martin Liška
  1 sibling, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2020-07-25  5:59 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches, jakub, Richard Biener

[-- Attachment #1: Type: text/plain, Size: 8128 bytes --]

Attached v3 to address nits.

On 2020-07-23, Martin Liška wrote:
>On 7/21/20 6:07 AM, Fangrui Song wrote:
>>If the value does not contain any path component separator (e.g. a
>>slash), the linker will be searched for using COMPILER_PATH followed by
>>PATH. Otherwise, it is either an absolute path or a path relative to the
>>current working directory.
>>
>>--ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
>>future, we want to make dfferent linker option decisions we can let
>>-fuse-ld= represent the linker flavor and --ld-path= the linker path.
>
>Hello.
>
>I have just few nits:
>
>=== ERROR type #3: trailing operator (1 error(s)) ===
>gcc/collect2.c:1155:14:	ld_file_name =
>
>>
>>	PR driver/93645
>>	* common.opt (--ld-path=): Add --ld-path=
>>	* opts.c (common_handle_option): Handle OPT__ld_path_.
>>	* gcc.c (driver_handle_option): Likewise.
>>	* collect2.c (main): Likewise.
>>	* doc/invoke.texi: Document --ld-path=.
>>
>>---
>>Changes in v2:
>>* Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
>>   The option does not affect code generation and is not a language feature,
>>   -f* is not suitable. Additionally, clang has other similar --*-path=
>>   options, e.g. --cuda-path=.
>>---
>>  gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
>>  gcc/common.opt      |  4 +++
>>  gcc/doc/invoke.texi |  9 +++++++
>>  gcc/gcc.c           |  2 +-
>>  gcc/opts.c          |  1 +
>>  5 files changed, 64 insertions(+), 15 deletions(-)
>>
>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>index f8a5ce45994..caa1b96ab52 100644
>>--- a/gcc/collect2.c
>>+++ b/gcc/collect2.c
>>@@ -844,6 +844,7 @@ main (int argc, char **argv)
>>    const char **ld1;
>>    bool use_plugin = false;
>>    bool use_collect_ld = false;
>>+  const char *ld_path = NULL;
>>    /* 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
>>@@ -961,12 +962,21 @@ main (int argc, char **argv)
>>  	    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;
>>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>-	  selected_linker = USE_LLD_LD;
>>+	else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
>>+		 && selected_linker != USE_LD_MAX)
>>+	  {
>>+	    if (strcmp (argv[i] + 9, "bfd") == 0)
>>+	      selected_linker = USE_BFD_LD;
>>+	    else if (strcmp (argv[i] + 9, "gold") == 0)
>>+	      selected_linker = USE_GOLD_LD;
>>+	    else if (strcmp (argv[i] + 9, "lld") == 0)
>>+	      selected_linker = USE_LLD_LD;
>>+	  }
>>+	else if (strncmp (argv[i], "--ld-path=", 10) == 0)
>>+	  {
>>+	    ld_path = argv[i] + 10;
>>+	    selected_linker = USE_LD_MAX;
>>+	  }
>>  	else if (strncmp (argv[i], "-o", 2) == 0)
>>  	  {
>>  	    /* Parse the output filename if it's given so that we can make
>>@@ -1117,14 +1127,34 @@ main (int argc, char **argv)
>>        ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>        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, ld_suffixes[selected_linker], X_OK);
>>-  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>+  if (selected_linker == USE_LD_MAX)
>>+    {
>>+      /* If --ld-path= does not contain a path component separator, search for
>>+	 the command using cpath, then using path.  Otherwise find the linker
>>+	 relative to the current working directory.  */
>>+      if (lbasename (ld_path) == ld_path)
>>+	{
>>+	  ld_file_name = find_a_file (&cpath, ld_path, X_OK);
>>+	  if (ld_file_name == 0)
>>+	    ld_file_name = find_a_file (&path, ld_path, X_OK);
>>+	}
>>+      else if (file_exists (ld_path))
>>+	{
>
>^^^ these braces are not needed.

Usually, if the 'if' branch has braces, I'd add braces to 'else' as
well.  Updated to follow your advice anyway.

>>+	  ld_file_name = ld_path;
>>+	}
>>+    }
>>+  else
>>+    {
>>+      /* Search the compiler directories for `ld'.  We have protection against
>>+	 recursive calls in find_a_file.  */
>>+      if (ld_file_name == 0)
>
>I would prefer '== NULL'.

Done.

>>+	ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>>+      /* 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, full_ld_suffixes[selected_linker], X_OK);
>>+    }
>>  #ifdef REAL_NM_FILE_NAME
>>    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>@@ -1461,6 +1491,11 @@ main (int argc, char **argv)
>>  		  ld2--;
>>  #endif
>>  		}
>>+	      else if (strncmp (arg, "--ld-path=", 10) == 0)
>>+		{
>>+		  ld1--;
>>+		  ld2--;
>>+		}
>
>Can you please explain more this change?

This is to mimick nearly lines. collect2 should filter out options like -fno-lto, -flto, -fuse-ld= before passing to ld. -f* are handled by case 'f'. --ld-path needs its own `else if`.

Honestly I don't know why both both ld1 and ld2 exist and I suspect this
can be cleaned up/at least documented, but it is not the scope of this patch.

>Thank you,
>Martin
>
>>  	      else if (strncmp (arg, "--sysroot=", 10) == 0)
>>  		target_system_root = arg + 10;
>>  	      else if (strcmp (arg, "--version") == 0)
>>diff --git a/gcc/common.opt b/gcc/common.opt
>>index a3893a4725e..5adbd8c18a3 100644
>>--- a/gcc/common.opt
>>+++ b/gcc/common.opt
>>@@ -2940,6 +2940,10 @@ fuse-ld=lld
>>  Common Driver Negative(fuse-ld=lld)
>>  Use the lld LLVM linker instead of the default linker.
>>+-ld-path=
>>+Common Driver Joined
>>+Use the specified executable instead of the default linker.
>>+
>>  fuse-linker-plugin
>>  Common Undocumented Var(flag_use_linker_plugin)
>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>index ba18e05fb1a..e185e40ffac 100644
>>--- a/gcc/doc/invoke.texi
>>+++ b/gcc/doc/invoke.texi
>>@@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
>>  @opindex fuse-ld=lld
>>  Use the LLVM @command{lld} linker instead of the default linker.
>>+@item --ld-path=@var{linker}
>>+@opindex -ld-path=linker
>>+Use the specified executable named @var{linker} instead of the default linker.
>>+If @var{linker} does not contain any path component separator (e.g. a slash),
>>+the linker will be searched for using @env{COMPILER_PATH} followed by
>>+@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
>>+current working directory.  If @option{-fuse-ld=} is also specified, the linker
>>+path is specified by @option{--ld-path=}.
>>+
>>  @cindex Libraries
>>  @item -l@var{library}
>>  @itemx -l @var{library}
>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>index c0eb3c10cfd..05fa5375f06 100644
>>--- a/gcc/gcc.c
>>+++ b/gcc/gcc.c
>>@@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>>      LINK_PLUGIN_SPEC \
>>     "%{flto|flto=*:%<fcompare-debug*} \
>>      %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
>>-   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>+   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>     "%X %{o*} %{e*} %{N} %{n} %{r}\
>>      %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>>      %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
>>diff --git a/gcc/opts.c b/gcc/opts.c
>>index 499eb900643..5cbf9b85549 100644
>>--- a/gcc/opts.c
>>+++ b/gcc/opts.c
>>@@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
>>        dc->max_errors = value;
>>        break;
>>+    case OPT__ld_path_:
>>      case OPT_fuse_ld_bfd:
>>      case OPT_fuse_ld_gold:
>>      case OPT_fuse_ld_lld:
>>
>

[-- Attachment #2: v3-0001-Add-ld-path-to-specify-an-arbitrary-executable-as.patch --]
[-- Type: text/x-diff, Size: 7117 bytes --]

From 042394387ecf67d0d4e57004f8c499d037dacf52 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Fri, 24 Jul 2020 22:50:26 -0700
Subject: [PATCH v3] Add --ld-path= to specify an arbitrary executable as the
 linker

If the value does not contain any path component separator (e.g. a
slash), the linker will be searched for using COMPILER_PATH followed by
PATH. Otherwise, it is either an absolute path or a path relative to the
current working directory.

--ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
future, we want to make dfferent linker option decisions we can let
-fuse-ld= represent the linker flavor and --ld-path= the linker path.

	PR driver/93645
	* common.opt (--ld-path=): Add --ld-path=
	* opts.c (common_handle_option): Handle OPT__ld_path_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
	* doc/invoke.texi: Document --ld-path=.

---
Changes in v2:
* Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
  The option does not affect code generation and is not a language feature,
  -f* is not suitable.
---
 gcc/collect2.c      | 62 +++++++++++++++++++++++++++++++++++----------
 gcc/common.opt      |  4 +++
 gcc/doc/invoke.texi |  9 +++++++
 gcc/gcc.c           |  2 +-
 gcc/opts.c          |  1 +
 5 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index f8a5ce45994..65d6b1414f6 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -844,6 +844,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *ld_path = NULL;
 
   /* 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
@@ -961,12 +962,21 @@ main (int argc, char **argv)
 	    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;
-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
-	  selected_linker = USE_LLD_LD;
+	else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
+		 && selected_linker != USE_LD_MAX)
+	  {
+	    if (strcmp (argv[i] + 9, "bfd") == 0)
+	      selected_linker = USE_BFD_LD;
+	    else if (strcmp (argv[i] + 9, "gold") == 0)
+	      selected_linker = USE_GOLD_LD;
+	    else if (strcmp (argv[i] + 9, "lld") == 0)
+	      selected_linker = USE_LLD_LD;
+	  }
+	else if (strncmp (argv[i], "--ld-path=", 10) == 0)
+	  {
+	    ld_path = argv[i] + 10;
+	    selected_linker = USE_LD_MAX;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1117,14 +1127,33 @@ main (int argc, char **argv)
       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
       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, ld_suffixes[selected_linker], X_OK);
-  /* 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, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker == USE_LD_MAX)
+    {
+      /* If --ld-path= does not contain a path component separator, search for
+	 the command using cpath, then using path. Otherwise the value is
+	 either an absolute path or a path relative to the current working
+	 directory. */
+      if (lbasename (ld_path) == ld_path)
+	{
+	  ld_file_name = find_a_file (&cpath, ld_path, X_OK);
+	  if (ld_file_name == NULL)
+	    ld_file_name = find_a_file (&path, ld_path, X_OK);
+	}
+      else if (file_exists (ld_path))
+	ld_file_name = ld_path;
+    }
+  else
+    {
+      /* Search the compiler directories for `ld'.  We have protection against
+	 recursive calls in find_a_file.  */
+      if (ld_file_name == NULL)
+	ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
+      /* Search the ordinary system bin directories
+	 for `ld' (if native linking) or `TARGET-ld' (if cross).  */
+      if (ld_file_name == NULL)
+	ld_file_name =
+	  find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
+    }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
@@ -1461,6 +1490,11 @@ main (int argc, char **argv)
 		  ld2--;
 #endif
 		}
+	      else if (strncmp (arg, "--ld-path=", 10) == 0)
+		{
+		  ld1--;
+		  ld2--;
+		}
 	      else if (strncmp (arg, "--sysroot=", 10) == 0)
 		target_system_root = arg + 10;
 	      else if (strcmp (arg, "--version") == 0)
diff --git a/gcc/common.opt b/gcc/common.opt
index a3893a4725e..5adbd8c18a3 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2940,6 +2940,10 @@ fuse-ld=lld
 Common Driver Negative(fuse-ld=lld)
 Use the lld LLVM linker instead of the default linker.
 
+-ld-path=
+Common Driver Joined
+Use the specified executable instead of the default linker.
+
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ba18e05fb1a..e185e40ffac 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
 @opindex fuse-ld=lld
 Use the LLVM @command{lld} linker instead of the default linker.
 
+@item --ld-path=@var{linker}
+@opindex -ld-path=linker
+Use the specified executable named @var{linker} instead of the default linker.
+If @var{linker} does not contain any path component separator (e.g. a slash),
+the linker will be searched for using @env{COMPILER_PATH} followed by
+@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
+current working directory.  If @option{-fuse-ld=} is also specified, the linker
+path is specified by @option{--ld-path=}.
+
 @cindex Libraries
 @item -l@var{library}
 @itemx -l @var{library}
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 10bc9881aed..a88da48157b 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1077,7 +1077,7 @@ proper position among the other output files.  */
     LINK_PLUGIN_SPEC \
    "%{flto|flto=*:%<fcompare-debug*} \
     %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
-   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
+   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
    "%X %{o*} %{e*} %{N} %{n} %{r}\
     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
     %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
diff --git a/gcc/opts.c b/gcc/opts.c
index 499eb900643..5cbf9b85549 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
       dc->max_errors = value;
       break;
 
+    case OPT__ld_path_:
     case OPT_fuse_ld_bfd:
     case OPT_fuse_ld_gold:
     case OPT_fuse_ld_lld:
-- 
2.28.0.rc0.142.g3c755180ce-goog


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-25  5:59                                         ` [PATCH v3] " Fangrui Song
@ 2020-07-25  7:09                                           ` Andreas Schwab
  2020-07-26  6:31                                             ` Fāng-ruì Sòng
  0 siblings, 1 reply; 44+ messages in thread
From: Andreas Schwab @ 2020-07-25  7:09 UTC (permalink / raw)
  To: Fangrui Song via Gcc-patches
  Cc: Martin Liška, Fangrui Song, jakub, Richard Biener

On Jul 24 2020, Fangrui Song via Gcc-patches wrote:

> This is to mimick nearly lines. collect2 should filter out options like -fno-lto, -flto, -fuse-ld= before passing to ld. -f* are handled by case 'f'. --ld-path needs its own `else if`.

If you handle --ld-path as -fld-path then you don't need that.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-25  7:09                                           ` Andreas Schwab
@ 2020-07-26  6:31                                             ` Fāng-ruì Sòng
  2020-07-26 11:02                                               ` Andreas Schwab
  0 siblings, 1 reply; 44+ messages in thread
From: Fāng-ruì Sòng @ 2020-07-26  6:31 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Fangrui Song via Gcc-patches, Martin Liška, jakub, Richard Biener

On Sat, Jul 25, 2020 at 12:09 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jul 24 2020, Fangrui Song via Gcc-patches wrote:
>
> > This is to mimick nearly lines. collect2 should filter out options like -fno-lto, -flto, -fuse-ld= before passing to ld. -f* are handled by case 'f'. --ld-path needs its own `else if`.
>
> If you handle --ld-path as -fld-path then you don't need that.
>

--ld-path is a deliberate design choice. -f* is not suitable
(https://sourceware.org/pipermail/gcc/2020-July/233089.html )
clang has several other --*-path= (e.g. --cuda-path)

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-26  6:31                                             ` Fāng-ruì Sòng
@ 2020-07-26 11:02                                               ` Andreas Schwab
  2020-07-26 15:48                                                 ` Fāng-ruì Sòng
  0 siblings, 1 reply; 44+ messages in thread
From: Andreas Schwab @ 2020-07-26 11:02 UTC (permalink / raw)
  To: Fāng-ruì Sòng
  Cc: Fangrui Song via Gcc-patches, Martin Liška, jakub, Richard Biener

On Jul 25 2020, Fāng-ruì Sòng wrote:

> On Sat, Jul 25, 2020 at 12:09 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>>
>> On Jul 24 2020, Fangrui Song via Gcc-patches wrote:
>>
>> > This is to mimick nearly lines. collect2 should filter out options like -fno-lto, -flto, -fuse-ld= before passing to ld. -f* are handled by case 'f'. --ld-path needs its own `else if`.
>>
>> If you handle --ld-path as -fld-path then you don't need that.
>>
>
> --ld-path is a deliberate design choice. -f* is not suitable
> (https://sourceware.org/pipermail/gcc/2020-July/233089.html )

I don't agree with that opinion.  --foo and -ffoo are equivalent and
interchangeable.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v3] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-26 11:02                                               ` Andreas Schwab
@ 2020-07-26 15:48                                                 ` Fāng-ruì Sòng
  0 siblings, 0 replies; 44+ messages in thread
From: Fāng-ruì Sòng @ 2020-07-26 15:48 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Fangrui Song via Gcc-patches, Martin Liška, jakub, Richard Biener

On Sun, Jul 26, 2020 at 4:02 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jul 25 2020, Fāng-ruì Sòng wrote:
>
> > On Sat, Jul 25, 2020 at 12:09 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >>
> >> On Jul 24 2020, Fangrui Song via Gcc-patches wrote:
> >>
> >> > This is to mimick nearly lines. collect2 should filter out options like -fno-lto, -flto, -fuse-ld= before passing to ld. -f* are handled by case 'f'. --ld-path needs its own `else if`.
> >>
> >> If you handle --ld-path as -fld-path then you don't need that.
> >>
> >
> > --ld-path is a deliberate design choice. -f* is not suitable
> > (https://sourceware.org/pipermail/gcc/2020-July/233089.html )
> > clang has several other --*-path= (e.g. --cuda-path)
>
> I don't agree with that opinion.  --foo and -ffoo are equivalent and
> interchangeable.
>
> Andreas.

For options only affecting linking, -f* are minority.

-fgnu-tm enables language-level constructs.
-flto/-fopenmp/-fprofile-arcs/-fsanitize=*/etc affect code generation.
-fuse-ld= is an exception. The other options (the majority) don't
start with -f.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2020-07-23 10:17                                       ` Martin Liška
  2020-07-25  5:59                                         ` [PATCH v3] " Fangrui Song
@ 2020-12-04 13:45                                         ` Martin Liška
  2020-12-17  0:13                                           ` Fāng-ruì Sòng
  2021-01-06 14:22                                           ` Martin Liška
  1 sibling, 2 replies; 44+ messages in thread
From: Martin Liška @ 2020-12-04 13:45 UTC (permalink / raw)
  To: Fangrui Song, gcc-patches; +Cc: jakub, Richard Biener

PING

May I please ping the patch, it's waiting here for a review
for quite some time.

Thanks,
Martin

On 7/23/20 12:17 PM, Martin Liška wrote:
> On 7/21/20 6:07 AM, Fangrui Song wrote:
>> If the value does not contain any path component separator (e.g. a
>> slash), the linker will be searched for using COMPILER_PATH followed by
>> PATH. Otherwise, it is either an absolute path or a path relative to the
>> current working directory.
>>
>> --ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
>> future, we want to make dfferent linker option decisions we can let
>> -fuse-ld= represent the linker flavor and --ld-path= the linker path.
> 
> Hello.
> 
> I have just few nits:
> 
> === ERROR type #3: trailing operator (1 error(s)) ===
> gcc/collect2.c:1155:14:    ld_file_name =
> 
>>
>>     PR driver/93645
>>     * common.opt (--ld-path=): Add --ld-path=
>>     * opts.c (common_handle_option): Handle OPT__ld_path_.
>>     * gcc.c (driver_handle_option): Likewise.
>>     * collect2.c (main): Likewise.
>>     * doc/invoke.texi: Document --ld-path=.
>>
>> ---
>> Changes in v2:
>> * Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
>>    The option does not affect code generation and is not a language feature,
>>    -f* is not suitable. Additionally, clang has other similar --*-path=
>>    options, e.g. --cuda-path=.
>> ---
>>   gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
>>   gcc/common.opt      |  4 +++
>>   gcc/doc/invoke.texi |  9 +++++++
>>   gcc/gcc.c           |  2 +-
>>   gcc/opts.c          |  1 +
>>   5 files changed, 64 insertions(+), 15 deletions(-)
>>
>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>> index f8a5ce45994..caa1b96ab52 100644
>> --- a/gcc/collect2.c
>> +++ b/gcc/collect2.c
>> @@ -844,6 +844,7 @@ main (int argc, char **argv)
>>     const char **ld1;
>>     bool use_plugin = false;
>>     bool use_collect_ld = false;
>> +  const char *ld_path = NULL;
>>     /* 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
>> @@ -961,12 +962,21 @@ main (int argc, char **argv)
>>           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;
>> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>> -      selected_linker = USE_LLD_LD;
>> +    else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
>> +         && selected_linker != USE_LD_MAX)
>> +      {
>> +        if (strcmp (argv[i] + 9, "bfd") == 0)
>> +          selected_linker = USE_BFD_LD;
>> +        else if (strcmp (argv[i] + 9, "gold") == 0)
>> +          selected_linker = USE_GOLD_LD;
>> +        else if (strcmp (argv[i] + 9, "lld") == 0)
>> +          selected_linker = USE_LLD_LD;
>> +      }
>> +    else if (strncmp (argv[i], "--ld-path=", 10) == 0)
>> +      {
>> +        ld_path = argv[i] + 10;
>> +        selected_linker = USE_LD_MAX;
>> +      }
>>       else if (strncmp (argv[i], "-o", 2) == 0)
>>         {
>>           /* Parse the output filename if it's given so that we can make
>> @@ -1117,14 +1127,34 @@ main (int argc, char **argv)
>>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>         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, ld_suffixes[selected_linker], X_OK);
>> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
>> +  if (selected_linker == USE_LD_MAX)
>> +    {
>> +      /* If --ld-path= does not contain a path component separator, search for
>> +     the command using cpath, then using path.  Otherwise find the linker
>> +     relative to the current working directory.  */
>> +      if (lbasename (ld_path) == ld_path)
>> +    {
>> +      ld_file_name = find_a_file (&cpath, ld_path, X_OK);
>> +      if (ld_file_name == 0)
>> +        ld_file_name = find_a_file (&path, ld_path, X_OK);
>> +    }
>> +      else if (file_exists (ld_path))
>> +    {
> 
> ^^^ these braces are not needed.
> 
>> +      ld_file_name = ld_path;
>> +    }
>> +    }
>> +  else
>> +    {
>> +      /* Search the compiler directories for `ld'.  We have protection against
>> +     recursive calls in find_a_file.  */
>> +      if (ld_file_name == 0)
> 
> I would prefer '== NULL'.
> 
>> +    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
>> +    }
>>   #ifdef REAL_NM_FILE_NAME
>>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>> @@ -1461,6 +1491,11 @@ main (int argc, char **argv)
>>             ld2--;
>>   #endif
>>           }
>> +          else if (strncmp (arg, "--ld-path=", 10) == 0)
>> +        {
>> +          ld1--;
>> +          ld2--;
>> +        }
> 
> Can you please explain more this change?
> 
> Thank you,
> Martin
> 
>>             else if (strncmp (arg, "--sysroot=", 10) == 0)
>>           target_system_root = arg + 10;
>>             else if (strcmp (arg, "--version") == 0)
>> diff --git a/gcc/common.opt b/gcc/common.opt
>> index a3893a4725e..5adbd8c18a3 100644
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -2940,6 +2940,10 @@ fuse-ld=lld
>>   Common Driver Negative(fuse-ld=lld)
>>   Use the lld LLVM linker instead of the default linker.
>> +-ld-path=
>> +Common Driver Joined
>> +Use the specified executable instead of the default linker.
>> +
>>   fuse-linker-plugin
>>   Common Undocumented Var(flag_use_linker_plugin)
>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>> index ba18e05fb1a..e185e40ffac 100644
>> --- a/gcc/doc/invoke.texi
>> +++ b/gcc/doc/invoke.texi
>> @@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
>>   @opindex fuse-ld=lld
>>   Use the LLVM @command{lld} linker instead of the default linker.
>> +@item --ld-path=@var{linker}
>> +@opindex -ld-path=linker
>> +Use the specified executable named @var{linker} instead of the default linker.
>> +If @var{linker} does not contain any path component separator (e.g. a slash),
>> +the linker will be searched for using @env{COMPILER_PATH} followed by
>> +@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
>> +current working directory.  If @option{-fuse-ld=} is also specified, the linker
>> +path is specified by @option{--ld-path=}.
>> +
>>   @cindex Libraries
>>   @item -l@var{library}
>>   @itemx -l @var{library}
>> diff --git a/gcc/gcc.c b/gcc/gcc.c
>> index c0eb3c10cfd..05fa5375f06 100644
>> --- a/gcc/gcc.c
>> +++ b/gcc/gcc.c
>> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>>       LINK_PLUGIN_SPEC \
>>      "%{flto|flto=*:%<fcompare-debug*} \
>>       %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
>> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
>> +   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>      "%X %{o*} %{e*} %{N} %{n} %{r}\
>>       %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>>       %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
>> diff --git a/gcc/opts.c b/gcc/opts.c
>> index 499eb900643..5cbf9b85549 100644
>> --- a/gcc/opts.c
>> +++ b/gcc/opts.c
>> @@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
>>         dc->max_errors = value;
>>         break;
>> +    case OPT__ld_path_:
>>       case OPT_fuse_ld_bfd:
>>       case OPT_fuse_ld_gold:
>>       case OPT_fuse_ld_lld:
>>
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2020-12-04 13:45                                         ` [PATCH v2] " Martin Liška
@ 2020-12-17  0:13                                           ` Fāng-ruì Sòng
  2021-01-06 14:22                                           ` Martin Liška
  1 sibling, 0 replies; 44+ messages in thread
From: Fāng-ruì Sòng @ 2020-12-17  0:13 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Biener; +Cc: Martin Liška, GCC Patches

On Fri, Dec 4, 2020 at 5:45 AM Martin Liška <mliska@suse.cz> wrote:
>
> PING
>
> May I please ping the patch, it's waiting here for a review
> for quite some time.
>
> Thanks,
> Martin

Ping. I think Martin LGTMed this patch and was waiting for a
maintainer to merge it

> On 7/23/20 12:17 PM, Martin Liška wrote:
> > On 7/21/20 6:07 AM, Fangrui Song wrote:
> >> If the value does not contain any path component separator (e.g. a
> >> slash), the linker will be searched for using COMPILER_PATH followed by
> >> PATH. Otherwise, it is either an absolute path or a path relative to the
> >> current working directory.
> >>
> >> --ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
> >> future, we want to make dfferent linker option decisions we can let
> >> -fuse-ld= represent the linker flavor and --ld-path= the linker path.
> >
> > Hello.
> >
> > I have just few nits:
> >
> > === ERROR type #3: trailing operator (1 error(s)) ===
> > gcc/collect2.c:1155:14:    ld_file_name =
> >
> >>
> >>     PR driver/93645
> >>     * common.opt (--ld-path=): Add --ld-path=
> >>     * opts.c (common_handle_option): Handle OPT__ld_path_.
> >>     * gcc.c (driver_handle_option): Likewise.
> >>     * collect2.c (main): Likewise.
> >>     * doc/invoke.texi: Document --ld-path=.
> >>
> >> ---
> >> Changes in v2:
> >> * Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
> >>    The option does not affect code generation and is not a language feature,
> >>    -f* is not suitable. Additionally, clang has other similar --*-path=
> >>    options, e.g. --cuda-path=.
> >> ---
> >>   gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
> >>   gcc/common.opt      |  4 +++
> >>   gcc/doc/invoke.texi |  9 +++++++
> >>   gcc/gcc.c           |  2 +-
> >>   gcc/opts.c          |  1 +
> >>   5 files changed, 64 insertions(+), 15 deletions(-)
> >>
> >> diff --git a/gcc/collect2.c b/gcc/collect2.c
> >> index f8a5ce45994..caa1b96ab52 100644
> >> --- a/gcc/collect2.c
> >> +++ b/gcc/collect2.c
> >> @@ -844,6 +844,7 @@ main (int argc, char **argv)
> >>     const char **ld1;
> >>     bool use_plugin = false;
> >>     bool use_collect_ld = false;
> >> +  const char *ld_path = NULL;
> >>     /* 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
> >> @@ -961,12 +962,21 @@ main (int argc, char **argv)
> >>           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;
> >> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
> >> -      selected_linker = USE_LLD_LD;
> >> +    else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
> >> +         && selected_linker != USE_LD_MAX)
> >> +      {
> >> +        if (strcmp (argv[i] + 9, "bfd") == 0)
> >> +          selected_linker = USE_BFD_LD;
> >> +        else if (strcmp (argv[i] + 9, "gold") == 0)
> >> +          selected_linker = USE_GOLD_LD;
> >> +        else if (strcmp (argv[i] + 9, "lld") == 0)
> >> +          selected_linker = USE_LLD_LD;
> >> +      }
> >> +    else if (strncmp (argv[i], "--ld-path=", 10) == 0)
> >> +      {
> >> +        ld_path = argv[i] + 10;
> >> +        selected_linker = USE_LD_MAX;
> >> +      }
> >>       else if (strncmp (argv[i], "-o", 2) == 0)
> >>         {
> >>           /* Parse the output filename if it's given so that we can make
> >> @@ -1117,14 +1127,34 @@ main (int argc, char **argv)
> >>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
> >>         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, ld_suffixes[selected_linker], X_OK);
> >> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
> >> +  if (selected_linker == USE_LD_MAX)
> >> +    {
> >> +      /* If --ld-path= does not contain a path component separator, search for
> >> +     the command using cpath, then using path.  Otherwise find the linker
> >> +     relative to the current working directory.  */
> >> +      if (lbasename (ld_path) == ld_path)
> >> +    {
> >> +      ld_file_name = find_a_file (&cpath, ld_path, X_OK);
> >> +      if (ld_file_name == 0)
> >> +        ld_file_name = find_a_file (&path, ld_path, X_OK);
> >> +    }
> >> +      else if (file_exists (ld_path))
> >> +    {
> >
> > ^^^ these braces are not needed.
> >
> >> +      ld_file_name = ld_path;
> >> +    }
> >> +    }
> >> +  else
> >> +    {
> >> +      /* Search the compiler directories for `ld'.  We have protection against
> >> +     recursive calls in find_a_file.  */
> >> +      if (ld_file_name == 0)
> >
> > I would prefer '== NULL'.
> >
> >> +    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
> >> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
> >> +    }
> >>   #ifdef REAL_NM_FILE_NAME
> >>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
> >> @@ -1461,6 +1491,11 @@ main (int argc, char **argv)
> >>             ld2--;
> >>   #endif
> >>           }
> >> +          else if (strncmp (arg, "--ld-path=", 10) == 0)
> >> +        {
> >> +          ld1--;
> >> +          ld2--;
> >> +        }
> >
> > Can you please explain more this change?
> >
> > Thank you,
> > Martin
> >
> >>             else if (strncmp (arg, "--sysroot=", 10) == 0)
> >>           target_system_root = arg + 10;
> >>             else if (strcmp (arg, "--version") == 0)
> >> diff --git a/gcc/common.opt b/gcc/common.opt
> >> index a3893a4725e..5adbd8c18a3 100644
> >> --- a/gcc/common.opt
> >> +++ b/gcc/common.opt
> >> @@ -2940,6 +2940,10 @@ fuse-ld=lld
> >>   Common Driver Negative(fuse-ld=lld)
> >>   Use the lld LLVM linker instead of the default linker.
> >> +-ld-path=
> >> +Common Driver Joined
> >> +Use the specified executable instead of the default linker.
> >> +
> >>   fuse-linker-plugin
> >>   Common Undocumented Var(flag_use_linker_plugin)
> >> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> >> index ba18e05fb1a..e185e40ffac 100644
> >> --- a/gcc/doc/invoke.texi
> >> +++ b/gcc/doc/invoke.texi
> >> @@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
> >>   @opindex fuse-ld=lld
> >>   Use the LLVM @command{lld} linker instead of the default linker.
> >> +@item --ld-path=@var{linker}
> >> +@opindex -ld-path=linker
> >> +Use the specified executable named @var{linker} instead of the default linker.
> >> +If @var{linker} does not contain any path component separator (e.g. a slash),
> >> +the linker will be searched for using @env{COMPILER_PATH} followed by
> >> +@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
> >> +current working directory.  If @option{-fuse-ld=} is also specified, the linker
> >> +path is specified by @option{--ld-path=}.
> >> +
> >>   @cindex Libraries
> >>   @item -l@var{library}
> >>   @itemx -l @var{library}
> >> diff --git a/gcc/gcc.c b/gcc/gcc.c
> >> index c0eb3c10cfd..05fa5375f06 100644
> >> --- a/gcc/gcc.c
> >> +++ b/gcc/gcc.c
> >> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
> >>       LINK_PLUGIN_SPEC \
> >>      "%{flto|flto=*:%<fcompare-debug*} \
> >>       %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
> >> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
> >> +   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
> >>      "%X %{o*} %{e*} %{N} %{n} %{r}\
> >>       %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
> >>       %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
> >> diff --git a/gcc/opts.c b/gcc/opts.c
> >> index 499eb900643..5cbf9b85549 100644
> >> --- a/gcc/opts.c
> >> +++ b/gcc/opts.c
> >> @@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
> >>         dc->max_errors = value;
> >>         break;
> >> +    case OPT__ld_path_:
> >>       case OPT_fuse_ld_bfd:
> >>       case OPT_fuse_ld_gold:
> >>       case OPT_fuse_ld_lld:
> >>
> >
>


-- 
宋方睿

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2020-12-04 13:45                                         ` [PATCH v2] " Martin Liška
  2020-12-17  0:13                                           ` Fāng-ruì Sòng
@ 2021-01-06 14:22                                           ` Martin Liška
  2021-01-14  9:04                                             ` Martin Liška
  1 sibling, 1 reply; 44+ messages in thread
From: Martin Liška @ 2021-01-06 14:22 UTC (permalink / raw)
  To: Fangrui Song, gcc-patches; +Cc: jakub, Richard Biener

PING^2

On 12/4/20 2:45 PM, Martin Liška wrote:
> PING
> 
> May I please ping the patch, it's waiting here for a review
> for quite some time.
> 
> Thanks,
> Martin
> 
> On 7/23/20 12:17 PM, Martin Liška wrote:
>> On 7/21/20 6:07 AM, Fangrui Song wrote:
>>> If the value does not contain any path component separator (e.g. a
>>> slash), the linker will be searched for using COMPILER_PATH followed by
>>> PATH. Otherwise, it is either an absolute path or a path relative to the
>>> current working directory.
>>>
>>> --ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
>>> future, we want to make dfferent linker option decisions we can let
>>> -fuse-ld= represent the linker flavor and --ld-path= the linker path.
>>
>> Hello.
>>
>> I have just few nits:
>>
>> === ERROR type #3: trailing operator (1 error(s)) ===
>> gcc/collect2.c:1155:14:    ld_file_name =
>>
>>>
>>>     PR driver/93645
>>>     * common.opt (--ld-path=): Add --ld-path=
>>>     * opts.c (common_handle_option): Handle OPT__ld_path_.
>>>     * gcc.c (driver_handle_option): Likewise.
>>>     * collect2.c (main): Likewise.
>>>     * doc/invoke.texi: Document --ld-path=.
>>>
>>> ---
>>> Changes in v2:
>>> * Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
>>>    The option does not affect code generation and is not a language feature,
>>>    -f* is not suitable. Additionally, clang has other similar --*-path=
>>>    options, e.g. --cuda-path=.
>>> ---
>>>   gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
>>>   gcc/common.opt      |  4 +++
>>>   gcc/doc/invoke.texi |  9 +++++++
>>>   gcc/gcc.c           |  2 +-
>>>   gcc/opts.c          |  1 +
>>>   5 files changed, 64 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>>> index f8a5ce45994..caa1b96ab52 100644
>>> --- a/gcc/collect2.c
>>> +++ b/gcc/collect2.c
>>> @@ -844,6 +844,7 @@ main (int argc, char **argv)
>>>     const char **ld1;
>>>     bool use_plugin = false;
>>>     bool use_collect_ld = false;
>>> +  const char *ld_path = NULL;
>>>     /* 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
>>> @@ -961,12 +962,21 @@ main (int argc, char **argv)
>>>           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;
>>> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>> -      selected_linker = USE_LLD_LD;
>>> +    else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
>>> +         && selected_linker != USE_LD_MAX)
>>> +      {
>>> +        if (strcmp (argv[i] + 9, "bfd") == 0)
>>> +          selected_linker = USE_BFD_LD;
>>> +        else if (strcmp (argv[i] + 9, "gold") == 0)
>>> +          selected_linker = USE_GOLD_LD;
>>> +        else if (strcmp (argv[i] + 9, "lld") == 0)
>>> +          selected_linker = USE_LLD_LD;
>>> +      }
>>> +    else if (strncmp (argv[i], "--ld-path=", 10) == 0)
>>> +      {
>>> +        ld_path = argv[i] + 10;
>>> +        selected_linker = USE_LD_MAX;
>>> +      }
>>>       else if (strncmp (argv[i], "-o", 2) == 0)
>>>         {
>>>           /* Parse the output filename if it's given so that we can make
>>> @@ -1117,14 +1127,34 @@ main (int argc, char **argv)
>>>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>>         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, ld_suffixes[selected_linker], X_OK);
>>> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>> +  if (selected_linker == USE_LD_MAX)
>>> +    {
>>> +      /* If --ld-path= does not contain a path component separator, search for
>>> +     the command using cpath, then using path.  Otherwise find the linker
>>> +     relative to the current working directory.  */
>>> +      if (lbasename (ld_path) == ld_path)
>>> +    {
>>> +      ld_file_name = find_a_file (&cpath, ld_path, X_OK);
>>> +      if (ld_file_name == 0)
>>> +        ld_file_name = find_a_file (&path, ld_path, X_OK);
>>> +    }
>>> +      else if (file_exists (ld_path))
>>> +    {
>>
>> ^^^ these braces are not needed.
>>
>>> +      ld_file_name = ld_path;
>>> +    }
>>> +    }
>>> +  else
>>> +    {
>>> +      /* Search the compiler directories for `ld'.  We have protection against
>>> +     recursive calls in find_a_file.  */
>>> +      if (ld_file_name == 0)
>>
>> I would prefer '== NULL'.
>>
>>> +    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>>> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
>>> +    }
>>>   #ifdef REAL_NM_FILE_NAME
>>>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>> @@ -1461,6 +1491,11 @@ main (int argc, char **argv)
>>>             ld2--;
>>>   #endif
>>>           }
>>> +          else if (strncmp (arg, "--ld-path=", 10) == 0)
>>> +        {
>>> +          ld1--;
>>> +          ld2--;
>>> +        }
>>
>> Can you please explain more this change?
>>
>> Thank you,
>> Martin
>>
>>>             else if (strncmp (arg, "--sysroot=", 10) == 0)
>>>           target_system_root = arg + 10;
>>>             else if (strcmp (arg, "--version") == 0)
>>> diff --git a/gcc/common.opt b/gcc/common.opt
>>> index a3893a4725e..5adbd8c18a3 100644
>>> --- a/gcc/common.opt
>>> +++ b/gcc/common.opt
>>> @@ -2940,6 +2940,10 @@ fuse-ld=lld
>>>   Common Driver Negative(fuse-ld=lld)
>>>   Use the lld LLVM linker instead of the default linker.
>>> +-ld-path=
>>> +Common Driver Joined
>>> +Use the specified executable instead of the default linker.
>>> +
>>>   fuse-linker-plugin
>>>   Common Undocumented Var(flag_use_linker_plugin)
>>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>> index ba18e05fb1a..e185e40ffac 100644
>>> --- a/gcc/doc/invoke.texi
>>> +++ b/gcc/doc/invoke.texi
>>> @@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
>>>   @opindex fuse-ld=lld
>>>   Use the LLVM @command{lld} linker instead of the default linker.
>>> +@item --ld-path=@var{linker}
>>> +@opindex -ld-path=linker
>>> +Use the specified executable named @var{linker} instead of the default linker.
>>> +If @var{linker} does not contain any path component separator (e.g. a slash),
>>> +the linker will be searched for using @env{COMPILER_PATH} followed by
>>> +@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
>>> +current working directory.  If @option{-fuse-ld=} is also specified, the linker
>>> +path is specified by @option{--ld-path=}.
>>> +
>>>   @cindex Libraries
>>>   @item -l@var{library}
>>>   @itemx -l @var{library}
>>> diff --git a/gcc/gcc.c b/gcc/gcc.c
>>> index c0eb3c10cfd..05fa5375f06 100644
>>> --- a/gcc/gcc.c
>>> +++ b/gcc/gcc.c
>>> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>>>       LINK_PLUGIN_SPEC \
>>>      "%{flto|flto=*:%<fcompare-debug*} \
>>>       %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
>>> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>> +   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>>      "%X %{o*} %{e*} %{N} %{n} %{r}\
>>>       %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>>>       %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
>>> diff --git a/gcc/opts.c b/gcc/opts.c
>>> index 499eb900643..5cbf9b85549 100644
>>> --- a/gcc/opts.c
>>> +++ b/gcc/opts.c
>>> @@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
>>>         dc->max_errors = value;
>>>         break;
>>> +    case OPT__ld_path_:
>>>       case OPT_fuse_ld_bfd:
>>>       case OPT_fuse_ld_gold:
>>>       case OPT_fuse_ld_lld:
>>>
>>
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2021-01-06 14:22                                           ` Martin Liška
@ 2021-01-14  9:04                                             ` Martin Liška
  2021-01-14 10:07                                               ` Richard Biener
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2021-01-14  9:04 UTC (permalink / raw)
  To: Fangrui Song, gcc-patches; +Cc: jakub, Richard Biener

PING^3

On 1/6/21 3:22 PM, Martin Liška wrote:
> PING^2
> 
> On 12/4/20 2:45 PM, Martin Liška wrote:
>> PING
>>
>> May I please ping the patch, it's waiting here for a review
>> for quite some time.
>>
>> Thanks,
>> Martin
>>
>> On 7/23/20 12:17 PM, Martin Liška wrote:
>>> On 7/21/20 6:07 AM, Fangrui Song wrote:
>>>> If the value does not contain any path component separator (e.g. a
>>>> slash), the linker will be searched for using COMPILER_PATH followed by
>>>> PATH. Otherwise, it is either an absolute path or a path relative to the
>>>> current working directory.
>>>>
>>>> --ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
>>>> future, we want to make dfferent linker option decisions we can let
>>>> -fuse-ld= represent the linker flavor and --ld-path= the linker path.
>>>
>>> Hello.
>>>
>>> I have just few nits:
>>>
>>> === ERROR type #3: trailing operator (1 error(s)) ===
>>> gcc/collect2.c:1155:14:    ld_file_name =
>>>
>>>>
>>>>     PR driver/93645
>>>>     * common.opt (--ld-path=): Add --ld-path=
>>>>     * opts.c (common_handle_option): Handle OPT__ld_path_.
>>>>     * gcc.c (driver_handle_option): Likewise.
>>>>     * collect2.c (main): Likewise.
>>>>     * doc/invoke.texi: Document --ld-path=.
>>>>
>>>> ---
>>>> Changes in v2:
>>>> * Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
>>>>    The option does not affect code generation and is not a language feature,
>>>>    -f* is not suitable. Additionally, clang has other similar --*-path=
>>>>    options, e.g. --cuda-path=.
>>>> ---
>>>>   gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
>>>>   gcc/common.opt      |  4 +++
>>>>   gcc/doc/invoke.texi |  9 +++++++
>>>>   gcc/gcc.c           |  2 +-
>>>>   gcc/opts.c          |  1 +
>>>>   5 files changed, 64 insertions(+), 15 deletions(-)
>>>>
>>>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>>>> index f8a5ce45994..caa1b96ab52 100644
>>>> --- a/gcc/collect2.c
>>>> +++ b/gcc/collect2.c
>>>> @@ -844,6 +844,7 @@ main (int argc, char **argv)
>>>>     const char **ld1;
>>>>     bool use_plugin = false;
>>>>     bool use_collect_ld = false;
>>>> +  const char *ld_path = NULL;
>>>>     /* 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
>>>> @@ -961,12 +962,21 @@ main (int argc, char **argv)
>>>>           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;
>>>> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>>> -      selected_linker = USE_LLD_LD;
>>>> +    else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
>>>> +         && selected_linker != USE_LD_MAX)
>>>> +      {
>>>> +        if (strcmp (argv[i] + 9, "bfd") == 0)
>>>> +          selected_linker = USE_BFD_LD;
>>>> +        else if (strcmp (argv[i] + 9, "gold") == 0)
>>>> +          selected_linker = USE_GOLD_LD;
>>>> +        else if (strcmp (argv[i] + 9, "lld") == 0)
>>>> +          selected_linker = USE_LLD_LD;
>>>> +      }
>>>> +    else if (strncmp (argv[i], "--ld-path=", 10) == 0)
>>>> +      {
>>>> +        ld_path = argv[i] + 10;
>>>> +        selected_linker = USE_LD_MAX;
>>>> +      }
>>>>       else if (strncmp (argv[i], "-o", 2) == 0)
>>>>         {
>>>>           /* Parse the output filename if it's given so that we can make
>>>> @@ -1117,14 +1127,34 @@ main (int argc, char **argv)
>>>>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>>>         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, ld_suffixes[selected_linker], X_OK);
>>>> -  /* 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, full_ld_suffixes[selected_linker], X_OK);
>>>> +  if (selected_linker == USE_LD_MAX)
>>>> +    {
>>>> +      /* If --ld-path= does not contain a path component separator, search for
>>>> +     the command using cpath, then using path.  Otherwise find the linker
>>>> +     relative to the current working directory.  */
>>>> +      if (lbasename (ld_path) == ld_path)
>>>> +    {
>>>> +      ld_file_name = find_a_file (&cpath, ld_path, X_OK);
>>>> +      if (ld_file_name == 0)
>>>> +        ld_file_name = find_a_file (&path, ld_path, X_OK);
>>>> +    }
>>>> +      else if (file_exists (ld_path))
>>>> +    {
>>>
>>> ^^^ these braces are not needed.
>>>
>>>> +      ld_file_name = ld_path;
>>>> +    }
>>>> +    }
>>>> +  else
>>>> +    {
>>>> +      /* Search the compiler directories for `ld'.  We have protection against
>>>> +     recursive calls in find_a_file.  */
>>>> +      if (ld_file_name == 0)
>>>
>>> I would prefer '== NULL'.
>>>
>>>> +    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>>>> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
>>>> +    }
>>>>   #ifdef REAL_NM_FILE_NAME
>>>>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>>> @@ -1461,6 +1491,11 @@ main (int argc, char **argv)
>>>>             ld2--;
>>>>   #endif
>>>>           }
>>>> +          else if (strncmp (arg, "--ld-path=", 10) == 0)
>>>> +        {
>>>> +          ld1--;
>>>> +          ld2--;
>>>> +        }
>>>
>>> Can you please explain more this change?
>>>
>>> Thank you,
>>> Martin
>>>
>>>>             else if (strncmp (arg, "--sysroot=", 10) == 0)
>>>>           target_system_root = arg + 10;
>>>>             else if (strcmp (arg, "--version") == 0)
>>>> diff --git a/gcc/common.opt b/gcc/common.opt
>>>> index a3893a4725e..5adbd8c18a3 100644
>>>> --- a/gcc/common.opt
>>>> +++ b/gcc/common.opt
>>>> @@ -2940,6 +2940,10 @@ fuse-ld=lld
>>>>   Common Driver Negative(fuse-ld=lld)
>>>>   Use the lld LLVM linker instead of the default linker.
>>>> +-ld-path=
>>>> +Common Driver Joined
>>>> +Use the specified executable instead of the default linker.
>>>> +
>>>>   fuse-linker-plugin
>>>>   Common Undocumented Var(flag_use_linker_plugin)
>>>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>>> index ba18e05fb1a..e185e40ffac 100644
>>>> --- a/gcc/doc/invoke.texi
>>>> +++ b/gcc/doc/invoke.texi
>>>> @@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the default linker.
>>>>   @opindex fuse-ld=lld
>>>>   Use the LLVM @command{lld} linker instead of the default linker.
>>>> +@item --ld-path=@var{linker}
>>>> +@opindex -ld-path=linker
>>>> +Use the specified executable named @var{linker} instead of the default linker.
>>>> +If @var{linker} does not contain any path component separator (e.g. a slash),
>>>> +the linker will be searched for using @env{COMPILER_PATH} followed by
>>>> +@env{PATH}. Otherwise, it is either an absolute path or a path relative to the
>>>> +current working directory.  If @option{-fuse-ld=} is also specified, the linker
>>>> +path is specified by @option{--ld-path=}.
>>>> +
>>>>   @cindex Libraries
>>>>   @item -l@var{library}
>>>>   @itemx -l @var{library}
>>>> diff --git a/gcc/gcc.c b/gcc/gcc.c
>>>> index c0eb3c10cfd..05fa5375f06 100644
>>>> --- a/gcc/gcc.c
>>>> +++ b/gcc/gcc.c
>>>> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
>>>>       LINK_PLUGIN_SPEC \
>>>>      "%{flto|flto=*:%<fcompare-debug*} \
>>>>       %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
>>>> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>>> +   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} " LINK_COMPRESS_DEBUG_SPEC \
>>>>      "%X %{o*} %{e*} %{N} %{n} %{r}\
>>>>       %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
>>>>       %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
>>>> diff --git a/gcc/opts.c b/gcc/opts.c
>>>> index 499eb900643..5cbf9b85549 100644
>>>> --- a/gcc/opts.c
>>>> +++ b/gcc/opts.c
>>>> @@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
>>>>         dc->max_errors = value;
>>>>         break;
>>>> +    case OPT__ld_path_:
>>>>       case OPT_fuse_ld_bfd:
>>>>       case OPT_fuse_ld_gold:
>>>>       case OPT_fuse_ld_lld:
>>>>
>>>
>>
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2021-01-14  9:04                                             ` Martin Liška
@ 2021-01-14 10:07                                               ` Richard Biener
  2021-01-14 13:21                                                 ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Richard Biener @ 2021-01-14 10:07 UTC (permalink / raw)
  To: Martin Liška; +Cc: Fangrui Song, gcc-patches, jakub

On Thu, 14 Jan 2021, Martin Liška wrote:

> PING^3

I see no particular reason to allow arbitrary garbage to be used as
linker.  It just asks for users to shoot themselves in the foot and
for strange bugreports to pop up.

Richard.

> On 1/6/21 3:22 PM, Martin Liška wrote:
> > PING^2
> > 
> > On 12/4/20 2:45 PM, Martin Liška wrote:
> >> PING
> >>
> >> May I please ping the patch, it's waiting here for a review
> >> for quite some time.
> >>
> >> Thanks,
> >> Martin
> >>
> >> On 7/23/20 12:17 PM, Martin Liška wrote:
> >>> On 7/21/20 6:07 AM, Fangrui Song wrote:
> >>>> If the value does not contain any path component separator (e.g. a
> >>>> slash), the linker will be searched for using COMPILER_PATH followed by
> >>>> PATH. Otherwise, it is either an absolute path or a path relative to the
> >>>> current working directory.
> >>>>
> >>>> --ld-path= complements and overrides -fuse-ld={bfd,gold,lld}. If in the
> >>>> future, we want to make dfferent linker option decisions we can let
> >>>> -fuse-ld= represent the linker flavor and --ld-path= the linker path.
> >>>
> >>> Hello.
> >>>
> >>> I have just few nits:
> >>>
> >>> === ERROR type #3: trailing operator (1 error(s)) ===
> >>> gcc/collect2.c:1155:14:    ld_file_name =
> >>>
> >>>>
> >>>>     PR driver/93645
> >>>>     * common.opt (--ld-path=): Add --ld-path=
> >>>>     * opts.c (common_handle_option): Handle OPT__ld_path_.
> >>>>     * gcc.c (driver_handle_option): Likewise.
> >>>>     * collect2.c (main): Likewise.
> >>>>     * doc/invoke.texi: Document --ld-path=.
> >>>>
> >>>> ---
> >>>> Changes in v2:
> >>>> * Renamed -fld-path= to --ld-path= (clang 12.0.0 new option).
> >>>>    The option does not affect code generation and is not a language
> >>>> feature,
> >>>>    -f* is not suitable. Additionally, clang has other similar --*-path=
> >>>>    options, e.g. --cuda-path=.
> >>>> ---
> >>>>   gcc/collect2.c      | 63 +++++++++++++++++++++++++++++++++++----------
> >>>>   gcc/common.opt      |  4 +++
> >>>>   gcc/doc/invoke.texi |  9 +++++++
> >>>>   gcc/gcc.c           |  2 +-
> >>>>   gcc/opts.c          |  1 +
> >>>>   5 files changed, 64 insertions(+), 15 deletions(-)
> >>>>
> >>>> diff --git a/gcc/collect2.c b/gcc/collect2.c
> >>>> index f8a5ce45994..caa1b96ab52 100644
> >>>> --- a/gcc/collect2.c
> >>>> +++ b/gcc/collect2.c
> >>>> @@ -844,6 +844,7 @@ main (int argc, char **argv)
> >>>>     const char **ld1;
> >>>>     bool use_plugin = false;
> >>>>     bool use_collect_ld = false;
> >>>> +  const char *ld_path = NULL;
> >>>>     /* 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
> >>>> @@ -961,12 +962,21 @@ main (int argc, char **argv)
> >>>>           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;
> >>>> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
> >>>> -      selected_linker = USE_LLD_LD;
> >>>> +    else if (strncmp (argv[i], "-fuse-ld=", 9) == 0
> >>>> +         && selected_linker != USE_LD_MAX)
> >>>> +      {
> >>>> +        if (strcmp (argv[i] + 9, "bfd") == 0)
> >>>> +          selected_linker = USE_BFD_LD;
> >>>> +        else if (strcmp (argv[i] + 9, "gold") == 0)
> >>>> +          selected_linker = USE_GOLD_LD;
> >>>> +        else if (strcmp (argv[i] + 9, "lld") == 0)
> >>>> +          selected_linker = USE_LLD_LD;
> >>>> +      }
> >>>> +    else if (strncmp (argv[i], "--ld-path=", 10) == 0)
> >>>> +      {
> >>>> +        ld_path = argv[i] + 10;
> >>>> +        selected_linker = USE_LD_MAX;
> >>>> +      }
> >>>>       else if (strncmp (argv[i], "-o", 2) == 0)
> >>>>         {
> >>>>           /* Parse the output filename if it's given so that we can make
> >>>> @@ -1117,14 +1127,34 @@ main (int argc, char **argv)
> >>>>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
> >>>>         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, ld_suffixes[selected_linker],
> >>>> X_OK);
> >>>> -  /* 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,
> >>>> full_ld_suffixes[selected_linker], X_OK);
> >>>> +  if (selected_linker == USE_LD_MAX)
> >>>> +    {
> >>>> +      /* If --ld-path= does not contain a path component separator,
> >>>> search for
> >>>> +     the command using cpath, then using path.  Otherwise find the
> >>>> linker
> >>>> +     relative to the current working directory.  */
> >>>> +      if (lbasename (ld_path) == ld_path)
> >>>> +    {
> >>>> +      ld_file_name = find_a_file (&cpath, ld_path, X_OK);
> >>>> +      if (ld_file_name == 0)
> >>>> +        ld_file_name = find_a_file (&path, ld_path, X_OK);
> >>>> +    }
> >>>> +      else if (file_exists (ld_path))
> >>>> +    {
> >>>
> >>> ^^^ these braces are not needed.
> >>>
> >>>> +      ld_file_name = ld_path;
> >>>> +    }
> >>>> +    }
> >>>> +  else
> >>>> +    {
> >>>> +      /* Search the compiler directories for `ld'.  We have protection
> >>>> against
> >>>> +     recursive calls in find_a_file.  */
> >>>> +      if (ld_file_name == 0)
> >>>
> >>> I would prefer '== NULL'.
> >>>
> >>>> +    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker],
> >>>> X_OK);
> >>>> +      /* 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, full_ld_suffixes[selected_linker], X_OK);
> >>>> +    }
> >>>>   #ifdef REAL_NM_FILE_NAME
> >>>>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
> >>>> @@ -1461,6 +1491,11 @@ main (int argc, char **argv)
> >>>>             ld2--;
> >>>>   #endif
> >>>>           }
> >>>> +          else if (strncmp (arg, "--ld-path=", 10) == 0)
> >>>> +        {
> >>>> +          ld1--;
> >>>> +          ld2--;
> >>>> +        }
> >>>
> >>> Can you please explain more this change?
> >>>
> >>> Thank you,
> >>> Martin
> >>>
> >>>>             else if (strncmp (arg, "--sysroot=", 10) == 0)
> >>>>           target_system_root = arg + 10;
> >>>>             else if (strcmp (arg, "--version") == 0)
> >>>> diff --git a/gcc/common.opt b/gcc/common.opt
> >>>> index a3893a4725e..5adbd8c18a3 100644
> >>>> --- a/gcc/common.opt
> >>>> +++ b/gcc/common.opt
> >>>> @@ -2940,6 +2940,10 @@ fuse-ld=lld
> >>>>   Common Driver Negative(fuse-ld=lld)
> >>>>   Use the lld LLVM linker instead of the default linker.
> >>>> +-ld-path=
> >>>> +Common Driver Joined
> >>>> +Use the specified executable instead of the default linker.
> >>>> +
> >>>>   fuse-linker-plugin
> >>>>   Common Undocumented Var(flag_use_linker_plugin)
> >>>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> >>>> index ba18e05fb1a..e185e40ffac 100644
> >>>> --- a/gcc/doc/invoke.texi
> >>>> +++ b/gcc/doc/invoke.texi
> >>>> @@ -14718,6 +14718,15 @@ Use the @command{gold} linker instead of the
> >>>> default linker.
> >>>>   @opindex fuse-ld=lld
> >>>>   Use the LLVM @command{lld} linker instead of the default linker.
> >>>> +@item --ld-path=@var{linker}
> >>>> +@opindex -ld-path=linker
> >>>> +Use the specified executable named @var{linker} instead of the default
> >>>> linker.
> >>>> +If @var{linker} does not contain any path component separator (e.g. a
> >>>> slash),
> >>>> +the linker will be searched for using @env{COMPILER_PATH} followed by
> >>>> +@env{PATH}. Otherwise, it is either an absolute path or a path relative
> >>>> to the
> >>>> +current working directory.  If @option{-fuse-ld=} is also specified, the
> >>>> linker
> >>>> +path is specified by @option{--ld-path=}.
> >>>> +
> >>>>   @cindex Libraries
> >>>>   @item -l@var{library}
> >>>>   @itemx -l @var{library}
> >>>> diff --git a/gcc/gcc.c b/gcc/gcc.c
> >>>> index c0eb3c10cfd..05fa5375f06 100644
> >>>> --- a/gcc/gcc.c
> >>>> +++ b/gcc/gcc.c
> >>>> @@ -1077,7 +1077,7 @@ proper position among the other output files.  */
> >>>>       LINK_PLUGIN_SPEC \
> >>>>      "%{flto|flto=*:%<fcompare-debug*} \
> >>>>       %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
> >>>> -   "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
> >>>> +   "%{fuse-ld=*:-fuse-ld=%*} %{-ld-path=*:--ld-path=%*} "
> >>>> LINK_COMPRESS_DEBUG_SPEC \
> >>>>      "%X %{o*} %{e*} %{N} %{n} %{r}\
> >>>>       %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
> >>>>       %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
> >>>> diff --git a/gcc/opts.c b/gcc/opts.c
> >>>> index 499eb900643..5cbf9b85549 100644
> >>>> --- a/gcc/opts.c
> >>>> +++ b/gcc/opts.c
> >>>> @@ -2755,6 +2755,7 @@ common_handle_option (struct gcc_options *opts,
> >>>>         dc->max_errors = value;
> >>>>         break;
> >>>> +    case OPT__ld_path_:
> >>>>       case OPT_fuse_ld_bfd:
> >>>>       case OPT_fuse_ld_gold:
> >>>>       case OPT_fuse_ld_lld:
> >>>>
> >>>
> >>
> > 
> 
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2021-01-14 10:07                                               ` Richard Biener
@ 2021-01-14 13:21                                                 ` Martin Liška
  2021-01-14 20:21                                                   ` Fangrui Song
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2021-01-14 13:21 UTC (permalink / raw)
  To: Richard Biener; +Cc: Fangrui Song, gcc-patches, jakub

On 1/14/21 11:07 AM, Richard Biener wrote:
> I see no particular reason to allow arbitrary garbage to be used as
> linker.  It just asks for users to shoot themselves in the foot and
> for strange bugreports to pop up.

Well, for a strange bug report, we'll see eventually usage of the --ld-path= option.

I see it handy when developing a ld feature to be able to point to a built ld
(without need to build GCC with it). Yes, one can use --save-temps --verbose
and invoke the built linker, but it's not handy.

Martin


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2021-01-14 13:21                                                 ` Martin Liška
@ 2021-01-14 20:21                                                   ` Fangrui Song
  2021-01-14 20:35                                                     ` Jakub Jelinek
  0 siblings, 1 reply; 44+ messages in thread
From: Fangrui Song @ 2021-01-14 20:21 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, Martin Liška, jakub

On 2021-01-14, Martin Liška wrote:
>On 1/14/21 11:07 AM, Richard Biener wrote:
>>I see no particular reason to allow arbitrary garbage to be used as
>>linker.  It just asks for users to shoot themselves in the foot and
>>for strange bugreports to pop up.
>
>Well, for a strange bug report, we'll see eventually usage of the --ld-path= option.
>
>I see it handy when developing a ld feature to be able to point to a built ld
>(without need to build GCC with it). Yes, one can use --save-temps --verbose
>and invoke the built linker, but it's not handy.
>
>Martin
>

I did this when I worked on some GNU ld features.
clang --ld-path=/path/to/binutils/out/debug/ld/ld-new
or debugging some Linux kernel issues related to ld.

Having --ld-path= in GCC will be handy.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v2] Add --ld-path= to specify an arbitrary executable as the linker
  2021-01-14 20:21                                                   ` Fangrui Song
@ 2021-01-14 20:35                                                     ` Jakub Jelinek
  0 siblings, 0 replies; 44+ messages in thread
From: Jakub Jelinek @ 2021-01-14 20:35 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Richard Biener, gcc-patches, Martin Liška

On Thu, Jan 14, 2021 at 12:21:05PM -0800, Fangrui Song wrote:
> On 2021-01-14, Martin Liška wrote:
> > On 1/14/21 11:07 AM, Richard Biener wrote:
> > > I see no particular reason to allow arbitrary garbage to be used as
> > > linker.  It just asks for users to shoot themselves in the foot and
> > > for strange bugreports to pop up.
> > 
> > Well, for a strange bug report, we'll see eventually usage of the --ld-path= option.
> > 
> > I see it handy when developing a ld feature to be able to point to a built ld
> > (without need to build GCC with it). Yes, one can use --save-temps --verbose
> > and invoke the built linker, but it's not handy.
> > 
> > Martin
> > 
> 
> I did this when I worked on some GNU ld features.
> clang --ld-path=/path/to/binutils/out/debug/ld/ld-new
> or debugging some Linux kernel issues related to ld.
> 
> Having --ld-path= in GCC will be handy.

If the linker is called ld and there isn't random unrelated stuff in the
same directory, one can always just use -B path/to/ld/

	Jakub


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 13:41       ` Artur Sinila
@ 2021-06-28 13:49         ` Jakub Jelinek
  0 siblings, 0 replies; 44+ messages in thread
From: Jakub Jelinek @ 2021-06-28 13:49 UTC (permalink / raw)
  To: freesoftware; +Cc: Martin Liška, gcc-patches, H.J. Lu, Jan Hubicka

On Mon, Jun 28, 2021 at 04:41:06PM +0300, Artur Sinila wrote:
> See https://reviews.llvm.org/D83015. Speaking about -B option, AFAIK it
> will make gcc to search for collect2, cc and other tools in specified
> directory, so apart from creating a symlink to mold, I'll also need to
> create symlinks to all those tools. Didn't try it in practice though.

You don't.  -B adds a path to the list of paths searched for the various
tools etc.  If the tool is not found in any of those directories, the
search continues in the standard paths etc. as described in the
documentation.

	Jakub


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 13:26     ` Martin Liška
  2021-06-28 13:41       ` Artur Sinila
@ 2021-06-28 13:46       ` Jakub Jelinek
  1 sibling, 0 replies; 44+ messages in thread
From: Jakub Jelinek @ 2021-06-28 13:46 UTC (permalink / raw)
  To: Martin Liška; +Cc: freesoftware, gcc-patches, H.J. Lu, Jan Hubicka

On Mon, Jun 28, 2021 at 03:26:21PM +0200, Martin Liška wrote:
> > There are 2 options:
> > 1. Add mold to -fuse-ld option
> > 2. Implement --ld-path
> > 
> > The 2nd option is much more future-proof: you won't need to add new
> > -fuse-ld variant each time new linker comes up. To provide some
> > context: clang had been supporting passing path to -fuse-ld, but since
> > clang 12 this is deprecated in favor of new --ld-path option. I think
> > we should take an example from clang and implement this useful feature
> > in gcc as well.
> 
> Can you please provide a pointer for the deprecation.
> I'm adding Jakub who recommended using the -B argument.

-B will work with any gcc version, at least from the past 3+ decades,
just mkdir /whatever/dir/ and put the linker or symlink (with ld basename)
to it there, then -B /whatever/dir/

--ld-path= is a bad idea, it doesn't follow use any usual option naming
conventions.

Note, all these extra linkers (lld, mold) will not really work properly,
gcc during configuration detects various assembler and linker properties
on which it then relies on and I'm sure neither lld nor mold supports
those features.

HAVE_LD_ALIGNED_SHF_MERGE
HAVE_LD_AS_NEEDED
HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH
HAVE_LD_BNDPLT_SUPPORT
HAVE_LD_BROKEN_PE_DWARF5
HAVE_LD_BUILDID
HAVE_LD_CLEARCAP
HAVE_LD_COMPRESS_DEBUG
HAVE_LD_DEMANGLE
HAVE_LD_EH_FRAME_CIEV3
HAVE_LD_EH_FRAME_HDR
HAVE_LD_EH_GC_SECTIONS
HAVE_LD_EH_GC_SECTIONS_BUG
HAVE_LD_LARGE_TOC
HAVE_LD_NO_DOT_SYMS
HAVE_LD_PERSONALITY_RELAXATION
HAVE_LD_PIE
HAVE_LD_PIE_COPYRELOC
HAVE_LD_PPC_GNU_ATTR_LONG_DOUBLE
HAVE_LD_PUSHPOPSTATE_SUPPORT
HAVE_LD_RO_RW_SECTION_MIXING
HAVE_LD_SOL2_EMULATION
HAVE_LD_STATIC_DYNAMIC
HAVE_LD_SYSROOT

is what is currently tested (not all of these for all targets).

	Jakub


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 13:26     ` Martin Liška
@ 2021-06-28 13:41       ` Artur Sinila
  2021-06-28 13:49         ` Jakub Jelinek
  2021-06-28 13:46       ` Jakub Jelinek
  1 sibling, 1 reply; 44+ messages in thread
From: Artur Sinila @ 2021-06-28 13:41 UTC (permalink / raw)
  To: Martin Liška, gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Jakub Jelinek

On Mon, 2021-06-28 at 15:26 +0200, Martin Liška wrote:
> On 6/28/21 2:24 PM, Artur Sinila wrote:
> > On Mon, 2021-06-28 at 14:08 +0200, Martin Liška wrote:
> > > On 6/26/21 4:44 PM, Artur Sinila wrote:
> > > > Not so gentle ping :)
> > > > What should happen in order for this patch to be accepted?
> > > > 
> > > 
> > > Hello.
> > > 
> > > We came up to conclusion that one can use the currently supported
> > > option
> > > -fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary
> > > path
> > > the such linker is expected.
> > > 
> > > Cheers,
> > > Martin
> > 
> > Hello.
> > 
> > Thank you for the reply. I'd like to use mold linker with gcc:
> > https://github.com/rui314/mold. So your solution doesn't help.
> 
> Well, kind of works. You only need to create a symlink called
> ld which will point to your linker (plus using -B argument as
> mentioned).
> 
> > 
> > There are 2 options:
> > 1. Add mold to -fuse-ld option
> > 2. Implement --ld-path
> > 
> > The 2nd option is much more future-proof: you won't need to add new
> > -fuse-ld variant each time new linker comes up. To provide some
> > context: clang had been supporting passing path to -fuse-ld, but
> > since
> > clang 12 this is deprecated in favor of new --ld-path option. I
> > think
> > we should take an example from clang and implement this useful
> > feature
> > in gcc as well.
> 
> Can you please provide a pointer for the deprecation.
> I'm adding Jakub who recommended using the -B argument.
> 
> Martin
> 
> > 
> > Cheers,
> > Artur Sinila
> > 
> 

See https://reviews.llvm.org/D83015. Speaking about -B option, AFAIK it
will make gcc to search for collect2, cc and other tools in specified
directory, so apart from creating a symlink to mold, I'll also need to
create symlinks to all those tools. Didn't try it in practice though.

Best regards,
Artur Sinila


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 12:24   ` Artur Sinila
@ 2021-06-28 13:26     ` Martin Liška
  2021-06-28 13:41       ` Artur Sinila
  2021-06-28 13:46       ` Jakub Jelinek
  0 siblings, 2 replies; 44+ messages in thread
From: Martin Liška @ 2021-06-28 13:26 UTC (permalink / raw)
  To: freesoftware, gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Jakub Jelinek

On 6/28/21 2:24 PM, Artur Sinila wrote:
> On Mon, 2021-06-28 at 14:08 +0200, Martin Liška wrote:
>> On 6/26/21 4:44 PM, Artur Sinila wrote:
>>> Not so gentle ping :)
>>> What should happen in order for this patch to be accepted?
>>>
>>
>> Hello.
>>
>> We came up to conclusion that one can use the currently supported
>> option
>> -fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary path
>> the such linker is expected.
>>
>> Cheers,
>> Martin
> 
> Hello.
> 
> Thank you for the reply. I'd like to use mold linker with gcc:
> https://github.com/rui314/mold. So your solution doesn't help.

Well, kind of works. You only need to create a symlink called
ld which will point to your linker (plus using -B argument as mentioned).

> 
> There are 2 options:
> 1. Add mold to -fuse-ld option
> 2. Implement --ld-path
> 
> The 2nd option is much more future-proof: you won't need to add new
> -fuse-ld variant each time new linker comes up. To provide some
> context: clang had been supporting passing path to -fuse-ld, but since
> clang 12 this is deprecated in favor of new --ld-path option. I think
> we should take an example from clang and implement this useful feature
> in gcc as well.

Can you please provide a pointer for the deprecation.
I'm adding Jakub who recommended using the -B argument.

Martin

> 
> Cheers,
> Artur Sinila
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 12:08 ` Martin Liška
@ 2021-06-28 12:24   ` Artur Sinila
  2021-06-28 13:26     ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Artur Sinila @ 2021-06-28 12:24 UTC (permalink / raw)
  To: Martin Liška, gcc-patches; +Cc: H.J. Lu, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]

On Mon, 2021-06-28 at 14:08 +0200, Martin Liška wrote:
> On 6/26/21 4:44 PM, Artur Sinila wrote:
> > Not so gentle ping :)
> > What should happen in order for this patch to be accepted?
> > 
> 
> Hello.
> 
> We came up to conclusion that one can use the currently supported
> option
> -fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary path
> the such linker is expected.
> 
> Cheers,
> Martin

Hello.

Thank you for the reply. I'd like to use mold linker with gcc:
https://github.com/rui314/mold. So your solution doesn't help.

There are 2 options:
1. Add mold to -fuse-ld option
2. Implement --ld-path

The 2nd option is much more future-proof: you won't need to add new
-fuse-ld variant each time new linker comes up. To provide some
context: clang had been supporting passing path to -fuse-ld, but since
clang 12 this is deprecated in favor of new --ld-path option. I think
we should take an example from clang and implement this useful feature
in gcc as well.

Cheers,
Artur Sinila

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-26 14:44 [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Artur Sinila
@ 2021-06-28 12:08 ` Martin Liška
  2021-06-28 12:24   ` Artur Sinila
  0 siblings, 1 reply; 44+ messages in thread
From: Martin Liška @ 2021-06-28 12:08 UTC (permalink / raw)
  To: freesoftware, gcc-patches; +Cc: H.J. Lu, Jan Hubicka

On 6/26/21 4:44 PM, Artur Sinila wrote:
> Not so gentle ping :)
> What should happen in order for this patch to be accepted?
> 

Hello.

We came up to conclusion that one can use the currently supported option
-fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary path
the such linker is expected.

Cheers,
Martin

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
@ 2021-06-26 14:44 Artur Sinila
  2021-06-28 12:08 ` Martin Liška
  0 siblings, 1 reply; 44+ messages in thread
From: Artur Sinila @ 2021-06-26 14:44 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Martin Liska

[-- Attachment #1: Type: text/plain, Size: 83 bytes --]

Not so gentle ping :)
What should happen in order for this patch to be accepted?

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2021-06-28 13:49 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10  0:02 [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Fangrui Song via gcc-patches
2020-02-13 17:59 ` Fangrui Song via gcc-patches
2020-02-24 23:02   ` Fangrui Song via gcc-patches
2020-03-10 17:19     ` [PING^3][PATCH] " Fangrui Song
2020-03-11 12:55 ` [PATCH] " Martin Liška
2020-04-05 22:32   ` Fangrui Song
2020-04-06  7:18     ` Martin Liška
2020-05-19 19:21       ` [PATCH] Add -fuse-ld= to specify an arbitrary executable as the linker Fangrui Song
2020-05-20 13:45         ` Martin Liška
2020-05-20 23:52           ` [PATCH v2] " Fangrui Song
2020-05-21  8:43             ` Martin Liška
2020-05-22  4:42               ` [PATCH v3] " Fangrui Song
2020-05-25  9:57                 ` Martin Liška
2020-05-29  1:10                   ` Fangrui Song
2020-06-30 12:51                     ` Martin Liška
2020-06-30 15:32                       ` Fāng-ruì Sòng
2020-07-01  7:13                         ` Martin Liška
2020-07-02  4:59                           ` Fāng-ruì Sòng
2020-07-02 19:34                             ` [PATCH] Add -fld-path= " Fāng-ruì Sòng
2020-07-03 13:06                               ` Martin Liška
2020-07-03 17:18                                 ` Fāng-ruì Sòng
2020-07-07 10:16                                   ` Martin Liška
2020-07-21  4:07                                     ` [PATCH v2] Add --ld-path= " Fangrui Song
2020-07-23 10:17                                       ` Martin Liška
2020-07-25  5:59                                         ` [PATCH v3] " Fangrui Song
2020-07-25  7:09                                           ` Andreas Schwab
2020-07-26  6:31                                             ` Fāng-ruì Sòng
2020-07-26 11:02                                               ` Andreas Schwab
2020-07-26 15:48                                                 ` Fāng-ruì Sòng
2020-12-04 13:45                                         ` [PATCH v2] " Martin Liška
2020-12-17  0:13                                           ` Fāng-ruì Sòng
2021-01-06 14:22                                           ` Martin Liška
2021-01-14  9:04                                             ` Martin Liška
2021-01-14 10:07                                               ` Richard Biener
2021-01-14 13:21                                                 ` Martin Liška
2021-01-14 20:21                                                   ` Fangrui Song
2021-01-14 20:35                                                     ` Jakub Jelinek
2021-06-26 14:44 [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Artur Sinila
2021-06-28 12:08 ` Martin Liška
2021-06-28 12:24   ` Artur Sinila
2021-06-28 13:26     ` Martin Liška
2021-06-28 13:41       ` Artur Sinila
2021-06-28 13:49         ` Jakub Jelinek
2021-06-28 13:46       ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).