Date: Fri, 15 Sep 2000 17:37:37 -0700 (PDT) From: John Polstra <jdp@polstra.com> To: hackers@freebsd.org Cc: fjoe@iclub.nsu.ru Subject: Re: Trouble with dynamic loading of C++ libs in PHP v4.02 on FreeBSD 4.1 Message-ID: <200009160037.RAA06418@vashon.polstra.com> In-Reply-To: <Pine.BSF.4.21.0009152318270.78659-300000@iclub.nsu.ru> References: <Pine.BSF.4.21.0009152318270.78659-300000@iclub.nsu.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
In article <Pine.BSF.4.21.0009152318270.78659-300000@iclub.nsu.ru>,
Max Khon <fjoe@iclub.nsu.ru> wrote:
>
> `__register_frame_info' should be called from `do_ctors' in
> src/lib/csu/common/crtbegin.c to load frame information from .eh_frame
> sections before any constructors are executed because try/catch can be
> used in constructors of static objects (`__register_frame_info'
> is defined in src/contrib/gcc/frame.c, this file is linked into
> libgcc[_r].a). however `__register_frame_info' uses locks and other
> threading stuff (using pthreads on FreeBSD) so we must have pthreads
> initialized before locks are used.
>
> another issue with our pthreads initialization is that pthreads can be
> used in static object constructors so the first `pthread_xxx' call can
> happen before `_thread_init' is called from constructor of our
> _thread_init_invoker (it depends on order in which constructors are placed
> in .ctors section).
>
> I see two solutions (both seem to be hacks for me):
> 1) we can insert if (!initted) ... in `pthread_once' (this seem to be the
> first pthreads function called from __register_frame_info)
> 2) we can insert
>
> #if __GTHREADS
> _thread_init();
> #endif
>
> at the very beginning of `__register_frame_info'
>
> The second approach seems to be cleaner but require changes in
> src/contrib/gcc/
Here is another possibility: we could call _thread_init() from
crt1.o. The patch (untested) is below. It calls _thread_init() if
and only if that symbol is defined -- i.e., libc_r is linked in.
What do you think about this solution?
John
Index: crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v
retrieving revision 1.4
diff -u -r1.4 crt1.c
--- crt1.c 1999/08/27 23:57:57 1.4
+++ crt1.c 2000/09/16 00:30:51
@@ -48,6 +48,9 @@
extern int _DYNAMIC;
#pragma weak _DYNAMIC
+extern void _thread_init(void);
+#pragma weak _thread_init
+
#ifdef __i386__
#define get_rtld_cleanup() \
({ fptr __value; \
@@ -91,6 +94,8 @@
#ifdef GCRT
monstartup(&eprol, &etext);
#endif
+ if (&_thread_init != NULL)
+ _thread_init();
_init();
exit( main(argc, argv, env) );
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009160037.RAA06418>
