since 1.1.0, musl has nominally required a thread pointer to be setup.
most of the remaining code that was checking for its availability was
doing so for the sake of being usable by the dynamic linker. as of
commit
71f099cb7db821c51d8f39dfac622c61e54d794c, this is no longer
necessary; the thread pointer is now valid before any libc code
(outside of dynamic linker bootstrap functions) runs.
this commit essentially concludes "phase 3" of the "transition path
for removing lazy init of thread pointer" project that began during
the 1.1.0 release cycle.
int r = __set_thread_area(TP_ADJ(p));
if (r < 0) return -1;
if (!r) libc.can_do_threads = 1;
- libc.has_thread_pointer = 1;
td->tid = __syscall(SYS_set_tid_address, &td->tid);
td->locale = &libc.global_locale;
td->robust_list.head = &td->robust_list.head;
mem = builtin_tls;
}
- /* Failure to initialize thread pointer is fatal if TLS is used. */
- if (__init_tp(__copy_tls(mem)) < 0 && tls_phdr)
+ /* Failure to initialize thread pointer is always fatal. */
+ if (__init_tp(__copy_tls(mem)) < 0)
a_crash();
}
#else
if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t));
else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245;
- if (libc.has_thread_pointer)
- __pthread_self()->canary = __stack_chk_guard;
+ __pthread_self()->canary = __stack_chk_guard;
}
void __stack_chk_fail(void)
int *__errno_location(void)
{
- static int e;
- if (libc.has_thread_pointer) return &__pthread_self()->errno_val;
- return &e;
+ return &__pthread_self()->errno_val;
}
};
struct __libc {
- int has_thread_pointer;
int can_do_threads;
int threaded;
int secure;
- size_t *auxv;
volatile int threads_minus_1;
+ size_t *auxv;
FILE *ofl_head;
volatile int ofl_lock[2];
size_t tls_size;
/* Add a shortname only if name arg was not an explicit pathname. */
if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
if (p->tls_image) {
- if (runtime && !libc.has_thread_pointer) {
- munmap(map, p->map_len);
- free(p);
- errno = ENOSYS;
- return 0;
- }
p->tls_id = ++tls_cnt;
tls_align = MAXP2(tls_align, p->tls_align);
#ifdef TLS_ABOVE_TP
* thread pointer at runtime. */
libc.tls_size = sizeof builtin_tls;
if (__init_tp(__copy_tls((void *)builtin_tls)) < 0) {
- dprintf(2, "%s: Thread-local storage not supported by kernel.\n", argv[0]);
- _exit(127);
+ a_crash();
}
/* Find aux vector just past environ[] */
_exit(127);
}
if (__init_tp(__copy_tls(initial_tls)) < 0) {
- dprintf(2, "%s: Failed to switch to new thread pointer.\n", argv[0]);
- _exit(127);
+ a_crash();
}
} else {
size_t tmp_tls_size = libc.tls_size;
#else
ret = syscall(SYS_clone, SIGCHLD, 0);
#endif
- if (libc.has_thread_pointer && !ret) {
+ if (!ret) {
pthread_t self = __pthread_self();
self->tid = __syscall(SYS_gettid);
self->robust_list.off = 0;
long r;
int st;
- if (!libc.has_thread_pointer || (st=(self=__pthread_self())->canceldisable)
+ if ((st=(self=__pthread_self())->canceldisable)
&& (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close))
return __syscall(nr, u, v, w, x, y, z);
void __testcancel()
{
- if (!libc.has_thread_pointer) return;
pthread_t self = __pthread_self();
if (self->cancel && !self->canceldisable)
__cancel();
void __do_cleanup_push(struct __ptcb *cb)
{
- if (!libc.has_thread_pointer) return;
struct pthread *self = __pthread_self();
cb->__next = self->cancelbuf;
self->cancelbuf = cb;
void __do_cleanup_pop(struct __ptcb *cb)
{
- if (!libc.has_thread_pointer) return;
__pthread_self()->cancelbuf = cb->__next;
}
{
unsigned i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX;
unsigned j = i;
+ pthread_t self = __pthread_self();
- if (libc.has_thread_pointer) {
- pthread_t self = __pthread_self();
- /* This can only happen in the main thread before
- * pthread_create has been called. */
- if (!self->tsd) self->tsd = __pthread_tsd_main;
- }
+ /* This can only happen in the main thread before
+ * pthread_create has been called. */
+ if (!self->tsd) self->tsd = __pthread_tsd_main;
if (!dtor) dtor = nodtor;
do {
int __pthread_setcancelstate(int new, int *old)
{
if (new > 2U) return EINVAL;
- if (!libc.has_thread_pointer) return ENOSYS;
struct pthread *self = __pthread_self();
if (old) *old = self->canceldisable;
self->canceldisable = new;