[lld][WebAssembly] Allow use of statically allocated TLS region.
authorSam Clegg <sbc@chromium.org>
Fri, 20 May 2022 21:39:33 +0000 (14:39 -0700)
committerSam Clegg <sbc@chromium.org>
Tue, 24 May 2022 00:27:17 +0000 (17:27 -0700)
commit74f98419770041deb983b4f736ebdc06de4ee2ac
tree2cd3f1629454af6c95af9eb94587bff401cc56ee
parent4f93d5cc1d47c6b54a948712b6181dc55d028c88
[lld][WebAssembly] Allow use of statically allocated TLS region.

It turns out we were already allocating static address space for TLS
data along with the non-TLS static data, but this space was going
unused/ignored.

With this change, we include the TLS segment in `__wasm_init_memory`
(which does the work of loading the passive segments into memory when a
module is first loaded).  We also set the `__tls_base` global to point
to the start of this segment.

This means that the runtime can use this static copy of the TLS data for
the first/primary thread if it chooses, rather than doing a runtime
allocation prior to calling `__wasm_init_tls`.

Practically speaking, this will allow emscripten to avoid dynamic
allocation of TLS region on the main thread.

Differential Revision: https://reviews.llvm.org/D126107
lld/test/wasm/data-segments.ll
lld/test/wasm/tls_init_symbols.s
lld/wasm/Writer.cpp
llvm/include/llvm/BinaryFormat/Wasm.h