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^2 precompiled header support for cygwin


This patch is based on  Earl Chew's 3.4 patch for precompiled header support for cygwin
	http://gcc.gnu.org/ml/gcc-patches/2004-10/msg01211.html
Earl:  Let we know if you no longer want your name associated with this?

Mainline has the additional hooks required, so this is much less intrusive.

One thing I was unsure about.  In host-cygwin.c(cygwin_gt_pch_get_address)
I use fdopen to associate a stream with a file descriptor.  Should I
close the stream or not?  I don't see any "bad things" if I leave the 
stream open.

Bootstrapped on i686-pc-cygwin, but running another bootstrap to be sure.  

OK for mainline?


2005-02-28  Earl Chew <earl_chew@agilent.com>
	    David Billinghurst <David.Billinghurst@riotinto.com>

	    * ggc-common.c (gt_pch_save): Detect ftell failure.
	    * config/i386/host-cygwin.c: New file
	    * config/i386/x-cygwin: Use host-cygwin.c on cygwin host
	    * config.host: Use above files for cygwin host


Index: config.host
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.host,v
retrieving revision 2.12
diff -u -p -r2.12 config.host
--- config.host	30 Nov 2004 03:11:28 -0000	2.12
+++ config.host	28 Feb 2005 01:16:11 -0000
@@ -146,6 +146,8 @@ case ${host} in
     ;;
   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*)
Index: ggc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-common.c,v
retrieving revision 1.91
diff -u -p -r1.91 ggc-common.c
--- ggc-common.c	12 Sep 2004 20:14:23 -0000	1.91
+++ ggc-common.c	28 Feb 2005 01:16:12 -0000
@@ -481,14 +481,11 @@ gt_pch_save (FILE *f)
   /* Pad the PCH file so that the mmapped area starts on an allocation
      granularity (usually 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 = mmap_offset_alignment - o % mmap_offset_alignment;
-    if (mmi.offset == mmap_offset_alignment)
-      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");
--- /dev/null	Mon Feb 28 12:17:04 2005
+++ config/i386/host-cygwin.c	Sun Feb 27 21:56:16 2005
@@ -0,0 +1,87 @@
+/* Cygwin host-specific hook definitions.
+ Copyright (C) 2004 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, int fd);
+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_ALLOC_GRANULARITY
+#define HOST_HOOKS_GT_PCH_ALLOC_GRANULARITY cygwin_gt_pch_alloc_granularity
+
+/*  Return the alignment required for allocating virtual memory. 
+    Usually this is the same as pagesize.  */
+static size_t
+cygwin_gt_pch_alloc_granularity (void)
+{
+  SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ return si.dwAllocationGranularity;
+}
+
+/* Identify an address that's likely to be free in a subsequent invocation
+   of the compiler.  The area should be able to hold SIZE bytes.  FD is an
+   open file descriptor if the host would like to probe with mmap.  */
+static void *
+cygwin_gt_pch_get_address (size_t sz, int fd)
+{
+  void *base;
+  FILE *f = fdopen(fd,"a+");
+  size_t p = ftell(f);
+
+  if (p == (size_t) -1)
+    fatal_error ("can't get position in PCH file: %m");
+
+   /* Cygwin requires that the underlying file be at least 
+      as large as the requested mapping.  */
+  if (p < sz)
+  {
+    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, fd, 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;
+}
+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
--- /dev/null	Mon Feb 28 12:17:04 2005
+++ config/i386/x-cygwin	Sat Feb 26 12:00:31 2005
@@ -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


NOTICE
This e-mail and any attachments are private and confidential and may contain privileged information. If you are not an authorised recipient, the copying or distribution of this e-mail and any attachments is prohibited and you must not read, print or act in reliance on this e-mail or attachments.
This notice should not be removed.


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