diff options
Diffstat (limited to 'lib/libpthread/uthread')
-rw-r--r-- | lib/libpthread/uthread/uthread_autoinit.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/lib/libpthread/uthread/uthread_autoinit.c b/lib/libpthread/uthread/uthread_autoinit.c index 197b7fb83c6..5ac4592e61c 100644 --- a/lib/libpthread/uthread/uthread_autoinit.c +++ b/lib/libpthread/uthread/uthread_autoinit.c @@ -1,52 +1,79 @@ +/* + * David Leonard, 1998. Public Domain. <david.leonard@csee.uq.edu.au> + * + * $OpenBSD: uthread_autoinit.c,v 1.4 1999/01/10 23:07:59 d Exp $ + */ #include <stdio.h> #include <pthread.h> #include "pthread_private.h" +__BEGIN_DECLS extern void _thread_init __P((void)); +__END_DECLS + +#ifdef DEBUG +#define init_debug(m) stderr_debug(m) +#else +#define init_debug(m) /* nothing */ +#endif -#ifdef __cplusplus /* - * Use C++ static initialiser + * Use C++'s static instance constructor to initialise threads. */ +#ifdef __cplusplus class Init { public: - Init() { _thread_init(); } + Init() { + init_debug("init: C++\n"); + _thread_init(); + } }; Init _thread_initialiser; #endif /* C++ */ /* - * a.out ld.so initialisation + * The a.out ld.so dynamic linker calls the function + * at symbol ".init" if it exists, just after linkage. */ extern void _thread_dot_init __P((void)) asm(".init"); void _thread_dot_init() { + init_debug("init: a.out .init\n"); _thread_init(); } -#ifdef mips /* - * elf ld.so initialisation + * The GNU ELF loader will place a function called _init + * found in the .dynamic section into the _INIT field. This then gets + * automatically run by GNU ELF's ld.so. */ +#ifdef mips extern int _init() __attribute__((constructor,section (".dynamic"))); int _init() { + init_debug("init: elf _init\n"); _thread_init(); return 0; } #endif /* mips */ -#ifdef _GNUC_ /* - * GNU CTOR_LIST constructor + * A GNU C installation may know how to automatically run + * constructors for other architectures. (It doesn't matter if + * we initialise multiple times.) This construct places + * the function in the __CTOR_LIST__ entry in the object, and later + * the collect2 stage of linkage will inform __main (from libgcc.a) + * to call it. */ +#ifdef _GNUC_ void _thread_init_constructor __P((void)) __attribute__((constructor)); void _thread_init_constructor() { + init_debug("init: GNU constructor"); _thread_init(); } #endif /* GNU C */ |