This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Revised precompiled header support on cygwin


Chris,

This code is a little dated. I'm hoping that you can direct me
to the appropriate cygwin person to use this as a basis to get
pch support into a newer version of gcc (presumably 3.4.2 and later).

I based this work on some earlier work I did:

http://gcc.gnu.org/ml/gcc-patches/2003-07/msg00963.html

which got left behind.

I have updated the patch for gcc-3.4.1. I took the liberty of
incorporating some of the more recent work in hooks* to make it
easier to revise the patch into a current version of gcc.

I am working with this patch on Cygwin 1.5.11.

Earl

	*  x-cygwin config.host ggc-common hooks.c hooks.h
	host-hooks-def.h hosthooks.h: Activate precompiled
	header support for cygwin.

diff -urN ../../gcc-3.4.1/gcc/config/i386/host-cygwin.c ./config/i386/host-cygwin.c
--- ../../gcc-3.4.1/gcc/config/i386/host-cygwin.c 1969-12-31 16:00:00.000000000 -0800
+++ ./config/i386/host-cygwin.c 2004-10-12 23:41:43.584000000 -0700
@@ -0,0 +1,99 @@
+/* Cygwin host-specific hook definitions.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC 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.
+
+ GCC 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 GCC; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include <sys/mman.h>
+#include "hosthooks.h"
+#include "hosthooks-def.h"
+#include "toplev.h"
+#include "diagnostic.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+static void * cygwin_gt_pch_get_address (size_t, FILE*);
+static bool cygwin_gt_pch_use_address (void *, size_t);
+static size_t cygwin_gt_pch_alloc_granularity (void);
+
+#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
+#define HOST_HOOKS_GT_PCH_GET_ADDRESS cygwin_gt_pch_get_address
+#undef HOST_HOOKS_GT_PCH_USE_ADDRESS
+#define HOST_HOOKS_GT_PCH_USE_ADDRESS cygwin_gt_pch_use_address
+#undef HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY
+#define HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY cygwin_gt_pch_alloc_granularity
+
+/* Granularity for reserving address space. */
+static size_t cygwin_gt_pch_alloc_granularity (void)
+{
+ SYSTEM_INFO si;
+
+ GetSystemInfo(&si);
+
+ return si.dwAllocationGranularity;
+}
+
+/* Return the address of the PCH address space, if the PCH will fit in it. */
+static void *
+cygwin_gt_pch_get_address (size_t sz, FILE *f)
+{
+ void *base;
+ size_t p = ftell (f);
+
+ if (p == (size_t) -1)
+ fatal_error ("can't get position in PCH file: %m");
+
+ if (p < sz)
+ {
+ /* Cygwin requires that the underlying file be at least as large as the
+ requested mapping. */
+ if (fseek (f, sz-1, SEEK_SET) != 0 ||
+ fputc ('\0', f) == EOF ||
+ fflush (f) != 0)
+ fatal_error ("can't extend PCH file: %m");
+ }
+
+ base = mmap (NULL, sz,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE,
+ fileno (f), 0);
+
+ if (base == MAP_FAILED)
+ base = NULL;
+ else
+ munmap (base, sz);
+
+ if (fseek (f, p, SEEK_SET) != 0)
+ fatal_error ("can't set position in PCH file: %m");
+
+ return base;
+}
+
+/* Check ADDR and SZ for validity, and deallocate (using munmap) that part of
+ pch_address_space beyond SZ. */
+
+static bool
+cygwin_gt_pch_use_address (void *addr ATTRIBUTE_UNUSED,
+ size_t sz ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
diff -urN ../../gcc-3.4.1/gcc/config/i386/x-cygwin ./config/i386/x-cygwin
--- ../../gcc-3.4.1/gcc/config/i386/x-cygwin 1969-12-31 16:00:00.000000000 -0800
+++ ./config/i386/x-cygwin 2004-10-12 14:51:44.440125000 -0700
@@ -0,0 +1,4 @@
+host-cygwin.o : $(srcdir)/config/i386/host-cygwin.c $(CONFIG_H) $(SYSTEM_H) \
+ coretypes.h hosthooks.h hosthooks-def.h toplev.h diagnostic.h
+ $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+ $(srcdir)/config/i386/host-cygwin.c
diff -urN ../../gcc-3.4.1/gcc/config.host ./config.host
--- ../../gcc-3.4.1/gcc/config.host 2003-10-13 20:41:41.000000000 -0700
+++ ./config.host 2004-10-12 14:53:22.018250000 -0700
@@ -129,6 +129,8 @@
;;
i[34567]86-*-pe | i[34567]86-*-cygwin*)
host_xm_file=i386/xm-cygwin.h
+ out_host_hook_obj=host-cygwin.o
+ host_xmake_file=i386/x-cygwin
host_exeext=.exe
;;
i[34567]86-*-mingw32*)
diff -urN ../../gcc-3.4.1/gcc/ggc-common.c ./ggc-common.c
--- ../../gcc-3.4.1/gcc/ggc-common.c 2003-10-29 14:13:59.000000000 -0800
+++ ./ggc-common.c 2004-10-12 23:27:50.771500000 -0700
@@ -429,7 +429,7 @@
char *this_object = NULL;
size_t this_object_size = 0;
struct mmap_info mmi;
- size_t page_size = getpagesize();
+ size_t mmap_offset_alignment = host_hooks.gt_pch_alloc_granularity();


gt_pch_save_stringpool ();

@@ -458,7 +458,7 @@
      and on the rest it's a lot of work to do better.
      (The extra work goes in HOST_HOOKS_GT_PCH_GET_ADDRESS and
      HOST_HOOKS_GT_PCH_USE_ADDRESS.)  */
-  mmi.preferred_base = host_hooks.gt_pch_get_address (mmi.size);
+  mmi.preferred_base = host_hooks.gt_pch_get_address (mmi.size, f);

 #if HAVE_MMAP_FILE
   if (mmi.preferred_base == NULL)
@@ -494,14 +494,11 @@

/* Pad the PCH file so that the mmapped area starts on a page boundary. */
{
- long o;
- o = ftell (state.f) + sizeof (mmi);
+ long o = ftell (state.f);
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;
+ o += sizeof (mmi) + mmap_offset_alignment - 1;
+ mmi.offset = o - o % mmap_offset_alignment;
}
if (fwrite (&mmi, sizeof (mmi), 1, state.f) != 1)
fatal_error ("can't write PCH file: %m");
diff -urN ../../gcc-3.4.1/gcc/hooks.c ./hooks.c
--- ../../gcc-3.4.1/gcc/hooks.c 2004-02-12 07:30:45.000000000 -0800
+++ ./hooks.c 2004-10-12 23:24:35.787125000 -0700
@@ -192,6 +192,13 @@
return false;
}


+
+size_t
+hook_size_t_void_pagesize (void)
+{
+  return getpagesize();
+}
+
 /* Generic hook that takes an rtx and returns it.  */
 rtx
 hook_rtx_rtx_identity (rtx x)
@@ -215,7 +222,8 @@

 /* Generic hook that takes a size_t and returns NULL.  */
 void *
-hook_voidp_size_t_null (size_t a ATTRIBUTE_UNUSED)
+hook_voidp_size_t_FILEptr_null (size_t a ATTRIBUTE_UNUSED,
+                                FILE *b ATTRIBUTE_UNUSED)
 {
   return NULL;
 }
diff -urN ../../gcc-3.4.1/gcc/hooks.h ./hooks.h
--- ../../gcc-3.4.1/gcc/hooks.h	2004-02-12 07:30:45.000000000 -0800
+++ ./hooks.h	2004-10-12 16:14:46.471375000 -0700
@@ -58,7 +58,8 @@
 extern rtx hook_rtx_rtx_identity (rtx);
 extern rtx hook_rtx_rtx_null (rtx);
 extern rtx hook_rtx_tree_int_null (tree, int);
-extern void * hook_voidp_size_t_null (size_t);
+extern void * hook_voidp_size_t_FILEptr_null (size_t, FILE*);
 extern bool hook_bool_voidp_size_t_false (void *, size_t);
+extern size_t hook_size_t_void_pagesize (void);

 #endif
diff -urN ../../gcc-3.4.1/gcc/hosthooks-def.h ./hosthooks-def.h
--- ../../gcc-3.4.1/gcc/hosthooks-def.h	2003-07-29 16:36:46.000000000 -0700
+++ ./hosthooks-def.h	2004-10-12 23:21:15.755875000 -0700
@@ -24,14 +24,16 @@
 #include "hooks.h"

 #define HOST_HOOKS_EXTRA_SIGNALS hook_void_void
-#define HOST_HOOKS_GT_PCH_GET_ADDRESS hook_voidp_size_t_null
+#define HOST_HOOKS_GT_PCH_GET_ADDRESS hook_voidp_size_t_FILEptr_null
 #define HOST_HOOKS_GT_PCH_USE_ADDRESS hook_bool_voidp_size_t_false
+#define HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY hook_size_t_void_pagesize

 /* The structure is defined in hosthooks.h.  */
 #define HOST_HOOKS_INITIALIZER {		\
   HOST_HOOKS_EXTRA_SIGNALS,			\
   HOST_HOOKS_GT_PCH_GET_ADDRESS,		\
-  HOST_HOOKS_GT_PCH_USE_ADDRESS			\
+  HOST_HOOKS_GT_PCH_USE_ADDRESS,		\
+  HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY		\
 }

 #endif /* GCC_HOST_HOOKS_DEF_H */
diff -urN ../../gcc-3.4.1/gcc/hosthooks.h ./hosthooks.h
--- ../../gcc-3.4.1/gcc/hosthooks.h	2003-07-29 16:36:46.000000000 -0700
+++ ./hosthooks.h	2004-10-12 16:14:23.674500000 -0700
@@ -25,9 +25,11 @@
 {
   void (*extra_signals) (void);

-  void * (*gt_pch_get_address) (size_t);
+  void * (*gt_pch_get_address) (size_t, FILE*);
   bool (*gt_pch_use_address) (void *, size_t);

+ size_t (*gt_pch_alloc_granularity) (void);
+
/* Whenever you add entries here, make sure you adjust hosthooks-def.h. */
};




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]