From patchwork Thu Nov 4 20:02:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 47070 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3AA4385803D for ; Thu, 4 Nov 2021 20:03:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3AA4385803D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636056235; bh=XC4wTifYrVzbvASBS5Lt8OKvLzLtlzY3Ib/knlsVAbc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=nUtWzJTbdyK+CFVzx9ZHsSt+FQnSh1nMZqC4YvfRprb0CXYOzmw+6iC09DjgfdqpT 68LphTCMPl5r0m+rBC6mHWhUljsz7iErL0nxRQMorNA2xHCkY73jIZjpfVV2pmERFZ HU3NOPiSdYBd6B62G3ejT1PEFo8lmH7TMdU20fPw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 92B7D385803B for ; Thu, 4 Nov 2021 20:02:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 92B7D385803B Received: by mail-wm1-x32a.google.com with SMTP id y84-20020a1c7d57000000b00330cb84834fso8084740wmc.2 for ; Thu, 04 Nov 2021 13:02:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=XC4wTifYrVzbvASBS5Lt8OKvLzLtlzY3Ib/knlsVAbc=; b=fe9CXr/Z4wiVLUw6BfJrjBSFIIYvjg3BLe3Xt3IxBSjtbaQJfIv+s2rcM6s0cekeQi Atms4PB+DodOlIhi+QSGcY7wA7NMGPzDYCjvGAI4hcr/CLoRE+vtnRTYA+HXhldBUJPD iroByXtiJlKXfHKwhDcXLyhA5+5D8s+YXWwjYuVXJLoGAm59gi4qqNf5khkHVxyLI1jx fDzXI5exBAoFyIOFkhefSy/IrWmIEQWigdOz+5h2JWbkF4OC3kDNOQsJwgKvAkFP5aSl gXUPvBw8SWPWiKROdaHTNfKqkUlpt1HXGYvVZqaWt2huNkQZC6VbL3JSCdc52safnyFq SGew== X-Gm-Message-State: AOAM532zmQAn6CrZs3Pb1iGssuOPuUbQpIJcQXAiO0bJltP1M1cRom0H QPXYqgwDcJQ7lHZkCytxk9MN50iLm/c= X-Google-Smtp-Source: ABdhPJwtillm549a8F+7z16J4FvhrNvaaiKlT2Tl5cwXayRYtlCOeGUGI2OriuL/b4tyiInz2m2Lnw== X-Received: by 2002:a1c:3504:: with SMTP id c4mr25257475wma.160.1636056146621; Thu, 04 Nov 2021 13:02:26 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id k27sm6650629wms.41.2021.11.04.13.02.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Nov 2021 13:02:26 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH 4/4] c-family, gcc: Allow configuring without support for PCH. Date: Thu, 4 Nov 2021 20:02:18 +0000 Message-Id: <20211104200218.24159-5-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211104200218.24159-4-iain@sandoe.co.uk> References: <20211104200218.24159-1-iain@sandoe.co.uk> <20211104200218.24159-2-iain@sandoe.co.uk> <20211104200218.24159-3-iain@sandoe.co.uk> <20211104200218.24159-4-iain@sandoe.co.uk> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Some hosts cannot (or do not wish to) support PCH with the current constraint that the executables must disable ASLR. This allows the configuration to disable support for PCH while still accepting the command lines (to avoid existing build recipes failing). Signed-off-by: Iain Sandoe gcc/c-family/ChangeLog: * c-pch.c (pch_cpp_save_state): Skip output if PCH is disabled. (c_common_write_pch): Likewise. (c_common_pch_pragma): Replace with a dummy routine that emits a diagnostic if we encounter a PCH pragma. gcc/ChangeLog: * config.in: Regenerate. * config/host-darwin.c (darwin_gt_pch_get_address, darwin_gt_pch_use_address): Dummy routines for the case that PCH is disabled (this avoids allocating and freeing the memory that would be used). * configure: Regenerate. * configure.ac: Act on the host PCH configure option. --- gcc/c-family/c-pch.c | 23 ++++++++++++++++++++++- gcc/config.in | 6 ++++++ gcc/config/host-darwin.c | 18 ++++++++++++++++++ gcc/configure | 29 +++++++++++++++++++++++++++-- gcc/configure.ac | 17 +++++++++++++++++ 5 files changed, 90 insertions(+), 3 deletions(-) diff --git a/gcc/c-family/c-pch.c b/gcc/c-family/c-pch.c index 5da60423354..84bd8b8e0fc 100644 --- a/gcc/c-family/c-pch.c +++ b/gcc/c-family/c-pch.c @@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. If not see #include "c-pragma.h" #include "langhooks.h" #include "hosthooks.h" +#include "diagnostic.h" /* This is a list of flag variables that must match exactly, and their names for the error message. The possible values for *flag_var must @@ -148,12 +149,14 @@ pch_cpp_save_state (void) { if (!pch_cpp_state_saved) { +#if ENABLE_HOST_PCH_SUPPORT if (pch_outfile) { cpp_save_state (parse_in, pch_outfile); pch_cpp_state_saved = true; } else +#endif pch_ready_to_save_cpp_state = true; } } @@ -172,6 +175,7 @@ c_common_write_pch (void) prepare_target_option_nodes_for_pch (); +#if ENABLE_HOST_PCH_SUPPORT cpp_write_pch_deps (parse_in, pch_outfile); gt_pch_save (pch_outfile); @@ -183,6 +187,10 @@ c_common_write_pch (void) if (fseek (pch_outfile, 0, SEEK_SET) != 0 || fwrite (get_ident (), IDENT_LENGTH, 1, pch_outfile) != 1) fatal_error (input_location, "cannot write %s: %m", pch_file); +#else + warning_at (input_location, 0, + "precompiled headers are not supported by this compiler"); +#endif fclose (pch_outfile); @@ -394,6 +402,7 @@ c_common_no_more_pch (void) } } +#if ENABLE_HOST_PCH_SUPPORT /* Handle #pragma GCC pch_preprocess, to load in the PCH file. */ void @@ -424,4 +433,16 @@ c_common_pch_pragma (cpp_reader *pfile, const char *name) close (fd); } - +#else +void +c_common_pch_pragma (cpp_reader *, const char *) +{ + /* We have encountered a PCH pragma, which presumably means that the user + has managed to emit a preprocessed file with a compiler supporting PCH + and is now trying to compile that on one without such support. It is + not going to work and not clear how we could recover sensibly - so best + not to allow it. */ + fatal_error (input_location, + "precompiled headers are not supported by this compiler"); +} +#endif diff --git a/gcc/config.in b/gcc/config.in index b5bec3971dc..0a3baab882e 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -193,6 +193,12 @@ #endif +/* Define this to enable support for precompiled header (c-family). */ +#ifndef USED_FOR_TARGET +#undef ENABLE_HOST_PCH_SUPPORT +#endif + + /* Define if gcc should always pass --build-id to linker. */ #ifndef USED_FOR_TARGET #undef ENABLE_LD_BUILDID diff --git a/gcc/config/host-darwin.c b/gcc/config/host-darwin.c index 14a01fe71f2..828d5763d8c 100644 --- a/gcc/config/host-darwin.c +++ b/gcc/config/host-darwin.c @@ -23,6 +23,7 @@ #include "diagnostic-core.h" #include "config/host-darwin.h" +#if ENABLE_HOST_PCH_SUPPORT /* Yes, this is really supposed to work. */ /* This allows for a pagesize of 16384, which we have on Darwin20, but should continue to work OK for pagesize 4096 which we have on earlier versions. @@ -79,3 +80,20 @@ darwin_gt_pch_use_address (void *addr, size_t sz, int fd, size_t off) return ret; } + +#else + +/* Dummy versions of the hooks that do nothing on Darwin versions without + PCH support, we also omit the allocation of the memory. */ +void * +darwin_gt_pch_get_address (size_t, int) +{ + return NULL; +} + +int +darwin_gt_pch_use_address (void *, size_t, int, size_t) +{ + return 0; +} +#endif diff --git a/gcc/configure b/gcc/configure index 920868bcd33..3a87dc8a687 100755 --- a/gcc/configure +++ b/gcc/configure @@ -818,6 +818,7 @@ LN LN_S AWK SET_MAKE +host_pch_support omp_device_property_deps omp_device_properties accel_dir_suffix @@ -976,6 +977,7 @@ with_changes_root_url enable_languages with_multilib_list with_multilib_generator +enable_host_pch_support with_zstd with_zstd_include with_zstd_lib @@ -1704,6 +1706,8 @@ Optional Features: --disable-shared don't provide a shared libgcc --disable-gcov don't provide libgcov and related host tools --enable-languages=LIST specify which front-ends to build + --disable-host-pch-support + Disable host support for precompiled headers --disable-rpath do not hardcode runtime library paths --enable-sjlj-exceptions arrange to use setjmp/longjmp exception handling @@ -8112,6 +8116,27 @@ else fi +# The current default is that PCH is supported by the host unless otherwise +# stated. +# Check whether --enable-host_pch_support was given. +if test "${enable_host_pch_support+set}" = set; then : + enableval=$enable_host_pch_support; host_pch_support=$enableval +else + host_pch_support=yes +fi + + + +if test x"$host_pch_support" != xno; then + +$as_echo "#define ENABLE_HOST_PCH_SUPPORT 1" >>confdefs.h + +else + $as_echo "#define ENABLE_HOST_PCH_SUPPORT 0" >>confdefs.h + +fi + + # ------------------------- # Checks for other programs # ------------------------- @@ -19455,7 +19480,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19458 "configure" +#line 19483 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -19561,7 +19586,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19564 "configure" +#line 19589 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index 065080a4b39..689abf03389 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1178,6 +1178,23 @@ AC_ARG_WITH(multilib-generator, :, with_multilib_generator=default) +# The current default is that PCH is supported by the host unless otherwise +# stated. +AC_ARG_ENABLE(host_pch_support, +AS_HELP_STRING([--disable-host-pch-support], + [Disable host support for precompiled headers]), +host_pch_support=$enableval, +host_pch_support=yes) +AC_SUBST(host_pch_support) + +if test x"$host_pch_support" != xno; then + AC_DEFINE(ENABLE_HOST_PCH_SUPPORT, 1, + [Define this to enable support for precompiled header (c-family).]) +else + AC_DEFINE(ENABLE_HOST_PCH_SUPPORT, 0) +fi + + # ------------------------- # Checks for other programs # -------------------------