Use tls_model("global-dynamic") for JKRHeap on GCC

This commit is contained in:
Luke Street
2026-02-28 13:16:42 -07:00
parent 6340087698
commit f38dcf3aef
+8 -1
View File
@@ -31,7 +31,14 @@ JKRHeap* JKRHeap::sSystemHeap;
#if TARGET_PC
// JSystem normally has a thread switch callback to track the correct heap.
// We can't do this as we're (currently) using true OS threads. So use a true thread local.
static thread_local JKRHeap* sCurrentHeap;
// On Linux/GCC, thread_local in a shared library requires global-dynamic TLS model
// (the default local-exec is incompatible with -fPIC). MSVC and macOS/Clang handle this automatically.
#if defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)
#define TLS_GLOBAL_DYNAMIC __attribute__((tls_model("global-dynamic")))
#else
#define TLS_GLOBAL_DYNAMIC
#endif
static thread_local TLS_GLOBAL_DYNAMIC JKRHeap* sCurrentHeap;
#else
JKRHeap* JKRHeap::sCurrentHeap;
#endif