+ /* At this point, we know it's a PCH file, so it ought to be long enough
+ that we can read a c_pch_validity structure. */
+ if (read (fd, &v, sizeof (v)) != sizeof (v))
+ fatal_error ("can't read %s: %m", name);
+
+ strings_length = (v.host_machine_length + v.target_machine_length
+ + v.version_length);
+ if (read (fd, short_strings, strings_length) != strings_length)
+ fatal_error ("can't read %s: %m", name);
+ if (v.host_machine_length != strlen (host_machine)
+ || memcmp (host_machine, short_strings, strlen (host_machine)) != 0)
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING,
+ "%s: created on host `%.*s', but used on host `%s'", name,
+ v.host_machine_length, short_strings, host_machine);
+ return 2;
+ }
+ if (v.target_machine_length != strlen (target_machine)
+ || memcmp (target_machine, short_strings + v.host_machine_length,
+ strlen (target_machine)) != 0)
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING,
+ "%s: created for target `%.*s', but used for target `%s'",
+ name, v.target_machine_length,
+ short_strings + v.host_machine_length, target_machine);
+ return 2;
+ }
+ if (v.version_length != strlen (version_string)
+ || memcmp (version_string,
+ (short_strings + v.host_machine_length
+ + v.target_machine_length),
+ v.version_length) != 0)
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING,
+ "%s: created by version `%.*s', but this is version `%s'",
+ name, v.version_length,
+ (short_strings + v.host_machine_length
+ + v.target_machine_length),
+ version_string);
+ return 2;
+ }
+
+ /* The allowable debug info combinations are that either the PCH file
+ was built with the same as is being used now, or the PCH file was
+ built for some kind of debug info but now none is in use. */
+ if (v.debug_info_type != write_symbols
+ && write_symbols != NO_DEBUG)
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING,
+ "%s: created with -g%s, but used with -g%s", name,
+ debug_type_names[v.debug_info_type],
+ debug_type_names[write_symbols]);
+ 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
+ pointers, but no support for that exists at present. */
+ if (v.pch_init != &pch_init)
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING,
+ "%s: had text segment at different address", name);
+ return 2;
+ }
+
+ /* Check the target-specific validity data. */
+ {
+ void *this_file_data = xmalloc (v.target_data_length);
+ const char *msg;
+
+ if ((size_t) read (fd, this_file_data, v.target_data_length)
+ != v.target_data_length)
+ fatal_error ("can't read %s: %m", name);
+ msg = targetm.pch_valid_p (this_file_data, v.target_data_length);
+ free (this_file_data);
+ if (msg != NULL)
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING, "%s: %s", name, msg);
+ return 2;
+ }
+ }
+