From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129794 invoked by alias); 2 Aug 2019 08:50:09 -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 129785 invoked by uid 89); 2 Aug 2019 08:50:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 08:50:07 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94BE73082132; Fri, 2 Aug 2019 08:50:06 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-200.ams2.redhat.com [10.36.116.200]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3416719C68; Fri, 2 Aug 2019 08:50:06 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x728o37N030221; Fri, 2 Aug 2019 10:50:03 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x728o1Ft030220; Fri, 2 Aug 2019 10:50:01 +0200 Date: Fri, 02 Aug 2019 08:50:00 -0000 From: Jakub Jelinek To: Martin =?utf-8?B?TGnFoWth?= Cc: Jan Hubicka , Jeff Law , gcc-patches@gcc.gnu.org, Michael Matz , Richard Biener Subject: Re: [PATCH] Properly detect working jobserver in gcc driver. Message-ID: <20190802085001.GK2726@tucnak> Reply-To: Jakub Jelinek References: <20190731085757.GX15878@tucnak> <20190731091215.f5yjjaevmvhiyma4@kam.mff.cuni.cz> <20190801131932.GA2726@tucnak> <089f4b9d-a29a-5031-a272-e005cb5ce78c@suse.cz> <20190801144126.GC2726@tucnak> <20190802074450.GG2726@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00115.txt.bz2 On Fri, Aug 02, 2019 at 10:47:10AM +0200, Martin Liška wrote: > > Can you strace if other fds are opened and not closed in the spot you had it > > before? Advantage of doing it there is that it will not be done for all the > > -E/-S/-c compilations when the linker is not spawned. > > I've used the same trick which you used and I'm attaching the output. > I believe it's fine, I can't see any opened fd by GCC. LGTM. > gcc/ChangeLog: > > 2019-08-02 Martin Liska > > * 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. > --- > gcc/gcc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > gcc/gcc.h | 1 + > gcc/lto-wrapper.c | 2 +- > 3 files changed, 44 insertions(+), 1 deletion(-) > > diff --git a/gcc/gcc.c b/gcc/gcc.c > index a4323eb146e..18a07426290 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 > diff --git a/gcc/gcc.h b/gcc/gcc.h > index a0a1d94c6e6..dc77dba67fb 100644 > --- a/gcc/gcc.h > +++ b/gcc/gcc.h > @@ -51,6 +51,7 @@ class driver > void do_spec_on_infiles () const; > void maybe_run_linker (const char *argv0) const; > void final_actions () const; > + void detect_jobserver () const; > int get_exit_code () const; > > private: > diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c > index 353187c6043..3414adedd26 100644 > --- a/gcc/lto-wrapper.c > +++ b/gcc/lto-wrapper.c > @@ -1234,7 +1234,7 @@ jobserver_active_p (void) > int rfd = -1; > int wfd = -1; > > - return ((sscanf(n, "--jobserver-auth=%d,%d", &rfd, &wfd) == 2) > + return (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2 > && rfd > 0 > && wfd > 0 > && fcntl (rfd, F_GETFD) >= 0 > -- > 2.22.0 > Jakub