[PATCH] D64776: [WebAssembly] Compile all TLS on Emscripten as local-exec
Guanzhong Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 15:21:34 PDT 2019
quantum created this revision.
quantum added reviewers: tlively, aheejin, sbc100.
Herald added subscribers: llvm-commits, sunfish, hiraditya, jgravelle-google, dschuff.
Herald added a project: LLVM.
Currently, on Emscripten, dynamic linking is not supported with threads.
This means that if thread-local storage is used, it must be used in a
statically-linked executable. Hence, local-exec is the only possible model.
This diff compiles all TLS variables to use local-exec on Emscripten as a
temporary measure until dynamic linking is supported with threads.
The goal for this is to allow C++ types with constructors to be thread-local.
Currently, when `clang` compiles a `thread_local` variable with a constructor,
it generates `__tls_guard` variable:
@__tls_guard = internal thread_local global i8 0, align 1
As no TLS model is specified, this is treated as general-dynamic, which we do
not support (and cannot support without implementing dynamic linking support
with threads in Emscripten). As a result, any C++ constructor in `thread_local`
variables would not compile.
By compiling all `thread_local` as local-exec, `__tls_guard` will compile and
we can support C++ constructors with TLS without implementing dynamic linking
with threads.
Depends on D64537 <https://reviews.llvm.org/D64537>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D64776
Files:
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
@@ -179,8 +179,12 @@
report_fatal_error("cannot use thread-local storage without bulk memory",
false);
+ // XXX Emscripten: currently Emscripten does not support dynamic linking
+ // with threads. Therefore, if we have thread-local storage, only the
+ // local-exec model is possible.
if (GA->getGlobal()->getThreadLocalMode() !=
- GlobalValue::LocalExecTLSModel) {
+ GlobalValue::LocalExecTLSModel &&
+ !Subtarget->getTargetTriple().isOSEmscripten()) {
report_fatal_error("only -ftls-model=local-exec is supported for now",
false);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64776.209970.patch
Type: text/x-patch
Size: 898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190715/fcf64040/attachment-0001.bin>
More information about the llvm-commits
mailing list