From owner-freebsd-threads@FreeBSD.ORG Wed May 28 18:22:23 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0A82D37B411; Wed, 28 May 2003 18:22:23 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4735543F93; Wed, 28 May 2003 18:22:22 -0700 (PDT) (envelope-from eischen@pcnet.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.8/8.12.1) with ESMTP id h4T1MKnb011544; Wed, 28 May 2003 21:22:21 -0400 (EDT) Date: Wed, 28 May 2003 21:22:20 -0400 (EDT) From: Daniel Eischen To: Petri Helenius In-Reply-To: <00b501c32529$ab429460$812a40c1@PETEX31> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-threads@freebsd.org cc: David Xu cc: Daniel Eischen Subject: Re: malloc(): error: recursive call X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 May 2003 01:22:23 -0000 On Wed, 28 May 2003, Petri Helenius wrote: > > > > >Unfortunatly I have run your test program for five minutes without problem. > > > I think we?re getting close. I suspect you didn?t link the binary static? > > With same object file and othervise same link line, if I remove -static it runs fine, > if I link the binary with -static it fails within a first few seconds. > > Now, thread guru?s, what happens differently when running statically linked > binary? It?s compiled and linked and run on the same box than the non-static one. What happens is that libkse doesn't make use of spinlocks itself, unlike libc_r which uses them internally. Spinlocks are not suppose to be used by applications either, and your application doesn't use them directly. In this instance, they are only being used internally by libc. So when the linker resolves references to _spin[un]lock() in libc, it has already examined libkse and ends up linking to the null spinlock stubs that are within libc. I'm not sure why this is, but linking dynamically doesn't have this problem. If you examine the innards of libc_r and libpthread (in uthread/uthread_init.c and thread/thr_init.c respectively), you'll see a table of references to work around the static linking problem. If you apply this patch, it will add references to spinlocks within the table and things should work again: -- Dan Eischen Index: thread/thr_init.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/thr_init.c,v retrieving revision 1.52 diff -u -r1.52 thr_init.c --- thread/thr_init.c 16 May 2003 19:58:29 -0000 1.52 +++ thread/thr_init.c 29 May 2003 01:13:10 -0000 @@ -66,6 +66,7 @@ #include "un-namespace.h" #include "libc_private.h" +#include "spinlock.h" #include "thr_private.h" #include "ksd.h" @@ -132,6 +133,8 @@ &_sigsuspend, &_socket, &_socketpair, + &_spinlock, + &_spinunlock, &_thread_init_hack, &_wait4, &_write,