From 57f6e85c9de417fef5eece2a5b00c1104321f543 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 24 Aug 2020 22:45:51 -0400 Subject: remove redundant pthread struct members repeated for layout purposes dtv_copy, canary2, and canary_at_end existed solely to match multiple ABI and asm-accessed layouts simultaneously. now that pthread_arch.h can be included before struct __pthread is defined, the struct layout can depend on macros defined by pthread_arch.h. --- src/env/__init_tls.c | 2 +- src/env/__stack_chk_fail.c | 2 +- src/internal/pthread_impl.h | 23 ++++++++++++++--------- src/thread/pthread_create.c | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c index 772baba3..a93141ed 100644 --- a/src/env/__init_tls.c +++ b/src/env/__init_tls.c @@ -67,7 +67,7 @@ void *__copy_tls(unsigned char *mem) } #endif dtv[0] = libc.tls_cnt; - td->dtv = td->dtv_copy = dtv; + td->dtv = dtv; return td; } diff --git a/src/env/__stack_chk_fail.c b/src/env/__stack_chk_fail.c index e32596d1..bf5a280a 100644 --- a/src/env/__stack_chk_fail.c +++ b/src/env/__stack_chk_fail.c @@ -9,7 +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; - __pthread_self()->CANARY = __stack_chk_guard; + __pthread_self()->canary = __stack_chk_guard; } void __stack_chk_fail(void) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index 58e06136..4d709bbc 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -11,16 +11,25 @@ #include "atomic.h" #include "futex.h" +#include "pthread_arch.h" + #define pthread __pthread struct pthread { /* Part 1 -- these fields may be external or * internal (accessed via asm) ABI. Do not change. */ struct pthread *self; +#ifndef TLS_ABOVE_TP uintptr_t *dtv; +#endif struct pthread *prev, *next; /* non-ABI */ uintptr_t sysinfo; - uintptr_t canary, canary2; +#ifndef TLS_ABOVE_TP +#ifdef CANARY_PAD + uintptr_t canary_pad; +#endif + uintptr_t canary; +#endif /* Part 2 -- implementation details, non-ABI. */ int tid; @@ -52,8 +61,10 @@ struct pthread { /* Part 3 -- the positions of these fields relative to * the end of the structure is external and internal ABI. */ - uintptr_t canary_at_end; - uintptr_t *dtv_copy; +#ifdef TLS_ABOVE_TP + uintptr_t canary; + uintptr_t *dtv; +#endif }; enum { @@ -99,12 +110,6 @@ struct __timer { #define _b_waiters2 __u.__vi[4] #define _b_inst __u.__p[3] -#include "pthread_arch.h" - -#ifndef CANARY -#define CANARY canary -#endif - #ifndef TP_OFFSET #define TP_OFFSET 0 #endif diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 10f1b7d8..55744155 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -314,7 +314,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att new->detach_state = DT_JOINABLE; } new->robust_list.head = &new->robust_list.head; - new->CANARY = self->CANARY; + new->canary = self->canary; new->sysinfo = self->sysinfo; /* Setup argument structure for the new thread on its stack. -- cgit v1.2.1