diff --git a/libc/platform/bionic/tls_defines.h b/libc/platform/bionic/tls_defines.h index 31481c30405062f1be04f6553a6deb1f9ef27edd..c089ea700ee0e937070927ed62dc9a548e1644ca 100644 --- a/libc/platform/bionic/tls_defines.h +++ b/libc/platform/bionic/tls_defines.h @@ -116,6 +116,13 @@ #elif (defined(__riscv) && (__riscv_xlen == 64)) +// RISC-V ELF Specification[1] specifies that: RISC-V uses Variant I as described +// by the ELF TLS specification, with tp containing the address one past the end +// of the TCB. +// +// [1]: RISC-V ELF Specification. Section: Thread Local Storage +// https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#thread-local-storage + #define MIN_TLS_SLOT (-9) // update this value when reserving a slot #define TLS_SLOT_BIONIC_TLS (-9) @@ -127,8 +134,6 @@ #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) #endif diff --git a/libc/private/bionic_elf_tls.h b/libc/private/bionic_elf_tls.h index 6223b3ca9cbe524457406ef531cae2ca5b0b82db..57db3425a364867dfab95f5584e3dbc9f2ee2597 100644 --- a/libc/private/bionic_elf_tls.h +++ b/libc/private/bionic_elf_tls.h @@ -203,5 +203,14 @@ void __free_dynamic_tls(bionic_tcb* tcb); void __notify_thread_exit_callbacks(); #if (defined(__riscv) && (__riscv_xlen == 64)) +// TLS_DTV_OFFSET is a constant used in relocation fields, defined in RISC-V ELF Specification[1] +// The front of the TCB contains a pointer to the DTV, and each pointer in DTV +// points to 0x800 past the start of a TLS block to make full use of the range +// of load/store instructions, refer to [2]. +// +// [1]: RISC-V ELF Specification. +// https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#constants +// [2]: Documentation of TLS data structures +// https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/53 #define TLS_DTV_OFFSET 0x800 #endif