Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/coreclr/vm/riscv64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LEAF_ENTRY GetCurrentIP, _TEXT
ret
LEAF_END GetCurrentIP, _TEXT

// void* GetCurrentSP(void)//
// LPVOID __stdcall GetCurrentSP(void)//
LEAF_ENTRY GetCurrentSP, _TEXT
addi a0, sp, 0
ret
Expand Down Expand Up @@ -848,10 +848,14 @@ LEAF_END JIT_PatchpointForced, _TEXT
// size_t GetThreadStaticsVariableOffset()

// Load offset of native thread local variable `t_ThreadStatics` in TCB and return it in `a0` register.
#if !defined(TARGET_LINUX_MUSL)
// Uses initial-exec TLS model which is faster but incompatible with musl's dynamic loading.
// On musl, this function is not compiled and the optimization is disabled in threadstatics.cpp.
LEAF_ENTRY GetThreadStaticsVariableOffset, _TEXT
la.tls.ie a0, t_ThreadStatics
EPILOG_RETURN
LEAF_END GetThreadStaticsVariableOffset, _TEXT
#endif // !TARGET_LINUX_MUSL

LEAF_ENTRY JIT_PollGC, _TEXT
PREPARE_EXTERNAL_VAR g_TrapReturningThreads, t0
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/vm/threadstatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ bool CanJITOptimizeTLSAccess()
// Optimization is disabled for linux/x86
#elif defined(TARGET_LINUX_MUSL) && defined(TARGET_ARM64)
// Optimization is disabled for linux musl arm64
#elif defined(TARGET_LINUX_MUSL) && defined(TARGET_RISCV64)
// Optimization is disabled for linux musl riscv64
#elif defined(TARGET_FREEBSD) && defined(TARGET_ARM64)
// Optimization is disabled for FreeBSD/arm64
#elif defined(TARGET_ANDROID)
Expand Down Expand Up @@ -1096,7 +1098,10 @@ void GetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo)
// For Linux arm64/loongarch64/riscv64, just get the offset of thread static variable, and during execution,
// this offset, arm64 taken from trpid_elp0 system register gives back the thread variable address.
// this offset, loongarch64 taken from $tp register gives back the thread variable address.
#if !(defined(TARGET_LINUX_MUSL) && defined(TARGET_RISCV64))
// On musl riscv64, this optimization is disabled due to initial-exec TLS incompatibility.
threadStaticBaseOffset = GetThreadStaticsVariableOffset();
#endif

#else
_ASSERTE_MSG(false, "Unsupported scenario of optimizing TLS access on Linux Arm32/x86 and Android");
Expand Down