This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Properly detect working jobserver in gcc driver.


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
>From 0a7f15566dda99146784eb3f85e8b4547f2ab71c Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
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  <mliska@suse.cz>

	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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]