From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 866C13858D20 for ; Fri, 28 Jul 2023 11:59:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 866C13858D20 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-x52f.google.com with SMTP id 4fb4d7f45d1cf-5222b917e0cso2785287a12.0 for ; Fri, 28 Jul 2023 04:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690545561; x=1691150361; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=+hePkJO45QHYhuDUnCYaQQ5O4v05njTJJdfABuRgU6I=; b=c4R39XBN3fw7+ie30Jf+qvNZjdvCa6p1x3yNR8F2rVni+cWh0vpA7wsoD44IBcK5yK AfeadQs6p8/6VM6L2jJfzk39XPQFDqenBxSqwz7f2YFr6+s0VeEGGy8dhT5hRSH/xrPY wS92jg6xS21BF27oIwYVCOi+irkze1jtPVBSWUbfKnyhYpdyQk0wYG+jgclIs766wT9g MqzRBch2vADx9UrfUcOfQJJpDMGmIEZaAcPrGUl43cyrRHULrjQD0sKsPtsQdndZwcvy b2x11DJtdokuRpJjl+D0J32dIm85I9+H4dfpaZB7hIz6gsi9gjpRz7EV4Vfciu8fPruP 7CJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690545561; x=1691150361; 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=+hePkJO45QHYhuDUnCYaQQ5O4v05njTJJdfABuRgU6I=; b=Z9rpUh9UAOrX69QxhQUYLgPRhqhdLtFx+UigInFNTiya9ewBQo7b+CM705Aybtf8T+ NJcMRZamO4/BpbEOtieR8FAnQcWqEajuXmmaO3yaCzpD+wyWfqKKisZQZDDg7/LfE/3t e7J+KVqMzb19rc0da0b4wEAHRMealVNaP6xRHohKNVA0XRGCPjTSe9Pim3YXk2j8HZc8 V5Xm1/Ev2QC3SUeagF+auJnrk6SB8Vvgg+nJ2WAbUgLz4P1QWxIzaWcMMSERW/A38J8z rHPVNlGc8/P8S9LqvRZUzxA4DU+bSwKrssW2dYRujb2X7hKl2y/nSvh9sYQi3SH13pqO pGow== X-Gm-Message-State: ABy/qLYwEJ2ju5kmVsN9ixsZHNJCF/c5NfbiyS4t03QLaK3lYLVumY/7 bCqEWVy8FuXY6KSpOu3ibBnfkHxJH3lBqrbv96t8Xv1AcGg= X-Google-Smtp-Source: APBJJlHg9VZuJ6pX3fMXxn1Ijm5bZKyxxejcAfjBhFpyfdDoj4mOYFkrcEcYn2XEtxMtoL+TtEZiiHnsJWPrjP3vFRk= X-Received: by 2002:a05:6402:219:b0:522:2c36:4c59 with SMTP id t25-20020a056402021900b005222c364c59mr1725192edv.4.1690545560822; Fri, 28 Jul 2023 04:59:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Costas Argyris Date: Fri, 28 Jul 2023 12:59:09 +0100 Message-ID: Subject: Re: [PATCH] gcc-ar: Handle response files properly [PR77576] To: gcc-patches@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000a128b006018acf8a" X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,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: --000000000000a128b006018acf8a Content-Type: text/plain; charset="UTF-8" ping On Fri, 14 Jul 2023 at 09:05, Costas Argyris wrote: > Pinging to try and get this bug in gcc-ar fixed. > > Note that the patch posted as an attachment in > > https://gcc.gnu.org/pipermail/gcc-patches/2023-July/623400.html > > is exactly the same as the patch embedded in > > https://gcc.gnu.org/pipermail/gcc-patches/2023-July/623855.html > > and the one posted in the PR itself > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77576 > > On Fri, 7 Jul 2023 at 13:00, Costas Argyris > wrote: > >> 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 >>> >> --000000000000a128b006018acf8a--