This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: other/5620: [3.1] GCC -save-temps foo.c fails to build foo.o
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Dara Hazeghi <dhazeghi at yahoo dot com>
- Date: Wed, 14 May 2003 13:01:05 +1000 (EST)
- Subject: Re: other/5620: [3.1] GCC -save-temps foo.c fails to build foo.o
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5620
As requested by Dara, this is the patch for PR5620, which I submitted in Dec.
http://gcc.gnu.org/ml/gcc-patches/2002-12/msg00605.html
refreshed to current sources.
Tested (C/C++) on mingw32/gcc version 3.4 20030511 (experimental)
The bug is due to the implementation of stat() by the msvcrt C library
used by mingw32: Inodes are meaningless on windows and the value of
stat.st_ino set by stat() is undefined. Using stat to determine if
files were the same was causing strange results when building an
executable from source in one step and using -save-temps.
(eg gcc -o foo.exe -save-temps foo.c) The driver tells cc1 to generate
new file foo.s from foo.c (which cc1.did), but tells the assembler to
use <tmpdir>/<tmpnam>.s as input.
This patch replaces the use of stat for determining if files are the
same with a simple comparison of full (canonical) pathnames on mingw32
hosts.
I don't know if this (using EXTRA_GCC_OBJS and x-make fragment) is the
best way to implement this, without adding __MINGW32__ specific code to gcc.c
Please advise of better alternative. (Would the libiberty/lrealpath.c
approach be better?)
ChangeLog
2003-05-13 Danny Smith <dannysmith@users.sourceforge.net>
* config.gcc (i[34567]86-*-mingw32*): Set xmake-file to
x-mingw32.
* gcc.c (do_spec_1): Use (HOST_FILE_ID_CMP) rather than stat,
if defined.
* config/i386/mingw32-1.c: New file.
(w32_file_id_cmp): Define.
* config/i386/xm-mingw32.h (w32_file_id_cmp): Declare.
(HOST_FILE_ID_CMP): Define as w32_file_id_cmp.
Update copyright year.
* config/i386/x-mingw32: New file. Set EXTRA_GCC_OBJS
to mingw32-1.o. Set rule for compiling mingw32-1.o.
Index: gcc/config.gcc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.299
diff -c -3 -p -r1.299 config.gcc
*** gcc/config.gcc 10 May 2003 12:07:00 -0000 1.299
--- gcc/config.gcc 14 May 2003 01:47:49 -0000
*************** i[34567]86-*-mingw32*)
*** 1345,1350 ****
--- 1345,1351 ----
tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h i386/cygming.h
i386/mingw32.h"
xm_file=i386/xm-mingw32.h
tmake_file="i386/t-cygming i386/t-mingw32"
+ xmake_file=i386/x-mingw32
extra_objs=winnt.o
if test x$enable_threads = xyes; then
thread_file='win32'
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.374
diff -c -3 -p -r1.374 gcc.c
*** gcc/gcc.c 7 May 2003 06:10:49 -0000 1.374
--- gcc/gcc.c 14 May 2003 01:48:05 -0000
*************** static int basename_length;
*** 4157,4163 ****
--- 4157,4165 ----
static int suffixed_basename_length;
static const char *input_basename;
static const char *input_suffix;
+ #ifndef HOST_FILE_ID_CMP
static struct stat input_stat;
+ #endif
static int input_stat_set;
/* The compiler used to process the current input file. */
*************** do_spec_1 (spec, inswitch, soft_matched_
*** 4665,4671 ****
*((char *) temp_filename + temp_filename_length) = '\0';
if (strcmp (temp_filename, input_filename) != 0)
{
! struct stat st_temp;
/* Note, set_input() resets input_stat_set to 0. */
if (input_stat_set == 0)
--- 4667,4676 ----
*((char *) temp_filename + temp_filename_length) = '\0';
if (strcmp (temp_filename, input_filename) != 0)
{
! #if defined HOST_FILE_ID_CMP
! if (HOST_FILE_ID_CMP(input_filename, temp_filename) != 0)
! #else
! struct stat st_temp;
/* Note, set_input() resets input_stat_set to 0. */
if (input_stat_set == 0)
*************** do_spec_1 (spec, inswitch, soft_matched_
*** 4684,4689 ****
--- 4689,4695 ----
|| stat (temp_filename, &st_temp) < 0
|| input_stat.st_dev != st_temp.st_dev
|| input_stat.st_ino != st_temp.st_ino)
+ #endif
{
temp_filename = save_string (temp_filename,
temp_filename_length + 1);
Index: gcc/config/i386/xm-mingw32.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/xm-mingw32.h,v
retrieving revision 1.15
diff -c -3 -p -r1.15 xm-mingw32.h
*** gcc/config/i386/xm-mingw32.h 10 Jan 2002 22:21:39 -0000 1.15
--- gcc/config/i386/xm-mingw32.h 14 May 2003 01:52:30 -0000
***************
*** 1,6 ****
/* Configuration for GNU C-compiler for hosting on Windows32.
using GNU tools and the Windows32 API Library.
! Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
This file is part of GNU CC.
--- 1,6 ----
/* Configuration for GNU C-compiler for hosting on Windows32.
using GNU tools and the Windows32 API Library.
! Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU CC.
*************** Boston, MA 02111-1307, USA. */
*** 31,33 ****
--- 31,40 ----
#undef PATH_SEPARATOR
#define PATH_SEPARATOR ';'
+
+ /* This replaces the use of stat to determine if files are different
+ in gcc.c (do_spec_1) handling of --save-temps switch. */
+
+ extern int
+ w32_file_id_cmp PARAMS((const char *, const char *));
+ #define HOST_FILE_ID_CMP(SRC,DST) w32_file_id_cmp (SRC, DST)
*** /dev/null Wed May 14 03:08:37 2003
--- gcc/config/i386/mingw32-1.c Tue May 13 07:15:56 2003
***************
*** 0 ****
--- 1,44 ----
+ /* This replaces the use of stat and struct stat.st_ino to determine if
+ files are different in gcc.c (do_spec_1) handling of --save-temps
+ switch.
+ Contributed by Danny Smith (dannysmith@users.sourceforge.net)
+ Copyright 2003 Free Software Foundation, Inc.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+
+ /* Return non-zero if src and dst filenames do not refer to same files. */
+
+ int w32_file_id_cmp (const char *, const char *);
+
+ int
+ w32_file_id_cmp (src, dst)
+ const char * src;
+ const char * dst;
+ {
+ char fullpath_src[MAX_PATH];
+ char fullpath_dst[MAX_PATH];
+ char* pfilename;
+
+ /* Just compare full pathnames, without regard to case. */
+ GetFullPathName (src,MAX_PATH,fullpath_src,&pfilename);
+ GetFullPathName (dst,MAX_PATH,fullpath_dst,&pfilename);
+ return (lstrcmpi (fullpath_src, fullpath_dst));
+ }
http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.