From patchwork Mon Sep 1 16:33:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 384899 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 06399140086 for ; Tue, 2 Sep 2014 02:33:35 +1000 (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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=TLrH9fUhaiQc8JjV9 oyYVXDUw3M4LZ5/K6+3my7Dmd2OABVCS5ui62iNsH1t8eBSr1w/XiBs8NzDmxO2o 9Su+e5cI1Dj34r/YqS4max36qxDrcW97rW3SuvaHlJPkr5SFKmtFBGGoykWOhF9x 0RwNJfQG1nJplZ6O7zTx/M7+1I= 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=jS9zzaKRFSnSvj9+rkV31aj Ukng=; b=Dxd+04PCOZMh5gfwfe+pZbtWmEge4beI9DejvImY89Y9rRNSPVmY6BC YApgSBcDUCxiTpBFWqfwcUKt8UwGVMlk+iYdqyxP9c7BDJRkbvjh+HJ0uamcWtRi JLoTQoBJHgXO0i6WY4KAqoye2hfYaEL9k52t0MLkvfP1qVEPF0R8= Received: (qmail 6723 invoked by alias); 1 Sep 2014 16:33:28 -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 6693 invoked by uid 89); 1 Sep 2014 16:33:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: one.firstfloor.org Received: from one.firstfloor.org (HELO one.firstfloor.org) (193.170.194.197) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 01 Sep 2014 16:33:15 +0000 Received: by one.firstfloor.org (Postfix, from userid 503) id D631786A02; Mon, 1 Sep 2014 18:33:10 +0200 (CEST) Date: Mon, 1 Sep 2014 18:33:10 +0200 From: Andi Kleen To: Richard Biener Cc: Andi Kleen , GCC Patches , Andi Kleen Subject: Re: [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm Message-ID: <20140901163310.GW4120@two.firstfloor.org> References: <1409496686-14681-1-git-send-email-andi@firstfloor.org> <1409496686-14681-2-git-send-email-andi@firstfloor.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) On Mon, Sep 01, 2014 at 01:34:17PM +0200, Richard Biener wrote: > On Sun, Aug 31, 2014 at 4:51 PM, Andi Kleen wrote: > > From: Andi Kleen > > > > To use gcc-{ar,ranlib} for boot strap we need to add a -B option > > to the tool. Since ar has weird and unusual argument conventions > > implement the code by hand instead of using any libraries. > > > > v2: Fix typo > > v3: Improve comments. Use strlen. Use DIR_SEPARATOR. Add prefixes at > > begin. > > Ok. Michael Chamberlain pointed out an argument parsing bug privately. I'm going to commit this v4 version which has a one-liner fix for it, after it passed rebootstrap. -Andi diff --git a/gcc/file-find.c b/gcc/file-find.c index 87d486d..be608b2 100644 --- a/gcc/file-find.c +++ b/gcc/file-find.c @@ -105,15 +105,16 @@ find_a_file (struct path_prefix *pprefix, const char *name, int mode) return 0; } -/* Add an entry for PREFIX to prefix list PPREFIX. */ +/* Add an entry for PREFIX to prefix list PREFIX. + Add at beginning if FIRST is true. */ void -add_prefix (struct path_prefix *pprefix, const char *prefix) +do_add_prefix (struct path_prefix *pprefix, const char *prefix, bool first) { struct prefix_list *pl, **prev; int len; - if (pprefix->plist) + if (pprefix->plist && !first) { for (pl = pprefix->plist; pl->next; pl = pl->next) ; @@ -138,6 +139,22 @@ add_prefix (struct path_prefix *pprefix, const char *prefix) *prev = pl; } +/* Add an entry for PREFIX at the end of prefix list PREFIX. */ + +void +add_prefix (struct path_prefix *pprefix, const char *prefix) +{ + do_add_prefix (pprefix, prefix, false); +} + +/* Add an entry for PREFIX at the begin of prefix list PREFIX. */ + +void +add_prefix_begin (struct path_prefix *pprefix, const char *prefix) +{ + do_add_prefix (pprefix, prefix, true); +} + /* Take the value of the environment variable ENV, break it into a path, and add of the entries to PPREFIX. */ diff --git a/gcc/file-find.h b/gcc/file-find.h index b438056..0754d99 100644 --- a/gcc/file-find.h +++ b/gcc/file-find.h @@ -40,6 +40,7 @@ struct path_prefix extern void find_file_set_debug (bool); extern char *find_a_file (struct path_prefix *, const char *, int); extern void add_prefix (struct path_prefix *, const char *); +extern void add_prefix_begin (struct path_prefix *, const char *); extern void prefix_from_env (const char *, struct path_prefix *); extern void prefix_from_string (const char *, struct path_prefix *); diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c index aebaa92..fdff89c 100644 --- a/gcc/gcc-ar.c +++ b/gcc/gcc-ar.c @@ -132,9 +132,52 @@ main (int ac, char **av) const char **nargv; bool is_ar = !strcmp (PERSONALITY, "ar"); int exit_code = FATAL_EXIT_CODE; + int i; setup_prefixes (av[0]); + /* Not using getopt for now. */ + for (i = 0; i < ac; i++) + if (!strncmp (av[i], "-B", 2)) + { + const char *arg = av[i] + 2; + const char *end; + size_t len; + + memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i)); + ac--; + if (*arg == 0) + { + arg = av[i]; + if (!arg) + { + fprintf (stderr, "Usage: gcc-ar [-B prefix] ar arguments ...\n"); + exit (EXIT_FAILURE); + } + memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i)); + ac--; + i++; + } + /* else it's a joined argument */ + + len = strlen (arg); + if (len > 0) + len--; + end = arg + len; + + /* Always add a dir separator for the prefix list. */ + if (end > arg && !IS_DIR_SEPARATOR (*end)) + { + static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; + arg = concat (arg, dir_separator_str, NULL); + } + + add_prefix_begin (&path, arg); + add_prefix_begin (&target_path, arg); + break; + } + + /* Find the GCC LTO plugin */ plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK); if (!plugin)