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


Eric Botcazou <ebotcazou@libertysurf.fr> writes:

> > Thanks for checking.  Would you mind trying out the appended patch, to
> > confirm that with this patch PCH still works on Solaris?  This patch
> > avoids using the mincore workaround for an mmap failure on Linux.  I
> > included the diffs for the generated files for convenience.
> 
> Works flawlessly on Solaris 8/SPARC 32-bit and 64-bit.  I don't expect any 
> difference whatsoever on other Solaris versions.

Thanks for testing it.

I think this patch should be checked into mainline.  This removes a
potential problem on Linux systems on which mincore won't detect a
conflict.  It should do no harm, since Linux systems don't appear to
need this particular workaround.

Ian


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

	* configure.ac: Add a test for whether mincore can detect an
	anonymous mmap.
	* ggc-common.c (gt_pch_restore): Only call mincore if
	HAVE_WORKING_MINCORE.  Free the map before calling mincore.
	* configure, config.in: Regenerate.


Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.ac,v
retrieving revision 2.20
diff -u -r2.20 configure.ac
--- configure.ac	5 Mar 2004 14:11:58 -0000	2.20
+++ configure.ac	5 Mar 2004 17:34:21 -0000
@@ -833,6 +833,50 @@
   fi
 fi
 
+if test x$ac_cv_func_mincore = xyes; then
+  AC_CACHE_CHECK(whether mincore detects anonymous mappings,
+		 gcc_cv_func_mincore_works,
+[    AC_TRY_RUN([
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *) -1)
+#endif
+
+int
+main ()
+{
+#ifndef MAP_ANONYMOUS
+  exit (0);
+#else
+  size_t pagesize = getpagesize ();
+  void *p = mmap (0, pagesize, PROT_READ | PROT_WRITE,
+		  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  char c;
+  if (p == MAP_FAILED)
+    exit (0);
+  errno = 0;
+  exit (mincore (p, pagesize, &c) == -1 && errno == ENOMEM);
+#endif
+}
+],
+    gcc_cv_func_mincore_works=yes,
+    gcc_cv_func_mincore_works=no,
+    [case "${host}" in
+     *-*-linux*) gcc_cv_func_mincore_works=no ;;
+     *) gcc_cv_func_mincore_works=yes ;;
+     esac
+    ])])
+  if test x$gcc_cv_func_mincore_works = xyes; then
+    AC_DEFINE(HAVE_WORKING_MINCORE, 1,
+  [Define this macro if mincore detects private anonymous mappings.])
+  fi
+fi
+
 AC_CHECK_TYPE(ssize_t, int)
 
 # Try to determine the array type of the second argument of getgroups
Index: ggc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-common.c,v
retrieving revision 1.84
diff -u -r1.84 ggc-common.c
--- ggc-common.c	5 Mar 2004 01:22:58 -0000	1.84
+++ ggc-common.c	5 Mar 2004 17:34:27 -0000
@@ -608,17 +608,23 @@
 		   PROT_READ | PROT_WRITE, MAP_PRIVATE,
 		   fileno (f), mmi.offset);
 
-#if HAVE_MINCORE
+#if defined (HAVE_MINCORE) && defined (HAVE_WORKING_MINCORE)
       if (addr != mmi.preferred_base)
 	{
 	  size_t page_size = getpagesize();
 	  char one_byte;
 
-	  /* 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.  */
+	  /* We didn't get the mapping we want.  On Solaris, this can
+	     happen even though the mapping we want is available.  Use
+	     mincore to see if the mapping could succeed.  If it
+	     could, then force it using MAP_FIXED.  */
+
+	  if (addr != (void *) MAP_FAILED)
+	    {
+	      munmap (addr, mmi.size);
+	      addr = (void *) MAP_FAILED;
+	    }
+
 	  errno = 0;
 
 	  for (i = 0; i < mmi.size; i+= page_size)
@@ -630,16 +636,11 @@
 	      break;
 
 	  if (i >= mmi.size)
-	    {
-	      if (addr != (void *) MAP_FAILED)
-		munmap (addr, mmi.size);
-
-	      addr = mmap (mmi.preferred_base, mmi.size, 
-			   PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
-			   fileno (f), mmi.offset);
-	    }
+	    addr = mmap (mmi.preferred_base, mmi.size, 
+			 PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
+			 fileno (f), mmi.offset);
 	}
-#endif /* HAVE_MINCORE */
+#endif /* defined (HAVE_MINCORE) && defined (HAVE_WORKING_MINCORE) */
 
       needs_read = addr == (void *) MAP_FAILED;
 


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