summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pthread/pt-internal.h17
-rw-r--r--sysdeps/mach/hurd/pt-sysdep.c34
2 files changed, 35 insertions, 16 deletions
diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h
index 84964bf..18b5b4c 100644
--- a/pthread/pt-internal.h
+++ b/pthread/pt-internal.h
@@ -35,6 +35,10 @@
#include <pt-sysdep.h>
#include <pt-machdep.h>
+#if IS_IN (libpthread)
+# include <ldsodefs.h>
+#endif
+
/* Thread state. */
enum pthread_state
{
@@ -323,17 +327,4 @@ const struct __pthread_rwlockattr __pthread_default_rwlockattr;
/* Default condition attributes. */
const struct __pthread_condattr __pthread_default_condattr;
-
-#ifdef ENABLE_TLS
-
-/* From glibc. */
-
-/* Dynamic linker TLS allocation. */
-extern void *_dl_allocate_tls(void *);
-
-/* Dynamic linker TLS deallocation. */
-extern void _dl_deallocate_tls(void *, int);
-
-#endif /* ENABLE_TLS */
-
#endif /* pt-internal.h */
diff --git a/sysdeps/mach/hurd/pt-sysdep.c b/sysdeps/mach/hurd/pt-sysdep.c
index 8d40185..b23d9df 100644
--- a/sysdeps/mach/hurd/pt-sysdep.c
+++ b/sysdeps/mach/hurd/pt-sysdep.c
@@ -39,16 +39,31 @@ void *(*_cthread_init_routine)(void) = &init_routine;
should return a new stack pointer for the main thread. The caller
will switch to this new stack before doing anything serious. */
static void *
-init_routine (void)
+_init_routine (void *stack)
{
struct __pthread *thread;
int err;
+ pthread_attr_t attr, *attrp = 0;
+
+ if (__pthread_threads)
+ /* Already initialized */
+ return 0;
/* Initialize the library. */
- ___pthread_init ();
+ __pthread_init ();
+
+ if (stack)
+ {
+ /* We are getting initialized due to dlopening a library using libpthread
+ while the main program was not linked against libpthread. */
+ /* Avoid allocating another stack */
+ attrp = &attr;
+ pthread_attr_init(attrp);
+ pthread_attr_setstack(attrp, __libc_stack_end, __vm_page_size);
+ }
/* Create the pthread structure for the main thread (i.e. us). */
- err = __pthread_create_internal (&thread, 0, 0, 0);
+ err = __pthread_create_internal (&thread, attrp, 0, 0);
assert_perror (err);
/* XXX The caller copies the command line arguments and the environment
@@ -68,3 +83,16 @@ init_routine (void)
return thread->mcontext.sp;
}
+
+static void *
+init_routine (void)
+{
+ return _init_routine (0);
+}
+
+#ifdef SHARED
+__attribute__ ((constructor)) static void dynamic_init_routine(void)
+{
+ _init_routine (__libc_stack_end);
+}
+#endif