@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
# -------------------------
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 <iain@sandoe.co.uk> 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(-)