From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23367 invoked by alias); 4 Apr 2011 16:34:20 -0000 Received: (qmail 23204 invoked by uid 22791); 4 Apr 2011 16:34:17 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from snape.CeBiTec.Uni-Bielefeld.DE (HELO smtp-relay.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Apr 2011 16:33:45 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id C90269CB; Mon, 4 Apr 2011 18:33:43 +0200 (CEST) Received: from smtp-relay.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id wxog5Cl8iQiz; Mon, 4 Apr 2011 18:33:41 +0200 (CEST) Received: from manam.CeBiTec.Uni-Bielefeld.DE (manam.CeBiTec.Uni-Bielefeld.DE [129.70.161.120]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id 404A29CA; Mon, 4 Apr 2011 18:33:41 +0200 (CEST) Received: (from ro@localhost) by manam.CeBiTec.Uni-Bielefeld.DE (8.14.4+Sun/8.14.4/Submit) id p34GXeT2021883; Mon, 4 Apr 2011 18:33:40 +0200 (MEST) From: Rainer Orth To: gcc-patches@gcc.gnu.org Cc: Ian Lance Taylor Subject: [libgo] Don't try to use uninitialized semaphores (PR go/48222) Date: Mon, 04 Apr 2011 16:34:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg00227.txt.bz2 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 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. 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); -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University