From patchwork Mon Dec 2 12:49:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 295910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6D7682C0085 for ; Mon, 2 Dec 2013 23:49:23 +1100 (EST) 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:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=ydYkd2J3hZcN4HT8ZbXYz8YaA5ZB4VvFh8Hg6lWfCX0wYyR45pXS2 ZZ4IGlKKKXeBi2raQ8r1yT3o5SBFbGXkoMke7G2onoTEoXPd/S/Loyp/jmPpYZah op6VCwTcaEUSPeLRaCiMezvDAY/7DxdiQJbVAaQ5LXhTOtb61Po1Zo= 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:to:subject:message-id:mime-version:content-type; s= default; bh=blMLfQpuRUExT6IMWg173Di6XII=; b=JzWeQqpCtdyon4l3BIv7 tsmQfvVL4OzuN8jGKYRU0Y1Kv5gP/RZejehByRsR49K4TolSJEtPikU2TWsyjd2R hILHDOBmTlTGQKsgz53wPwdjkt6eCdkDFUvgPzyq99I6U83oWMTeHt6Zc5eCzbZL jFFPKOXNfecETvb34xYRjxU= Received: (qmail 17244 invoked by alias); 2 Dec 2013 12:49:13 -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 17232 invoked by uid 89); 2 Dec 2013 12:49:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-yh0-f44.google.com Received: from Unknown (HELO mail-yh0-f44.google.com) (209.85.213.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 02 Dec 2013 12:49:11 +0000 Received: by mail-yh0-f44.google.com with SMTP id f64so8749693yha.3 for ; Mon, 02 Dec 2013 04:49:04 -0800 (PST) X-Received: by 10.236.115.137 with SMTP id e9mr55593323yhh.39.1385988543960; Mon, 02 Dec 2013 04:49:03 -0800 (PST) Received: from gnu-tools-1.localdomain (76-220-57-190.lightspeed.sntcca.sbcglobal.net. [76.220.57.190]) by mx.google.com with ESMTPSA id d26sm38524357yhj.25.2013.12.02.04.49.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Dec 2013 04:49:03 -0800 (PST) Received: by gnu-tools-1.localdomain (Postfix, from userid 1000) id 9CA914080E; Mon, 2 Dec 2013 04:49:01 -0800 (PST) Date: Mon, 2 Dec 2013 04:49:01 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: PATCH: PR driver/59321: -fuse-ld has no effect on -print-prog-name nor on --with-ld= Message-ID: <20131202124901.GA2429@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, "ld" is a special name for GCC driver. find_a_file has #ifdef DEFAULT_LINKER if (! strcmp (name, "ld") && access (DEFAULT_LINKER, mode) == 0) return xstrdup (DEFAULT_LINKER); #endif #endif It does 2 things: 1. Print DEFAULT_LINKER for -print-prog-name=ld. 2. Run DEFAULT_LINKER when ld is needed to run. But gcc.c fails to check -print-prog-name=ld with -fuse-ld= and collect2.c fails to properly handle -fuse-ld= when DEFAULT_LINKER is defined. This patches fixes those 2 problems: 1. Check "ld" + suffix specicied by -fuse-ld= for -print-prog-name=ld. 2. Try DEFAULT_LINKER + suffix specicied by -fuse-ld=. This patch also tries to handle HOST_EXECUTABLE_SUFFIX. Tested on Linux/x86. OK to install? Thanks. H.J. --- 2013-11-30 H.J. Lu PR driver/59321 * collect2.c (main): Check -fuse-ld=[bfd|gold] when DEFAULT_LINKER is defined. * gcc.c (use_ld): New variable. (process_command): Set use_ld for OPT_fuse_ld_bfd and OPT_fuse_ld_gold. (main): Check -fuse-ld=[bfd|gold] for -print-prog-name=ld. diff --git a/gcc/collect2.c b/gcc/collect2.c index 95f817d..1d8ea4f 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -1121,7 +1121,35 @@ main (int argc, char **argv) /* Maybe we know the right file to use (if not cross). */ ld_file_name = 0; #ifdef DEFAULT_LINKER - if (access (DEFAULT_LINKER, X_OK) == 0) + if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD) + { + char *linker_name; +# ifdef HOST_EXECUTABLE_SUFFIX + int len = (sizeof (DEFAULT_LINKER) + - sizeof (HOST_EXECUTABLE_SUFFIX)); + linker_name = NULL; + if (len > 0) + { + char *default_linker = xstrdup (DEFAULT_LINKER); + /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains + HOST_EXECUTABLE_SUFFIX. */ + if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX)) + { + default_linker[len] = '\0'; + linker_name = concat (default_linker, + &ld_suffixes[selected_linker][2], + HOST_EXECUTABLE_SUFFIX, NULL); + } + } + if (linker_name == NULL) +# endif + linker_name = concat (DEFAULT_LINKER, + &ld_suffixes[selected_linker][2], + NULL); + if (access (linker_name, X_OK) == 0) + ld_file_name = linker_name; + } + if (ld_file_name == 0 && access (DEFAULT_LINKER, X_OK) == 0) ld_file_name = DEFAULT_LINKER; if (ld_file_name == 0) #endif diff --git a/gcc/gcc.c b/gcc/gcc.c index b895f22..68b3df6 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -105,6 +105,9 @@ static int verbose_only_flag; static int print_subprocess_help; +/* Linker suffix passed to -fuse-ld=... */ +static const char *use_ld; + /* Whether we should report subprocess execution times to a file. */ FILE *report_times_to_file = NULL; @@ -3952,6 +3955,10 @@ process_command (unsigned int decoded_options_count, free (fname); continue; } + else if (decoded_options[j].opt_index == OPT_fuse_ld_bfd) + use_ld = ".bfd"; + else if (decoded_options[j].opt_index == OPT_fuse_ld_gold) + use_ld = ".gold"; read_cmdline_option (&global_options, &global_options_set, decoded_options + j, UNKNOWN_LOCATION, @@ -6708,6 +6715,38 @@ main (int argc, char **argv) if (print_prog_name) { + if (use_ld != NULL && ! strcmp (print_prog_name, "ld")) + { + /* Append USE_LD to to the default linker. */ +#ifdef DEFAULT_LINKER + char *ld; +# ifdef HAVE_HOST_EXECUTABLE_SUFFIX + int len = (sizeof (DEFAULT_LINKER) + - sizeof (HOST_EXECUTABLE_SUFFIX)); + ld = NULL; + if (len > 0) + { + char *default_linker = xstrdup (DEFAULT_LINKER); + /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains + HOST_EXECUTABLE_SUFFIX. */ + if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX)) + { + default_linker[len] = '\0'; + ld = concat (default_linker, use_ld, + HOST_EXECUTABLE_SUFFIX, NULL); + } + } + if (ld == NULL) +# endif + 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); + } char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0); printf ("%s\n", (newname ? newname : print_prog_name)); return (0);