diff mbox

[libgo] Don't try to use uninitialized semaphores (PR go/48222)

Message ID yddwrjac6xn.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth April 4, 2011, 4:33 p.m. UTC
After some time with DTrace, I found what caused the intermittend
assertion failures in thread.c:

/vol/gcc/src/hg/trunk/local/libgo/runtime/thread.c:63: libgo assertion failure
/vol/gcc/src/hg/trunk/local/libgo/runtime/thread.c:40: libgo assertion failure

It turned out that sem_wait or sem_post was called with an uninitialized
semaphore, and always the same one:

> fffffd7fc79407a8::whatis
fffffd7fc79407a8 is libgo.so.0.0.0`proflock+8, in 
/vol/gcc/obj/gcc-4.7.0-20110401/11-gcc/i386-pc-solaris2.11/amd64/libgo/.libs/lib
go.so.0.0.0 [fffffd7fc7940000,fffffd7fc9978000)

Lock proflock is initialized in runtime/mprof.goc (runtime_Mprof_Init),
but that is never called.  There are two other instances of the same
problem:

* Lock finlock in mfinal.c, initialized in runtime_initfintab, which
  again isn't called.

* Lock lk in cpuprof.c, which even lacks an initialization function.

The following patch fixes all this and makes those random assertion
failures go away.

	Rainer


2011-04-03  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	PR go/48222
	* runtime/malloc.goc (runtime_mallocinit): Call
	runtime_Mprof_Init, runtime_initfintab.
	* runtime/cpuprof.c (runtime_cpuprofinit): New function.
	* runtime/runtime.h (runtime_cpuprofinit): Declare it.
	* runtime/go-main.c (main): Use it.

Comments

Ian Lance Taylor April 4, 2011, 11:44 p.m. UTC | #1
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> 2011-04-03  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>
> 	PR go/48222
> 	* runtime/malloc.goc (runtime_mallocinit): Call
> 	runtime_Mprof_Init, runtime_initfintab.
> 	* runtime/cpuprof.c (runtime_cpuprofinit): New function.
> 	* runtime/runtime.h (runtime_cpuprofinit): Declare it.
> 	* runtime/go-main.c (main): Use it.

Thanks for tracking this down.  I wonder why I never saw the problem on
GNU/Linux?

I committed your patch.

Ian
diff mbox

Patch

diff --git a/libgo/runtime/cpuprof.c b/libgo/runtime/cpuprof.c
--- a/libgo/runtime/cpuprof.c
+++ b/libgo/runtime/cpuprof.c
@@ -114,6 +114,12 @@  static void add(Profile*, uintptr*, int3
 static bool evict(Profile*, Entry*);
 static bool flushlog(Profile*);
 
+void
+runtime_cpuprofinit(void)
+{
+	runtime_initlock(&lk);
+}
+
 // LostProfileData is a no-op function used in profiles
 // to mark the number of profiling stack traces that were
 // discarded due to slow data writers.
diff --git a/libgo/runtime/go-main.c b/libgo/runtime/go-main.c
--- a/libgo/runtime/go-main.c
+++ b/libgo/runtime/go-main.c
@@ -48,6 +48,7 @@  main (int argc, char **argv)
   struct __go_string *values;
 
   runtime_mallocinit ();
+  runtime_cpuprofinit ();
   __go_gc_goroutine_init (&argc);
 
   Args.__count = argc;
diff --git a/libgo/runtime/malloc.goc b/libgo/runtime/malloc.goc
--- a/libgo/runtime/malloc.goc
+++ b/libgo/runtime/malloc.goc
@@ -350,6 +350,12 @@  runtime_mallocinit(void)
 	runtime_MHeap_Init(&runtime_mheap, runtime_SysAlloc);
 	m->mcache = runtime_allocmcache();
 
+	// Initialize malloc profiling.
+	runtime_Mprof_Init();
+
+	// Initialize finalizer.
+	runtime_initfintab();
+
 	// See if it works.
 	runtime_free(runtime_malloc(1));
 }
diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -189,6 +189,7 @@  void	runtime_walkfintab(void (*fn)(void*
 #define runtime_casp(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
 
 void	runtime_sigprof(uint8 *pc, uint8 *sp, uint8 *lr);
+void	runtime_cpuprofinit(void);
 void	runtime_resetcpuprofiler(int32);
 void	runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);