aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index a4323eb..18a0742 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -8268,6 +8268,8 @@ driver::maybe_run_linker (const char *argv0) const
{
int tmp = execution_count;
+ detect_jobserver ();
+
if (! have_c)
{
#if HAVE_LTO_PLUGIN > 0
@@ -8357,6 +8359,46 @@ driver::final_actions () const
}
}
+/* Detect whether jobserver is active and working. If not drop
+ --jobserver-auth from MAKEFLAGS. */
+
+void
+driver::detect_jobserver () const
+{
+ /* Detect jobserver and drop it if it's not working. */
+ const char *makeflags = env.get ("MAKEFLAGS");
+ if (makeflags != NULL)
+ {
+ const char *needle = "--jobserver-auth=";
+ const char *n = strstr (makeflags, needle);
+ if (n != NULL)
+ {
+ int rfd = -1;
+ int wfd = -1;
+
+ bool jobserver
+ = (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2
+ && rfd > 0
+ && wfd > 0
+ && fcntl (rfd, F_GETFD) >= 0
+ && fcntl (wfd, F_GETFD) >= 0);
+
+ /* Drop the jobserver if it's not working now. */
+ if (!jobserver)
+ {
+ unsigned offset = n - makeflags;
+ char *dup = xstrdup (makeflags);
+ dup[offset] = '\0';
+
+ const char *space = strchr (makeflags + offset, ' ');
+ if (space != NULL)
+ strcpy (dup + offset, space);
+ xputenv (concat ("MAKEFLAGS=", dup, NULL));
+ }
+ }
+ }
+}
+
/* Determine what the exit code of the driver should be. */
int