From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id A7229395202B for ; Fri, 7 Jul 2023 12:00:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7229395202B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-51d7f350758so2459928a12.3 for ; Fri, 07 Jul 2023 05:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688731245; x=1691323245; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=gi2EeLniSbtgH1sbrf9zvdEQyESJpdNPRe+B0dKRioY=; b=OZIiJrkqsmjACG+iq6Ya2CiMothdGSUMUwG8+7vd2ysNeNjwxu61QQQwVt8wdh0y8L h5xwyjyrcFwPcgqBiaG7ePgCIO8JqauR9Aopw/+478em9KjyqOfZe01+xtxp8gXSpF53 dOZVVuHwA35J9LV1rxwj+yKlFYMWIONzE73Xg3LOeK29OtNpBKutU+kFShP0YKs2VmCV OL5djZSn9JPHzovQNF3SSqHBHH+/2csZS1ZU7F1V4bPg7bexyq+CMnA4lAmO+1but4RG ftUdqAWFqdkAL47ayYrGNvZ/6bQ5CglMkcY9zBxMGiMzHLkiR5Ayh7RieaBPDv/Jj7r5 4eig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688731245; x=1691323245; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gi2EeLniSbtgH1sbrf9zvdEQyESJpdNPRe+B0dKRioY=; b=I4eXGv+EvDOxP9ZOM5EGj06e6sA2LujBThZG0XSMdjqnczB+Tq9QaJ8Aav9cclBNgp rMjrf5kLfGMDNlzQ5d9Qq0juglWbS+Gn0FQKWsgAy4mEWd8X7Pd8ibCqdeUGQx9+Rnpn +gn4TrvXwGBVqMtttApeUQlq2oecUA1RHsKvACEdM2eBHwdM/ez1njJtKuDtruXbmGC4 QNCGIVRoEb2lE7oznrp9QoM6IaZwL1NT7gmnQeimdODEi93avZMWpOXQ3ATDEbjI6nt+ HTybhCvrcL5fyjiAbtnk4EcUL2paMEe8EGAK0yxedUA+UfRBt6RneQGC+kgV9MOXrMWw GkSA== X-Gm-Message-State: ABy/qLap4L6acGIV5c+x52MysKp0R7L0xGLg/1DhYtojFR34y/xL2tC5 lgh9xOeOqDX2CQo6TnO9gBNyCTBnOEsxsmxWmNKd4XoKUbs= X-Google-Smtp-Source: APBJJlEOw5Kf2Zae/NY61tGtYvdWxp+7Q/Ftd7cq3MiF6CTul4aWGV/fSBf7p2IsAfXx5b8lyvl2152PNDwosF0Ei0Q= X-Received: by 2002:aa7:cfc3:0:b0:51e:1705:155c with SMTP id r3-20020aa7cfc3000000b0051e1705155cmr3332240edy.35.1688731244595; Fri, 07 Jul 2023 05:00:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Costas Argyris Date: Fri, 7 Jul 2023 13:00:33 +0100 Message-ID: Subject: Re: [PATCH] gcc-ar: Handle response files properly [PR77576] To: gcc-patches@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000f4905805ffe46143" X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000f4905805ffe46143 Content-Type: text/plain; charset="UTF-8" Bootstrapped successfully on x86_64-pc-linux-gnu On Fri, 7 Jul 2023 at 11:33, Costas Argyris wrote: > Problem: gcc-ar fails when a @file is passed to it: > > $ cat rsp > --version > $ gcc-ar @rsp > /usr/bin/ar: invalid option -- '@' > > This is because a dash '-' is prepended to the first > argument if it doesn't start with one, resulting in > the wrong call 'ar -@rsp'. > > Fix: Expand argv to get rid of any @files and if any > expansions were made, pass everything through a > temporary response file. > > $ gcc-ar @rsp > GNU ar (GNU Binutils for Debian) 2.35.2 > ... > > > PR gcc-ar/77576 > * gcc/gcc-ar.cc (main): Expand argv and use > temporary response file to call ar if any > expansions were made. > --- > gcc/gcc-ar.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 47 insertions(+) > > diff --git a/gcc/gcc-ar.cc b/gcc/gcc-ar.cc > index 4e4c525927d..417c4913793 100644 > --- a/gcc/gcc-ar.cc > +++ b/gcc/gcc-ar.cc > @@ -135,6 +135,10 @@ main (int ac, char **av) > int k, status, err; > const char *err_msg; > const char **nargv; > + char **old_argv; > + const char *rsp_file = NULL; > + const char *rsp_arg = NULL; > + const char *rsp_argv[3]; > bool is_ar = !strcmp (PERSONALITY, "ar"); > int exit_code = FATAL_EXIT_CODE; > int i; > @@ -209,6 +213,13 @@ main (int ac, char **av) > } > } > > + /* Expand any @files before modifying the command line > + and use a temporary response file if there were any. */ > + old_argv = av; > + expandargv (&ac, &av); > + if (av != old_argv) > + rsp_file = make_temp_file (""); > + > /* Prepend - if necessary. */ > if (is_ar && av[1] && av[1][0] != '-') > av[1] = concat ("-", av[1], NULL); > @@ -225,6 +236,39 @@ main (int ac, char **av) > nargv[j + k] = av[k]; > nargv[j + k] = NULL; > > + /* If @file was passed, put nargv into the temporary response > + file and then change it to a single @FILE argument, where > + FILE is the temporary filename. */ > + if (rsp_file) > + { > + FILE *f; > + int status; > + f = fopen (rsp_file, "w"); > + if (f == NULL) > + { > + fprintf (stderr, "Cannot open temporary file %s\n", rsp_file); > + exit (1); > + } > + status = writeargv ( > + CONST_CAST2 (char * const *, const char **, nargv) + 1, f); > + if (status) > + { > + fprintf (stderr, "Cannot write to temporary file %s\n", > rsp_file); > + exit (1); > + } > + status = fclose (f); > + if (EOF == status) > + { > + fprintf (stderr, "Cannot close temporary file %s\n", rsp_file); > + exit (1); > + } > + rsp_arg = concat ("@", rsp_file, NULL); > + rsp_argv[0] = nargv[0]; > + rsp_argv[1] = rsp_arg; > + rsp_argv[2] = NULL; > + nargv = rsp_argv; > + } > + > /* Run utility */ > /* ??? the const is misplaced in pex_one's argv? */ > err_msg = pex_one (PEX_LAST|PEX_SEARCH, > @@ -249,5 +293,8 @@ main (int ac, char **av) > else > exit_code = SUCCESS_EXIT_CODE; > > + if (rsp_file) > + unlink (rsp_file); > + > return exit_code; > } > -- > 2.30.2 > --000000000000f4905805ffe46143--