From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 9C567158020 for ; Sat, 17 Dec 2022 04:54:14 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 77EA9E085E; Sat, 17 Dec 2022 04:54:13 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 03948E085E for ; Sat, 17 Dec 2022 04:54:13 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BE8AB341196 for ; Sat, 17 Dec 2022 04:54:11 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 55685621 for ; Sat, 17 Dec 2022 04:54:10 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1671252844.a535dea3848bd10f950f72281bb7d1563586d1d8.sam@gentoo> Subject: [gentoo-commits] proj/gcc-patches:master commit in: 10.5.0/gentoo/ X-VCS-Repository: proj/gcc-patches X-VCS-Files: 10.5.0/gentoo/77_all_Factor-out-jobserver_active_p.patch 10.5.0/gentoo/78_all_lto-support-jobserver-style-fifo-for-recent-GNU-make.patch 10.5.0/gentoo/README.history X-VCS-Directories: 10.5.0/gentoo/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: a535dea3848bd10f950f72281bb7d1563586d1d8 X-VCS-Branch: master Date: Sat, 17 Dec 2022 04:54:10 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 0c9f4459-0a83-4bf2-a5e0-44e04200dfdd X-Archives-Hash: 7cf160dde3547234e396b3ac199194fe commit: a535dea3848bd10f950f72281bb7d1563586d1d8 Author: Arsen Arsenović aarsen me> AuthorDate: Fri Dec 9 14:37:14 2022 +0000 Commit: Sam James gentoo org> CommitDate: Sat Dec 17 04:54:04 2022 +0000 URL: https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=a535dea3 10.5.0: backport make 4.4 jobserver fixes Bug: https://bugs.gentoo.org/884633 Signed-off-by: Arsen Arsenović aarsen.me> Signed-off-by: Sam James gentoo.org> .../77_all_Factor-out-jobserver_active_p.patch | 320 +++++++++++++++++++++ ...-jobserver-style-fifo-for-recent-GNU-make.patch | 66 +++++ 10.5.0/gentoo/README.history | 4 + 3 files changed, 390 insertions(+) diff --git a/10.5.0/gentoo/77_all_Factor-out-jobserver_active_p.patch b/10.5.0/gentoo/77_all_Factor-out-jobserver_active_p.patch new file mode 100644 index 0000000..5658a1b --- /dev/null +++ b/10.5.0/gentoo/77_all_Factor-out-jobserver_active_p.patch @@ -0,0 +1,320 @@ +https://bugs.gentoo.org/884633 + +https://build.opensuse.org/package/view_file/devel:gcc/gcc12/gcc12-fifo-jobserver-support.patch +https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=1270ccda70ca09f7d4fe76b5156dca8992bd77a6 + +Rebased by Arsen Arsenović . + +From f8ca9e3ea075f5a3743fc74ae227a361f355c0f0 Mon Sep 17 00:00:00 2001 +From: Martin Liska +Date: Tue, 9 Aug 2022 13:59:32 +0200 +Subject: [PATCH 1/2] Factor out jobserver_active_p. + +gcc/ChangeLog: + + * gcc.cc (driver::detect_jobserver): Remove and move to + jobserver.h. + * lto-wrapper.cc (jobserver_active_p): Likewise. + (run_gcc): Likewise. + * opts-jobserver.h: New file. + * opts-common.cc (jobserver_info::jobserver_info): New function. +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -27,6 +27,7 @@ CC recognizes how to compile each input file by suffixes in the file names. + Once it knows which kind of compilation to perform, the procedure for + compilation is specified by a string called a "spec". */ + ++#define INCLUDE_STRING + #include "config.h" + #include "system.h" + #include "coretypes.h" +@@ -43,6 +44,7 @@ compilation is specified by a string called a "spec". */ + #include "opts.h" + #include "filenames.h" + #include "spellcheck.h" ++#include "opts-jobserver.h" + + + +@@ -8399,38 +8401,9 @@ driver::final_actions () const + 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 +- && is_valid_fd (rfd) +- && is_valid_fd (wfd)); +- +- /* 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)); +- } +- } +- } ++ jobserver_info jinfo; ++ if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ()) ++ xputenv (jinfo.skipped_makeflags.c_str ()); + } + + /* Determine what the exit code of the driver should be. */ +--- a/gcc/lto-wrapper.c ++++ b/gcc/lto-wrapper.c +@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see + ./ccCJuXGv.lto.ltrans.o + */ + ++#define INCLUDE_STRING + #include "config.h" + #include "system.h" + #include "coretypes.h" +@@ -48,6 +49,8 @@ along with GCC; see the file COPYING3. If not see + #include "simple-object.h" + #include "lto-section-names.h" + #include "collect-utils.h" ++#include "opts-diagnostic.h" ++#include "opts-jobserver.h" + + /* Environment variable, used for passing the names of offload targets from GCC + driver to lto-wrapper. */ +@@ -1295,32 +1298,43 @@ init_num_threads (void) + #endif + } + +-/* FIXME: once using -std=c++11, we can use std::thread::hardware_concurrency. */ +- +-/* Return true when a jobserver is running and can accept a job. */ +- +-static bool +-jobserver_active_p (void) ++void ++print_lto_docs_link () + { +- const char *makeflags = getenv ("MAKEFLAGS"); +- if (makeflags == NULL) +- return false; ++ bool print_url = global_dc->printer->url_format != URL_FORMAT_NONE; ++ const char *url = global_dc->get_option_url (global_dc, OPT_flto); + +- const char *needle = "--jobserver-auth="; +- const char *n = strstr (makeflags, needle); +- if (n == NULL) +- return false; +- +- int rfd = -1; +- int wfd = -1; +- +- return (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2 +- && rfd > 0 +- && wfd > 0 +- && is_valid_fd (rfd) +- && is_valid_fd (wfd)); ++ pretty_printer pp; ++ pp.url_format = URL_FORMAT_DEFAULT; ++ pp_string (&pp, "see the "); ++ if (print_url) ++ pp_begin_url (&pp, url); ++ pp_string (&pp, "%<-flto%> option documentation"); ++ if (print_url) ++ pp_end_url (&pp); ++ pp_string (&pp, " for more information"); ++ inform (UNKNOWN_LOCATION, pp_formatted_text (&pp)); + } + ++/* Test that a make command is present and working, return true if so. */ ++ ++static bool ++make_exists (void) ++{ ++ const char *make = "make"; ++ char **make_argv = buildargv (getenv ("MAKE")); ++ if (make_argv) ++ make = make_argv[0]; ++ const char *make_args[] = {make, "--version", NULL}; ++ ++ int exit_status = 0; ++ int err = 0; ++ const char *errmsg ++ = pex_one (PEX_SEARCH, make_args[0], CONST_CAST (char **, make_args), ++ "make", NULL, NULL, &exit_status, &err); ++ freeargv (make_argv); ++ return errmsg == NULL && exit_status == 0 && err == 0; ++} + /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */ + + static void +@@ -1535,10 +1549,20 @@ run_gcc (unsigned argc, char *argv[]) + auto_parallel = 0; + parallel = 0; + } +- else if (!jobserver && jobserver_active_p ()) ++ else + { +- parallel = 1; +- jobserver = 1; ++ jobserver_info jinfo; ++ if (jobserver && !jinfo.is_active) ++ { ++ /* Fall back to auto parallelism. */ ++ jobserver = 0; ++ auto_parallel = 1; ++ } ++ else if (!jobserver && jinfo.is_active) ++ { ++ parallel = 1; ++ jobserver = 1; ++ } + } + + if (linker_output) +@@ -1861,6 +1885,20 @@ cont: + maybe_unlink (ltrans_output_file); + ltrans_output_file = NULL; + ++ if (nr > 1) ++ { ++ if (jobserver_requested && !jinfo.is_active) ++ { ++ warning (0, jinfo.error_msg.c_str ()); ++ print_lto_docs_link (); ++ } ++ else if (parallel == 0) ++ { ++ warning (0, "using serial compilation of %d LTRANS jobs", nr); ++ print_lto_docs_link (); ++ } ++ } ++ + if (parallel) + { + makefile = make_temp_file (".mk"); +--- a/gcc/opts-common.c ++++ b/gcc/opts-common.c +@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ + ++#define INCLUDE_STRING + #include "config.h" + #include "system.h" + #include "intl.h" +@@ -25,6 +26,7 @@ along with GCC; see the file COPYING3. If not see + #include "options.h" + #include "diagnostic.h" + #include "spellcheck.h" ++#include "opts-jobserver.h" + + static void prune_options (struct cl_decoded_option **, unsigned int *); + +@@ -1805,3 +1807,42 @@ void prepend_xassembler_to_collect_as_options (const char *collect_as_options, + obstack_1grow (o, '\''); + } + } ++ ++jobserver_info::jobserver_info () ++{ ++ /* Detect jobserver and drop it if it's not working. */ ++ string js_needle = "--jobserver-auth="; ++ ++ const char *envval = getenv ("MAKEFLAGS"); ++ if (envval != NULL) ++ { ++ string makeflags = envval; ++ 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 ++ && rfd > 0 ++ && wfd > 0 ++ && is_valid_fd (rfd) ++ && is_valid_fd (wfd)) ++ 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; ++ error_msg ++ = "cannot access %<" + js_needle + "%> file descriptors"; ++ } ++ } ++ error_msg = "%<" + js_needle + "%> is not present in %"; ++ } ++ else ++ error_msg = "% environment variable is unset"; ++ ++ if (!error_msg.empty ()) ++ error_msg = "jobserver is not available: " + error_msg; ++} +--- /dev/null ++++ b/gcc/opts-jobserver.h +@@ -0,0 +1,44 @@ ++/* GNU make's jobserver related functionality. ++ Copyright (C) 2022 Free Software Foundation, Inc. ++ ++This file is part of GCC. ++ ++GCC is free software; you can redistribute it and/or modify it under ++the terms of the GNU General Public License as published by the Free ++Software Foundation; either version 3, or (at your option) any later ++version. ++ ++GCC is distributed in the hope that it will be useful, but WITHOUT ANY ++WARRANTY; without even the implied warranty of MERCHANTABILITY or ++FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ++for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GCC; see the file COPYING3. If not see ++. ++ ++See dbgcnt.def for usage information. */ ++ ++#ifndef GCC_JOBSERVER_H ++#define GCC_JOBSERVER_H ++ ++using namespace std; ++ ++struct jobserver_info ++{ ++ /* Default constructor. */ ++ jobserver_info (); ++ ++ /* Error message if there is a problem. */ ++ string error_msg = ""; ++ /* Skipped MAKEFLAGS where --jobserver-auth is skipped. */ ++ string skipped_makeflags = ""; ++ /* File descriptor for reading used for jobserver communication. */ ++ int rfd = -1; ++ /* File descriptor for writing used for jobserver communication. */ ++ int wfd = -1; ++ /* Return true if jobserver is active. */ ++ bool is_active = false; ++}; ++ ++#endif /* GCC_JOBSERVER_H */ +-- +2.38.1 diff --git a/10.5.0/gentoo/78_all_lto-support-jobserver-style-fifo-for-recent-GNU-make.patch b/10.5.0/gentoo/78_all_lto-support-jobserver-style-fifo-for-recent-GNU-make.patch new file mode 100644 index 0000000..5d50461 --- /dev/null +++ b/10.5.0/gentoo/78_all_lto-support-jobserver-style-fifo-for-recent-GNU-make.patch @@ -0,0 +1,66 @@ +https://bugs.gentoo.org/884633 + +https://build.opensuse.org/package/view_file/devel:gcc/gcc12/gcc12-fifo-jobserver-support.patch +https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=53e3b2bf16a486c15c20991c6095f7be09012b55 + +Rebased by Arsen Arsenović . + +From ab7a17b024ec3efabb3803e4d1dab461082044a9 Mon Sep 17 00:00:00 2001 +From: Martin Liska +Date: Tue, 9 Aug 2022 13:59:36 +0200 +Subject: [PATCH 2/2] lto: support --jobserver-style=fifo for recent GNU make + +gcc/ChangeLog: + + * opts-jobserver.h: Add one member. + * opts-common.cc (jobserver_info::jobserver_info): Parse FIFO + format of --jobserver-auth. +--- a/gcc/opts-common.c ++++ b/gcc/opts-common.c +@@ -1810,8 +1810,14 @@ void prepend_xassembler_to_collect_as_options (const char *collect_as_options, + + 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) +@@ -1820,8 +1826,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) +--- a/gcc/opts-jobserver.h ++++ b/gcc/opts-jobserver.h +@@ -37,6 +37,8 @@ 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; + }; +-- +2.38.1 + diff --git a/10.5.0/gentoo/README.history b/10.5.0/gentoo/README.history index 41e961c..6d8c5c2 100644 --- a/10.5.0/gentoo/README.history +++ b/10.5.0/gentoo/README.history @@ -1,3 +1,7 @@ +2 9 Dec 2022 + + 77_all_Factor-out-jobserver_active_p.patch + + 78_all_lto-support-jobserver-style-fifo-for-recent-GNU-make.patch + 1 19 Nov 2022 + 76_all_configure-c89.patch