This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch/PR 5620] Fix -save-temps on mingw32 host
- From: Danny Smith <danny_smith_0000 at yahoo dot co dot nz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 27 Jun 2004 00:09:58 +1200 (NZST)
- Subject: [Patch/PR 5620] Fix -save-temps on mingw32 host
The -save-temps switch has not worked correctly on mingw32 hosts since
gcc-3.1.0 because the logic to determine if an output temp file will
overwrite an input file depends on the st_ino field of struct stat being
meaningful. Windows filesystems don't have inode numbers and the st_ino
field of struct stat after a successful call to stat is always 0.
This fixes by using lrealpath on Windows hosts. Since Windows
filesystems don't have Posix style symlinks, lrealpath just returns a
canonicalized full pathname.
The addition of a reasonable lrealpath for Windows hosts will also allow it
to be used in c-incpath.c:remove_duplicates to identify duplicate
include paths.
libiberty/ChangeLog
2004-06-27 Danny Smith <dannysmith@users.sourceforge.net>
PR 5620
* lrealpath.c (lrealpath): Add _WIN32 support.
ChangeLog
2004-06-27 Danny Smith <dannysmith@users.sourceforge.net>
PR 5620
* gcc.c (struct stat input_stat): Don't define if
HOST_LACKS_INODE_NUMBERS
(do_spec_1): If HOST_LACKS_INODE_NUMBERS, use lrealpath rather
than stat to determine if temp file is same as input file.
* doc/hostconfig.texi: Document HOST_LACKS_INODE_NUMBERS.
* config/i386/xm-mingw32.h: Define HOST_LACKS_INODE_NUMBERS
Index: lrealpath.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/lrealpath.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 lrealpath.c
*** lrealpath.c 20 Feb 2003 22:11:13 -0000 1.1
--- lrealpath.c 26 Jun 2004 11:57:20 -0000
*************** extern char *canonicalize_file_name (con
*** 64,69 ****
--- 64,75 ----
# define REALPATH_LIMIT MAXPATHLEN
# endif
# endif
+ #else
+ /* cygwin has realpath, so it won't get here. */
+ # if defined (_WIN32)
+ # define WIN32_LEAN_AND_MEAN
+ # include <windows.h> /* for GetFullPathName */
+ # endif
#endif
char *
*************** lrealpath (filename)
*** 123,128 ****
--- 129,159 ----
}
#endif
+ /* The MS Windows method. If we don't have realpath, we assume we
+ don't have symlinks and just canonicalize to a Windows absolute
+ path. GetFullPath converts ../ and ./ in relative paths to
+ absolute paths, filling in current drive if one is not given
+ or using the current directory of a specified drive (eg, "E:foo").
+ It also converts all forward slashes to backslashes. */
+
+ #if defined (_WIN32)
+ {
+ char buf[MAX_PATH];
+ char* basename;
+ DWORD len = GetFullPathName (filename, MAX_PATH, buf, &basename);
+ if (len == 0 || len > MAX_PATH - 1)
+ return strdup (filename);
+ else
+ {
+ /* The file system is case-preserving but case-insensitive,
+ Canonicalize to lowercase, using the codepage associated
+ with the process locale. */
+ CharLowerBuff (buf, len);
+ return strdup (buf);
+ }
+ }
+ #endif
+
/* This system is a lost cause, just duplicate the filename. */
return strdup (filename);
}
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.424
diff -c -3 -p -r1.424 gcc.c
*** gcc.c 4 Jun 2004 20:13:14 -0000 1.424
--- gcc.c 25 Jun 2004 23:51:51 -0000
*************** static int basename_length;
*** 4217,4223 ****
--- 4219,4227 ----
static int suffixed_basename_length;
static const char *input_basename;
static const char *input_suffix;
+ #ifndef HOST_LACKS_INODE_NUMBERS
static struct stat input_stat;
+ #endif
static int input_stat_set;
/* The compiler used to process the current input file. */
*************** do_spec_1 (const char *spec, int inswitc
*** 4781,4786 ****
--- 4785,4791 ----
*((char *) temp_filename + temp_filename_length) = '\0';
if (strcmp (temp_filename, input_filename) != 0)
{
+ #ifndef HOST_LACKS_INODE_NUMBERS
struct stat st_temp;
/* Note, set_input() resets input_stat_set to 0. */
*************** do_spec_1 (const char *spec, int inswitc
*** 4795,4805 ****
and we can do the stat for the temp_filename
then the they could still refer to the same
file if st_dev/st_ino's are the same. */
-
if (input_stat_set != 1
|| stat (temp_filename, &st_temp) < 0
|| input_stat.st_dev != st_temp.st_dev
|| input_stat.st_ino != st_temp.st_ino)
{
temp_filename = save_string (temp_filename,
temp_filename_length + 1);
--- 4800,4818 ----
and we can do the stat for the temp_filename
then the they could still refer to the same
file if st_dev/st_ino's are the same. */
if (input_stat_set != 1
|| stat (temp_filename, &st_temp) < 0
|| input_stat.st_dev != st_temp.st_dev
|| input_stat.st_ino != st_temp.st_ino)
+ #else
+ /* Just compare canonical pathnames. */
+ char* input_realname = lrealpath (input_filename);
+ char* temp_realname = lrealpath (temp_filename);
+ bool files_differ = strcmp (input_realname, temp_realname);
+ free (input_realname);
+ free (temp_realname);
+ if (files_differ)
+ #endif
{
temp_filename = save_string (temp_filename,
temp_filename_length + 1);
Index: doc/hostconfig.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/hostconfig.texi,v
retrieving revision 1.11
diff -c -3 -p -r1.11 hostconfig.texi
*** doc/hostconfig.texi 5 Jun 2004 07:28:27 -0000 1.11
--- doc/hostconfig.texi 25 Jun 2004 23:06:52 -0000
*************** If you do not define this macro, GCC wil
*** 163,168 ****
--- 163,172 ----
should define this macro if the default version does not reliably remove
the temp file as, for example, on VMS which allows multiple versions
of a file.
+
+ @item HOST_LACKS_INODE_NUMBERS
+ Define this macro if the host filesystem does not report meaningful inode
+ numbers in struct stat.
@end ftable
@node Host Misc
Index: config/i386/xm-mingw32.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/xm-mingw32.h,v
retrieving revision 1.20
diff -c -3 -p -r1.20 xm-mingw32.h
*** config/i386/xm-mingw32.h 31 Jan 2004 02:06:57 -0000 1.20
--- config/i386/xm-mingw32.h 25 Jun 2004 23:06:52 -0000
*************** Software Foundation, 59 Temple Place - S
*** 27,29 ****
--- 27,32 ----
/* This is the name of the null device on windows. */
#define HOST_BIT_BUCKET "nul"
+
+ /* The st_ino field of struct stat is always 0. */
+ #define HOST_LACKS_INODE_NUMBERS
Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com