OSDN Git Service

[WebAssembly] Compile all TLS on Emscripten as local-exec
authorGuanzhong Chen <gzchen@google.com>
Tue, 16 Jul 2019 22:22:08 +0000 (22:22 +0000)
committerGuanzhong Chen <gzchen@google.com>
Tue, 16 Jul 2019 22:22:08 +0000 (22:22 +0000)
commit9eb4a3996776f8b6a94be0a656c516852aa51cbe
tree66feed06b2bbea12d4b89f07680bdba0d43d7d50
parent8a6db15ff251a73f47ebf135010b5da90f352aa7
[WebAssembly] Compile all TLS on Emscripten as local-exec

Summary:
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

Reviewers: tlively, aheejin, sbc100

Reviewed By: aheejin

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

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366275 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
test/CodeGen/WebAssembly/tls-general-dynamic.ll [new file with mode: 0644]
test/CodeGen/WebAssembly/tls-local-exec.ll [moved from test/CodeGen/WebAssembly/tls.ll with 100% similarity]