public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: Fangrui Song <maskray@google.com>, rui314@gmail.com
Subject: [PATCH] Support ld.mold linker.
Date: Tue, 28 Dec 2021 14:10:06 +0100	[thread overview]
Message-ID: <8b943a67-4b1e-9fa1-4422-220d984387ac@suse.cz> (raw)

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


             reply	other threads:[~2021-12-28 13:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-28 13:10 Martin Liška [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8b943a67-4b1e-9fa1-4422-220d984387ac@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=maskray@google.com \
    --cc=rui314@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).