diff --git a/src/JSystem/JKernel/JKRHeap.cpp b/src/JSystem/JKernel/JKRHeap.cpp index 6b9ec1e685..606ff3def9 100644 --- a/src/JSystem/JKernel/JKRHeap.cpp +++ b/src/JSystem/JKernel/JKRHeap.cpp @@ -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