This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
-save-temps still produces different .s and .o
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, per at bothner dot com
- Date: 14 Jan 2004 02:06:44 -0200
- Subject: -save-temps still produces different .s and .o
- Organization: GCC Team, Red Hat
It turns out that -fworking-directory was totally disabled with a
patch that Per Bothner installed on Oct 1. I'd noticed make bootstrap
with distcc stopped working, but only today have I been able to
investigate why.
It turns out that we no longer see the main input filename early
enough when compiling a file that was already preprocessed, so debug
info produced by the compiler points to the wrong filename and, worse,
the current directory simply doesn't make it to the preprocessed file
any longer. Also, since the initial printing of the main input
filename and working directory are no longer there, we just lose the
ability to recover them, and the code in there that attempts to do
that is totally useless.
This patch reverts some of the changes and makes re-preprocessing with
-E -fpreprocessed a file generated with -E -fworking-directory an
operation that outputs its input, as designed.
Unfortunately, this still isn't enough to get identical assembly
output for the -save-temps case: we now output an initial `.file'
directive with the name of the preprocessed file, instead of with the
name of the main input file recovered from it, and then the assembler
generates a different object file. Ugh.
The only way I see to fix this problem is to arrange for all front
ends to call the init code from within their parse code, after they
find out the real main_input_filename. I.e., lang_dependent_init(),
init_final() and coverage_init() would no longer be called in toplev.c
before lang_hooks.compile_file, but rather within their code. Would
such a change be acceptable?
Meanwhile, here's the patch that restores at least identical debug
info with and without -save-temps. Per, does any of this conflict
with your needs? I'm asking before running a full regression test on
the patch, so this is not an `ok to install?' yet, but I surely
wouldn't mind early reviews. Thanks,
? gcc/TAGS.sub
Index: gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* cpphash.h (struct cpp_reader): Replace main_file with
main_file_name.
* cpplib.h (cpp_find_main_file): Return filename.
(cpp_rename_to_main_file): Renamed from cpp_push_main_file.
* cppfiles.c (search_path_head): Adjust.
* c-opts.c (finish_options): Set main_input_filename. Don't
LC_ENTER into <built-in>.
(push_command_line_include): Don't LC_LEAVE to get back to the
main map.
* cppinit.c (cpp_find_main_file): Adjust. Restore printing of
current directory, and early-enough printing of main file name.
Return main file name.
(cpp_rename_to_main_file): Renamed from cpp_push_main_file. Just
LC_RENAME to the main file name.
* fix-header.c (read_scan_file): Adjust.
Index: gcc/c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.96
diff -u -p -r1.96 c-opts.c
--- gcc/c-opts.c 22 Dec 2003 23:57:03 -0000 1.96
+++ gcc/c-opts.c 14 Jan 2004 03:56:26 -0000
@@ -1,5 +1,5 @@
/* C/ObjC/C++ command line option handling.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Neil Booth.
This file is part of GCC.
@@ -1382,14 +1382,16 @@ static bool
finish_options (const char *tif)
{
this_input_filename = tif;
- if (! cpp_find_main_file (parse_in, this_input_filename))
+ if (! (tif = cpp_find_main_file (parse_in, this_input_filename)))
return false;
+ main_input_filename = tif;
+
if (!cpp_opts->preprocessed)
{
size_t i;
- cpp_change_file (parse_in, LC_ENTER, _("<built-in>"));
+ cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
cpp_init_builtins (parse_in, flag_hosted);
c_cpp_builtins (parse_in);
@@ -1458,12 +1460,9 @@ push_command_line_include (void)
if (include_cursor == deferred_count)
{
include_cursor++;
- /* Restore the line map from <command line>. */
- if (! cpp_opts->preprocessed)
- cpp_change_file (parse_in, LC_LEAVE, NULL);
/* -Wunused-macros should only warn about macros defined hereafter. */
cpp_opts->warn_unused_macros = warn_unused_macros;
- cpp_push_main_file (parse_in);
+ cpp_rename_to_main_file (parse_in);
}
}
Index: gcc/cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.198
diff -u -p -r1.198 cppfiles.c
--- gcc/cppfiles.c 31 Dec 2003 05:11:44 -0000 1.198
+++ gcc/cppfiles.c 14 Jan 2004 03:56:27 -0000
@@ -1,6 +1,6 @@
/* Part of CPP library. File handling.
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998,
- 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -679,8 +679,7 @@ search_path_head (cpp_reader *pfile, con
if (IS_ABSOLUTE_PATH (fname))
return &pfile->no_search_path;
- /* pfile->buffer is NULL when processing an -include command-line flag. */
- file = pfile->buffer == NULL ? pfile->main_file : pfile->buffer->file;
+ file = pfile->buffer->file;
/* For #include_next, skip in the search path past the dir in which
the current file was found, but if it was found via an absolute
Index: gcc/cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.203
diff -u -p -r1.203 cpphash.h
--- gcc/cpphash.h 3 Dec 2003 16:48:17 -0000 1.203
+++ gcc/cpphash.h 14 Jan 2004 03:56:27 -0000
@@ -1,5 +1,5 @@
/* Part of CPP library.
- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -357,7 +357,8 @@ struct cpp_reader
/* Chain of all hashed _cpp_file instances. */
struct _cpp_file *all_files;
- struct _cpp_file *main_file;
+ /* Name of the main filename. */
+ const char *main_file_name;
/* File and directory hash table. */
struct htab *file_hash;
Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.297
diff -u -p -r1.297 cppinit.c
--- gcc/cppinit.c 1 Nov 2003 22:56:51 -0000 1.297
+++ gcc/cppinit.c 14 Jan 2004 03:56:28 -0000
@@ -1,6 +1,6 @@
/* CPP Library.
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -451,9 +451,11 @@ cpp_post_options (cpp_reader *pfile)
/* Setup for processing input from the file named FNAME, or stdin if
it is the empty string. Returns true if the file was found. */
-bool
+const char *
cpp_find_main_file (cpp_reader *pfile, const char *fname)
{
+ struct _cpp_file *main_file;
+
if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
{
if (!pfile->deps)
@@ -463,10 +465,21 @@ cpp_find_main_file (cpp_reader *pfile, c
deps_add_default_target (pfile->deps, fname);
}
- pfile->main_file
- = _cpp_find_file (pfile, fname, &pfile->no_search_path, false);
- if (_cpp_find_failed (pfile->main_file))
- return false;
+ main_file = _cpp_find_file (pfile, fname, &pfile->no_search_path, false);
+ if (_cpp_find_failed (main_file))
+ return NULL;
+
+ _cpp_stack_file (pfile, main_file, false);
+
+ /* For foo.i, read the original filename foo.c now, for the benefit
+ of the front ends. */
+ if (CPP_OPTION (pfile, preprocessed))
+ {
+ read_original_filename (pfile);
+ fname = pfile->map->to_file;
+ }
+
+ pfile->main_file_name = fname;
if (CPP_OPTION (pfile, working_directory))
{
@@ -478,22 +491,24 @@ cpp_find_main_file (cpp_reader *pfile, c
if (pfile->cb.dir_change)
pfile->cb.dir_change (pfile, dir);
+ /* Emit file renames that will be recognized by
+ read_directory_filename, since dir_change doesn't output
+ anything. */
+ _cpp_do_file_change (pfile, LC_RENAME, dir_with_slashes, 1, 0);
+ _cpp_do_file_change (pfile, LC_RENAME, fname, 1, 0);
}
- return true;
+
+ return fname;
}
/* This function reads the file, but does not start preprocessing.
This will generate at least one file change callback, and possibly
a line change callback. */
void
-cpp_push_main_file (cpp_reader *pfile)
+cpp_rename_to_main_file (cpp_reader *pfile)
{
- _cpp_stack_file (pfile, pfile->main_file, false);
-
- /* For foo.i, read the original filename foo.c now, for the benefit
- of the front ends. */
- if (CPP_OPTION (pfile, preprocessed))
- read_original_filename (pfile);
+ if (!CPP_OPTION (pfile, preprocessed))
+ _cpp_do_file_change (pfile, LC_RENAME, pfile->main_file_name, 1, 0);
/* Set this here so the client can change the option if it wishes,
and after stacking the main file so we don't trace the main
Index: gcc/cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.270
diff -u -p -r1.270 cpplib.h
--- gcc/cpplib.h 21 Dec 2003 14:08:32 -0000 1.270
+++ gcc/cpplib.h 14 Jan 2004 03:56:28 -0000
@@ -1,6 +1,6 @@
/* Definitions for CPP library.
- Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
+ 2004 Free Software Foundation, Inc.
Written by Per Bothner, 1994-95.
This program is free software; you can redistribute it and/or modify it
@@ -534,12 +534,12 @@ extern void cpp_set_callbacks (cpp_reade
/* This function finds the main file, but does not start reading it.
Returns true iff the file was found. */
-extern bool cpp_find_main_file (cpp_reader *, const char *);
+extern const char *cpp_find_main_file (cpp_reader *, const char *);
/* This function reads the file, but does not start preprocessing.
This will generate at least one file change callback, and possibly
a line change callback. */
-extern void cpp_push_main_file (cpp_reader *);
+extern void cpp_rename_to_main_file (cpp_reader *);
/* Set up built-ins like __FILE__. */
extern void cpp_init_builtins (cpp_reader *, int);
Index: gcc/fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.104
diff -u -p -r1.104 fix-header.c
--- gcc/fix-header.c 1 Nov 2003 22:56:54 -0000 1.104
+++ gcc/fix-header.c 14 Jan 2004 03:56:29 -0000
@@ -1,6 +1,6 @@
/* fix-header.c - Make C header file suitable for C++.
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -606,11 +606,10 @@ read_scan_file (char *in_fname, int argc
if (!cpp_find_main_file (scan_in, in_fname))
exit (FATAL_EXIT_CODE);
- cpp_push_main_file (scan_in);
cpp_change_file (scan_in, LC_RENAME, "<built-in>");
cpp_init_builtins (scan_in, true);
- cpp_change_file (scan_in, LC_RENAME, in_fname);
+ cpp_rename_to_main_file (scan_in);
/* Process switches after builtins so -D can override them. */
for (i = 0; i < argc; i += strings_processed)
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Happy GNU Year! oliva@{lsd.ic.unicamp.br, gnu.org}
Red Hat GCC Developer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist Professional serial bug killer