On Tue, 16 Nov 2021, Giuliano Belinassi wrote:

> 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.

I think matching '/dev/*' is broken.  Either failure to open a dump
file should be an error or not.  Btw, some configure tests check
for compiler output as well which still breaks in this case.

IMHO a more reasonable thing to do would be to not treat
-o /dev/null as a source for -dumpdir and friends.  Alex?
You did the last re-org, where'd we put such special casing?

Of course configure checks using -fdump-... with -o /dev/null are
a bit fragile.  They could use -fdump-...=FILENAME

Thnaks,
Richard.

> gcc/ChangeLog
> 2021-11-16  Giuliano Belinassi  <gbelina...@suse.de>
> 
>       * dumpfile.c (dump_open): Do not halt compilation when file
>       matches /dev/*.
> 
> gcc/testsuite/ChangeLog
> 2021-11-16  Giuliano Belinassi  <gbelina...@suse.de>
> 
>       * gcc.dg/devnull-dump.c: New.
> 
> Signed-off-by: Giuliano Belinassi <gbelina...@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;
> +}
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)

Reply via email to