From patchwork Thu Jul 2 19:34:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 1321881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=mQNOE8N6; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49ySwk01dcz9sPF for ; Fri, 3 Jul 2020 05:35:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EFB2E3861910; Thu, 2 Jul 2020 19:34:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFB2E3861910 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593718498; bh=tx+Tpz5Kgw/4ltUjkEaLszTSVeUEY1eLcTruK/v7tMA=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=mQNOE8N68D+q/fZe61kBihV4Qyce+p708kAFgYTGqimgVN0zLja/F+GzqAd2VZoip 38Zki8QYi99L1r46yoCyo5P9F8sxjQwdI4aUollGP9MwBIpPHuxn9ktcDNqEsAX2NK IkvbLmzlwXIuXCUDEwA3kCdf4G5erA4dllDQ9gzw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by sourceware.org (Postfix) with ESMTPS id 2B0FD38618BD for ; Thu, 2 Jul 2020 19:34:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2B0FD38618BD Received: by mail-pf1-x442.google.com with SMTP id 207so12766714pfu.3 for ; Thu, 02 Jul 2020 12:34:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=tx+Tpz5Kgw/4ltUjkEaLszTSVeUEY1eLcTruK/v7tMA=; b=jK4B51UTDTmf+o8xjzfO679pVIi9PZbBMtugG7MigwysQE42uEyAWfjRgn8hiesFJ2 VEwtxE0fgRhsuYIQ89HSbATrt/3oo79NP3MZJoL4zmBQJZztWtsK8J21f9e+Z9mairKK MLVDdSRS+d9l8FwfF2CrsclG5UwiX8kMcz9G914lJTWa+NMiaaeI8ycvjI0OYvSjLf4R lwnNnKoLWQ5Y9ehnmNRafmD9ln5+W5R2FYzsOhmIRXhmBCxHaPyUlr7kD5XAXCfLfPLV AFcNWP56VUzRD7f7m+DwWyQKcO0FSoWF5CUH02oIkYrVHJ5gr5D+6ILVEMgDXr5n8Prw 2tXQ== X-Gm-Message-State: AOAM531ZoB6Gi0Vr3R16YCdak7WiDROQu064ZDibGWi8mLo4c2b9Fi74 j6knk9i8dEgfgo3Ly2nKdApp/Q== X-Google-Smtp-Source: ABdhPJzTJrODUoyu/GAcddpQ26eVUcg2jaCg25+crs/0zLJUaIqT2geRkn82CkLJeLz3RVU+kq7eOw== X-Received: by 2002:a63:8c4f:: with SMTP id q15mr25756301pgn.373.1593718492893; Thu, 02 Jul 2020 12:34:52 -0700 (PDT) Received: from google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) by smtp.gmail.com with ESMTPSA id j13sm8596186pjz.8.2020.07.02.12.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jul 2020 12:34:52 -0700 (PDT) Date: Thu, 2 Jul 2020 12:34:49 -0700 To: Martin =?utf-8?b?TGnFoWth?= Subject: [PATCH] Add -fld-path= to specify an arbitrary executable as the linker Message-ID: <20200702193449.cz6bhplp5kvdmkkd@google.com> References: <20200520235237.d3mfzn7a2yjos2mh@google.com> <20200522044207.yzano7rtgybapizb@google.com> <20200529011045.mwelrhglbo5s2zfa@google.com> <85c68e0e-ed06-23ef-02b1-e8ebea5973b4@suse.cz> <54a2849d-3435-46be-2fc5-9648b9e15d49@suse.cz> <20200702045904.3xwlx53g42zcrnqm@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200702045904.3xwlx53g42zcrnqm@google.com> X-Spam-Status: No, score=-25.4 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: =?utf-8?q?F=C4=81ng-ru=C3=AC_S=C3=B2ng_via_Gcc-patches?= From: Fangrui Song Reply-To: =?utf-8?b?RsSBbmctcnXDrCBTw7JuZw==?= Cc: jakub@redhat.com, GCC Patches , Richard Biener Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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. From e7f86cdcaf03e4ddb98d0df9d07894d9ffb7d91a Mon Sep 17 00:00:00 2001 From: Fangrui Song 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=*:%