On Thu, 22 Sept 2022 at 07:45, LIU Hao via Gcc-help <gcc-help@xxxxxxxxxxx> wrote: > > 在 2022/9/21 00:02, mizo 91 via Gcc-help 写道: > > Hello, > > > > I'm having trouble compiling simple test program on windows 10 with long > > list of includes provided via '@response_file' argument > > > > > > Greetings. mingw-w64 developer speaking. > > As far as I can see, there are at least two issues about your report: > > > The first, obvious issue is that the error message is incorrect. The reason for that is, if we take > a look at 'libiberty/pex-win32.c' we see the following: > > 853 /* Create the child process. */ > 854 pid = win32_spawn (executable, (flags & PEX_SEARCH) != 0, > 855 argv, env, dwCreationFlags, &si, &pi); > 856 if (pid == (pid_t) -1) > 857 pid = spawn_script (executable, argv, env, dwCreationFlags, > 858 &si, &pi); > 859 if (pid == (pid_t) -1) > 860 { > 861 *err = ENOENT; > 862 *errmsg = "CreateProcess"; > 863 } > > We also notice this is the only place where `"CreateProcess"` appears as a sole part of an error > message. > > The cause of this issue is apparent: libiberty tries `win32_spawn`, and if for whatever reason it > fails, it makes another attempt with `spawn_script`, and if it fails again, `*err` is always set to > `ENOENT` i.e. `No such file or directory`, no matter why. It seems to me that pex-win32.c should use GetLastError() (and maybe FormatMessage) to get a Windows error code, rather than assuming ENOENT. Using C++ that would look something like: std::string errmsg = "CreateProcess:" + std::system_category().message(GetLastError()); Or maybe win32_spawn should call GetLastError() and convert that to an errno value and store it in errno: std::error_condition ec = std::system_category().default_error_condition(GetLastError()); if (ec.category() == std::generic_category()) errno = ec.value(); else errno = ENOENT; // or EINVAL might be better?