atom feed23 messages in org.freebsd.freebsd-threadsmalloc(): error: recursive call
FromSent OnAttachments
Petri HeleniusMay 27, 2003 5:52 am 
Daniel EischenMay 27, 2003 7:46 am 
Petri HeleniusMay 27, 2003 11:03 am 
Daniel EischenMay 27, 2003 11:10 am 
Petri HeleniusMay 27, 2003 2:17 pm 
Daniel EischenMay 27, 2003 3:03 pm 
Daniel EischenMay 27, 2003 4:29 pm 
Petri HeleniusMay 27, 2003 10:57 pm 
Petri HeleniusMay 27, 2003 11:30 pm 
Petri HeleniusMay 28, 2003 12:24 am 
Mike MakonnenMay 28, 2003 12:59 am 
David XuMay 28, 2003 1:56 am 
Petri HeleniusMay 28, 2003 2:25 am 
David XuMay 28, 2003 2:37 am 
Petri HeleniusMay 28, 2003 6:51 am 
Petri HeleniusMay 28, 2003 8:01 am 
Daniel EischenMay 28, 2003 6:23 pm 
Daniel EischenMay 28, 2003 6:28 pm 
Petri HeleniusMay 29, 2003 12:58 am 
Daniel EischenMay 29, 2003 6:28 am 
Martin BlappMay 29, 2003 6:44 am 
Daniel EischenMay 29, 2003 7:57 am 
Terry LambertMay 29, 2003 8:36 am 
Subject:malloc(): error: recursive call
From:Daniel Eischen (eisc@pcnet.com)
Date:May 28, 2003 6:23:50 pm
List:org.freebsd.freebsd-threads

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,