public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Support ld.mold linker.
@ 2021-12-28 13:10 Martin Liška
  2021-12-28 13:21 ` H.J. Lu
  2022-01-03 14:48 ` Richard Biener
  0 siblings, 2 replies; 8+ messages in thread
From: Martin Liška @ 2021-12-28 13:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: Fangrui Song, rui314

Hello.

The mold linker is getting quite popular and I think we should support it:
https://github.com/rui314/mold

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

---
  gcc/collect2.c | 10 +++++++---
  gcc/common.opt |  4 ++++
  gcc/gcc.c      |  4 ++++
  gcc/opts.c     |  1 +
  4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index d47fe3f9195..b322527847c 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -776,6 +776,7 @@ main (int argc, char **argv)
        USE_GOLD_LD,
        USE_BFD_LD,
        USE_LLD_LD,
+      USE_MOLD_LD,
        USE_LD_MAX
      } selected_linker = USE_DEFAULT_LD;
    static const char *const ld_suffixes[USE_LD_MAX] =
@@ -784,7 +785,8 @@ main (int argc, char **argv)
        PLUGIN_LD_SUFFIX,
        "ld.gold",
        "ld.bfd",
-      "ld.lld"
+      "ld.lld",
+      "ld.mold"
      };
    static const char *const real_ld_suffix = "real-ld";
    static const char *const collect_ld_suffix = "collect-ld";
@@ -957,6 +959,8 @@ 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 (strcmp (argv[i], "-fuse-ld=mold") == 0)
+	  selected_linker = USE_MOLD_LD;
  	else if (startswith (argv[i], "-o"))
  	  {
  	    /* Parse the output filename if it's given so that we can make
@@ -1048,7 +1052,7 @@ main (int argc, char **argv)
    ld_file_name = 0;
  #ifdef DEFAULT_LINKER
    if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
-      selected_linker == USE_LLD_LD)
+      selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD)
      {
        char *linker_name;
  # ifdef HOST_EXECUTABLE_SUFFIX
@@ -1283,7 +1287,7 @@ main (int argc, char **argv)
  	      else if (!use_collect_ld
  		       && startswith (arg, "-fuse-ld="))
  		{
-		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
+		  /* Do not pass -fuse-ld={bfd|gold|lld|mold} to the linker. */
  		  ld1--;
  		  ld2--;
  		}
diff --git a/gcc/common.opt b/gcc/common.opt
index 2ed818d6057..dba3fa886f9 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3046,6 +3046,10 @@ fuse-ld=lld
  Common Driver Negative(fuse-ld=lld)
  Use the lld LLVM linker instead of the default linker.
  
+fuse-ld=mold
+Common Driver Negative(fuse-ld=mold)
+Use the Modern linker (MOLD) linker instead of the default linker.
+
  fuse-linker-plugin
  Common Undocumented Var(flag_use_linker_plugin)
  
diff --git a/gcc/gcc.c b/gcc/gcc.c
index b75b50b87b2..06e18a75b52 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4282,6 +4282,10 @@ driver_handle_option (struct gcc_options *opts,
         use_ld = ".gold";
         break;
  
+    case OPT_fuse_ld_mold:
+       use_ld = ".mold";
+       break;
+
      case OPT_fcompare_debug_second:
        compare_debug_second = 1;
        break;
diff --git a/gcc/opts.c b/gcc/opts.c
index cdd6463e49b..60f1cf045c9 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -3094,6 +3094,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_mold:
      case OPT_fuse_linker_plugin:
        /* No-op. Used by the driver and passed to us because it starts with f.*/
        break;
-- 
2.34.1


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

* Re: [PATCH] Support ld.mold linker.
  2021-12-28 13:10 [PATCH] Support ld.mold linker Martin Liška
@ 2021-12-28 13:21 ` H.J. Lu
  2021-12-28 14:19   ` Martin Liška
  2022-01-03 14:48 ` Richard Biener
  1 sibling, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2021-12-28 13:21 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, rui314

On Tue, Dec 28, 2021 at 5:10 AM Martin Liška <mliska@suse.cz> wrote:
>
> Hello.
>
> The mold linker is getting quite popular and I think we should support it:
> https://github.com/rui314/mold
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> ---
>   gcc/collect2.c | 10 +++++++---
>   gcc/common.opt |  4 ++++
>   gcc/gcc.c      |  4 ++++
>   gcc/opts.c     |  1 +
>   4 files changed, 16 insertions(+), 3 deletions(-)

Missing invoke.texi change.

> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index d47fe3f9195..b322527847c 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -776,6 +776,7 @@ main (int argc, char **argv)
>         USE_GOLD_LD,
>         USE_BFD_LD,
>         USE_LLD_LD,
> +      USE_MOLD_LD,
>         USE_LD_MAX
>       } selected_linker = USE_DEFAULT_LD;
>     static const char *const ld_suffixes[USE_LD_MAX] =
> @@ -784,7 +785,8 @@ main (int argc, char **argv)
>         PLUGIN_LD_SUFFIX,
>         "ld.gold",
>         "ld.bfd",
> -      "ld.lld"
> +      "ld.lld",
> +      "ld.mold"
>       };
>     static const char *const real_ld_suffix = "real-ld";
>     static const char *const collect_ld_suffix = "collect-ld";
> @@ -957,6 +959,8 @@ 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 (strcmp (argv[i], "-fuse-ld=mold") == 0)
> +         selected_linker = USE_MOLD_LD;
>         else if (startswith (argv[i], "-o"))
>           {
>             /* Parse the output filename if it's given so that we can make
> @@ -1048,7 +1052,7 @@ main (int argc, char **argv)
>     ld_file_name = 0;
>   #ifdef DEFAULT_LINKER
>     if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
> -      selected_linker == USE_LLD_LD)
> +      selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD)
>       {
>         char *linker_name;
>   # ifdef HOST_EXECUTABLE_SUFFIX
> @@ -1283,7 +1287,7 @@ main (int argc, char **argv)
>               else if (!use_collect_ld
>                        && startswith (arg, "-fuse-ld="))
>                 {
> -                 /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
> +                 /* Do not pass -fuse-ld={bfd|gold|lld|mold} to the linker. */
>                   ld1--;
>                   ld2--;
>                 }
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 2ed818d6057..dba3fa886f9 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -3046,6 +3046,10 @@ fuse-ld=lld
>   Common Driver Negative(fuse-ld=lld)
>   Use the lld LLVM linker instead of the default linker.
>
> +fuse-ld=mold
> +Common Driver Negative(fuse-ld=mold)
> +Use the Modern linker (MOLD) linker instead of the default linker.
> +
>   fuse-linker-plugin
>   Common Undocumented Var(flag_use_linker_plugin)
>
> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index b75b50b87b2..06e18a75b52 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -4282,6 +4282,10 @@ driver_handle_option (struct gcc_options *opts,
>          use_ld = ".gold";
>          break;
>
> +    case OPT_fuse_ld_mold:
> +       use_ld = ".mold";
> +       break;
> +
>       case OPT_fcompare_debug_second:
>         compare_debug_second = 1;
>         break;
> diff --git a/gcc/opts.c b/gcc/opts.c
> index cdd6463e49b..60f1cf045c9 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -3094,6 +3094,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_mold:
>       case OPT_fuse_linker_plugin:
>         /* No-op. Used by the driver and passed to us because it starts with f.*/
>         break;
> --
> 2.34.1
>


-- 
H.J.

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

* Re: [PATCH] Support ld.mold linker.
  2021-12-28 13:21 ` H.J. Lu
@ 2021-12-28 14:19   ` Martin Liška
  2021-12-28 15:29     ` Jeff Law
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Liška @ 2021-12-28 14:19 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches, rui314

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

On 12/28/21 14:21, H.J. Lu wrote:
> Missing invoke.texi change.

Oh, sure and I also missed ChangeLog entry.

Fixed in the attached patch.
Martin

[-- Attachment #2: 0001-Support-ld.mold-linker.patch --]
[-- Type: text/x-patch, Size: 4028 bytes --]

From ca60317a60ee20ce848b36588b905b5a63d81350 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Tue, 21 Dec 2021 17:43:55 +0100
Subject: [PATCH] Support ld.mold linker.

gcc/ChangeLog:

	* collect2.c (main): Add ld.mold.
	* common.opt: Add -fuse-ld=mold.
	* doc/invoke.texi: Document it.
	* gcc.c (driver_handle_option): Handle -fuse-ld=mold.
	* opts.c (common_handle_option): Likewise.
---
 gcc/collect2.c      | 10 +++++++---
 gcc/common.opt      |  4 ++++
 gcc/doc/invoke.texi |  4 ++++
 gcc/gcc.c           |  4 ++++
 gcc/opts.c          |  1 +
 5 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index d47fe3f9195..b322527847c 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -776,6 +776,7 @@ main (int argc, char **argv)
       USE_GOLD_LD,
       USE_BFD_LD,
       USE_LLD_LD,
+      USE_MOLD_LD,
       USE_LD_MAX
     } selected_linker = USE_DEFAULT_LD;
   static const char *const ld_suffixes[USE_LD_MAX] =
@@ -784,7 +785,8 @@ main (int argc, char **argv)
       PLUGIN_LD_SUFFIX,
       "ld.gold",
       "ld.bfd",
-      "ld.lld"
+      "ld.lld",
+      "ld.mold"
     };
   static const char *const real_ld_suffix = "real-ld";
   static const char *const collect_ld_suffix = "collect-ld";
@@ -957,6 +959,8 @@ 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 (strcmp (argv[i], "-fuse-ld=mold") == 0)
+	  selected_linker = USE_MOLD_LD;
 	else if (startswith (argv[i], "-o"))
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1048,7 +1052,7 @@ main (int argc, char **argv)
   ld_file_name = 0;
 #ifdef DEFAULT_LINKER
   if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
-      selected_linker == USE_LLD_LD)
+      selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD)
     {
       char *linker_name;
 # ifdef HOST_EXECUTABLE_SUFFIX
@@ -1283,7 +1287,7 @@ main (int argc, char **argv)
 	      else if (!use_collect_ld
 		       && startswith (arg, "-fuse-ld="))
 		{
-		  /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
+		  /* Do not pass -fuse-ld={bfd|gold|lld|mold} to the linker. */
 		  ld1--;
 		  ld2--;
 		}
diff --git a/gcc/common.opt b/gcc/common.opt
index 2ed818d6057..dba3fa886f9 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3046,6 +3046,10 @@ fuse-ld=lld
 Common Driver Negative(fuse-ld=lld)
 Use the lld LLVM linker instead of the default linker.
 
+fuse-ld=mold
+Common Driver Negative(fuse-ld=mold)
+Use the Modern linker (MOLD) linker 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 e644c63767b..54fa75ba138 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -16266,6 +16266,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=mold
+@opindex fuse-ld=mold
+Use the Modern Linker (@command{mold}) instead of the default linker.
+
 @cindex Libraries
 @item -l@var{library}
 @itemx -l @var{library}
diff --git a/gcc/gcc.c b/gcc/gcc.c
index b75b50b87b2..06e18a75b52 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4282,6 +4282,10 @@ driver_handle_option (struct gcc_options *opts,
        use_ld = ".gold";
        break;
 
+    case OPT_fuse_ld_mold:
+       use_ld = ".mold";
+       break;
+
     case OPT_fcompare_debug_second:
       compare_debug_second = 1;
       break;
diff --git a/gcc/opts.c b/gcc/opts.c
index e4e47ff77b3..f820052307c 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -3105,6 +3105,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_mold:
     case OPT_fuse_linker_plugin:
       /* No-op. Used by the driver and passed to us because it starts with f.*/
       break;
-- 
2.34.1


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

* Re: [PATCH] Support ld.mold linker.
  2021-12-28 14:19   ` Martin Liška
@ 2021-12-28 15:29     ` Jeff Law
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Law @ 2021-12-28 15:29 UTC (permalink / raw)
  To: Martin Liška, H.J. Lu; +Cc: rui314, GCC Patches



On 12/28/2021 7:19 AM, Martin Liška wrote:
> On 12/28/21 14:21, H.J. Lu wrote:
>> Missing invoke.texi change.
>
> Oh, sure and I also missed ChangeLog entry.
>
> Fixed in the attached patch.
> Martin
>
> 0001-Support-ld.mold-linker.patch
>
>  From ca60317a60ee20ce848b36588b905b5a63d81350 Mon Sep 17 00:00:00 2001
> From: Martin Liska <mliska@suse.cz>
> Date: Tue, 21 Dec 2021 17:43:55 +0100
> Subject: [PATCH] Support ld.mold linker.
>
> gcc/ChangeLog:
>
> 	* collect2.c (main): Add ld.mold.
> 	* common.opt: Add -fuse-ld=mold.
> 	* doc/invoke.texi: Document it.
> 	* gcc.c (driver_handle_option): Handle -fuse-ld=mold.
> 	* opts.c (common_handle_option): Likewise.
OK.
jeff


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

* Re: [PATCH] Support ld.mold linker.
  2021-12-28 13:10 [PATCH] Support ld.mold linker Martin Liška
  2021-12-28 13:21 ` H.J. Lu
@ 2022-01-03 14:48 ` Richard Biener
  2022-01-03 15:23   ` Martin Liška
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Biener @ 2022-01-03 14:48 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, rui314

On Tue, Dec 28, 2021 at 2:10 PM Martin Liška <mliska@suse.cz> wrote:
>
> Hello.
>
> The mold linker is getting quite popular and I think we should support it:
> https://github.com/rui314/mold

Does it support the gold plugin API/ABI and thus proper LTO?  If not
I'm not sure we should encourage use.   For example using
-flto -fuse-ld=lld will report strange

ld.lld: error: undefined symbol: main
>>> referenced by start.S:104 (../sysdeps/x86_64/start.S:104)
>>>               /usr/lib/../lib64/crt1.o:(_start)
collect2: error: ld returned 1 exit status

on a simple test with a main() unless I manually add -fno-use-linker-plugin.

Richard.

> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> ---
>   gcc/collect2.c | 10 +++++++---
>   gcc/common.opt |  4 ++++
>   gcc/gcc.c      |  4 ++++
>   gcc/opts.c     |  1 +
>   4 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index d47fe3f9195..b322527847c 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -776,6 +776,7 @@ main (int argc, char **argv)
>         USE_GOLD_LD,
>         USE_BFD_LD,
>         USE_LLD_LD,
> +      USE_MOLD_LD,
>         USE_LD_MAX
>       } selected_linker = USE_DEFAULT_LD;
>     static const char *const ld_suffixes[USE_LD_MAX] =
> @@ -784,7 +785,8 @@ main (int argc, char **argv)
>         PLUGIN_LD_SUFFIX,
>         "ld.gold",
>         "ld.bfd",
> -      "ld.lld"
> +      "ld.lld",
> +      "ld.mold"
>       };
>     static const char *const real_ld_suffix = "real-ld";
>     static const char *const collect_ld_suffix = "collect-ld";
> @@ -957,6 +959,8 @@ 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 (strcmp (argv[i], "-fuse-ld=mold") == 0)
> +         selected_linker = USE_MOLD_LD;
>         else if (startswith (argv[i], "-o"))
>           {
>             /* Parse the output filename if it's given so that we can make
> @@ -1048,7 +1052,7 @@ main (int argc, char **argv)
>     ld_file_name = 0;
>   #ifdef DEFAULT_LINKER
>     if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
> -      selected_linker == USE_LLD_LD)
> +      selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD)
>       {
>         char *linker_name;
>   # ifdef HOST_EXECUTABLE_SUFFIX
> @@ -1283,7 +1287,7 @@ main (int argc, char **argv)
>               else if (!use_collect_ld
>                        && startswith (arg, "-fuse-ld="))
>                 {
> -                 /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
> +                 /* Do not pass -fuse-ld={bfd|gold|lld|mold} to the linker. */
>                   ld1--;
>                   ld2--;
>                 }
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 2ed818d6057..dba3fa886f9 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -3046,6 +3046,10 @@ fuse-ld=lld
>   Common Driver Negative(fuse-ld=lld)
>   Use the lld LLVM linker instead of the default linker.
>
> +fuse-ld=mold
> +Common Driver Negative(fuse-ld=mold)
> +Use the Modern linker (MOLD) linker instead of the default linker.
> +
>   fuse-linker-plugin
>   Common Undocumented Var(flag_use_linker_plugin)
>
> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index b75b50b87b2..06e18a75b52 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -4282,6 +4282,10 @@ driver_handle_option (struct gcc_options *opts,
>          use_ld = ".gold";
>          break;
>
> +    case OPT_fuse_ld_mold:
> +       use_ld = ".mold";
> +       break;
> +
>       case OPT_fcompare_debug_second:
>         compare_debug_second = 1;
>         break;
> diff --git a/gcc/opts.c b/gcc/opts.c
> index cdd6463e49b..60f1cf045c9 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -3094,6 +3094,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_mold:
>       case OPT_fuse_linker_plugin:
>         /* No-op. Used by the driver and passed to us because it starts with f.*/
>         break;
> --
> 2.34.1
>

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

* Re: [PATCH] Support ld.mold linker.
  2022-01-03 14:48 ` Richard Biener
@ 2022-01-03 15:23   ` Martin Liška
  2022-01-04  7:23     ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Liška @ 2022-01-03 15:23 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, rui314

On 1/3/22 15:48, Richard Biener wrote:
> On Tue, Dec 28, 2021 at 2:10 PM Martin Liška <mliska@suse.cz> wrote:
>>
>> Hello.
>>
>> The mold linker is getting quite popular and I think we should support it:
>> https://github.com/rui314/mold
> 
> Does it support the gold plugin API/ABI and thus proper LTO?

No, but it's planned to be added:
https://github.com/rui314/mold/issues/181

> If not
> I'm not sure we should encourage use.   For example using
> -flto -fuse-ld=lld will report strange
> 
> ld.lld: error: undefined symbol: main
>>>> referenced by start.S:104 (../sysdeps/x86_64/start.S:104)
>>>>                /usr/lib/../lib64/crt1.o:(_start)
> collect2: error: ld returned 1 exit status
> 
> on a simple test with a main() unless I manually add -fno-use-linker-plugin.

Yep, that's consequence of the fact a compiler is not built with such linker.
Maybe we can add a documentation note, what do you think?

Cheers,
Martin

> 
> Richard.
> 
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
>> Thanks,
>> Martin
>>
>> ---
>>    gcc/collect2.c | 10 +++++++---
>>    gcc/common.opt |  4 ++++
>>    gcc/gcc.c      |  4 ++++
>>    gcc/opts.c     |  1 +
>>    4 files changed, 16 insertions(+), 3 deletions(-)
>>
>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>> index d47fe3f9195..b322527847c 100644
>> --- a/gcc/collect2.c
>> +++ b/gcc/collect2.c
>> @@ -776,6 +776,7 @@ main (int argc, char **argv)
>>          USE_GOLD_LD,
>>          USE_BFD_LD,
>>          USE_LLD_LD,
>> +      USE_MOLD_LD,
>>          USE_LD_MAX
>>        } selected_linker = USE_DEFAULT_LD;
>>      static const char *const ld_suffixes[USE_LD_MAX] =
>> @@ -784,7 +785,8 @@ main (int argc, char **argv)
>>          PLUGIN_LD_SUFFIX,
>>          "ld.gold",
>>          "ld.bfd",
>> -      "ld.lld"
>> +      "ld.lld",
>> +      "ld.mold"
>>        };
>>      static const char *const real_ld_suffix = "real-ld";
>>      static const char *const collect_ld_suffix = "collect-ld";
>> @@ -957,6 +959,8 @@ 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 (strcmp (argv[i], "-fuse-ld=mold") == 0)
>> +         selected_linker = USE_MOLD_LD;
>>          else if (startswith (argv[i], "-o"))
>>            {
>>              /* Parse the output filename if it's given so that we can make
>> @@ -1048,7 +1052,7 @@ main (int argc, char **argv)
>>      ld_file_name = 0;
>>    #ifdef DEFAULT_LINKER
>>      if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>> -      selected_linker == USE_LLD_LD)
>> +      selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD)
>>        {
>>          char *linker_name;
>>    # ifdef HOST_EXECUTABLE_SUFFIX
>> @@ -1283,7 +1287,7 @@ main (int argc, char **argv)
>>                else if (!use_collect_ld
>>                         && startswith (arg, "-fuse-ld="))
>>                  {
>> -                 /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
>> +                 /* Do not pass -fuse-ld={bfd|gold|lld|mold} to the linker. */
>>                    ld1--;
>>                    ld2--;
>>                  }
>> diff --git a/gcc/common.opt b/gcc/common.opt
>> index 2ed818d6057..dba3fa886f9 100644
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -3046,6 +3046,10 @@ fuse-ld=lld
>>    Common Driver Negative(fuse-ld=lld)
>>    Use the lld LLVM linker instead of the default linker.
>>
>> +fuse-ld=mold
>> +Common Driver Negative(fuse-ld=mold)
>> +Use the Modern linker (MOLD) linker instead of the default linker.
>> +
>>    fuse-linker-plugin
>>    Common Undocumented Var(flag_use_linker_plugin)
>>
>> diff --git a/gcc/gcc.c b/gcc/gcc.c
>> index b75b50b87b2..06e18a75b52 100644
>> --- a/gcc/gcc.c
>> +++ b/gcc/gcc.c
>> @@ -4282,6 +4282,10 @@ driver_handle_option (struct gcc_options *opts,
>>           use_ld = ".gold";
>>           break;
>>
>> +    case OPT_fuse_ld_mold:
>> +       use_ld = ".mold";
>> +       break;
>> +
>>        case OPT_fcompare_debug_second:
>>          compare_debug_second = 1;
>>          break;
>> diff --git a/gcc/opts.c b/gcc/opts.c
>> index cdd6463e49b..60f1cf045c9 100644
>> --- a/gcc/opts.c
>> +++ b/gcc/opts.c
>> @@ -3094,6 +3094,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_mold:
>>        case OPT_fuse_linker_plugin:
>>          /* No-op. Used by the driver and passed to us because it starts with f.*/
>>          break;
>> --
>> 2.34.1
>>


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

* Re: [PATCH] Support ld.mold linker.
  2022-01-03 15:23   ` Martin Liška
@ 2022-01-04  7:23     ` Richard Biener
  2022-01-05 11:36       ` Martin Liška
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2022-01-04  7:23 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, rui314

On Mon, Jan 3, 2022 at 4:23 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 1/3/22 15:48, Richard Biener wrote:
> > On Tue, Dec 28, 2021 at 2:10 PM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> Hello.
> >>
> >> The mold linker is getting quite popular and I think we should support it:
> >> https://github.com/rui314/mold
> >
> > Does it support the gold plugin API/ABI and thus proper LTO?
>
> No, but it's planned to be added:
> https://github.com/rui314/mold/issues/181
>
> > If not
> > I'm not sure we should encourage use.   For example using
> > -flto -fuse-ld=lld will report strange
> >
> > ld.lld: error: undefined symbol: main
> >>>> referenced by start.S:104 (../sysdeps/x86_64/start.S:104)
> >>>>                /usr/lib/../lib64/crt1.o:(_start)
> > collect2: error: ld returned 1 exit status
> >
> > on a simple test with a main() unless I manually add -fno-use-linker-plugin.
>
> Yep, that's consequence of the fact a compiler is not built with such linker.
> Maybe we can add a documentation note, what do you think?

Since we have a fixed set of supported linkers and we know their implementation
status with respect to linker plugin support we can maybe auto-add
-fno-use-linker-plugin
(via specs?) when -fuse-ld=lld or -fuse-ld=mold is used?  But yes,
adding a note to
the documentation that for lld and mold LTO support is severely
restricted compared to
GNU ld or gold on platforms that support the linker plugin and thus
their use is discouraged
there might be a good idea.

Richard.

>
> Cheers,
> Martin
>
> >
> > Richard.
> >
> >> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> >>
> >> Ready to be installed?
> >> Thanks,
> >> Martin
> >>
> >> ---
> >>    gcc/collect2.c | 10 +++++++---
> >>    gcc/common.opt |  4 ++++
> >>    gcc/gcc.c      |  4 ++++
> >>    gcc/opts.c     |  1 +
> >>    4 files changed, 16 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/gcc/collect2.c b/gcc/collect2.c
> >> index d47fe3f9195..b322527847c 100644
> >> --- a/gcc/collect2.c
> >> +++ b/gcc/collect2.c
> >> @@ -776,6 +776,7 @@ main (int argc, char **argv)
> >>          USE_GOLD_LD,
> >>          USE_BFD_LD,
> >>          USE_LLD_LD,
> >> +      USE_MOLD_LD,
> >>          USE_LD_MAX
> >>        } selected_linker = USE_DEFAULT_LD;
> >>      static const char *const ld_suffixes[USE_LD_MAX] =
> >> @@ -784,7 +785,8 @@ main (int argc, char **argv)
> >>          PLUGIN_LD_SUFFIX,
> >>          "ld.gold",
> >>          "ld.bfd",
> >> -      "ld.lld"
> >> +      "ld.lld",
> >> +      "ld.mold"
> >>        };
> >>      static const char *const real_ld_suffix = "real-ld";
> >>      static const char *const collect_ld_suffix = "collect-ld";
> >> @@ -957,6 +959,8 @@ 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 (strcmp (argv[i], "-fuse-ld=mold") == 0)
> >> +         selected_linker = USE_MOLD_LD;
> >>          else if (startswith (argv[i], "-o"))
> >>            {
> >>              /* Parse the output filename if it's given so that we can make
> >> @@ -1048,7 +1052,7 @@ main (int argc, char **argv)
> >>      ld_file_name = 0;
> >>    #ifdef DEFAULT_LINKER
> >>      if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
> >> -      selected_linker == USE_LLD_LD)
> >> +      selected_linker == USE_LLD_LD || selected_linker == USE_MOLD_LD)
> >>        {
> >>          char *linker_name;
> >>    # ifdef HOST_EXECUTABLE_SUFFIX
> >> @@ -1283,7 +1287,7 @@ main (int argc, char **argv)
> >>                else if (!use_collect_ld
> >>                         && startswith (arg, "-fuse-ld="))
> >>                  {
> >> -                 /* Do not pass -fuse-ld={bfd|gold|lld} to the linker. */
> >> +                 /* Do not pass -fuse-ld={bfd|gold|lld|mold} to the linker. */
> >>                    ld1--;
> >>                    ld2--;
> >>                  }
> >> diff --git a/gcc/common.opt b/gcc/common.opt
> >> index 2ed818d6057..dba3fa886f9 100644
> >> --- a/gcc/common.opt
> >> +++ b/gcc/common.opt
> >> @@ -3046,6 +3046,10 @@ fuse-ld=lld
> >>    Common Driver Negative(fuse-ld=lld)
> >>    Use the lld LLVM linker instead of the default linker.
> >>
> >> +fuse-ld=mold
> >> +Common Driver Negative(fuse-ld=mold)
> >> +Use the Modern linker (MOLD) linker instead of the default linker.
> >> +
> >>    fuse-linker-plugin
> >>    Common Undocumented Var(flag_use_linker_plugin)
> >>
> >> diff --git a/gcc/gcc.c b/gcc/gcc.c
> >> index b75b50b87b2..06e18a75b52 100644
> >> --- a/gcc/gcc.c
> >> +++ b/gcc/gcc.c
> >> @@ -4282,6 +4282,10 @@ driver_handle_option (struct gcc_options *opts,
> >>           use_ld = ".gold";
> >>           break;
> >>
> >> +    case OPT_fuse_ld_mold:
> >> +       use_ld = ".mold";
> >> +       break;
> >> +
> >>        case OPT_fcompare_debug_second:
> >>          compare_debug_second = 1;
> >>          break;
> >> diff --git a/gcc/opts.c b/gcc/opts.c
> >> index cdd6463e49b..60f1cf045c9 100644
> >> --- a/gcc/opts.c
> >> +++ b/gcc/opts.c
> >> @@ -3094,6 +3094,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_mold:
> >>        case OPT_fuse_linker_plugin:
> >>          /* No-op. Used by the driver and passed to us because it starts with f.*/
> >>          break;
> >> --
> >> 2.34.1
> >>
>

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

* Re: [PATCH] Support ld.mold linker.
  2022-01-04  7:23     ` Richard Biener
@ 2022-01-05 11:36       ` Martin Liška
  0 siblings, 0 replies; 8+ messages in thread
From: Martin Liška @ 2022-01-05 11:36 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, rui314

On 1/4/22 08:23, Richard Biener wrote:
> Since we have a fixed set of supported linkers and we know their implementation
> status with respect to linker plugin support we can maybe auto-add
> -fno-use-linker-plugin
> (via specs?) when -fuse-ld=lld or -fuse-ld=mold is used?

Well, if I'm correct, we do so when GCC is configured with --with-ld=...
That can perform version detection and so on. I still hope that ld.mold will
support LTO plug-in quite soon. It's even possible that it will be there
once GCC 12.1 is released.

> But yes,
> adding a note to
> the documentation that for lld and mold LTO support is severely
> restricted compared to
> GNU ld or gold on platforms that support the linker plugin and thus
> their use is discouraged
> there might be a good idea.

I'm going to do that if ld.mold LTO support won't be available
when 12.1 gets released.

Martin

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

end of thread, other threads:[~2022-01-05 11:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 13:10 [PATCH] Support ld.mold linker Martin Liška
2021-12-28 13:21 ` H.J. Lu
2021-12-28 14:19   ` Martin Liška
2021-12-28 15:29     ` Jeff Law
2022-01-03 14:48 ` Richard Biener
2022-01-03 15:23   ` Martin Liška
2022-01-04  7:23     ` Richard Biener
2022-01-05 11:36       ` Martin Liška

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).