This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix file descriptor existence of MinGW.
- From: Martin Liška <mliska at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: pexu at gcc-bugzilla dot mail dot kapsi dot fi
- Date: Tue, 6 Aug 2019 14:04:54 +0200
- Subject: [PATCH] Fix file descriptor existence of MinGW.
Hi.
The patch is about proper checking of file descriptors on Windows.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
@Pekka: Can you please test it on Windows?
Ready to be installed?
Thanks,
Martin
gcc/ChangeLog:
2019-08-06 Martin Liska <mliska@suse.cz>
PR bootstrap/91352
* gcc.c (fd_exists): New.
(driver::detect_jobserver): Use fd_exists.
* lto-wrapper.c (fd_exists): New.
(jobserver_active_p): Use fd_exists.
---
gcc/gcc.c | 19 +++++++++++++++++--
gcc/lto-wrapper.c | 19 +++++++++++++++++--
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 18a07426290..6bcd989ee30 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -8359,6 +8359,21 @@ driver::final_actions () const
}
}
+/* Return true when FD file descriptor exists. */
+
+static bool
+fd_exists (int fd)
+{
+#if defined (F_GETFD)
+ return fcntl (fd, F_GETFD) >= 0;
+#elif defined(_WIN32)
+ HANDLE h = (HANDLE) _get_osfhandle (fd);
+ return h != (HANDLE) -1;
+#else
+ return false;
+#endif
+}
+
/* Detect whether jobserver is active and working. If not drop
--jobserver-auth from MAKEFLAGS. */
@@ -8380,8 +8395,8 @@ driver::detect_jobserver () const
= (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2
&& rfd > 0
&& wfd > 0
- && fcntl (rfd, F_GETFD) >= 0
- && fcntl (wfd, F_GETFD) >= 0);
+ && fd_exists (rfd)
+ && fd_exists (wfd));
/* Drop the jobserver if it's not working now. */
if (!jobserver)
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index 3414adedd26..065a1d0ad02 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -1217,6 +1217,21 @@ init_num_threads (void)
/* FIXME: once using -std=c11, we can use std::thread::hardware_concurrency. */
+/* Return true when FD file descriptor exists. */
+
+static bool
+fd_exists (int fd)
+{
+#if defined (F_GETFD)
+ return fcntl (fd, F_GETFD) >= 0;
+#elif defined(_WIN32)
+ HANDLE h = (HANDLE) _get_osfhandle (fd);
+ return h != (HANDLE) -1;
+#else
+ return false;
+#endif
+}
+
/* Return true when a jobserver is running and can accept a job. */
static bool
@@ -1237,8 +1252,8 @@ jobserver_active_p (void)
return (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2
&& rfd > 0
&& wfd > 0
- && fcntl (rfd, F_GETFD) >= 0
- && fcntl (wfd, F_GETFD) >= 0);
+ && fd_exists (rfd)
+ && fd_exists (wfd));
}
/* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */