>From 9aed146bb46b2ba5fbef5cdba5972ce1f8855d87 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 19 Jun 2026 18:27:34 +0000 Subject: [PATCH 2/2] tls: rename GAP_ABOVE_TP to EXE_TLS_GAP in the TLS_ABOVE_TP layout tp - TP_OFFSET is aligned to libc.tls_align, and the tls of the main exe is at tp - TP_OFFSET + EXE_TLS_GAP aligned up as needed. so the old name was misleading with TP_OFFSET != 0. rename and default to 0, no change of logic otherwise. --- arch/aarch64/pthread_arch.h | 2 +- arch/arm/pthread_arch.h | 2 +- arch/loongarch64/pthread_arch.h | 2 -- arch/m68k/pthread_arch.h | 1 - arch/mips/pthread_arch.h | 1 - arch/mips64/pthread_arch.h | 1 - arch/mipsn32/pthread_arch.h | 1 - arch/or1k/pthread_arch.h | 2 +- arch/powerpc/pthread_arch.h | 1 - arch/powerpc64/pthread_arch.h | 1 - arch/riscv32/pthread_arch.h | 1 - arch/riscv64/pthread_arch.h | 1 - arch/sh/pthread_arch.h | 2 +- ldso/dynlink.c | 4 ++-- src/env/__init_tls.c | 4 ++-- src/internal/pthread_impl.h | 4 ++++ 16 files changed, 12 insertions(+), 18 deletions(-) diff --git a/arch/aarch64/pthread_arch.h b/arch/aarch64/pthread_arch.h index 3909616c..7129e060 100644 --- a/arch/aarch64/pthread_arch.h +++ b/arch/aarch64/pthread_arch.h @@ -6,6 +6,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 16 +#define EXE_TLS_GAP 16 #define MC_PC pc diff --git a/arch/arm/pthread_arch.h b/arch/arm/pthread_arch.h index 157e2eae..e8e492bb 100644 --- a/arch/arm/pthread_arch.h +++ b/arch/arm/pthread_arch.h @@ -27,6 +27,6 @@ static inline uintptr_t __get_tp() #endif #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 8 +#define EXE_TLS_GAP 8 #define MC_PC arm_pc diff --git a/arch/loongarch64/pthread_arch.h b/arch/loongarch64/pthread_arch.h index 365f6ca8..1657ecf0 100644 --- a/arch/loongarch64/pthread_arch.h +++ b/arch/loongarch64/pthread_arch.h @@ -6,6 +6,4 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 -#define DTP_OFFSET 0 #define MC_PC __pc diff --git a/arch/m68k/pthread_arch.h b/arch/m68k/pthread_arch.h index 5bea4e1a..b41d8160 100644 --- a/arch/m68k/pthread_arch.h +++ b/arch/m68k/pthread_arch.h @@ -4,7 +4,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define TP_OFFSET 0x7000 #define DTP_OFFSET 0x8000 diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h index 376b7741..2d1f504e 100644 --- a/arch/mips/pthread_arch.h +++ b/arch/mips/pthread_arch.h @@ -10,7 +10,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define TP_OFFSET 0x7000 #define DTP_OFFSET 0x8000 diff --git a/arch/mips64/pthread_arch.h b/arch/mips64/pthread_arch.h index c45347ab..f5f7ce2f 100644 --- a/arch/mips64/pthread_arch.h +++ b/arch/mips64/pthread_arch.h @@ -11,7 +11,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define TP_OFFSET 0x7000 #define DTP_OFFSET 0x8000 diff --git a/arch/mipsn32/pthread_arch.h b/arch/mipsn32/pthread_arch.h index c45347ab..f5f7ce2f 100644 --- a/arch/mipsn32/pthread_arch.h +++ b/arch/mipsn32/pthread_arch.h @@ -11,7 +11,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define TP_OFFSET 0x7000 #define DTP_OFFSET 0x8000 diff --git a/arch/or1k/pthread_arch.h b/arch/or1k/pthread_arch.h index 97197c8e..90c41673 100644 --- a/arch/or1k/pthread_arch.h +++ b/arch/or1k/pthread_arch.h @@ -11,7 +11,7 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 16 +#define EXE_TLS_GAP 16 #define TP_OFFSET 16 #define MC_PC regs.pc diff --git a/arch/powerpc/pthread_arch.h b/arch/powerpc/pthread_arch.h index 42e88b07..02cb9cf8 100644 --- a/arch/powerpc/pthread_arch.h +++ b/arch/powerpc/pthread_arch.h @@ -6,7 +6,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define TP_OFFSET 0x7000 #define DTP_OFFSET 0x8000 diff --git a/arch/powerpc64/pthread_arch.h b/arch/powerpc64/pthread_arch.h index 1b7b9079..aaf817d9 100644 --- a/arch/powerpc64/pthread_arch.h +++ b/arch/powerpc64/pthread_arch.h @@ -6,7 +6,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define TP_OFFSET 0x7000 #define DTP_OFFSET 0x8000 diff --git a/arch/riscv32/pthread_arch.h b/arch/riscv32/pthread_arch.h index a20d7fba..e3c226c8 100644 --- a/arch/riscv32/pthread_arch.h +++ b/arch/riscv32/pthread_arch.h @@ -6,7 +6,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define DTP_OFFSET 0x800 diff --git a/arch/riscv64/pthread_arch.h b/arch/riscv64/pthread_arch.h index a20d7fba..e3c226c8 100644 --- a/arch/riscv64/pthread_arch.h +++ b/arch/riscv64/pthread_arch.h @@ -6,7 +6,6 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 0 #define DTP_OFFSET 0x800 diff --git a/arch/sh/pthread_arch.h b/arch/sh/pthread_arch.h index 199c2d55..2b42f5fe 100644 --- a/arch/sh/pthread_arch.h +++ b/arch/sh/pthread_arch.h @@ -6,7 +6,7 @@ static inline uintptr_t __get_tp() } #define TLS_ABOVE_TP -#define GAP_ABOVE_TP 8 +#define EXE_TLS_GAP 8 #define MC_PC pc diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 0d43f27b..2f78e4cf 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1930,8 +1930,8 @@ void __dls3(size_t *sp, size_t *auxv) libc.tls_head = tls_tail = &app.tls; app.tls_id = tls_cnt = 1; #ifdef TLS_ABOVE_TP - app.tls.offset = GAP_ABOVE_TP; - app.tls.offset += (-GAP_ABOVE_TP + (uintptr_t)app.tls.image) + app.tls.offset = EXE_TLS_GAP; + app.tls.offset += (-EXE_TLS_GAP + (uintptr_t)app.tls.image) & (app.tls.align-1); tls_offset = app.tls.offset + app.tls.size; #else diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c index a93141ed..91ec89d2 100644 --- a/src/env/__init_tls.c +++ b/src/env/__init_tls.c @@ -114,8 +114,8 @@ static void static_init_tls(size_t *aux) main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) & (main_tls.align-1); #ifdef TLS_ABOVE_TP - main_tls.offset = GAP_ABOVE_TP; - main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) + main_tls.offset = EXE_TLS_GAP; + main_tls.offset += (-EXE_TLS_GAP + (uintptr_t)main_tls.image) & (main_tls.align-1); #else main_tls.offset = main_tls.size; diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index de2b9d8b..cfffedf9 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -106,6 +106,10 @@ enum { #define _b_waiters2 __u.__vi[4] #define _b_inst __u.__p[3] +#ifndef EXE_TLS_GAP +#define EXE_TLS_GAP 0 +#endif + #ifndef TP_OFFSET #define TP_OFFSET 0 #endif -- 2.52.0