conrade-ctc wrote: Thanks for the pointer @vgvassilev — I dug into #187040. It's also an emulated-TLS issue, but a distinct one from what this PR fixes, and I don't think it can ride along here.
**This PR** is an internal-bookkeeping fix: `IRMaterializationUnit`'s ctor registers `__emutls_t.<var>` in `SymbolFlags` but not `SymbolToDefinition`, so `discard()` of a duplicated weak `thread_local` dereferences `end()` (assertion in +Asserts, heap corruption otherwise). I verified it against a large weak/COMDAT set (many template-method specializations + function-local guards + a vtable, pulled into two PTUs): crashes before, clean after. `release/21.x` `Layer.cpp` is byte-identical here, so it's the same single bug on 21/22/main. **#187040** is a different failure mode — `Symbols not found: __emutls_get_address, __emutls_v._Init_thread_epoch`. Root cause is that the JIT forces `EmulatedTLS = true` (`JITTargetMachineBuilder`), but on Windows/MSVC there is no emulated-TLS runtime and the CRT's `_Init_thread_epoch` is *native* TLS, so emutls-lowered code can never resolve against it. The tempting fix (#127468, disable emutls on Windows) is incomplete because **JITLink has no native-TLS support for COFF**. ELF has `TLSInfoTableManager_ELF_x86_64` + the `$__TLSINFO` section, but the COFF path has nothing equivalent: no `_tls_index`/`_tls_used`, `COFFPlatform` does no TLS setup, and `COFF_x86_64`'s SECREL handling still carries `FIXME: SECREL to external symbol should be handled`. So disabling emutls fixes CRT-thread_local interop at best while leaving JIT-*defined* thread_locals unsupported on Windows — which is likely why #127468 stalled and your "is native TLS actually implemented in jitlink?" question there didn't get resolved. So #187040 really needs native TLS implemented in JITLink COFF + `COFFPlatform` (mirroring the ELF `TLSInfoTableManager`), which is a sizeable change on its own. I'd prefer to keep this PR scoped to the discard fix; happy to help on the COFF native-TLS side as a separate effort if that's useful. https://github.com/llvm/llvm-project/pull/207161 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
