Subject: Re: bin/37347: ld.elf_so does not execute .init/.fini functions in order
To: None <gnats-bugs@NetBSD.org>
From: Andrew Doran <ad@netbsd.org>
List: netbsd-bugs
Date: 11/11/2007 01:54:03
On Fri, Nov 09, 2007 at 06:20:01AM +0000, J.T. Conklin wrote:
> As reported in recent messages to tech-userland, I encountered
> problems with ACE (A C++ Library/Framework) and TAO (A CORBA ORB
> implementation that uses ACE) because TAO's static constructors
> used the pthread library to create thread specific storage before
> the pthread library was initialized itself.
I have tried out the supplied patch and it works for me on -current with
free -> xfree. There is another problem: I see a lot of calls into
libpthread before it is initialized, and those calls are made from within
libc.
I think that the setup for libpthread should happen via a constructor in
libc, which solves the problem for me. Below is the libc bit; in libpthread
we just override __libc_thr_init().
Thanks,
Andrew
Index: lib/libc/thread-stub/thread-stub.c
===================================================================
RCS file: /cvsroot/src/lib/libc/thread-stub/thread-stub.c,v
retrieving revision 1.14
diff -u -p -r1.14 thread-stub.c
--- lib/libc/thread-stub/thread-stub.c 29 Nov 2005 03:12:00 -0000 1.14
+++ lib/libc/thread-stub/thread-stub.c 11 Nov 2007 01:46:42 -0000
@@ -74,6 +74,28 @@ do { \
#define CHECK_NOT_THREADED() /* nothing */
#endif
+/* libpthread init */
+
+void __libc_thr_init(void);
+void __libc_thr_init_stub(void);
+void __libc_thr_constructor(void) __attribute__((__constructor__));
+
+__weak_alias(__libc_thr_init,__libc_thr_init_stub)
+
+void
+__libc_thr_constructor(void)
+{
+
+ __libc_thr_init();
+}
+
+void
+__libc_thr_init_stub(void)
+{
+
+ /* nothing, may be overridden by libpthread */
+}
+
/* mutexes */
int __libc_mutex_init_stub(mutex_t *, const mutexattr_t *);