From 0fddb1847019ceb570c6e0aea0ea779f1f9988cf Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 8 Aug 2019 09:50:28 +0200 Subject: [PATCH] Fix file descriptor existence of MinGW. 2019-08-08 Martin Liska PR bootstrap/91352 * gcc.c (driver::detect_jobserver): Use is_valid_fd. * lto-wrapper.c (jobserver_active_p): Likewise. 2019-08-08 Martin Liska PR bootstrap/91352 * libiberty.h (is_valid_fd): New function. 2019-08-08 Martin Liska PR bootstrap/91352 * lrealpath.c (is_valid_fd): New function. From-SVN: r274208 --- gcc/ChangeLog | 6 ++++++ gcc/gcc.c | 4 ++-- gcc/lto-wrapper.c | 4 ++-- include/ChangeLog | 5 +++++ include/libiberty.h | 4 ++++ libiberty/ChangeLog | 5 +++++ libiberty/lrealpath.c | 16 ++++++++++++++++ 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fd18c4f2bfe..54f7d974821 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-08-08 Martin Liska + + PR bootstrap/91352 + * gcc.c (driver::detect_jobserver): Use is_valid_fd. + * lto-wrapper.c (jobserver_active_p): Likewise. + 2019-08-08 Martin Liska * cgraphclones.c (set_new_clone_decl_and_node_flags): Drop diff --git a/gcc/gcc.c b/gcc/gcc.c index 18a07426290..1216cdd505a 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -8380,8 +8380,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); + && is_valid_fd (rfd) + && is_valid_fd (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 f93ff504e88..f1253cdc91c 100644 --- a/gcc/lto-wrapper.c +++ b/gcc/lto-wrapper.c @@ -1237,8 +1237,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); + && is_valid_fd (rfd) + && is_valid_fd (wfd)); } /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */ diff --git a/include/ChangeLog b/include/ChangeLog index a4f3fe5d5ce..83bd789dd2e 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2019-08-08 Martin Liska + + PR bootstrap/91352 + * libiberty.h (is_valid_fd): New function. + 2019-07-18 Eduard-Mihai Burtescu * demangle.h (rust_is_mangled): Move to libiberty/rust-demangle.h. diff --git a/include/libiberty.h b/include/libiberty.h index 635519e088a..71192a29377 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -137,6 +137,10 @@ extern const char *unix_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRI extern char *lrealpath (const char *); +/* Return true when FD file descriptor exists. */ + +extern int is_valid_fd (int fd); + /* Concatenate an arbitrary number of strings. You must pass NULL as the last argument of this function, to terminate the list of strings. Allocates memory using xmalloc. */ diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index c22d49f157a..95cb1525f2c 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,8 @@ +2019-08-08 Martin Liska + + PR bootstrap/91352 + * lrealpath.c (is_valid_fd): New function. + 2019-07-24 Martin Liska PR lto/91228 diff --git a/libiberty/lrealpath.c b/libiberty/lrealpath.c index 7f66dc2b1bd..ac914a7a4f4 100644 --- a/libiberty/lrealpath.c +++ b/libiberty/lrealpath.c @@ -49,6 +49,9 @@ components will be simplified. The returned value will be allocated using #ifdef HAVE_STRING_H #include #endif +#ifdef HAVE_FCNTL_H +#include +#endif /* On GNU libc systems the declaration is only visible with _GNU_SOURCE. */ #if defined(HAVE_CANONICALIZE_FILE_NAME) \ @@ -155,3 +158,16 @@ lrealpath (const char *filename) /* This system is a lost cause, just duplicate the filename. */ return strdup (filename); } + +/* Return true when FD file descriptor exists. */ + +int +is_valid_fd (int fd) +{ +#if defined(_WIN32) + HANDLE h = (HANDLE) _get_osfhandle (fd); + return h != (HANDLE) -1; +#else + return fcntl (fd, F_GETFD) >= 0; +#endif +} -- 2.30.2