From patchwork Tue Nov 16 16:52:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Belinassi X-Patchwork-Id: 47776 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 B47A83857405 for ; Tue, 16 Nov 2021 16:53:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B47A83857405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637081622; bh=B06uUYyxcp9BWPIh6UFUUQgWSQbCYJi3cZH2O3X+IJ8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=KgISgP/tDOKZ89s1U1UbLcxJK7l6V1H/7Kuqv+xAuOIJKHUr8xIBmbGMgy0qieMqx 0beFMq2uLueqb8E6DWxCjSx/Ee59VfwtWHmgFG13yFzmmve2NjIotXjEGQANYAklWv maHozHz7wHtdxOq05UB7NM8JdApb0pEyOxNk5bpg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from localhost (unknown [IPv6:2804:14c:70:2c6a:936e:f273:49a3:9033]) by sourceware.org (Postfix) with ESMTP id 3013A3858401 for ; Tue, 16 Nov 2021 16:53:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3013A3858401 Received: by localhost (Postfix, from userid 1000) id 408929CC6AD; Tue, 16 Nov 2021 13:53:11 -0300 (-03) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Do not abort compilation when dump file is /dev/* Date: Tue, 16 Nov 2021 13:52:32 -0300 Message-Id: <20211116165231.11822-1-gbelinassi@suse.de> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-Spam-Status: No, score=-8.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, 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 , matz@suse.com, 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 dump folder is /dev/. If yes, then it just informs the user and disables dumping, but does not halt the compilation and the compiler retuns 0 to the shell. gcc/ChangeLog 2021-11-16 Giuliano Belinassi * dumpfile.c (dump_open): Do not halt compilation when file matches /dev/*. gcc/testsuite/ChangeLog 2021-11-16 Giuliano Belinassi * gcc.dg/devnull-dump.c: New. Signed-off-by: Giuliano Belinassi --- gcc/dumpfile.c | 17 ++++++++++++++++- gcc/testsuite/gcc.dg/devnull-dump.c | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/devnull-dump.c diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c index 8169daf7f59..b1dbfb371af 100644 --- a/gcc/dumpfile.c +++ b/gcc/dumpfile.c @@ -378,7 +378,22 @@ dump_open (const char *filename, bool trunc) FILE *stream = fopen (filename, trunc ? "w" : "a"); if (!stream) - error ("could not open dump file %qs: %m", filename); + { + /* Autoconf tests compiler functionalities by setting output to /dev/null. + In this case, if dumps are enabled, it will try to set the output + folder to /dev/*, which is of course invalid and the compiler will exit + with an error, resulting in configure script reporting the tested + feature as being unavailable. Here we test this case by checking if the + output file prefix has /dev/ and only inform the user in this case + rather than refusing to compile. */ + + const char *const slash_dev = "/dev/"; + if (strncmp(slash_dev, filename, strlen(slash_dev)) == 0) + inform (UNKNOWN_LOCATION, + "could not open dump file %qs: %m. Dumps are disabled.", filename); + else + error ("could not open dump file %qs: %m", filename); + } return stream; } 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; +}