diff mbox

[4.4,libmudflap] backport FreeBSD fixes

Message ID alpine.LSU.1.99.1006202135050.9343@acrux.dbai.tuwien.ac.at
State New
Headers show

Commit Message

Gerald Pfeifer June 20, 2010, 7:59 p.m. UTC
Looking at testresults more often the last weeks, those 353 failures
from libmudflap coming from my FreeBSD testers really annoyed/worried
me, so I investigated a bit and found that Loren had fixed this for
GCC 4.4 and later.

Here are the straightforward backports

	Backport from mainline:
	2009-09-01  Loren J. Rittle  <ljrittle@acm.org>

	* mf-runtime.c (__mf_init): Support FreeBSD.
	Prime mutex which calls calloc upon first lock to avoid deadlock.
	* mf-hooks1.c (__mf_0fn_mmap): Support FreeBSD.
	Ignore red zone allocation request for initial thread's stack.

	Backport from mainline:
	2009-09-01  Loren J. Rittle  <ljrittle@acm.org>
	            Andreas Schwab  <schwab@linux-m68k.org>

	* testsuite/libmudflap.c/pass51-frag.c (MAP_FAILED): Define,
	if not in system header; use it.  On FreeBSD, must pass fd==-1
	with MAP_ANON flag.  Correct mmap error check.
	* testsuite/libmudflap.c/fail40-frag.c: Ditto.

which I tested on i386-unknown-freebsd9.0 to see libmudflap go from
  # of expected passes		1541
  # of unexpected failures	353
to
  # of expected passes		1889
  # of unexpected failures	5

  FAIL: libmudflap.c++/pass41-frag.cxx execution test
  FAIL: libmudflap.c++/pass41-frag.cxx (-static) execution test
  FAIL: libmudflap.c++/pass41-frag.cxx ( -O) execution test
  FAIL: libmudflap.c++/pass41-frag.cxx (-O2) execution test
  FAIL: libmudflap.c++/pass41-frag.cxx (-O3) execution test

Installed based on a general approval by Loren.

Gerald
diff mbox

Patch

Index: mf-hooks1.c
===================================================================
--- mf-hooks1.c	(revision 151277)
+++ mf-hooks1.c	(revision 151278)
@@ -321,6 +321,11 @@ 
 void *
 __mf_0fn_mmap (void *start, size_t l, int prot, int f, int fd, off_t off)
 {
+#if defined(__FreeBSD__)
+  if (f == 0x1000 && fd == -1 && prot == 0 && off == 0)
+    return 0;
+#endif /* Ignore red zone allocation request for initial thread's stack. */
+
   return (void *) -1;
 }
 #endif
Index: mf-runtime.c
===================================================================
--- mf-runtime.c	(revision 151277)
+++ mf-runtime.c	(revision 151278)
@@ -695,6 +695,12 @@ 
   if (LIKELY (__mf_starting_p == 0))
     return;
 
+#if defined(__FreeBSD__) && defined(LIBMUDFLAPTH)
+  pthread_self();
+  LOCKTH ();
+  UNLOCKTH ();
+#endif /* Prime mutex which calls calloc upon first lock to avoid deadlock. */
+
   /* This initial bootstrap phase requires that __mf_starting_p = 1. */
 #ifdef PIC
   __mf_resolve_dynamics ();

Index: testsuite/libmudflap.c/pass51-frag.c
===================================================================
--- testsuite/libmudflap.c/pass51-frag.c	(revision 151276)
+++ testsuite/libmudflap.c/pass51-frag.c	(revision 151277)
@@ -13,14 +13,17 @@ 
 #ifndef MAP_ANONYMOUS
 #define MAP_ANONYMOUS MAP_ANON
 #endif
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
 #ifdef HAVE_MMAP
   void *p;
   unsigned pg = getpagesize ();
   int rc;
 
   p = mmap (NULL, 4 * pg, PROT_READ|PROT_WRITE, 
-            MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
-  if (p == NULL)
+            MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  if (p == MAP_FAILED)
     return 1;
 
   memset (p, 0, 4*pg);
Index: testsuite/libmudflap.c/fail40-frag.c
===================================================================
--- testsuite/libmudflap.c/fail40-frag.c	(revision 151276)
+++ testsuite/libmudflap.c/fail40-frag.c	(revision 151277)
@@ -14,6 +14,9 @@ 
 #ifndef MAP_ANONYMOUS
 #define MAP_ANONYMOUS MAP_ANON
 #endif
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
 #ifdef HAVE_MMAP
   volatile unsigned char *p;
   unsigned num = getpagesize ();
@@ -23,8 +26,8 @@ 
   /* Get a bit of usable address space.  We really want an 2**N+1-sized object,
      so the low/high addresses wrap when hashed into the lookup cache.  So we
      will manually unregister the entire mmap, then re-register a slice.  */
-  p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
-  if (p == NULL)
+  p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  if (p == MAP_FAILED)
     return 1;
   /* Now unregister it, as if munmap was called.  But don't actually munmap, so
      we can write into the memory.  */