summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/Makefile.in3
-rw-r--r--gcc/c-pch.c97
-rw-r--r--gcc/flags.h3
-rw-r--r--gcc/toplev.c11
5 files changed, 92 insertions, 31 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a7968be400c..1e7e8362be7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -2,6 +2,15 @@
* doc/extend.texi (Empty Structures): New.
+ * c-pch.c: Include flags.h. Add comments to routines.
+ (struct c_pch_validity): New.
+ (get_ident): Update PCH file version number.
+ (pch_init): Output current debugging type.
+ (c_common_valid_pch): Check debugging type.
+ * Makefile.in (c-pch.o): Update dependencies.
+ * flags.h (debug_type_names): Declare.
+ * toplev.c (debug_type_names): Move out of decode_g_option.
+
2003-04-11 Eric Christopher <echristo@redhat.com>
* emit-rtl.c (gen_rtx): Fix typos.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 1ab232f3c3d..7f183f06cca 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1336,7 +1336,8 @@ c-dump.o : c-dump.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(C_TREE_H) tree-dump.h
c-pch.o : c-pch.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(CPPLIB_H) $(TREE_H) \
- c-common.h output.h toplev.h c-pragma.h $(GGC_H) debug.h langhooks.h
+ c-common.h output.h toplev.h c-pragma.h $(GGC_H) debug.h langhooks.h \
+ flags.h
# Language-independent files.
diff --git a/gcc/c-pch.c b/gcc/c-pch.c
index 27a299ffd3e..a7fa879fb88 100644
--- a/gcc/c-pch.c
+++ b/gcc/c-pch.c
@@ -23,6 +23,7 @@ Boston, MA 02111-1307, USA. */
#include "coretypes.h"
#include "cpplib.h"
#include "tree.h"
+#include "flags.h"
#include "c-common.h"
#include "output.h"
#include "toplev.h"
@@ -31,6 +32,11 @@ Boston, MA 02111-1307, USA. */
#include "ggc.h"
#include "langhooks.h"
+struct c_pch_validity
+{
+ unsigned char debug_info_type;
+};
+
struct c_pch_header
{
unsigned long asm_size;
@@ -45,11 +51,16 @@ static long asm_file_startpos;
static const char * get_ident PARAMS((void));
+/* Compute an appropriate 8-byte magic number for the PCH file, so that
+ utilities like file(1) can identify it, and so that GCC can quickly
+ ignore non-PCH files and PCH files that are of a completely different
+ format. */
+
static const char *
get_ident()
{
static char result[IDENT_LENGTH];
- static const char template[IDENT_LENGTH] = "gpch.010";
+ static const char template[IDENT_LENGTH] = "gpch.011";
memcpy (result, template, IDENT_LENGTH);
if (c_language == clk_c)
@@ -61,36 +72,45 @@ get_ident()
return result;
}
+/* Prepare to write a PCH file. This is called at the start of
+ compilation. */
+
void
pch_init ()
{
FILE *f;
+ struct c_pch_validity v;
- if (pch_file)
- {
- f = fopen (pch_file, "w+b");
- if (f == NULL)
- fatal_io_error ("can't open %s", pch_file);
- pch_outfile = f;
-
- if (fwrite (get_ident(), IDENT_LENGTH, 1, f) != 1)
- fatal_io_error ("can't write to %s", pch_file);
-
- /* We need to be able to re-read the output. */
- /* The driver always provides a valid -o option. */
- if (asm_file_name == NULL
- || strcmp (asm_file_name, "-") == 0)
- fatal_error ("`%s' is not a valid output file", asm_file_name);
-
- asm_file_startpos = ftell (asm_out_file);
-
- /* Let the debugging format deal with the PCHness. */
- (*debug_hooks->handle_pch) (0);
-
- cpp_save_state (parse_in, f);
- }
+ if (! pch_file)
+ return;
+
+ f = fopen (pch_file, "w+b");
+ if (f == NULL)
+ fatal_io_error ("can't open %s", pch_file);
+ pch_outfile = f;
+
+ v.debug_info_type = write_symbols;
+ if (fwrite (get_ident(), IDENT_LENGTH, 1, f) != 1
+ || fwrite (&v, sizeof (v), 1, f) != 1)
+ fatal_io_error ("can't write to %s", pch_file);
+
+ /* We need to be able to re-read the output. */
+ /* The driver always provides a valid -o option. */
+ if (asm_file_name == NULL
+ || strcmp (asm_file_name, "-") == 0)
+ fatal_error ("`%s' is not a valid output file", asm_file_name);
+
+ asm_file_startpos = ftell (asm_out_file);
+
+ /* Let the debugging format deal with the PCHness. */
+ (*debug_hooks->handle_pch) (0);
+
+ cpp_save_state (parse_in, f);
}
+/* Write the PCH file. This is called at the end of a compilation which
+ will produce a PCH file. */
+
void
c_common_write_pch ()
{
@@ -134,6 +154,9 @@ c_common_write_pch ()
fclose (pch_outfile);
}
+/* Check the PCH file called NAME, open on FD, to see if it can be used
+ in this compilation. */
+
int
c_common_valid_pch (pfile, name, fd)
cpp_reader *pfile;
@@ -144,12 +167,13 @@ c_common_valid_pch (pfile, name, fd)
int result;
char ident[IDENT_LENGTH];
const char *pch_ident;
+ struct c_pch_validity v;
if (! allow_pch)
return 2;
/* Perform a quick test of whether this is a valid
- precompiled header for C. */
+ precompiled header for the current language. */
sizeread = read (fd, ident, IDENT_LENGTH);
if (sizeread == -1)
@@ -181,6 +205,26 @@ c_common_valid_pch (pfile, name, fd)
return 2;
}
+ if (read (fd, &v, sizeof (v)) != sizeof (v))
+ {
+ fatal_io_error ("can't read %s", name);
+ 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, 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 the preprocessor macros are the same as when the PCH was
generated. */
@@ -191,6 +235,9 @@ c_common_valid_pch (pfile, name, fd)
return result == 0;
}
+/* Load in the PCH file NAME, open on FD. It was originally searched for
+ by ORIG_NAME. */
+
void
c_common_read_pch (pfile, name, fd, orig_name)
cpp_reader *pfile;
diff --git a/gcc/flags.h b/gcc/flags.h
index 88ed465e010..1ca9de2f196 100644
--- a/gcc/flags.h
+++ b/gcc/flags.h
@@ -41,6 +41,9 @@ enum debug_info_type
/* Specify which kind of debugging info to generate. */
extern enum debug_info_type write_symbols;
+/* Names of debug_info_type, for error messages. */
+extern const char *const debug_type_names[];
+
enum debug_info_level
{
DINFO_LEVEL_NONE, /* Write no debugging info. */
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 1be5202344a..25a6905095a 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -4268,6 +4268,12 @@ decode_W_option (arg)
return 1;
}
+/* Indexed by enum debug_info_type. */
+const char *const debug_type_names[] =
+{
+ "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
+};
+
/* Parse a -g... command line switch. ARG is the value after the -g.
It is safe to access 'ARG - 2' to generate the full switch name.
Return the number of strings consumed. */
@@ -4287,11 +4293,6 @@ decode_g_option (arg)
-g and -ggdb don't explicitly set the debugging format so
-gdwarf -g3 is equivalent to -gdwarf3. */
static int type_explicitly_set_p = 0;
- /* Indexed by enum debug_info_type. */
- static const char *const debug_type_names[] =
- {
- "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
- };
/* The maximum admissible debug level value. */
static const unsigned max_debug_level = 3;