[llvm-dev] JIT - Thread-safe Local Static Initialization not working for Windows?

Gaier, Bjoern via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 25 00:19:13 PST 2019

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...
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190125/976e854b/attachment.html>

More information about the llvm-dev mailing list