diff --git a/libc/bionic/bionic_elf_tls.cpp b/libc/bionic/bionic_elf_tls.cpp index cce36c9f97cbeac5ab4d49a28957aa4dcc811206..8ab9a39eaed8df0d82f08a04f579bbf69050d831 100644 --- a/libc/bionic/bionic_elf_tls.cpp +++ b/libc/bionic/bionic_elf_tls.cpp @@ -140,7 +140,11 @@ size_t StaticTlsLayout::reserve_exe_segment_and_tcb(const TlsSegment* exe_segmen #elif __riscv_xlen == 64 // FIXME: Align TCB block and EXE's segment more accurate. For current implementation, // alignment requirement is not considered carefully. + + // First reserve enough space for the TCB before the executable segment. offset_bionic_tcb_ = reserve(sizeof(bionic_tcb), 1); + + // Then reserve the segment itself. const size_t exe_size = round_up_with_overflow_check(exe_segment->size, exe_segment->alignment); return reserve(exe_size, 1); diff --git a/libc/platform/bionic/tls_defines.h b/libc/platform/bionic/tls_defines.h index 225e32301efd7411c22e8a9a7f251338c9824da6..c8e6b150ee1fcc5f7811f0923cd16ff109ee47aa 100644 --- a/libc/platform/bionic/tls_defines.h +++ b/libc/platform/bionic/tls_defines.h @@ -96,19 +96,19 @@ #elif __riscv_xlen == 64 -#define MIN_TLS_SLOT -10 - -#define TLS_SLOT_SELF -10 -#define TLS_SLOT_THREAD_ID -9 -#define TLS_SLOT_APP -8 // was historically used for errno -#define TLS_SLOT_OPENGL -7 -#define TLS_SLOT_OPENGL_API -6 -#define TLS_SLOT_STACK_GUARD -5 -#define TLS_SLOT_SANITIZER -4 // was historically used for dlerror -#define TLS_SLOT_ART_THREAD_SELF -3 -#define TLS_SLOT_DTV -2 -#define TLS_SLOT_BIONIC_TLS -1 -#define MAX_TLS_SLOT -1 // update this value when reserving a slot +#define MIN_TLS_SLOT (-9) // update this value when reserving a slot +#define TLS_SLOT_BIONIC_TLS (-9) +#define TLS_SLOT_DTV (-8) +#define TLS_SLOT_THREAD_ID (-7) +#define TLS_SLOT_APP (-6) // was historically used for errno +#define TLS_SLOT_OPENGL (-5) +#define TLS_SLOT_OPENGL_API (-4) +#define TLS_SLOT_STACK_GUARD (-3) +#define TLS_SLOT_SANITIZER (-2) // was historically used for dlerror +#define TLS_SLOT_ART_THREAD_SELF (-1) + +// The maximum slot is fixed by the minimum TLS alignment in Bionic executables. +#define MAX_TLS_SLOT (-1) #elif defined(__i386__) || defined(__x86_64__)