166 lines
4.8 KiB
Diff
166 lines
4.8 KiB
Diff
From 57f6e85c9de417fef5eece2a5b00c1104321f543 Mon Sep 17 00:00:00 2001
|
|
From: Rich Felker <dalias@aerifal.cx>
|
|
Date: Mon, 24 Aug 2020 22:45:51 -0400
|
|
Subject: [PATCH 2/2] 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.
|
|
---
|
|
arch/powerpc/pthread_arch.h | 2 --
|
|
arch/powerpc64/pthread_arch.h | 2 --
|
|
arch/x32/pthread_arch.h | 2 +-
|
|
ldso/dynlink.c | 2 +-
|
|
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 +-
|
|
8 files changed, 19 insertions(+), 18 deletions(-)
|
|
|
|
diff --git a/arch/powerpc/pthread_arch.h b/arch/powerpc/pthread_arch.h
|
|
index a0947763..42e88b07 100644
|
|
--- a/arch/powerpc/pthread_arch.h
|
|
+++ b/arch/powerpc/pthread_arch.h
|
|
@@ -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
|
|
diff --git a/arch/powerpc64/pthread_arch.h b/arch/powerpc64/pthread_arch.h
|
|
index 08a557d2..1b7b9079 100644
|
|
--- a/arch/powerpc64/pthread_arch.h
|
|
+++ b/arch/powerpc64/pthread_arch.h
|
|
@@ -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
|
|
diff --git a/arch/x32/pthread_arch.h b/arch/x32/pthread_arch.h
|
|
index 6e2495da..c1e7716d 100644
|
|
--- a/arch/x32/pthread_arch.h
|
|
+++ b/arch/x32/pthread_arch.h
|
|
@@ -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
|
|
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
|
|
index d3d4ddd2..f7474743 100644
|
|
--- a/ldso/dynlink.c
|
|
+++ b/ldso/dynlink.c
|
|
@@ -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();
|
|
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.
|
|
--
|
|
2.47.0
|
|
|