This is the mail archive of the
mailing list for the GCC project.
[PATCH] Properly detect working jobserver in gcc driver.
- From: Martin Liška <mliska at suse dot cz>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Jan Hubicka <hubicka at ucw dot cz>, Jeff Law <law at redhat dot com>, gcc-patches at gcc dot gnu dot org, Michael Matz <matz at suse dot de>, Richard Biener <richard dot guenther at gmail dot com>
- Date: Thu, 1 Aug 2019 16:34:09 +0200
- Subject: [PATCH] Properly detect working jobserver in gcc driver.
- References: <20190730233230.GS15878@tucnak> <email@example.com> <20190731073407.GU15878@tucnak> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <20190731085757.GX15878@tucnak> <email@example.com> <firstname.lastname@example.org> <email@example.com> <20190801131932.GA2726@tucnak>
On 8/1/19 3:19 PM, Jakub Jelinek wrote:
> On Wed, Jul 31, 2019 at 05:00:37PM +0200, Martin Liška wrote:
>> On 7/31/19 12:01 PM, Martin Liška wrote:
>>> Anyway, the auto-detection of jobserver seems very ugly to me :/
>>> I tend to remove the support and start working on a proper implementation
>>> that can be used not only by make build system.
>> Can you Jakub test the attached patch please?
> That works. I guess it didn't actually act as a fork-bomb because most of
> our lto tests are small and there aren't enough functions to create so many
Ok, after deeper discussion with Honza, I would like to suggest the original
patch that was about proper detection of jobserver.
Can you please Jakub test the patch in your environment?
>From 0a7f15566dda99146784eb3f85e8b4547f2ab71c Mon Sep 17 00:00:00 2001
From: Martin Liska <firstname.lastname@example.org>
Date: Thu, 1 Aug 2019 16:30:01 +0200
Subject: [PATCH] Properly detect working jobserver in gcc driver.
2019-08-01 Martin Liska <email@example.com>
* gcc.c (driver::maybe_run_linker): 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
gcc/gcc.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/gcc/gcc.c b/gcc/gcc.c
index a4323eb146e..fc11abf1f88 100644
@@ -8268,6 +8268,39 @@ driver::maybe_run_linker (const char *argv0) const
int tmp = execution_count;
+ /* 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, "--jobserver-auth=%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));
if (! have_c)
#if HAVE_LTO_PLUGIN > 0