From cc4ce2ed94f555fa1bc7e217bd4ec367507e41b3 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 24 May 2022 16:23:43 +0800 Subject: [PATCH] pass elftls/elftls_dl --- libc/bionic/bionic_elf_tls.cpp | 8 -------- libc/private/bionic_elf_tls.h | 2 ++ linker/linker.cpp | 2 +- linker/linker_relocate.cpp | 2 +- linker/linker_relocs.h | 1 + 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/libc/bionic/bionic_elf_tls.cpp b/libc/bionic/bionic_elf_tls.cpp index 6de51eb38..15d383b61 100644 --- a/libc/bionic/bionic_elf_tls.cpp +++ b/libc/bionic/bionic_elf_tls.cpp @@ -323,11 +323,7 @@ __attribute__((noinline)) static void* tls_get_addr_slow_path(const TlsIndex* ti } } -#if (defined(__riscv) && (__riscv_xlen == 64)) return static_cast(mod_ptr) + ti->offset + TLS_DTV_OFFSET; -#else - return static_cast(mod_ptr) + ti->offset; -#endif } // Returns the address of a thread's TLS memory given a module ID and an offset @@ -347,11 +343,7 @@ extern "C" void* TLS_GET_ADDR(const TlsIndex* ti) TLS_GET_ADDR_CCONV { if (__predict_true(generation == dtv->generation)) { void* mod_ptr = dtv->modules[__tls_module_id_to_idx(ti->module_id)]; if (__predict_true(mod_ptr != nullptr)) { -#if (defined(__riscv) && (__riscv_xlen == 64)) return static_cast(mod_ptr) + ti->offset + TLS_DTV_OFFSET; -#else - return static_cast(mod_ptr) + ti->offset; -#endif } } diff --git a/libc/private/bionic_elf_tls.h b/libc/private/bionic_elf_tls.h index 57db3425a..04e353c9c 100644 --- a/libc/private/bionic_elf_tls.h +++ b/libc/private/bionic_elf_tls.h @@ -213,4 +213,6 @@ void __notify_thread_exit_callbacks(); // [2]: Documentation of TLS data structures // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/53 #define TLS_DTV_OFFSET 0x800 +#else +#define TLS_DTV_OFFSET 0 #endif diff --git a/linker/linker.cpp b/linker/linker.cpp index 3488f5cc7..6af2a9540 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -371,7 +371,7 @@ static inline void* get_tls_block_for_this_thread(const soinfo_tls* si_tls, bool char* static_tls = reinterpret_cast(__get_bionic_tcb()) - layout.offset_bionic_tcb(); return static_tls + tls_mod.static_offset; } else if (should_alloc) { - const TlsIndex ti { si_tls->module_id, 0 }; + const TlsIndex ti { si_tls->module_id, static_cast(0 - TLS_DTV_OFFSET) }; return TLS_GET_ADDR(&ti); } else { TlsDtv* dtv = __get_tcb_dtv(__get_bionic_tcb()); diff --git a/linker/linker_relocate.cpp b/linker/linker_relocate.cpp index 72be5f74c..0198e9221 100644 --- a/linker/linker_relocate.cpp +++ b/linker/linker_relocate.cpp @@ -413,7 +413,7 @@ static bool process_relocation_impl(Relocator& relocator, const rel_t& reloc) { case R_GENERIC_TLS_DTPREL: count_relocation_if(kRelocRelative); { - const ElfW(Addr) result = sym_addr + get_addend_rel(); + const ElfW(Addr) result = sym_addr + get_addend_rel() - TLS_DTV_OFFSET; trace_reloc("RELO TLS_DTPREL %16p <- %16p %s", rel_target, reinterpret_cast(result), sym_name); *static_cast(rel_target) = result; diff --git a/linker/linker_relocs.h b/linker/linker_relocs.h index 375a0764e..e53499ce4 100644 --- a/linker/linker_relocs.h +++ b/linker/linker_relocs.h @@ -97,6 +97,7 @@ #define R_GENERIC_TLS_DTPMOD R_RISCV_TLS_DTPMOD64 #define R_GENERIC_TLS_DTPREL R_RISCV_TLS_DTPREL64 #define R_GENERIC_TLS_TPREL R_RISCV_TLS_TPREL64 +// TBD: riscv has not supported TLSDESC actually. #define R_GENERIC_TLSDESC R_RISCV_TLS_GOT_HI20 #endif -- Gitee