From patchwork Thu Aug 4 08:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp239918pxt; Thu, 4 Aug 2022 01:58:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR50OAmULuuswTH7IhflBHw/Nj5plrQQ2HcDyRPUH/8OQXd8P1PxCyRTE7ice+5pY08PpeMk X-Received: by 2002:a17:907:7208:b0:72f:368f:2eb4 with SMTP id dr8-20020a170907720800b0072f368f2eb4mr667611ejc.457.1659603489647; Thu, 04 Aug 2022 01:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659603489; cv=none; d=google.com; s=arc-20160816; b=ZZllRMUDB9YzVCntxlx1NWQsWhHyjarLvJaHalg6nlS25/+TBDzcQBeKIUBu/5lO0B I2xNoyya3JxmQNLC4jhyMoVCY1JmLR/mgaNuybHMOqHZNdPZ2Dm2kOttYYjeFdhORE+M aW+pBuDK1KYBBN3+ee6ooUOOCciRYm/aja1HE4fy5itQwBKBdyyvHvLM1kBfA7RMTT1p zXFjWIjzzdPmosETLlHcMKtaaSeGMNfX5azjik6Vwae8Oz5CYEZTt2VUyHwkWWLQoq/G LUrWlyJFgG7HEqdTLTqOCzQkXziSSrvnUzRWiN5sKh45+Bwt4yTCqshZ1MfdmSY22XiR Ioow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=v3ya+6uonmwHuhyDw5I4GovlC0JGsQVHTPxUEtWuyWA=; b=G+4lxsUpHn2kDQhYtPeieFJQfpYIut4C2/6JQUXSaKIUWqhKFKaJ66BtsDk/UO8kfy Q1wnUI2v7EJnjDE7pyQJiBJlXlwH04wGIGHOyNAk5j7jakTRwiYt2YgUU1yePusWj6la B6C9L/f5bPrhlwC9zljqcfEswOSZ5rc/hj5zcfwIc8fb8VtdmNFIn//9UkxGBLWnPdWB etHYSShN7HkwAzweDdZ+u/jspPi70wboj2fS5tiYFQKm67cLIWBIoU6CXsf35lI03prk V9vDhMvdjXrMufbSmrZo03JKgeIjzW06dws7p/cKsOzjRa86YHohS86PQs982GvhTbwW UNsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@suse.cz header.s=susede2_rsa header.b=fjyjCy+T; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l18-20020a056402231200b0043bc832d514si638351eda.318.2022.08.04.01.58.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 01:58:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@suse.cz header.s=susede2_rsa header.b=fjyjCy+T; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B3293857379 for ; Thu, 4 Aug 2022 08:58:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 0C2D73858C00 for ; Thu, 4 Aug 2022 08:57:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0C2D73858C00 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 656EC4E39A; Thu, 4 Aug 2022 08:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1659603458; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=v3ya+6uonmwHuhyDw5I4GovlC0JGsQVHTPxUEtWuyWA=; b=fjyjCy+TBHVTocJJacV4DX176O0+/jCXP8CnryKSVbfjqxvLFwxu+i3iaynsFFqiYdmMUN 5NvU2J9OPGP5UEWJlLIPvSvXJ4cloLNfyQ8CS4XuZW1SQxivio6Yrik9zr9zY/9zXaHR3P yWdE4F4zkcSCw3y+6NTvr0zQAekM5zA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1659603458; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=v3ya+6uonmwHuhyDw5I4GovlC0JGsQVHTPxUEtWuyWA=; b=meljvnejk5YOjvQYkeqwg2e++Af6zJfWFrYc8gL5uHtI28l7q17raQ5+WXSRakpgr2RoSN R+LDyLh5fYKD7bBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4DF201348A; Thu, 4 Aug 2022 08:57:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id h7r8EQKK62LWQAAAMHmgww (envelope-from ); Thu, 04 Aug 2022 08:57:38 +0000 Message-ID: Date: Thu, 4 Aug 2022 10:57:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] lto: support --jobserver-style=fifo for recent GNU make To: gcc-patches@gcc.gnu.org Content-Language: en-US X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Hubicka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740220388528026379?= X-GMAIL-MSGID: =?utf-8?q?1740220388528026379?= After a long time, GNU make has finally implemented named pipes when it comes to --jobserver-auth. The traditional approach are provided opened file descriptors that causes troubles: https://savannah.gnu.org/bugs/index.php?57242 GNU make commit: https://git.savannah.gnu.org/cgit/make.git/commit/?id=7ad2593b2d2bb5b9332f4444d8bf93ac6f958bc6 I tested that locally with TOT GNU make and it works: $ cat Makefile all: g++ tramp3d-v4.ii -c -flto -O2 g++ tramp3d-v4.o -flto=jobserver $ MAKE=/tmp/bin/bin/make /tmp/bin/bin/make -j16 --jobserver-style=fifo g++ tramp3d-v4.ii -c -flto -O2 g++ tramp3d-v4.o -flto=jobserver (ltrans run in parallel) Ready to be installed after tests? Martin gcc/ChangeLog: * gcc.cc (driver::detect_jobserver): Support --jobserver-style=fifo. * lto-wrapper.cc (jobserver_active_p): Likewise. --- gcc/gcc.cc | 15 ++++++++++++--- gcc/lto-wrapper.cc | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 5cbb38560b2..c98407fe03d 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -9182,15 +9182,24 @@ driver::detect_jobserver () const const char *makeflags = env.get ("MAKEFLAGS"); if (makeflags != NULL) { - const char *needle = "--jobserver-auth="; - const char *n = strstr (makeflags, needle); + /* Traditionally, GNU make uses opened pieps for jobserver-auth, + e.g. --jobserver-auth=3,4. */ + const char *pipe_needle = "--jobserver-auth="; + + /* Starting with GNU make 4.4, one can use --jobserver-style=fifo + and then named pipe is used: --jobserver-auth=fifo:/tmp/hcsparta. */ + const char *fifo_needle = "--jobserver-auth=fifo:"; + if (strstr (makeflags, fifo_needle) != NULL) + return; + + const char *n = strstr (makeflags, pipe_needle); if (n != NULL) { int rfd = -1; int wfd = -1; bool jobserver - = (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2 + = (sscanf (n + strlen (pipe_needle), "%d,%d", &rfd, &wfd) == 2 && rfd > 0 && wfd > 0 && is_valid_fd (rfd) diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc index 795ab74555c..756350d5ace 100644 --- a/gcc/lto-wrapper.cc +++ b/gcc/lto-wrapper.cc @@ -1342,27 +1342,37 @@ static const char * jobserver_active_p (void) { #define JS_PREFIX "jobserver is not available: " - #define JS_NEEDLE "--jobserver-auth=" + + /* Traditionally, GNU make uses opened pieps for jobserver-auth, + e.g. --jobserver-auth=3,4. */ + #define JS_PIPE_NEEDLE "--jobserver-auth=" + + /* Starting with GNU make 4.4, one can use --jobserver-style=fifo + and then named pipe is used: --jobserver-auth=fifo:/tmp/hcsparta. */ + #define JS_FIFO_NEEDLE "--jobserver-auth=fifo:" const char *makeflags = getenv ("MAKEFLAGS"); if (makeflags == NULL) return JS_PREFIX "% environment variable is unset"; - const char *n = strstr (makeflags, JS_NEEDLE); + if (strstr (makeflags, JS_FIFO_NEEDLE) != NULL) + return NULL; + + const char *n = strstr (makeflags, JS_PIPE_NEEDLE); if (n == NULL) - return JS_PREFIX "%<" JS_NEEDLE "%> is not present in %"; + return JS_PREFIX "%<" JS_PIPE_NEEDLE "%> is not present in %"; int rfd = -1; int wfd = -1; - if (sscanf (n + strlen (JS_NEEDLE), "%d,%d", &rfd, &wfd) == 2 + if (sscanf (n + strlen (JS_PIPE_NEEDLE), "%d,%d", &rfd, &wfd) == 2 && rfd > 0 && wfd > 0 && is_valid_fd (rfd) && is_valid_fd (wfd)) return NULL; else - return JS_PREFIX "cannot access %<" JS_NEEDLE "%> file descriptors"; + return JS_PREFIX "cannot access %<" JS_PIPE_NEEDLE "%> file descriptors"; } /* Print link to -flto documentation with a hint message. */