remove redundant pthread struct members repeated for layout purposes
authorRich Felker <dalias@aerifal.cx>
Tue, 25 Aug 2020 02:45:51 +0000 (22:45 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 27 Aug 2020 22:36:45 +0000 (18:36 -0400)
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.

arch/powerpc/pthread_arch.h
arch/powerpc64/pthread_arch.h
arch/x32/pthread_arch.h
ldso/dynlink.c
src/env/__init_tls.c
src/env/__stack_chk_fail.c
src/internal/pthread_impl.h
src/thread/pthread_create.c

index a094776..42e88b0 100644 (file)
@@ -14,5 +14,3 @@ static inline uintptr_t __get_tp()
 // the kernel calls the ip "nip", it's the first saved value after the 32
 // GPRs.
 #define MC_PC gregs[32]
-
-#define CANARY canary_at_end
index 08a557d..1b7b907 100644 (file)
@@ -14,5 +14,3 @@ static inline uintptr_t __get_tp()
 // the kernel calls the ip "nip", it's the first saved value after the 32
 // GPRs.
 #define MC_PC gp_regs[32]
-
-#define CANARY canary_at_end
index 6e2495d..c1e7716 100644 (file)
@@ -7,6 +7,6 @@ static inline uintptr_t __get_tp()
 
 #define MC_PC gregs[REG_RIP]
 
-#define CANARY canary2
+#define CANARY_PAD
 
 #define tls_mod_off_t unsigned long long
index d3d4ddd..f747474 100644 (file)
@@ -1579,7 +1579,7 @@ static void install_new_tls(void)
 
        /* Install new dtv for each thread. */
        for (j=0, td=self; !j || td!=self; j++, td=td->next) {
-               td->dtv = td->dtv_copy = newdtv[j];
+               td->dtv = newdtv[j];
        }
 
        __tl_unlock();
index 772baba..a93141e 100644 (file)
@@ -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;
 }
 
index e32596d..bf5a280 100644 (file)
@@ -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)
index 58e0613..4d709bb 100644 (file)
 #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
index 10f1b7d..5574415 100644 (file)
@@ -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.