public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Do not abort compilation when dump file is /dev/*
@ 2021-11-16 16:52 Giuliano Belinassi
  2021-11-18  9:43 ` Richard Biener
  2021-11-18 11:48 ` [PATCH] " Martin Liška
  0 siblings, 2 replies; 16+ messages in thread
From: Giuliano Belinassi @ 2021-11-16 16:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: rguenther, matz, Giuliano Belinassi

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  <gbelinassi@suse.de>

	* dumpfile.c (dump_open): Do not halt compilation when file
	matches /dev/*.

gcc/testsuite/ChangeLog
2021-11-16  Giuliano Belinassi  <gbelinassi@suse.de>

	* gcc.dg/devnull-dump.c: New.

Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>
---
 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;
+}
-- 
2.33.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-11-22 12:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 16:52 [PATCH] Do not abort compilation when dump file is /dev/* Giuliano Belinassi
2021-11-18  9:43 ` Richard Biener
2021-11-18 12:52   ` Giuliano Belinassi
2021-11-18 14:24     ` Richard Biener
2021-11-18 21:35       ` [PATCH v2] " Giuliano Belinassi
2021-11-19  8:11         ` Richard Biener
2021-11-19  9:22   ` [PATCH] " Alexandre Oliva
2021-11-19  9:35     ` Richard Biener
2021-11-19 12:25       ` Bernhard Reutner-Fischer
2021-11-19 12:51         ` Richard Biener
2021-11-19 13:42     ` [PATCH v3] " Giuliano Belinassi
2021-11-19 14:12       ` Richard Biener
2021-11-19 14:47         ` Bernhard Reutner-Fischer
2021-11-21  3:47         ` Alexandre Oliva
2021-11-22 12:35           ` Giuliano Belinassi
2021-11-18 11:48 ` [PATCH] " Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).