This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Enable PCH support on Solaris
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 7 Jun 2003 23:36:59 +0200
- Subject: [PATCH] Enable PCH support on Solaris
Hi,
Now that the configure machinery has been fixed on Solaris regarding mmap()
et al., I gave the PCH stuff another try. I finally settled for Ulrich's
approach, which is more robust that the one I had initially advocated:
http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00265.html
Compiled and tested on the following platforms:
sparc64-sun-solaris2.9
sparc-sun-solaris2.8
sparc-sun-solaris2.7
sparc-sun-solaris2.6
sparc-sun-solaris2.5.1
i586-redhat-linux-gnu
All PCH tests now pass on SPARC64, almost all on SPARC32. I'm tracking down
the few (7) failures.
--
Eric Botcazou
2003-06-07 Eric Botcazou <ebotcazou@libertysurf.fr>
Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
* ggc-common.c (HAVE_MMAP_FILE): Include sys/types.h
if HAVE_MINCORE is defined.
(MAP_FAILED): Define if not defined.
(gt_pch_save): Test against MAP_FAILED.
(gt_pch_restore): If HAVE_MINCORE, use MAP_FIXED to force
the mapping address to the preferred base after checking it is
possible to do so. Test against MAP_FAILED.
* configure.in: Test for the presence of mincore in libc.
* config.in: Regenerate.
* configure: Regenerate.
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.in,v
retrieving revision 1.679
diff -u -p -r1.679 configure.in
--- configure.in 7 Jun 2003 07:28:15 -0000 1.679
+++ configure.in 7 Jun 2003 21:20:30 -0000
@@ -797,7 +797,7 @@ dnl gcc_AC_C_ENUM_BF_UNSIGNED
AC_CHECK_FUNCS(times clock dup2 kill getrlimit setrlimit atoll atoq \
sysconf strsignal putc_unlocked fputc_unlocked fputs_unlocked \
fwrite_unlocked fprintf_unlocked getrusage nl_langinfo lstat \
- scandir alphasort gettimeofday mbstowcs wcswidth mmap)
+ scandir alphasort gettimeofday mbstowcs wcswidth mmap mincore)
if test x$ac_cv_func_mbstowcs = xyes; then
AC_CACHE_CHECK(whether mbstowcs works, gcc_cv_func_mbstowcs_works,
Index: ggc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-common.c,v
retrieving revision 1.68
diff -u -p -r1.68 ggc-common.c
--- ggc-common.c 13 May 2003 18:06:45 -0000 1.68
+++ ggc-common.c 7 Jun 2003 21:20:31 -0000
@@ -36,6 +36,14 @@ Software Foundation, 59 Temple Place - S
#ifdef HAVE_MMAP_FILE
# include <sys/mman.h>
+# ifdef HAVE_MINCORE
+/* This is on Solaris. */
+# include <sys/types.h>
+# endif
+#endif
+
+#ifndef MAP_FAILED
+# define MAP_FAILED ((void *)-1)
#endif
#ifdef ENABLE_VALGRIND_CHECKING
@@ -477,7 +485,7 @@ gt_pch_save (f)
mmi.preferred_base = mmap (NULL, mmi.size,
PROT_READ | PROT_WRITE, MAP_PRIVATE,
fileno (state.f), 0);
- if (mmi.preferred_base == (void *)-1)
+ if (mmi.preferred_base == MAP_FAILED)
mmi.preferred_base = NULL;
else
munmap (mmi.preferred_base, mmi.size);
@@ -596,10 +604,41 @@ gt_pch_restore (f)
addr = mmap (mmi.preferred_base, mmi.size,
PROT_READ | PROT_WRITE, MAP_PRIVATE,
fileno (f), mmi.offset);
-#else
- addr = (void *)-1;
-#endif
- if (addr == (void *)-1)
+
+#if HAVE_MINCORE
+ if (addr != mmi.preferred_base)
+ {
+ size_t page_size = getpagesize();
+ char one_byte;
+
+ if (addr != MAP_FAILED)
+ munmap (addr, mmi.size);
+
+ /* We really want to be mapped at mmi.preferred_base
+ so we're going to resort to MAP_FIXED. But before,
+ make sure that we can do so without destroying a
+ previously mapped area, by looping over all pages
+ that would be affected by the fixed mapping. */
+ errno = 0;
+
+ for (i = 0; i < mmi.size; i+= page_size)
+ if (mincore ((char *)mmi.preferred_base + i, page_size, (void *)&one_byte) == -1
+ && errno == ENOMEM)
+ continue; /* The page is not mapped. */
+ else
+ break;
+
+ if (i >= mmi.size)
+ addr = mmap (mmi.preferred_base, mmi.size,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
+ fileno (f), mmi.offset);
+ }
+#endif /* HAVE_MINCORE */
+
+#else /* HAVE_MMAP_FILE */
+ addr = MAP_FAILED;
+#endif /* HAVE_MMAP_FILE */
+ if (addr == MAP_FAILED)
{
addr = xmalloc (mmi.size);
if (fseek (f, mmi.offset, SEEK_SET) != 0