From patchwork Tue Aug 6 12:04:54 2019 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: 1142751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506312-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Mguls8ux"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 462tcN04Syz9s7T for ; Tue, 6 Aug 2019 22:05:06 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=WLjCCAf1kus3hM9yMV8BCzZlCVzm5wTIJg1bVkInl6aYCoe8l8 T8c+2Kz3LPb+5qsv2mc3ds1xxa5Z3vlolbQ9+spYztWicFLqc5kKM2AbmGkd/azJ 4knpsicz0Cp82toXLq1wK1jJpNfqP+W4P8fnhIwx6D0JIIbljP9lLutM0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=r97kby1ZtL//mKspsk2tGbVhpS4=; b=Mguls8uxFxXHKiosFXjO ksYBlKmrHMNxYFsPhLazPuKlQeG/OcPDkTVZ9YJa6bkCkhFkaBtFKHyUUk4TMnxc +QjEeAvZPoxt2JbMpCiv5osHxtALVoHDyucohR8hl8jUb5t+0awwxt7S1XTWmR57 1yN6rjZMTB7XYDI+GdIjPKs= Received: (qmail 63121 invoked by alias); 6 Aug 2019 12:04:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 62316 invoked by uid 89); 6 Aug 2019 12:04:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=H*Ad:D*fi, needle, F_GETFD, jobserver X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Aug 2019 12:04:56 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8F0FFABE3; Tue, 6 Aug 2019 12:04:54 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Fix file descriptor existence of MinGW. To: gcc-patches@gcc.gnu.org Cc: pexu@gcc-bugzilla.mail.kapsi.fi Message-ID: <03e5f4cf-7955-76fc-f94e-11695857f0f1@suse.cz> Date: Tue, 6 Aug 2019 14:04:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi. The patch is about proper checking of file descriptors on Windows. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. @Pekka: Can you please test it on Windows? Ready to be installed? Thanks, Martin gcc/ChangeLog: 2019-08-06 Martin Liska PR bootstrap/91352 * gcc.c (fd_exists): New. (driver::detect_jobserver): Use fd_exists. * lto-wrapper.c (fd_exists): New. (jobserver_active_p): Use fd_exists. --- gcc/gcc.c | 19 +++++++++++++++++-- gcc/lto-wrapper.c | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/gcc/gcc.c b/gcc/gcc.c index 18a07426290..6bcd989ee30 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -8359,6 +8359,21 @@ driver::final_actions () const } } +/* Return true when FD file descriptor exists. */ + +static bool +fd_exists (int fd) +{ +#if defined (F_GETFD) + return fcntl (fd, F_GETFD) >= 0; +#elif defined(_WIN32) + HANDLE h = (HANDLE) _get_osfhandle (fd); + return h != (HANDLE) -1; +#else + return false; +#endif +} + /* Detect whether jobserver is active and working. If not drop --jobserver-auth from MAKEFLAGS. */ @@ -8380,8 +8395,8 @@ driver::detect_jobserver () const = (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2 && rfd > 0 && wfd > 0 - && fcntl (rfd, F_GETFD) >= 0 - && fcntl (wfd, F_GETFD) >= 0); + && fd_exists (rfd) + && fd_exists (wfd)); /* Drop the jobserver if it's not working now. */ if (!jobserver) diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c index 3414adedd26..065a1d0ad02 100644 --- a/gcc/lto-wrapper.c +++ b/gcc/lto-wrapper.c @@ -1217,6 +1217,21 @@ init_num_threads (void) /* FIXME: once using -std=c11, we can use std::thread::hardware_concurrency. */ +/* Return true when FD file descriptor exists. */ + +static bool +fd_exists (int fd) +{ +#if defined (F_GETFD) + return fcntl (fd, F_GETFD) >= 0; +#elif defined(_WIN32) + HANDLE h = (HANDLE) _get_osfhandle (fd); + return h != (HANDLE) -1; +#else + return false; +#endif +} + /* Return true when a jobserver is running and can accept a job. */ static bool @@ -1237,8 +1252,8 @@ jobserver_active_p (void) return (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2 && rfd > 0 && wfd > 0 - && fcntl (rfd, F_GETFD) >= 0 - && fcntl (wfd, F_GETFD) >= 0); + && fd_exists (rfd) + && fd_exists (wfd)); } /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */