JIT - Thread-safe Local Static Initialization not working for Windows?

Hello LLVM-World,

some days ago I asked how I can disable the emulated TLS support for the JIT Execution Engine. This worked and I got my undefined references to:





I used the Linker to export those symbols, to resolve them for the JIT - but! My test code is crashing when I call the static constructors and destructors. The code is really simple and does work when I disable TLS.

Some background:

0.) I’m talking about this: https://docs.microsoft.com/en-gb/cpp/build/reference/zc-threadsafeinit-thread-safe-local-static-initialization?view=vs-2017

1.) I develop for Windows 7 x64 and use the LLVM 7 and Clang-CL

2.) The test code:

I have a global variable that awaits the address of a structure, this address is assigned via a lambda function that gets executed when calling the static constructors.

This lambda function has a static variable, instantiating a class - then it returns the address of this static instance.

3.) I don’t use the Execution Engine to execute the static constructors - I took there address while the JIT process.

I can verify that I reach the lambda function when calling the static constructors, but the constructor of my class will never be called, because the application crashes before that.

Does anyone got TLS running on Windows? Am I overseeing something? I’m still a beginner (with annoying questions as I fear…)

Kind greetings and thank you for reading


@Lang: Sorry for pinging you… You seem to know so much about this area and Windows…