From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11890 invoked by alias); 1 Aug 2019 14:34:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 11880 invoked by uid 89); 1 Aug 2019 14:34:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Aug 2019 14:34:11 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 106D1ADA2; Thu, 1 Aug 2019 14:34:09 +0000 (UTC) Subject: [PATCH] Properly detect working jobserver in gcc driver. To: Jakub Jelinek Cc: Jan Hubicka , Jeff Law , gcc-patches@gcc.gnu.org, Michael Matz , Richard Biener References: <20190730233230.GS15878@tucnak> <87d4b006-bb01-a608-7abe-680dffcc937a@suse.cz> <20190731073407.GU15878@tucnak> <20190731080809.g2uerujjqvsaut74@kam.mff.cuni.cz> <20190731085757.GX15878@tucnak> <20190731091215.f5yjjaevmvhiyma4@kam.mff.cuni.cz> <20190801131932.GA2726@tucnak> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <089f4b9d-a29a-5031-a272-e005cb5ce78c@suse.cz> Date: Thu, 01 Aug 2019 14:34:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190801131932.GA2726@tucnak> Content-Type: multipart/mixed; boundary="------------ED9CFF7A05ADA9D6A685E249" X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00040.txt.bz2 This is a multi-part message in MIME format. --------------ED9CFF7A05ADA9D6A685E249 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-length: 792 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 > partitions. > > Jakub > 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? Thanks, Martin --------------ED9CFF7A05ADA9D6A685E249 Content-Type: text/x-patch; name="0001-Properly-detect-working-jobserver-in-gcc-driver.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Properly-detect-working-jobserver-in-gcc-driver.patch" Content-length: 1805 >From 0a7f15566dda99146784eb3f85e8b4547f2ab71c Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 1 Aug 2019 16:30:01 +0200 Subject: [PATCH] Properly detect working jobserver in gcc driver. gcc/ChangeLog: 2019-08-01 Martin Liska PR lto/91313 * 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 detection. --- gcc/gcc.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gcc/gcc.c b/gcc/gcc.c index a4323eb146e..fc11abf1f88 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -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 -- 2.22.0 --------------ED9CFF7A05ADA9D6A685E249--