提交 19a1fe67 编写于 作者: R Rich Felker

remove remnants of support for running in no-thread-pointer mode

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 71f099cb, 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.
上级 71f099cb
......@@ -15,7 +15,6 @@ int __init_tp(void *p)
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;
......@@ -112,8 +111,8 @@ void __init_tls(size_t *aux)
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
......
......@@ -9,8 +9,7 @@ void __init_ssp(void *entropy)
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)
......
......@@ -2,7 +2,5 @@
int *__errno_location(void)
{
static int e;
if (libc.has_thread_pointer) return &__pthread_self()->errno_val;
return &e;
return &__pthread_self()->errno_val;
}
......@@ -14,12 +14,11 @@ struct __locale_struct {
};
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;
......
......@@ -810,12 +810,6 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
/* 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
......@@ -1165,8 +1159,7 @@ _Noreturn void __dls3(size_t *sp)
* 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[] */
......@@ -1352,8 +1345,7 @@ _Noreturn void __dls3(size_t *sp)
_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;
......
......@@ -22,7 +22,7 @@ pid_t fork(void)
#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;
......
......@@ -30,7 +30,7 @@ long __syscall_cp_c(syscall_arg_t nr,
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);
......@@ -69,7 +69,6 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
void __testcancel()
{
if (!libc.has_thread_pointer) return;
pthread_t self = __pthread_self();
if (self->cancel && !self->canceldisable)
__cancel();
......
......@@ -122,7 +122,6 @@ _Noreturn void __pthread_exit(void *result)
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;
......@@ -130,7 +129,6 @@ void __do_cleanup_push(struct __ptcb *cb)
void __do_cleanup_pop(struct __ptcb *cb)
{
if (!libc.has_thread_pointer) return;
__pthread_self()->cancelbuf = cb->__next;
}
......
......@@ -13,13 +13,11 @@ int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
{
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 {
......
......@@ -3,7 +3,6 @@
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册