From patchwork Thu Nov 18 21:35:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Belinassi X-Patchwork-Id: 47907 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D35963857C6A for ; Thu, 18 Nov 2021 21:37:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D35963857C6A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637271463; bh=o9cYZ0adAQ2anw2lVdwL9xB2iD1sT9ATFp85oiM5A7I=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Cuxsm2lqdoMElafijY3saqwkoMT7sDh0xLl2oQw4N8NQGddZgX2txBEgf852cDU6g iSfbO5pKaAr4YfPNicole898R4jE7NPycEGM3al7rUOQbTcs75sKYEJqYCDygQkvq2 mZxYkb57wnJQKTPgeXQxDPIzn0rWSi39VMJyddso= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from localhost (unknown [189.33.66.9]) by sourceware.org (Postfix) with ESMTP id 6E1973857C51 for ; Thu, 18 Nov 2021 21:36:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E1973857C51 Received: by localhost (Postfix, from userid 1000) id 2DF14A73036; Thu, 18 Nov 2021 18:36:53 -0300 (-03) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] Do not abort compilation when dump file is /dev/* Date: Thu, 18 Nov 2021 18:35:00 -0300 Message-Id: <20211118213459.26463-1-gbelinassi@suse.de> X-Mailer: git-send-email 2.33.1 In-Reply-To: <872p73ns-6n4o-p115-2r12-203p97628o8r@fhfr.qr> References: <872p73ns-6n4o-p115-2r12-203p97628o8r@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, FSL_HELO_NON_FQDN_1, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, HELO_LOCALHOST, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_PBL, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Belinassi via Gcc-patches From: Giuliano Belinassi Reply-To: Giuliano Belinassi Cc: Giuliano Belinassi , rguenther@suse.de Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The `configure` scripts generated with autoconf often tests compiler features by setting output to `/dev/null`, which then sets the dump folder as being /dev/* and the compilation halts with an error because GCC cannot create files in /dev/. This is a problem when configure is testing for compiler features because it cannot tell if the failure was due to unsupported features or any other problem, and disable it even if it is working. As an example, running configure overriding CFLAGS="-fdump-ipa-clones" will result in several compiler-features as being disabled because of gcc halting with an error creating files in /dev/*. This commit fixes this issue by checking if the output file is /dev/null or /dev/zero. In this case we use the current working directory for dump output instead of the directory of the output file because we cannot write to /dev/*. gcc/ChangeLog 2021-11-16 Giuliano Belinassi * gcc.c (process_command): Skip dumpdir override on -o /dev/null or -o /dev/zero. gcc/testsuite/ChangeLog 2021-11-16 Giuliano Belinassi * gcc.dg/devnull-dump.c: New. Signed-off-by: Giuliano Belinassi --- gcc/doc/invoke.texi | 4 +++- gcc/gcc.c | 19 +++++++++++++++---- gcc/testsuite/gcc.dg/devnull-dump.c | 7 +++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/devnull-dump.c diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 6070288856c..4c056606e0c 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1877,7 +1877,9 @@ named @file{dir/bar.*}, combining the given @var{dumppfx} with the default @var{dumpbase} derived from the primary output name. Dump outputs also take the input name suffix: @file{dir/bar.c.*}. -It defaults to the location of the output file; options +It defaults to the location of the output file, unless @option{-o /dev/null} +or @option{-o /dev/zero} is passed to the compiler: on those cases the @option{cwd} +will be used instead. Options @option{-save-temps=cwd} and @option{-save-temps=obj} override this default, just like an explicit @option{-dumpdir} option. In case multiple such options are given, the last one prevails: diff --git a/gcc/gcc.c b/gcc/gcc.c index 506c2acc282..0173018ac04 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -5109,10 +5109,21 @@ process_command (unsigned int decoded_options_count, { free (dumpdir); dumpdir = NULL; - temp = lbasename (output_file); - if (temp != output_file) - dumpdir = xstrndup (output_file, - strlen (output_file) - strlen (temp)); + if (strcmp(output_file, "/dev/null") == 0 + || strcmp(output_file, "/dev/zero") == 0) + { + /* If output is /dev/null or /dev/zero, we cannot set the dumpdir to + /dev/ because no files can be created on that directory. In this + case, we do nothing. */ + } + else + { + /* Set dumpdir as being the same directory where the output file is. */ + temp = lbasename (output_file); + if (temp != output_file) + dumpdir = xstrndup (output_file, + strlen (output_file) - strlen (temp)); + } } else if (dumpdir) { diff --git a/gcc/testsuite/gcc.dg/devnull-dump.c b/gcc/testsuite/gcc.dg/devnull-dump.c new file mode 100644 index 00000000000..378e0901c28 --- /dev/null +++ b/gcc/testsuite/gcc.dg/devnull-dump.c @@ -0,0 +1,7 @@ +/* { dg-do assemble } */ +/* { dg-options "-fdump-ipa-clones -o /dev/null" } */ + +int main() +{ + return 0; +}