llvm-project/lld/wasm
Guanzhong Chen 42bba4b852 [WebAssembly] Implement thread-local storage (local-exec model)
Summary:
Thread local variables are placed inside a `.tdata` segment. Their symbols are
offsets from the start of the segment. The address of a thread local variable
is computed as `__tls_base` + the offset from the start of the segment.

`.tdata` segment is a passive segment and `memory.init` is used once per thread
to initialize the thread local storage.

`__tls_base` is a wasm global. Since each thread has its own wasm instance,
it is effectively thread local. Currently, `__tls_base` must be initialized
at thread startup, and so cannot be used with dynamic libraries.

`__tls_base` is to be initialized with a new linker-synthesized function,
`__wasm_init_tls`, which takes as an argument a block of memory to use as the
storage for thread locals. It then initializes the block of memory and sets
`__tls_base`. As `__wasm_init_tls` will handle the memory initialization,
the memory does not have to be zeroed.

To help allocating memory for thread-local storage, a new compiler intrinsic
is introduced: `__builtin_wasm_tls_size()`. This instrinsic function returns
the size of the thread-local storage for the current function.

The expected usage is to run something like the following upon thread startup:

    __wasm_init_tls(malloc(__builtin_wasm_tls_size()));

Reviewers: tlively, aheejin, kripken, sbc100

Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D64537

llvm-svn: 366272
2019-07-16 22:00:45 +00:00
..
CMakeLists.txt [WebAssembly] Refactor synthetic sections and relocation processing. NFC. 2019-05-21 09:13:09 +00:00
Config.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
Driver.cpp [WebAssembly] Implement thread-local storage (local-exec model) 2019-07-16 22:00:45 +00:00
InputChunks.cpp [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
InputChunks.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
InputEvent.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
InputFiles.cpp [WebAssembly] Rename variale references in comments after VariableName -> variableName change 2019-07-16 08:08:17 +00:00
InputFiles.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
InputGlobal.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
LTO.cpp [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
LTO.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
MarkLive.cpp [WebAssembly] Rename variale references in comments after VariableName -> variableName change 2019-07-16 08:08:17 +00:00
MarkLive.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Options.td [WebAssembly] Add option to emit passive segments 2019-07-03 22:04:54 +00:00
OutputSections.cpp [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
OutputSections.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
OutputSegment.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
Relocations.cpp [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
Relocations.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
SymbolTable.cpp [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
SymbolTable.h [WebAssembly] Rename variale references in comments after VariableName -> variableName change 2019-07-16 08:08:17 +00:00
Symbols.cpp [WebAssembly] Implement thread-local storage (local-exec model) 2019-07-16 22:00:45 +00:00
Symbols.h [WebAssembly] Implement thread-local storage (local-exec model) 2019-07-16 22:00:45 +00:00
SyntheticSections.cpp [WebAssembly] Rename variale references in comments after VariableName -> variableName change 2019-07-16 08:08:17 +00:00
SyntheticSections.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00
Writer.cpp [WebAssembly] Implement thread-local storage (local-exec model) 2019-07-16 22:00:45 +00:00
Writer.h [WebAssembly] Refactor synthetic sections and relocation processing. NFC. 2019-05-21 09:13:09 +00:00
WriterUtils.cpp [WebAssembly] Rename except_ref type to exnref 2019-07-15 22:49:25 +00:00
WriterUtils.h [Coding style change][lld] Rename variables for non-ELF ports 2019-07-11 05:40:30 +00:00