malloc(): error: recursive call

Daniel Eischen eischen at pcnet.com
Wed May 28 18:22:23 PDT 2003


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,




More information about the freebsd-threads mailing list