From patchwork Mon Feb 10 00:02:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1235580 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519200-incoming=patchwork.ozlabs.org@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-sha1 header.s=default header.b=PQ6RuO2s; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=mXqpsaPB; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48G5hG4FyWz9s29 for ; Mon, 10 Feb 2020 11:02:51 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:reply-to:to:subject:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=peV2P72N9Z2Xyeve YD8yIrG8xBNDG6mKid1OC/RkbXD6bGLVB/myxtE88Ef5mD2EKE+N8fU24v/U+vgg aAh1rM8Jw7pSCkkMzI27F9SD2pEkwC6aKFMMalye0/+EabW6EyQu8Foi50KyzmVD +A8mhxpfC8O6xeJoc3EIL0I9+C4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:reply-to:to:subject:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=jE2W1FPbfIZiLtxzNn8WXk AaBg8=; b=PQ6RuO2sc5F5gvZofSYGeczGl1VJ60+JPyqyn9AAAQTDLL9oEoGKTX 0xSgoy43ufOoMG8iQ+Awmu212ZA4tja6GS/MAKe4Dz5DGWlvZWIj7B2ji9ZIAqrn pN7p8lNew2QdwWx9jFuNNymSTSz1OToS30ZItCEZzXuB+mmYJGwWI= Received: (qmail 92523 invoked by alias); 10 Feb 2020 00:02:43 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 92513 invoked by uid 89); 10 Feb 2020 00:02:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-30.5 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, FSL_HELO_FAKE, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy=ordinary, joined, @opindex, opindex X-HELO: mail-pl1-f182.google.com Received: from mail-pl1-f182.google.com (HELO mail-pl1-f182.google.com) (209.85.214.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Feb 2020 00:02:40 +0000 Received: by mail-pl1-f182.google.com with SMTP id y1so2085350plp.7 for ; Sun, 09 Feb 2020 16:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding; bh=QGcwpHQKrzIL+Tq/xB70xzzD5cVBop1CvIKNjNeQ2UU=; b=mXqpsaPBQWuhRJilaHEtvs9BGdI7xmNIVmjih3+Ae+3YNd/0iOEZy13oUfSA+DokYF 6f9Ru7c4e81AV1I6Pk7f/9jIyRwvYm2MZejzU10xNOtEQFfoi+S7Ko93DQLLLs3gE3XZ Y65hTc2C+FprLS17GwtMFIG11hHktnSo5psmBwdV7b4WOUv6wrfU6/Iz4bdvjaV0ByNG vf5/oCFtC5zqRNtW4cIsKDV9W3XRmGKamyfW1HwOpxif1idgANVPqdTulp+yfm+YtNsC oyitrm4TbiTd6Jh033GC8BlkddgnFZNNp39rfuvcfqJnijPGCdk0Et6Ikf1HLYEfmYdq kCkQ== Received: from google.com ([2620:15c:2ce:0:9efe:9f1:9267:2b27]) by smtp.gmail.com with ESMTPSA id az9sm9043289pjb.3.2020.02.09.16.02.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2020 16:02:37 -0800 (PST) Date: Sun, 9 Feb 2020 16:02:34 -0800 X-Patchwork-Original-From: "Fangrui Song via gcc-patches" From: "Li, Pan2 via Gcc-patches" Reply-To: Fangrui Song To: gcc-patches@gcc.gnu.org Subject: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Message-ID: <20200210000234.aemsyusopeatxb6i@google.com> MIME-Version: 1.0 Content-Disposition: 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 + + 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 * 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|] 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;