aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2019-08-02 11:23:56 +0200
committerMartin Liska <marxin@gcc.gnu.org>2019-08-02 09:23:56 +0000
commite006ead5230560030c44856952967ca0cfea4db2 (patch)
tree1036c571824eb7e7daa673d13ab75084ac68003c /gcc/gcc.c
parentc0cc62604f163289afaa37ba45f729ae31a45e71 (diff)
downloadgcc-e006ead5230560030c44856952967ca0cfea4db2.zip
gcc-e006ead5230560030c44856952967ca0cfea4db2.tar.gz
gcc-e006ead5230560030c44856952967ca0cfea4db2.tar.bz2
Properly detect working jobserver in gcc driver.
2019-08-02 Martin Liska <mliska@suse.cz> PR lto/91313 * gcc.c (driver::maybe_run_linker): Call detect_jobserver to detect working job server. (driver::detect_jobserver): Test whether jobserver is active from GCC driver. That will prevent situation where GCC is invoked from a LD plugin and the linker already uses file descriptors suggested by make. That leads to a wrong detection. * gcc.h (driver): Add detect_jobserver. * lto-wrapper.c (jobserver_active_p): Simplify sscanf by not scanning for --jobserver-auth prefix. From-SVN: r274003
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