Index: glibc-2.21/sysdeps/mach/bits/libc-lock.h =================================================================== --- glibc-2.21.orig/sysdeps/mach/bits/libc-lock.h +++ glibc-2.21/sysdeps/mach/bits/libc-lock.h @@ -124,8 +124,15 @@ struct __libc_once #define __libc_mutex_unlock __mutex_unlock #endif -#define __libc_key_create(KEY,DEST) cthread_keycreate (KEY) -#define __libc_setspecific(KEY,VAL) cthread_setspecific (KEY, VAL) +#define __libc_ctf_call(FUNC, ARGS, ELSE) \ + (&_cthread_init_routine && _cthread_init_routine \ + ? FUNC ARGS : ELSE) + +extern void *(*_cthread_init_routine) (void) __attribute__ ((weak)); +#define __libc_key_create(KEY,DEST) \ + __libc_ctf_call (cthread_keycreate, (KEY), 1) +#define __libc_setspecific(KEY,VAL) \ + __libc_ctf_call (cthread_setspecific, (KEY, VAL), 0) void *__libc_getspecific (__libc_key_t key); /* XXX until cthreads supports recursive locks */ Index: glibc-2.21/sysdeps/mach/hurd/bits/libc-lock.h =================================================================== --- glibc-2.21.orig/sysdeps/mach/hurd/bits/libc-lock.h +++ glibc-2.21/sysdeps/mach/hurd/bits/libc-lock.h @@ -200,8 +200,15 @@ struct __libc_once /* Type for key of thread specific data. */ typedef cthread_key_t __libc_key_t; -#define __libc_key_create(KEY,DEST) cthread_keycreate (KEY) -#define __libc_setspecific(KEY,VAL) cthread_setspecific (KEY, VAL) +#define __libc_ctf_call(FUNC, ARGS, ELSE) \ + (&_cthread_init_routine && _cthread_init_routine \ + ? FUNC ARGS : ELSE) + +extern void *(*_cthread_init_routine) (void) __attribute__ ((weak)); +#define __libc_key_create(KEY,DEST) \ + __libc_ctf_call (cthread_keycreate, (KEY), 1) +#define __libc_setspecific(KEY,VAL) \ + __libc_ctf_call (cthread_setspecific, (KEY, VAL), 0) void *__libc_getspecific (__libc_key_t key); #endif /* _CTHREADS_ */ Index: glibc-2.21/sysdeps/mach/hurd/cthreads.c =================================================================== --- glibc-2.21.orig/sysdeps/mach/hurd/cthreads.c +++ glibc-2.21/sysdeps/mach/hurd/cthreads.c @@ -55,14 +55,11 @@ cthread_setspecific (key, val) return -1; } -/* Call cthread_getspecific which gets a pointer to the return value instead - of just returning it. */ +/* Follow NPTL, return NULL when pthread is not available. */ void * weak_function __libc_getspecific (key) cthread_key_t key; { - void *val; - cthread_getspecific (key, &val); - return val; + return NULL; }