From patchwork Tue May 14 14:02:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1099496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-500642-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QMkOQV6C"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PFCPc1DG"; 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 453KBN6xqcz9s4Y for ; Wed, 15 May 2019 00:02:20 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=bLPq31sV2EN76UV9lOJ7zT2RmVik7B8ALhzVsm/lWku95iEdDa ff4DrHqJYtB+0IDjrd43bU2BmNl8zJ/lc+nLgiJDT46UJ92vnmSzaoYGEfPAHJ+E xpHMXN2M4kuDD7OywWmK2r0Oram9lJ2b0R0/sWFaEA8nqTOhQVCupiJ5w= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=8jyeaeadbw6DDVjym0r6YUBLK8o=; b=QMkOQV6CQCBf1zyChmf4 A9YldUKxFrY/gXYRzDLPP+Egy9VumbTs5btn3qZ9xVd/lkzaxVH97/tlVn7KMNjv xwu4+9VT5pCjRsGi1zgaTB2rvLsZXActFvBoFDly8p/p3MhhTVV7JTXOxtHemp0K ejaF5NoXMInBKaQlevFV0NY= Received: (qmail 121208 invoked by alias); 14 May 2019 14:02: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 121198 invoked by uid 89); 14 May 2019 14:02:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=thereby, whence, locate, driver's X-HELO: mail-pg1-f195.google.com Received: from mail-pg1-f195.google.com (HELO mail-pg1-f195.google.com) (209.85.215.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 May 2019 14:02:06 +0000 Received: by mail-pg1-f195.google.com with SMTP id w22so8692200pgi.6 for ; Tue, 14 May 2019 07:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=NK06nYoqKS9TwaOFlQrLlQIib3Omdzx1fYj/thlDXXs=; b=PFCPc1DG8kF9LjtbXhOpN2t6EHNpu8toai+4FGEwYyOU2irlCSyb0hx7TtvbwG2Jw4 IqpKnZGMkXP2N2GYpmaRv7ly1+/V1hZWbfYJ0bvkx9J6i7xw5lq7xKWrxs99AB+ib9fe /TOcythCVHF4LAmp9n0sbxXCvIdEmj9qNEufUBE1qGFUIRBltMe1P/SeAHpQ7l9war0+ o9IbeAdSJGVRED4y58vYK/1kWLX6fsBzb4adKQQTJHZm/mG1HDZEPnQN4jnDTsaQSDoq YQkxihQ6iMT2UDa8QDGYzOX8EH5bbf9ATkql0owPByRQjTAqQ82UeW3B+LTv2uyOn2bQ Ofnw== Received: from ?IPv6:2620:10d:c0a3:1407:9d19:1ed7:1312:4eda? ([2620:10d:c091:500::2:89c]) by smtp.googlemail.com with ESMTPSA id h13sm3031488pfo.98.2019.05.14.07.02.03 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 07:02:03 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [DRIVER PATCH]: Nadger subprocess argv[0] Message-ID: <377b67a8-72aa-16a4-2c53-1efb9e2e6d6a@acm.org> Date: Tue, 14 May 2019 10:02:02 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 This patch nadgers the driver's subprocess names to include the driver name. It results in more informative error messages. For instance, rather than: >./xg++ -B./ frob.cc -c -fdump-tree-nope cc1plus: error: unrecognized command line option '-fdump-tree-nope' we get: >./xg++ -B./ frob.cc -c -fdump-tree-nope xg++(cc1plus): error: unrecognized command line option '-fdump-tree-nope' Thereby cluing the user into this being a compiler error. (When this error is buried inside a build log, the poor user can be more confused as to what this cc1plus thing might be). I achieve this by taking advantage of the subprocess spawning taking separate arguments for the program to exec, and the argv[0] value passed to that program. Because subprocesses can use argv[0] to locate themselves I propagate the directory name, so that remains as before. When using valgrind, this substitution is not performed, because valgrind relies on argv[0] being the program pathname. The -v output is unaffected, as that is emitted before altering argv[0]. argv[0] is also restored after spawning. This then allows us to elide process_command's check of whether the input file exists. That's optimizing for failure, but I suspect is desired merely to avoid an error of the form: cc1plus: fatal error: frob.cc: No such file or directory As you can see process_command does some special handling for lto & @files, which is kind of icky and now goes away. We get: xg++(cc1plus): fatal error: frob.cc: No such file or directory Thoughts? Ok? Stupid idea? nathan 2019-05-14 Nathan Sidwell * gcc.c (execute): Splice current executable name into spawned argv[0] for better subprocess diagnostics. (process_command): Do not check if input file exists. * lib/prune.exp (prune_gcc_output): Adjust collect regexps. Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 271131) +++ gcc/gcc.c (working copy) @@ -3206,6 +3206,48 @@ execute (void) int err; const char *string = commands[i].argv[0]; + if (commands[i].argv == argbuf.address ()) + { + /* Munge argv[0], the one given in the exec'd command's + argv, to include information about from whence it was + spawned. We preserve the directory component so the + command can determine where it is, but not what it was + called. Thus its otherwise-unlocated errors specify + something like 'g++(cc1plus)' rather than plain + 'cc1plus'. Only do this if argv is the argbuf address, + so as to not interfere with valgrind insertion. */ + size_t slen = strlen (string); + size_t plen = strlen (progname); + size_t tlen = strlen (commands[i].prog); + + /* Remove the filename component from the path. */ + while (slen && !IS_DIR_SEPARATOR (string[slen-1])) + slen--; + char *ren = XNEWVEC (char, slen + plen + tlen + 3); + size_t off = 0; + + /* Copy directory, including final dir separator. */ + memcpy (ren + off, string, slen); + off += slen; + /* Append our progname. */ + memcpy (ren + off, progname, plen); + off += plen; + + ren[off++] = '('; + + /* Append the plain progname (lacking any os-specific + suffix). */ + memcpy (ren + off, commands[i].prog, tlen); + off += tlen; + + ren[off++] = ')'; + + /* And a NUL. */ + ren[off++] = 0; + + commands[i].argv[0] = ren; + } + errmsg = pex_run (pex, ((i + 1 == n_commands ? PEX_LAST : 0) | (string == commands[i].prog ? PEX_SEARCH : 0)), @@ -3220,6 +3262,12 @@ execute (void) string, errmsg); } + if (commands[i].argv[0] != string) + { + free (const_cast (commands[i].argv[0])); + commands[i].argv[0] = string; + } + if (i && string != commands[i].prog) free (CONST_CAST (char *, string)); } @@ -4561,44 +4609,11 @@ process_command (unsigned int decoded_op if (decoded_options[j].opt_index == OPT_SPECIAL_input_file) { const char *arg = decoded_options[j].arg; - const char *p = strrchr (arg, '@'); - char *fname; - long offset; - int consumed; #ifdef HAVE_TARGET_OBJECT_SUFFIX arg = convert_filename (arg, 0, access (arg, F_OK)); #endif - /* For LTO static archive support we handle input file - specifications that are composed of a filename and - an offset like FNAME@OFFSET. */ - if (p - && p != arg - && sscanf (p, "@%li%n", &offset, &consumed) >= 1 - && strlen (p) == (unsigned int)consumed) - { - fname = (char *)xmalloc (p - arg + 1); - memcpy (fname, arg, p - arg); - fname[p - arg] = '\0'; - /* Only accept non-stdin and existing FNAME parts, otherwise - try with the full name. */ - if (strcmp (fname, "-") == 0 || access (fname, F_OK) < 0) - { - free (fname); - fname = xstrdup (arg); - } - } - else - fname = xstrdup (arg); - - if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) - { - bool resp = fname[0] == '@' && access (fname + 1, F_OK) < 0; - error ("%s: %m", fname + resp); - } - else - add_infile (arg, spec_lang); + add_infile (arg, spec_lang); - free (fname); continue; } Index: gcc/testsuite/lib/prune.exp =================================================================== --- gcc/testsuite/lib/prune.exp (revision 271131) +++ gcc/testsuite/lib/prune.exp (working copy) @@ -37,8 +37,8 @@ proc prune_gcc_output { text } { regsub -all "(^|\n)\[^\n\]*: . skipping \[0-9\]* instantiation contexts \[^\n\]*" $text "" text regsub -all "(^|\n)\[^\n\]*: in constexpr expansion \[^\n\]*" $text "" text regsub -all "(^|\n) inlined from \[^\n\]*" $text "" text - regsub -all "(^|\n)collect2: error: ld returned \[^\n\]*" $text "" text - regsub -all "(^|\n)collect: re(compiling|linking)\[^\n\]*" $text "" text + regsub -all "(^|\n)\[a-z+]*\\(?collect2\\)?: error: ld returned \[^\n\]*" $text "" text + regsub -all "(^|\n)\[a-z+]*\\(?collect\\)?: re(compiling|linking)\[^\n\]*" $text "" text regsub -all "(^|\n)Please submit.*instructions\[^\n\]*" $text "" text regsub -all "(^|\n)\[0-9\]\[0-9\]* errors\." $text "" text regsub -all "(^|\n)(In file included|\[ \]+from)\[^\n\]*" $text "" text