<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">thread_local storage on MacOS is handled by dyld and uses and Apple-specific implementation that came into being in 10.7.<div class=""><br class=""></div><div class="">The thread_local infrastructure uses symbols that start with “_tlv_*”.</div><div class=""><br class=""></div><div class="">See here for details:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/apple-opensource/dyld/blob/b6b86eb2db14440d373f6f7fd21be4a2bc0da897/src/threadLocalVariables.c" class="">https://github.com/apple-opensource/dyld/blob/b6b86eb2db14440d373f6f7fd21be4a2bc0da897/src/threadLocalVariables.c</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">On < 10.6 I have implemented the “emulated_tls” infrastructure that systems without OS implemented TLS use. </div><div class=""><br class=""></div><div class="">This is what gcc uses on every macOS system from 10.4 to BigSur.</div><div class=""><br class=""></div><div class="">The variables have different names, cxa_thread_*.</div><div class=""><br class=""></div><div class="">They normally live in libc on Linux, but I added them the libcxxabi using their mechanism for doing that on systems other than Apple.</div><div class=""><br class=""></div><div class="">To make that change, I added a small test and switch the implementation here:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/macports/macports-ports/blob/19157729c2b2081d3434eca941440846ef8b796d/lang/llvm-9.0/files/9000-patch-clang-7.0-support-emulated-tls.diff#L23" class="">https://github.com/macports/macports-ports/blob/19157729c2b2081d3434eca941440846ef8b796d/lang/llvm-9.0/files/9000-patch-clang-7.0-support-emulated-tls.diff#L23</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I have pondered making some “work-alike” functions with the Apple names “tlv_init” etc, so the links would work, and then making perhaps the tlv_* functions call the cxa_thread_* functions, but I just never got around to it.</div><div class=""><br class=""></div><div class="">It might be do-able. Or we might do better to figure out how to make rust use the cxa_thread_* functions instead; probably, it already can. rust is backended by llvm, and we’ve already sorted out how to make llvm do this.</div><div class=""><br class=""></div><div class="">Stay in touch!</div><div class=""><br class=""></div><div class="">Ken</div></body></html>