about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/env/__init_tls.c5
-rw-r--r--src/env/__stack_chk_fail.c3
-rw-r--r--src/errno/__errno_location.c4
-rw-r--r--src/internal/libc.h3
-rw-r--r--src/ldso/dynlink.c12
-rw-r--r--src/process/fork.c2
-rw-r--r--src/thread/pthread_cancel.c3
-rw-r--r--src/thread/pthread_create.c2
-rw-r--r--src/thread/pthread_key_create.c10
-rw-r--r--src/thread/pthread_setcancelstate.c1
10 files changed, 13 insertions, 32 deletions
diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c
index ac4d9e7f..67f14094 100644
--- a/src/env/__init_tls.c
+++ b/src/env/__init_tls.c
@@ -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
diff --git a/src/env/__stack_chk_fail.c b/src/env/__stack_chk_fail.c
index 87ac473d..cc55460b 100644
--- a/src/env/__stack_chk_fail.c
+++ b/src/env/__stack_chk_fail.c
@@ -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)
diff --git a/src/errno/__errno_location.c b/src/errno/__errno_location.c
index 49654efd..7172a1be 100644
--- a/src/errno/__errno_location.c
+++ b/src/errno/__errno_location.c
@@ -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;
 }
diff --git a/src/internal/libc.h b/src/internal/libc.h
index 3751cca2..79d53fc8 100644
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -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;
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 31f59392..8b15daa2 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -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;
diff --git a/src/process/fork.c b/src/process/fork.c
index 8d676828..b96f0024 100644
--- a/src/process/fork.c
+++ b/src/process/fork.c
@@ -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;
diff --git a/src/thread/pthread_cancel.c b/src/thread/pthread_cancel.c
index a507f923..7c5dda31 100644
--- a/src/thread/pthread_cancel.c
+++ b/src/thread/pthread_cancel.c
@@ -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();
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index 33808ce5..6963f0d6 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -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;
 }
 
diff --git a/src/thread/pthread_key_create.c b/src/thread/pthread_key_create.c
index 198ae56e..a78e507a 100644
--- a/src/thread/pthread_key_create.c
+++ b/src/thread/pthread_key_create.c
@@ -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 {
diff --git a/src/thread/pthread_setcancelstate.c b/src/thread/pthread_setcancelstate.c
index 822a1398..5ab8c338 100644
--- a/src/thread/pthread_setcancelstate.c
+++ b/src/thread/pthread_setcancelstate.c
@@ -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;