This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Precompiled header support on Cygwin
- From: Earl Chew <earl_chew at agilent dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 09 Jul 2003 10:06:45 -0700
- Subject: [PATCH] Precompiled header support on Cygwin
- Organization: Agilent Technologies
This patch detects extra alignment and file sizing requirements to
enable precompiled header support on Cygwin.
Reliable collaboration between the two mmap() calls
(gt_pch_save and the subsequent gt_pch_restore) requires use
of Cygwin mmap.cc 1.78 or later.
I've tested this on i386-pc-cygwin.
2003-07-09 Earl Chew <earl_chew@agilent.com>
* aclocal.m4: Add new macro to detect Win32 GetSystemInfo
* configure.in: Detect Win32 GetSystemInfo
* ggc-common.c (gt_pch_save): Perform extra alignment actions
to allow Cygwin mmap() to succeed both here and later in
during gt_pch_restore
Index: aclocal.m4
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/aclocal.m4,v
retrieving revision 1.70
diff -c -r1.70 aclocal.m4
*** aclocal.m4 17 Jun 2003 14:09:54 -0000 1.70
--- aclocal.m4 9 Jul 2003 16:26:17 -0000
***************
*** 458,463 ****
--- 458,478 ----
fi
])
+ # GetSystemInfo() is available on Win32 implementations.
+ # One of the important parameters it makes available is
+ # the MapViewOfFile() or mmap() granularity.
+ AC_DEFUN(gcc_AC_FUNC_GETSYSTEMINFO,
+ [AC_CACHE_CHECK([for GetSystemInfo],
+ ac_cv_func_GetSystemInfo,
+ [AC_TRY_COMPILE([#include <windows.h>],
+ [SYSTEM_INFO si; GetSystemInfo(&si);],
+ ac_cv_func_GetSystemInfo=yes,
ac_cv_func_GetSystemInfo=no)])
+ if test $ac_cv_func_GetSystemInfo = yes; then
+ AC_DEFINE(HAVE_GETSYSTEMINFO, 1,
+ [Define if you have a working GetSystemInfo.])
+ fi
+ ])
+
dnl Locate a program and check that its version is acceptable.
dnl AC_PROG_CHECK_VER(var, name, version-switch,
dnl version-extract-regexp, version-glob)
Index: ggc-common.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/ggc-common.c,v
retrieving revision 1.70
diff -c -r1.70 ggc-common.c
*** ggc-common.c 8 Jun 2003 06:41:28 -0000 1.70
--- ggc-common.c 9 Jul 2003 16:26:29 -0000
***************
*** 34,39 ****
--- 34,44 ----
# include <sys/resource.h>
#endif
+ #ifdef HAVE_GETSYSTEMINFO
+ # define WIN32_LEAN_AND_MEAN
+ # include <windows.h>
+ #endif
+
#ifdef HAVE_MMAP_FILE
# include <sys/mman.h>
# ifdef HAVE_MINCORE
***************
*** 428,433 ****
--- 433,447 ----
struct mmap_info mmi;
size_t page_size = getpagesize();
+ #ifdef HAVE_GETSYSTEMINFO
+ {
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ if (page_size < si.dwAllocationGranularity)
+ page_size = si.dwAllocationGranularity;
+ }
+ #endif
+
gt_pch_save_stringpool ();
saving_htab = htab_create (50000, saving_htab_hash, saving_htab_eq,
free);
***************
*** 454,466 ****
but don't try very hard. On most platforms, this will always work,
and on the rest it's a lot of work to do better. */
#if HAVE_MMAP_FILE
! mmi.preferred_base = mmap (NULL, mmi.size,
! PROT_READ | PROT_WRITE, MAP_PRIVATE,
! fileno (state.f), 0);
! if (mmi.preferred_base == MAP_FAILED)
! mmi.preferred_base = NULL;
! else
! munmap (mmi.preferred_base, mmi.size);
#else /* HAVE_MMAP_FILE */
mmi.preferred_base = NULL;
#endif /* HAVE_MMAP_FILE */
--- 468,497 ----
but don't try very hard. On most platforms, this will always work,
and on the rest it's a lot of work to do better. */
#if HAVE_MMAP_FILE
! {
! size_t p = ftell (state.f);
! if (p == (size_t) -1)
! fatal_error ("can't get position in PCH file: %m");
! if (p < mmi.size)
! {
! /* Some implementations, notably Cygwin, require that
! the underlying file be at least as large as the
! requested mapping. */
! if (fseek (state.f, mmi.size-1, SEEK_SET) != 0 ||
! fputc ('\0', state.f) == EOF ||
! fflush (state.f) != 0)
! fatal_error ("can't extend PCH file: %m");
! }
! mmi.preferred_base = mmap (NULL, mmi.size,
! PROT_READ | PROT_WRITE, MAP_PRIVATE,
! fileno (state.f), 0);
! if (mmi.preferred_base == MAP_FAILED)
! mmi.preferred_base = NULL;
! else
! munmap (mmi.preferred_base, mmi.size);
! if (fseek (state.f, p, SEEK_SET) != 0)
! fatal_error ("can't set position in PCH file: %m");
! }
#else /* HAVE_MMAP_FILE */
mmi.preferred_base = NULL;
#endif /* HAVE_MMAP_FILE */
***************
*** 486,499 ****
/* Pad the PCH file so that the mmaped area starts on a page
boundary. */
{
! long o;
! o = ftell (state.f) + sizeof (mmi);
if (o == -1)
fatal_error ("can't get position in PCH file: %m");
! mmi.offset = page_size - o % page_size;
! if (mmi.offset == page_size)
! mmi.offset = 0;
! mmi.offset += o;
}
if (fwrite (&mmi, sizeof (mmi), 1, state.f) != 1)
fatal_error ("can't write PCH file: %m");
--- 517,527 ----
/* Pad the PCH file so that the mmaped area starts on a page
boundary. */
{
! long o = ftell (state.f);
if (o == -1)
fatal_error ("can't get position in PCH file: %m");
! o += sizeof (mmi) + page_size - 1;
! mmi.offset = o - o % page_size;
}
if (fwrite (&mmi, sizeof (mmi), 1, state.f) != 1)
fatal_error ("can't write PCH file: %m");
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/configure.in,v
retrieving revision 1.689
diff -c -r1.689 configure.in
*** configure.in 17 Jun 2003 21:53:45 -0000 1.689
--- configure.in 9 Jul 2003 16:29:48 -0000
***************
*** 829,834 ****
--- 829,835 ----
gcc_AC_FUNC_PRINTF_PTR
gcc_AC_FUNC_MMAP_BLACKLIST
+ gcc_AC_FUNC_GETSYSTEMINFO
case "${host}" in
*-*-uwin*)