[PATCH] D64537: [WebAssembly] Implement thread-local storage (local-exec model)
Sam Clegg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 17 08:27:58 PDT 2019
sbc100 added a comment.
In D64537#1586614 <https://reviews.llvm.org/D64537#1586614>, @quantum wrote:
> In D64537#1586577 <https://reviews.llvm.org/D64537#1586577>, @dschuff wrote:
> > Another high-level question (based just on reading the CL description): The TLS-size intrinsic is per-function, does that mean that the tls-init function is called for every function? are there just multiple TLS sections per object file?
> The TLS-size intrinsic returns the total size of TLS for the module it's called from. The initialization function initializes the TLS for the entire module.
> In D64537#1586556 <https://reviews.llvm.org/D64537#1586556>, @dschuff wrote:
> > The `offset` field of a segment can be a constant expression <https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions> which can be a `global.get` of an imported global. So we could have an imported global `__tls_base` which is different for each thread, and have an active segment with that as its segment offset?
> I didn't know that it could have been a constant expression. I don't think this would have worked very well on the main thread though, since we need to run `malloc` before we can compute `__tls_base`. I think this requires the global to be mutable, if only because we need to be able to initialize it on the main thread.
Interesting. I was assuming we could be clever and make the main thread special and have the linker allocate its tls space upfront (like we do for main thread stack space) rather than do it a runtime, but maybe that needlessly complicated. Seems like ideally we could want to import __tls_base but not for the main thread but I don't think of a way to express that.
CHANGES SINCE LAST ACTION
More information about the cfe-commits