From 5ae3346507bbc39731bf4d43efe56cdb208f23fc Mon Sep 17 00:00:00 2001 From: Senthil Kumar Selvaraj Date: Thu, 18 Dec 2025 11:45:50 +0530 Subject: [PATCH] Do not skip jobserver flags with negative file descriptors As part of jobserver detection, the jobserver_info constructor looks for the last occurence of "--jobserver-auth=", and parses the argument for that option to look for either a named pipe (has a "fifo:" prefix) or read and write pipe fds separated by a comma. With GNU Make 4.4 and above, named pipes are used by default because anonymous pipe fds cannot be used reliably (see https://savannah.gnu.org/bugs/?57242), but it still supports a --jobserver-style=pipe option for compatibility reasons. With that flag enabled, or with older GNU Make versions, the jobserver detection code checks if the provided fds are greater than 0 and valid. If invalid, it drops them from MAKEFLAGS used for subsequent child processes. However, GNU Make explicitly provides negative jobserver pipe fds if the command is not marked as recursive (i.e is missing a '+' prefix in the Makefile) - see https://savannah.gnu.org/bugs/?57242#comment13. The MAKEFLAGS look like this in that case. -j4 --jobserver-auth=3,4 --jobserver-auth=-2,-2 Stripping off the final --jobserver-auth with negative fds undoes this helpful hint from GNU Make, and exposes child processes (like lto-wrapper) to all the issues with anonymous pipe fds that forced GNU Make to switch to named pipes by default. This patch prevents that stripping if jobserver communication is *not* via a named pipe *and* file descriptors are negative. As a result, child processes receive MAKEFLAGS with negative file descriptors too, and correctly decide that a jobserver is not available. gcc/ChangeLog: * opts-common.cc (jobserver_info::jobserver_info): Do not skip negative file descriptors in simple UNIX pipe mode. --- gcc/opts-common.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index 379402e68a6..aaed63d1344 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -2110,7 +2110,8 @@ jobserver_info::jobserver_info () if (n != string::npos) { string ending = makeflags.substr (n + js_needle.size ()); - if (ending.find (fifo_prefix) == 0) + bool is_named_pipe = ending.find (fifo_prefix) == 0; + if (is_named_pipe) { ending = ending.substr (fifo_prefix.size ()); pipe_path = ending.substr (0, ending.find (' ')); @@ -2125,11 +2126,15 @@ jobserver_info::jobserver_info () is_active = true; else { - string dup = makeflags.substr (0, n); - size_t pos = makeflags.find (' ', n); - if (pos != string::npos) - dup += makeflags.substr (pos); - skipped_makeflags = "MAKEFLAGS=" + dup; + bool negative_fds = !is_named_pipe && rfd < 0 && wfd < 0; + if (!negative_fds) + { + string dup = makeflags.substr (0, n); + size_t pos = makeflags.find (' ', n); + if (pos != string::npos) + dup += makeflags.substr (pos); + skipped_makeflags = "MAKEFLAGS=" + dup; + } error_msg = "cannot access %<" + js_needle + "%> file descriptors"; }