@@ -213,7 +213,15 @@ struct self_bounds {
213213 int state; // 0 not yet asked, 1 answered
214214};
215215
216- thread_local self_bounds g_self = { nullptr , 0 , 0 };
216+ // A standalone implementation establishes the program's one native TLS block.
217+ // PIC must not add a call into a C library's dynamic TLS resolver beneath it.
218+ // The hosted arrangement retains the compiler's dynamic-loading convention.
219+ #ifdef OKL_STANDALONE
220+ #define OKL_TLS_MODEL __attribute__ ((tls_model(" initial-exec" )))
221+ #else
222+ #define OKL_TLS_MODEL
223+ #endif
224+ thread_local OKL_TLS_MODEL self_bounds g_self = { nullptr , 0 , 0 };
217225
218226#ifdef OKL_STANDALONE
219227
@@ -243,7 +251,7 @@ okl_uptr pages_per_chunk() {
243251// apart from "not mapped" because the two lead to different reports: a range
244252// derived from a refusal is a range derived from nothing, and the caller is
245253// owed the refusal instead.
246- thread_local okl_long g_refusal = 0 ;
254+ thread_local OKL_TLS_MODEL okl_long g_refusal = 0 ;
247255
248256// Whether every page in the range is mapped. False with `mapped' unset means
249257// at least one is not; false with `g_refusal' set means the environment would
@@ -620,7 +628,7 @@ kal_uintptr kal_task_current(void) {
620628 // The identity is the kernel's, read once per context. It is unique among
621629 // contexts running at the same moment and may be reused after one ends,
622630 // which is what the specification says of it.
623- static thread_local int cached = 0 ;
631+ static thread_local OKL_TLS_MODEL int cached = 0 ;
624632 if (cached == 0 ) cached = static_cast <int >(okl::sys (okl::nr_gettid));
625633 return static_cast <kal_uintptr>(cached);
626634}
0 commit comments