MINGW-packages icon indicating copy to clipboard operation
MINGW-packages copied to clipboard

[gcc] -freport-bug doesn't work on ICEs

Open lazka opened this issue 1 year ago • 2 comments

As pointed out in #20864 passing -freport-bug to GCC when it triggers an ICE leads to another error:

Please submit a full bug report, with preprocessed source.
See <https://github.com/msys2/MINGW-packages/issues> for instructions.
gcc: fatal error: cannot execute 'C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/cc1.exe': open temporary output file: No such file or directory

I don't know what it's supposed to do and if that is worth looking into, since I don't know how to make it do anything without knowing a way to crash gcc.

lazka avatar May 13 '24 18:05 lazka

I did a quick grep of the gcc sources for "open temporary output file" and found the likely reason for this.

In gcc/gcc.cc do_report_bug() calls run_attempt(append=1), this append flag gets through pex_run/pex_run_in_environment in libiberty/pex-common.c, which ends in a call of pex_win32_open_write(append=1) in libiberty/pex-win32.c. The function looks like this:

static int
pex_win32_open_write (struct pex_obj *obj ATTRIBUTE_UNUSED, const char *name,
		      int binary, int append)
{
  /* Note that we can't use O_EXCL here because gcc may have already
     created the temporary file via make_temp_file.  */
  if (append)
    return -1;
  return _open (name,
		(_O_WRONLY | _O_CREAT | _O_TRUNC
		 | (binary ? _O_BINARY : _O_TEXT)),
		_S_IREAD | _S_IWRITE);
}

So it immediately returns -1, which results in this error in pex_run_in_environment():

      out = obj->funcs->open_write (obj, outname,
				    (flags & PEX_BINARY_OUTPUT) != 0,
				    (flags & PEX_STDOUT_APPEND) != 0);
      if (out < 0)
	{
	  *err = errno;
	  errmsg = "open temporary output file";
	  goto error_exit;
	}

No clue how to solve this.

ssbssa avatar May 15 '24 17:05 ssbssa

This fixes -freport-bug for me:

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 728332b8153..78505086ee3 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -7720,8 +7720,8 @@ files_equal_p (char *file1, char *file2)
   const int bufsize = 8192;
   char *buf = XNEWVEC (char, bufsize);
 
-  fd1 = open (file1, O_RDONLY);
-  fd2 = open (file2, O_RDONLY);
+  fd1 = open (file1, O_RDONLY | O_BINARY);
+  fd2 = open (file2, O_RDONLY | O_BINARY);
 
   if (fd1 < 0 || fd2 < 0)
     goto error;
diff --git a/libiberty/pex-win32.c b/libiberty/pex-win32.c
index 3780f1de02d..56478df47e3 100644
--- a/libiberty/pex-win32.c
+++ b/libiberty/pex-win32.c
@@ -130,10 +130,9 @@ pex_win32_open_write (struct pex_obj *obj ATTRIBUTE_UNUSED, const char *name,
 {
   /* Note that we can't use O_EXCL here because gcc may have already
      created the temporary file via make_temp_file.  */
-  if (append)
-    return -1;
   return _open (name,
-		(_O_WRONLY | _O_CREAT | _O_TRUNC
+		(_O_WRONLY | _O_CREAT
+		 | (append ? _O_APPEND : _O_TRUNC)
 		 | (binary ? _O_BINARY : _O_TEXT)),
 		_S_IREAD | _S_IWRITE);
 }

ssbssa avatar Sep 06 '24 15:09 ssbssa

what to do:

[1/6] Building CXX object CMakeFiles/KickC.dir/src/main/kickc/parse/CParser.ixx.obj FAILED: CMakeFiles/KickC.dir/src/main/kickc/parse/CParser.ixx.obj CMakeFiles/KickC.dir/CParser.gcm C:\msys64\ucrt64\bin\g++.exe -DANTLR4CPP_STATIC -IC:/Users/svenv/CLionProjects/KickC/cmake-build-debug-mingw-msys2/antlr4_runtime/src/antlr4_runtime/runtime/Cpp/runtime/src -IC:/Users/svenv/CLionProjects/KickC -IC:/Users/svenv/CLionProjects/KickC/libs -IC:/Users/svenv/CLionProjects/KickC/src/main/include -IC:/Users/svenv/CLionProjects/KickC/src/main/kickc -IC:/Users/svenv/CLionProjects/KickC/src/main/modules -IC:/Users/svenv/CLionProjects/KickC/cmake-build-debug-mingw-msys2/antlr4cpp_generated_src/KickCLexer -IC:/Users/svenv/CLionProjects/KickC/cmake-build-debug-mingw-msys2/antlr4cpp_generated_src/KickCParser -Mmodules -freport-bug -g -std=gnu++23 -fdiagnostics-color=always -MD -MT CMakeFiles/KickC.dir/src/main/kickc/parse/CParser.ixx.obj -MF CMakeFiles\KickC.dir\src\main\kickc\parse\CParser.ixx.obj.d -fmodules-ts -fmodule-mapper=CMakeFiles\KickC.dir\src\main\kickc\parse\CParser.ixx.obj.modmap -MD -fdeps-format=p1689r5 -x c++ -o CMakeFiles/KickC.dir/src/main/kickc/parse/CParser.ixx.obj -c C:/Users/svenv/CLionProjects/KickC/src/main/kickc/parse/CParser.ixx In module imported at C:/Users/svenv/CLionProjects/KickC/src/main/kickc/cpu/Cpu65xx.ixx:14:1, of module Cpu65xx, imported at C:/Users/svenv/CLionProjects/KickC/src/main/kickc/cpu/CpuHuc6280.h:10, included from C:/Users/svenv/CLionProjects/KickC/src/main/kickc/model/TargetCpu.h:21, from C:/Users/svenv/CLionProjects/KickC/src/main/kickc/model/TargetPlatform.h:13, from C:/Users/svenv/CLionProjects/KickC/src/main/kickc/model/Program.h:12, from C:/Users/svenv/CLionProjects/KickC/src/main/kickc/parse/CParser.ixx:13: CpuAddressingMode: note: unable to represent further imported source locations C:/Users/svenv/CLionProjects/KickC/src/main/kickc/parse/CParser.ixx:21:9: internal compiler error: in write_location, at cp/module.cc:16271 21 | export module CParser; | ^ Please submit a full bug report, with preprocessed source. See https://github.com/msys2/MINGW-packages/issues for instructions. g++.exe: fatal error: cannot execute 'C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/cc1plus.exe': open temporary output file: No such file or directory compilation terminated. ninja: build stopped: subcommand failed.

FlightControl-User avatar Feb 15 '25 05:02 FlightControl-User

is this already reported to GCC? if not i'll report a bug there.

G-M-twostay avatar Apr 26 '25 20:04 G-M-twostay