Properly detect working jobserver in gcc driver.
2019-08-02 Martin Liska <mliska@suse.cz> PR lto/91313 * 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. From-SVN: r274003
This commit is contained in:
parent
c0cc62604f
commit
e006ead523
4 changed files with 58 additions and 1 deletions
|
@ -1,3 +1,17 @@
|
|||
2019-08-02 Martin Liska <mliska@suse.cz>
|
||||
|
||||
PR lto/91313
|
||||
* 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.
|
||||
|
||||
2019-08-02 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR tree-optimization/91201
|
||||
|
|
42
gcc/gcc.c
42
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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue