Open llvmbot opened 10 years ago
Well that's unfortunate.
We could do slightly better by always using the last static TLS slot in the TEB, ie TlsSlots[63]. That would still require the runtime to carefully mark that slot used in the free TLS bitmap during startup, which isn't very user friendly.
The "normal" Unix-y thing to do is to create a thread-local variable with the generaldynamic TLS model described in LLVM langref, but I don't think that's implementable on Windows without heavy function calls on every access.
Extended Description
The implementation of segmented stacks for i686 and x86_64 Windows uses the 'pvArbitrary' (aka 'ArbitraryUserPointer') field of the TCB to store the stack limit (
$fs:0x14
on win32 or$gs:0x28
on win64).As indicated by Raymond Chen1 this slot is, contrary to some information, not free for use by applications, and will cause various mysterious bugs.
This has been a major source of pain in Rust24, which at this point only uses segmented stacks for stack overflow protection, and is presently switching to stack probes instead.
I'm not aware of other candidate TCB slots to use for this purpose, so segmented stacks on Windows may not be viable with the current technique.