From patchwork Tue Aug 15 17:20:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Geissler X-Patchwork-Id: 135683 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:3f2:4152:657d with SMTP id x8csp578841vqo; Tue, 15 Aug 2023 10:22:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEayE58G0BhVQ3QkDWUXLYog20J6HNLqWWEqZ68giEIjcbpeM/m2HnhbpaYtlW0nWT4BasF X-Received: by 2002:a17:906:cb:b0:99d:e417:d6f9 with SMTP id 11-20020a17090600cb00b0099de417d6f9mr212290eji.41.1692120132386; Tue, 15 Aug 2023 10:22:12 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gg22-20020a170906e29600b0099daaf200b5si3722410ejb.952.2023.08.15.10.22.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 10:22:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TUmCBxFA; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 442CB3856975 for ; Tue, 15 Aug 2023 17:22:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 442CB3856975 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692120131; bh=6WT+Wh9NnyhW05bCTfaGxTu956uaKPOsHbEiEwtHoZo=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=TUmCBxFAzXA53EcnCgZgjLSou2D8syS3KpUBsxoVoCOH4zmhnQlEqZpEEyYzTP7JN XEkcLXsXlnwq7fOfodt1/cMiYt3xXImMlSQoSmTy8/ufoELiCPU9QGbkPlYBE16mBX lxrFnfygnRaPjobfV2LJBrrUh382Sxith7DAs0Gs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2052.outbound.protection.outlook.com [40.107.14.52]) by sourceware.org (Postfix) with ESMTPS id 1EA043857715 for ; Tue, 15 Aug 2023 17:21:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EA043857715 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lQMsWR2EfbjlkRQcgMl9Zby8+NfiBmC74nyHwISLGUKed1YpYfXAXHyBmvfvuQfHurK3maIUV1mcfH3rAElJHySDUrpVPzAYb/F9PRZsGgsB9HI8Xxso6LPPjC7RumgAmnIYRHfQtXlRwJPVvOfSYMCSKV7YOGzcvBTRDOO7PcPtLDmOsRPZDxWuwxSsIIXPT5b5SGjBy7iCAwSjEKeBSWidKOmsGe6yEXvqA8+on1lARWiiAcIYl7dsLZMrVbCYtdIDiY30jyZMNekwNYT+sr3fQMm5gpAj/m+N5MXlDXaTJ/9v0e1IroYRWCkX3WXbaBKkIlHGuuD//5Jwp7wXXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6WT+Wh9NnyhW05bCTfaGxTu956uaKPOsHbEiEwtHoZo=; b=iYETZ1abaVX106cOyMH5hQGgAHV3Rh0xY08KpV3wphbyHFyAC9wQgnVih+A+5mYu0QiqqumSAVje2PT5nuwYz0mYqcKkDpvDqHKvm251wqw9s9UC2Kh8ZysYr+5pXpsgGJBEtpfLzIGPDYcYIIqgk63Pb1xfXdm8HwM8lZLSsN3bvbW+uJlgy4zvwk6/bNe+X3LSXGDZIeH4RGRDjizYOftXQEApXQUUFUJZjmo8QzfkOi13HkkVdZ2fdgQSgSLPpmKzVh4zID1TJ+RtYmnlvyHalOubQdChKYzizWUkY3NsganXO12F7gQWLZYZgxBbQCED9WV90JTNgEIbCWRgJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 171.17.131.35) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=amadeus.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=amadeus.com; dkim=none (message not signed); arc=none Received: from DUZPR01CA0338.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b8::8) by AS1PR10MB5367.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:4a1::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Tue, 15 Aug 2023 17:21:20 +0000 Received: from DU6PEPF00009527.eurprd02.prod.outlook.com (2603:10a6:10:4b8:cafe::32) by DUZPR01CA0338.outlook.office365.com (2603:10a6:10:4b8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.33 via Frontend Transport; Tue, 15 Aug 2023 17:21:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 171.17.131.35) smtp.mailfrom=amadeus.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amadeus.com; Received-SPF: Pass (protection.outlook.com: domain of amadeus.com designates 171.17.131.35 as permitted sender) receiver=protection.outlook.com; client-ip=171.17.131.35; helo=smtpexch.amadeus.com; pr=C Received: from smtpexch.amadeus.com (171.17.131.35) by DU6PEPF00009527.mail.protection.outlook.com (10.167.8.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Tue, 15 Aug 2023 17:21:18 +0000 Received: from MUCEX20MBX001.iis.amadeus.net (172.19.131.74) by smtpexch.amadeus.com (172.19.134.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Tue, 15 Aug 2023 17:19:51 +0000 Received: from adee84621c31.rnd.amadeus.net (10.64.176.26) by MUCEX20MBX001.iis.amadeus.net (172.19.131.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Tue, 15 Aug 2023 17:21:17 +0000 To: CC: , Subject: [gcc 11 backport] Support ld.mold linker. Date: Tue, 15 Aug 2023 17:20:30 +0000 Message-ID: <20230815172029.63-1-romain.geissler@amadeus.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-ClientProxiedBy: MUCEXHYBP01.iis.amadeus.net (172.19.131.107) To MUCEX20MBX001.iis.amadeus.net (172.19.131.74) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF00009527:EE_|AS1PR10MB5367:EE_ X-MS-Office365-Filtering-Correlation-Id: 03c29778-acea-465a-54d4-08db9db409e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8QBDbP2RZDm43AOpZ9xf/3wzfnN9CJ91AYOOdtIbfAbYdwUOH7Do3CNBx4RwyYZdu9mHb0p7XWQ9G7z1iDfVrQby3VQJ/sHo8kv0zaVnHHRD6cSyg+IqtjZiepqS5j2mSZPjGvL6a9D3DMzOBfZdbJ+oSJmMOKj5wJW06e6nMqx9AKp3Gzcd16nGONREwCA+A7u5UGAgHKhOjogHMo7xnktGXqWwFmO8q4p1KX35UONAfhqHex0s5VMX0BdbLnYagz16ODdEdQ1rsGFCTv1QItb7nVY+u5lQNfyYsx7BNujRuvAv6fGfjg+IfwS2p6QcRmpndunC1Pon/VnptowB8vUC1DhbH8ojdSRl/sQ5+mB7Oh2eZyvJGbdEg5eW7QbLbr269xzE9QNmiy/j+3nA4/vWphl4bHTI9cn0xxqiU2Dxe+fLD1vYQWgbZrsnJNJGN6V9lfGTmAKv/Ju1SXQDi3wKd/888vr/vuljzNdemZr//tdpIgVLjrOg9Ffbk8C8+F7JqU0JNNOJIgd6fY1RI9T8xBrD6X6O7XIZz6o7LBdH/2GwdGQfBTrJsZRT8+TBD9C9yeefej/MedFjWcLVri2y9AAcXBdj3QAkIgpnROQ6oUChZ6lBS1fJcHFuW7hizDApqmB/2iWphVwD5FuyuEwIx5E/iB95CCEs2QT3eNqX+g+/n/xhZ45ddMQFYF3dxUe6macfxoSHQctwWAprJpQRabD1kZHd4E3P2WLThVUgshkRwdiyVyQA3H9wv6zxwFQfPqBRw3snfaCCQnH+5g== X-Forefront-Antispam-Report: CIP:171.17.131.35; CTRY:DE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:smtpexch.amadeus.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199024)(1800799009)(186009)(82310400011)(46966006)(36840700001)(40470700004)(478600001)(47076005)(4326008)(8936002)(6916009)(316002)(82740400003)(336012)(1076003)(356005)(26005)(70586007)(41300700001)(2906002)(36756003)(5660300002)(8676002)(70206006)(40460700003)(2616005)(83380400001)(82960400001)(81166007)(86362001)(6666004)(36860700001)(44832011)(54906003)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amadeus.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2023 17:21:18.7687 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03c29778-acea-465a-54d4-08db9db409e3 X-MS-Exchange-CrossTenant-Id: b3f4f7c2-72ce-4192-aba4-d6c7719b5766 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=b3f4f7c2-72ce-4192-aba4-d6c7719b5766; Ip=[171.17.131.35]; Helo=[smtpexch.amadeus.com] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF00009527.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR10MB5367 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Romain Geissler via Gcc-patches From: Romain Geissler Reply-To: Romain Geissler Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774316560127427496 X-GMAIL-MSGID: 1774316560127427496 Hi, Is it ok to backport small unrisky features to the old gcc 11 branch ? Here is a proposal to merge the ld.mold linker support which Martin has pushed in gcc >= 12. It's a cherry-pick of commit ad964f7eaef9c03ce68a01cfdd7fde9d56524868. Note that it doesn't backport the gcc build machinery to be able to link gcc itself with mold. Note: it also doesn't backport Martin's change in the LTO machinery to support LTO plugin with mold. Cheers, Romain 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 3e212fc75f3..558016af486 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -785,6 +785,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] = @@ -793,7 +794,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"; @@ -970,6 +972,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 (strncmp (argv[i], "-o", 2) == 0) { /* Parse the output filename if it's given so that we can make @@ -1082,7 +1086,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 @@ -1317,7 +1321,7 @@ main (int argc, char **argv) else if (!use_collect_ld && strncmp (arg, "-fuse-ld=", 9) == 0) { - /* 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 4a3f09d9e1f..b7f0a52348c 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2967,6 +2967,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 fffa899585e..3ecdb850000 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -15606,6 +15606,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 20a649ea08e..ecda8cbba02 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -4196,6 +4196,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 24bb64198c8..9192ca75743 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2875,6 +2875,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;