[Bug driver/107007] New: libiberty's win32_spawn error handling is poor
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Sep 22 08:42:22 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107007
Bug ID: 107007
Summary: libiberty's win32_spawn error handling is poor
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: driver
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Host: *-*-mingw*
As described in
https://gcc.gnu.org/pipermail/gcc-help/2022-September/141906.html the
pex_win32_exec_child function just assumes that all errors are ENOENT:
/* Create the child process. */
pid = win32_spawn (executable, (flags & PEX_SEARCH) != 0,
argv, env, dwCreationFlags, &si, &pi);
if (pid == (pid_t) -1)
pid = spawn_script (executable, argv, env, dwCreationFlags,
&si, &pi);
if (pid == (pid_t) -1)
{
*err = ENOENT;
*errmsg = "CreateProcess";
}
This gives users incorrect information when something goes wrong for a reason
that isn't "No such file or directory".
Maybe win32_spawn should use the Win32 GetLastError() function to get a Windows
Error Code and then translate that to an errno value, and store it in errno. Or
ensure that GetLastError will still be valid for the caller of win32_spawn and
spawn_script to retrieve.
libstdc++-v3/src/c++11/system_error.cc already has code to do that translation
(so maybe it should move to libiberty, and then reuse that in libstdc++).
More information about the Gcc-bugs
mailing list