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]

Re: Give a better error for PCH with exec-shield-randomize


Geoff Keating <geoffk@desire.geoffk.org> writes:

> I really don't like the ggc_pch_overlap part.  I don't like it for
> three reasons:

OK, instead I wrote some code which makes the PCH testsuite work on
Linux with exec-shield-randomize.

I don't have a good way to do some real testing without using the
testsuite, though.  It's pretty hard to be confident that this will
always do the right thing.

Any opinions from Linux kernel experts?

Ian


2004-03-04  Ian Lance Taylor  <ian@wasabisystems.com>

	* config.host (*-*-linux*): New case.
	* config/host-linux.c: New file.
	* config/x-linux: New file.


Index: config.host
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.host,v
retrieving revision 2.7
diff -p -u -r2.7 config.host
--- config.host	14 Oct 2003 03:41:41 -0000	2.7
+++ config.host	4 Mar 2004 21:08:44 -0000
@@ -152,4 +152,8 @@ case ${host} in
     out_host_hook_obj=host-darwin.o
     host_xmake_file=rs6000/x-darwin
     ;;
+  *-*-linux*)
+    out_host_hook_obj=host-linux.o
+    host_xmake_file=x-linux
+    ;;
 esac
Index: config/host-linux.c
===================================================================
RCS file: config/host-linux.c
diff -N config/host-linux.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/host-linux.c	4 Mar 2004 21:08:49 -0000
@@ -0,0 +1,65 @@
+/* GNU/Linux host-specific hook definitions.
+   Copyright (C) 2004 Free Software Foundation, Inc.
+   Contributed by Ian Lance Taylor <ian@wasabisystems.com>.
+
+   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 "hosthooks.h"
+#include "hosthooks-def.h"
+
+#include <sys/mman.h>
+
+static void *linux_gt_pch_get_address (size_t);
+
+#undef HOST_HOOKS_GT_PCH_GET_ADDRESS
+#define HOST_HOOKS_GT_PCH_GET_ADDRESS linux_gt_pch_get_address
+
+/* The Linux kernel parameter exec-shield-randomize tells the kernel
+   to randomize the stack address.  This changes the memory map and
+   causes the default mmap done by the PCH stuff to return different
+   results at different times, which fails because PCH requires the
+   same address at all times.  We work out a memory address which we
+   hope will work even when randomize the stack address.  We do this
+   by asking for a lot of memory, enough to leave room for trailing
+   mapped areas, and then return just the first SIZE bytes.  */
+
+#define BIG_ALLOCATION 0x10000000
+
+static void *
+linux_gt_pch_get_address (size_t size)
+{
+  void *m;
+  size_t pagesize;
+
+  if (size > BIG_ALLOCATION)
+    return NULL;
+  m = mmap (NULL, BIG_ALLOCATION, PROT_READ | PROT_WRITE,
+	    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  if (m == (void *) MAP_FAILED)
+    return NULL;
+  pagesize = getpagesize ();
+  if (size % pagesize != 0)
+    size += pagesize - size % pagesize;
+  munmap ((char *) m + size, BIG_ALLOCATION - size);
+  return m;
+}
+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
Index: config/x-linux
===================================================================
RCS file: config/x-linux
diff -N config/x-linux
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/x-linux	4 Mar 2004 21:08:50 -0000
@@ -0,0 +1,4 @@
+host-linux.o : $(srcdir)/config/host-linux.c $(CONFIG_H) $(SYSTEM_H) \
+  coretypes.h hosthooks.h hosthooks-def.h
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+		$(srcdir)/config/host-linux.c


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