#include "hosthooks.h"
#include "target.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
+ fit in a 'signed char'. */
+
+static const struct c_pch_matching
+{
+ int *flag_var;
+ const char *flag_name;
+} pch_matching[] = {
+ { &flag_exceptions, "-fexceptions" },
+ { &flag_unit_at_a_time, "-funit-at-a-time" }
+};
+
+enum {
+ MATCH_SIZE = ARRAY_SIZE (pch_matching)
+};
+
/* This structure is read very early when validating the PCH, and
might be read for a PCH which is for a completely different compiler
for a different operating system. Thus, it should really only contain
unsigned char target_machine_length;
unsigned char version_length;
unsigned char debug_info_type;
+ signed char match[MATCH_SIZE];
void (*pch_init) (void);
size_t target_data_length;
};
v.target_machine_length = strlen (target_machine);
v.version_length = strlen (version_string);
v.debug_info_type = write_symbols;
+ {
+ size_t i;
+ for (i = 0; i < MATCH_SIZE; i++)
+ {
+ v.match[i] = *pch_matching[i].flag_var;
+ if (v.match[i] != *pch_matching[i].flag_var)
+ abort ();
+ }
+ }
v.pch_init = &pch_init;
target_validity = targetm.get_pch_validity (&v.target_data_length);
return 2;
}
+ /* Check flags that must match exactly. */
+ {
+ size_t i;
+ for (i = 0; i < MATCH_SIZE; i++)
+ if (*pch_matching[i].flag_var != v.match[i])
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING,
+ "%s: settings for %s do not match", name,
+ pch_matching[i].flag_name);
+ return 2;
+ }
+ }
+
/* If the text segment was not loaded at the same address as it was
when the PCH file was created, function pointers loaded from the
PCH will not be valid. We could in theory remap all the function
If you need to precompile the same header file for different
languages, targets, or compiler options, you can instead make a
@emph{directory} named like @file{all.h.gch}, and put each precompiled
-header in the directory. (It doesn't matter what you call the files
-in the directory, every precompiled header in the directory will be
-considered.) The first precompiled header encountered in the
-directory that is valid for this compilation will be used; they're
-searched in no particular order.
+header in the directory, perhaps using @option{-o}. It doesn't matter
+what you call the files in the directory, every precompiled header in
+the directory will be considered. The first precompiled header
+encountered in the directory that is valid for this compilation will
+be used; they're searched in no particular order.
There are many other possibilities, limited only by your imagination,
good sense, and the constraints of your build system.
@itemize
@item
Only one precompiled header can be used in a particular compilation.
+
@item
A precompiled header can't be used once the first C token is seen. You
can have preprocessor directives before a precompiled header; you can
even include a precompiled header from inside another header, so long as
there are no C tokens before the @code{#include}.
+
@item
The precompiled header file must be produced for the same language as
the current compilation. You can't use a C precompiled header for a C++
compilation.
+
@item
The precompiled header file must be produced by the same compiler
version and configuration as the current compilation is using.
The easiest way to guarantee this is to use the same compiler binary
for creating and using precompiled headers.
+
@item
-Any macros defined before the precompiled header (including with
-@option{-D}) must either be defined in the same way as when the
-precompiled header was generated, or must not affect the precompiled
-header, which usually means that the they don't appear in the
-precompiled header at all.
+Any macros defined before the precompiled header is included must
+either be defined in the same way as when the precompiled header was
+generated, or must not affect the precompiled header, which usually
+means that the they don't appear in the precompiled header at all.
+
+The @option{-D} option is one way to define a macro before a
+precompiled header is included; using a @code{#define} can also do it.
+There are also some options that define macros implicitly, like
+@option{-O} and @option{-Wdeprecated}; the same rule applies to macros
+defined this way.
+
+@item If debugging information is output when using the precompiled
+header, using @option{-g} or similar, the same kind of debugging information
+must have been output when building the precompiled header. However,
+a precompiled header built using @option{-g} can be used in a compilation
+when no debugging information is being output.
+
+@item The same @option{-m} options must generally be used when building
+and using the precompiled header. @xref{Submodel Options},
+for any cases where this rule is relaxed.
+
+@item Each of the following options must be the same when building and using
+the precompiled header:
+
+@gccoptlist{-fexceptions -funit-at-a-time}
+
@item
-Certain command-line options must be defined in the same way as when the
-precompiled header was generated. At present, it's not clear which
-options are safe to change and which are not; the safest choice is to
-use exactly the same options when generating and using the precompiled
-header.
+Some other command-line options starting with @option{-f},
+@option{-p}, or @option{-O} must be defined in the same way as when
+the precompiled header was generated. At present, it's not clear
+which options are safe to change and which are not; the safest choice
+is to use exactly the same options when generating and using the
+precompiled header. The following are known to be safe:
+
+@gccoptlist{-pedantic-errors}
+
@end itemize
-For all of these but the last, the compiler will automatically ignore
-the precompiled header if the conditions aren't met. For the last item,
-some option changes will cause the precompiled header to be rejected,
-but not all incompatible option combinations have yet been found. If
-you find a new incompatible combination, please consider filing a bug
-report, see @ref{Bugs}.
+For all of these except the last, the compiler will automatically
+ignore the precompiled header if the conditions aren't met. If you
+find an option combination that doesn't work and doesn't cause the
+precompiled header to be ignored, please consider filing a bug report,
+see @ref{Bugs}.
@node Running Protoize
@section Running Protoize