From patchwork Thu Jan 3 10:54:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Pfau X-Patchwork-Id: 1020247 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-493321-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CK/w4OkN"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QziibMsR"; 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 43VlDs6TyYz9s9G for ; Thu, 3 Jan 2019 21:55:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=KtHzJp3v6LywadLF YSH5HHmPLdK409X1tHWH5HX0RThzJLZkcA99GFXjidMs3Q5KPSqD6RH3eQ+1tpgt h6cp4W0s0/mS6i51uRzeRLB7G9XVkZiaTt2+5ygpHFePfqep7b2i39Qx1D4ad5qZ hh/i1JVmrUXNTd5JaaQsxAZTVpY= 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 :to:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=r17ETmqVy97xPGa43nm+oE FMJa8=; b=CK/w4OkNGsSnaJ0/wLH6sdTqiUrG2Zubc8ZKfqkge2zVfv2oHWAXJa wB3KJyeKvHNG7Zl5qcXzui9ST0XXq3HsgzH01Ifg1YlE7Jc8Tacn2gOcsW340/in QvO2ubhOdcWPp5P/w6WBMbEfBLiP9WIIiTp6ySR31wxH61W2z32SY= Received: (qmail 58308 invoked by alias); 3 Jan 2019 10:55:01 -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 58284 invoked by uid 89); 3 Jan 2019 10:55:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mail-wm1-f68.google.com Received: from mail-wm1-f68.google.com (HELO mail-wm1-f68.google.com) (209.85.128.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Jan 2019 10:54:58 +0000 Received: by mail-wm1-f68.google.com with SMTP id p6so29888856wmc.1 for ; Thu, 03 Jan 2019 02:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=9ZS7Y00zBBnUvDDeZLKv95NGwJz5xlry9MowCCpbfvQ=; b=QziibMsRnH4gbm6pUrVoW93dUH5Ml/6vxein+Sfhv4LXjRU4rzBgQ76JhjfRGoV9W9 dMNNYqYdSBtqW6weSBtZsX4+On4iblOFvDHtn9iTEK5XXSadfb60DFQkpOlbEB1wTISB BDVAY5E1RR/MXtDSQ1nOTEDOYVqzxWlpZg+SnlD2sDxtOUpLdF4OXtnBoR0tzwDleTYq itK5D/kPBXgcw6A8jV4fpNlN3hioLcUL6r3D7h0rQ1sGRNhybL/DC7MZOmOvyDkRbQ0Z LyHhE40ZUq2QIxxBvs6jwVnI+BPfh/mf49wMSwu6FBe/bk5Fc8mEdPBZtdd9CDqYdYee 71kw== Received: from jp-laptop.mbh.lan ([91.137.122.112]) by smtp.gmail.com with ESMTPSA id k3sm73479368wrm.7.2019.01.03.02.54.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jan 2019 02:54:54 -0800 (PST) From: Johannes Pfau To: gcc-patches@gcc.gnu.org Subject: [RFC/PATCH] gcc.c: access does not work in new msvcr for nul file Date: Thu, 3 Jan 2019 11:54:53 +0100 Message-Id: <20190103105453.6105-1-johannespfau@gmail.com> MIME-Version: 1.0 X-IsSubscribed: yes Hello list, I'm currently adding D support to the MinGW targets. As the libphobos upstream only targets newer msvcr runtime libraries, I tried building GCC against libmsvcr120. When doing that, the build fails when building s-selftest-c++: /home/jpfau/mingw-gcc-trunk/x86_64-trunk-win32-seh-rt_v6/build/gcc-trunk/./gcc/xgcc \ -B/home/jpfau/mingw-gcc-trunk/x86_64-trunk-win32-seh-rt_v6/build/gcc-trunk/./gcc/ \ -xc++ -nostdinc nul -S -o nul -fself-test=../../../../src/gcc-trunk/gcc/testsuite/selftests xgcc.exe: error: nul: Invalid argument xgcc.exe: warning: '-x c' after last input file has no effect xgcc.exe: fatal error: no input files compilation terminated. make[2]: *** [../../../../src/gcc-trunk/gcc/cp/Make-lang.in:178: s-selftest-c++] Error 1 Debugging shows that the access function used to check if the input files exist has different behavior in newer msvcr libraries: It does return proper results for the 'nul' file in the old msvcrt.dll but in newer libraries it returns EINVAL for the nul file. I can think of at least two possible solutions: 1) Manually strcmp the input to find nul files. As far as I know there are many paths which count as nul files on windows, so it might be difficult to actually properly support all valid paths. 2) Use the windows API to check if the file exists. A RFC patch for 2) is attached. I guess we don't want such platform specific code in GCC, so any recommendation how to proceed? Should this be placed in libiberty as a generic int file_exists(const char *path, **error) instead? Best regards, Johannes --- gcc/gcc.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/gcc/gcc.c b/gcc/gcc.c index 955a08cc8e8..674313facf1 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -45,6 +45,10 @@ compilation is specified by a string called a "spec". */ #include "filenames.h" #include "spellcheck.h" +#ifdef _WIN32 +#include +#endif + /* Manage the manipulation of env vars. @@ -4552,12 +4556,26 @@ process_command (unsigned int decoded_options_count, else fname = xstrdup (arg); - if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) +#ifdef _WIN32 + // _access does not work for the nul file on newer msvc versions + if (strcmp (fname, "-") != 0 && GetFileAttributes(fname) == INVALID_FILE_ATTRIBUTES) + { + bool resp = fname[0] == '@' + && GetFileAttributes(fname + 1) == INVALID_FILE_ATTRIBUTES; + + char error_msg[256] = "\0"; + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, + (LPSTR)&error_msg, 256, NULL); + error ("%s: %s", fname + resp, error_msg); + } +#else + if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) { bool resp = fname[0] == '@' && access (fname + 1, F_OK) < 0; error ("%s: %m", fname + resp); } - else +#endif + else add_infile (arg, spec_lang); free (fname);