Sp0tless wrote: I checked the history, and this appears to be an intentional generic JIT default rather than an MSVC-specific choice or an accident. `EngineBuilder` enabled emulated TLS when TLS support was added to the JIT, and `JITTargetMachineBuilder` retained that behavior to match `EngineBuilder`. `clang-repl` currently inherits this default.
There are real obstacles to using native MSVC TLS for JIT-allocated code. Native MSVC TLS assumes a loader-managed PE image: the loader allocates a module TLS index and writes it through the image's TLS index location (conventionally exposed as `_tls_index`), creates per-thread storage from the image's TLS template, and invokes TLS callbacks during thread attach and detach. JIT allocations are not registered as PE modules, and the current COFF JIT path does not provide a complete equivalent. This is consistent with the conclusion in #127468 that disabling emutls would only mask the issue because native TLS was not supported by the Windows JIT. Cling explicitly overrides the generic JIT default and disables emutls on Windows. In my local tests, however, its RuntimeDyld path caused multiple JIT-defined TLS variables in one thread to alias and lose their initial values. Switching that experiment to emutls fixed the basic per-thread storage tests, although dynamic initialization, destruction, and unloading remained unresolved. The Windows compiler-rt emutls implementation is not a pure thread-ID map. It uses one `TlsAlloc` slot to locate a per-thread address array, and each `__emutls_v.*` descriptor contains an index into that array. It therefore uses Win32 TLS as an implementation primitive, but remains emulated TLS at the compiler and object-file ABI level: accesses call `__emutls_get_address` instead of using `_tls_index` and a loader-created PE TLS block. So the default does not appear accidental, and native MSVC TLS still has Windows JIT runtime support gaps. This patch handles the two implicit accesses to CRT-owned native TLS that Clang currently emits when emutls is selected; it does not attempt to add complete native COFF TLS support. https://github.com/llvm/llvm-project/pull/220215 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
