[2/3] lto: support --jobserver-style=fifo for recent GNU make

Message ID 62cc745a-052a-fbde-7a8e-bccacf249bb8@suse.cz
State New, archived
Headers
Series [1/3] Factor out jobserver_active_p. |

Commit Message

Martin Liška Aug. 9, 2022, noon UTC
  Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

	* jobserver.h (jobserver_info::jobserver_info): Parse FIFO
	format of --jobserver-auth.
---
 gcc/jobserver.h | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
  

Comments

Martin Liška Aug. 10, 2022, 11:11 a.m. UTC | #1
On 8/9/22 14:00, Martin Liška wrote:
> |Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin|

Sending v2 where I renamed the file. I'm going to install it as the original fifo support
patch was already approved by Richi.

Cheers,
Martin
  

Patch

diff --git a/gcc/jobserver.h b/gcc/jobserver.h
index 85453dd3c79..856e326ddfc 100644
--- a/gcc/jobserver.h
+++ b/gcc/jobserver.h
@@ -39,14 +39,22 @@  struct jobserver_info
   int rfd = -1;
   /* File descriptor for writing used for jobserver communication.  */
   int wfd = -1;
+  /* Named pipe path.  */
+  string pipe_path = "";
   /* Return true if jobserver is active.  */
   bool is_active = false;
 };
 
 jobserver_info::jobserver_info ()
 {
+  /* Traditionally, GNU make uses opened pipes for jobserver-auth,
+    e.g. --jobserver-auth=3,4.
+    Starting with GNU make 4.4, one can use --jobserver-style=fifo
+    and then named pipe is used: --jobserver-auth=fifo:/tmp/hcsparta.  */
+
   /* Detect jobserver and drop it if it's not working.  */
   string js_needle = "--jobserver-auth=";
+  string fifo_prefix = "fifo:";
 
   const char *envval = getenv ("MAKEFLAGS");
   if (envval != NULL)
@@ -55,8 +63,15 @@  jobserver_info::jobserver_info ()
       size_t n = makeflags.rfind (js_needle);
       if (n != string::npos)
 	{
-	  if (sscanf (makeflags.c_str () + n + js_needle.size (),
-		      "%d,%d", &rfd, &wfd) == 2
+	  string ending = makeflags.substr (n + js_needle.size ());
+	  if (ending.find (fifo_prefix) == 0)
+	    {
+	      ending = ending.substr (fifo_prefix.size ());
+	      pipe_path = ending.substr (0, ending.find (' '));
+	      is_active = true;
+	    }
+	  else if (sscanf (makeflags.c_str () + n + js_needle.size (),
+			   "%d,%d", &rfd, &wfd) == 2
 	      && rfd > 0
 	      && wfd > 0
 	      && is_valid_fd (rfd)