Skip to content

Commit

Permalink
[wasm] Work around glibc thread-local storage bug
Browse files Browse the repository at this point in the history
glibc before 2.17 has a bug that makes it impossible to execute binaries
that have single-byte thread-local variables:

    % node --version
    node: error while loading shared libraries: cannot allocate memory
    in static TLS block

Work around that by making the one instance in the V8 code base an int.

See: https://sourceware.org/bugzilla/show_bug.cgi?id=14898
See: nodesource/distributions#513
See: nodejs/build#809
Change-Id: Iefd8009100cd93e26cf8dc5dc03f2d622b423385
Reviewed-on: https://chromium-review.googlesource.com/612351
Commit-Queue: Ben Noordhuis <[email protected]>
Reviewed-by: Eric Holk <[email protected]>
Cr-Commit-Position: refs/heads/master@{#47400}
  • Loading branch information
bnoordhuis authored and Commit Bot committed Aug 17, 2017
1 parent 73ec559 commit e020aae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/trap-handler/handler-shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ namespace v8 {
namespace internal {
namespace trap_handler {

THREAD_LOCAL bool g_thread_in_wasm_code = false;
// We declare this as int rather than bool as a workaround for a glibc bug, in
// which the dynamic loader cannot handle executables whose TLS area is only
// 1 byte in size; see https://sourceware.org/bugzilla/show_bug.cgi?id=14898.
THREAD_LOCAL int g_thread_in_wasm_code = false;

static_assert(sizeof(g_thread_in_wasm_code) > 1,
"sizeof(thread_local_var) must be > 1, see "
"https://sourceware.org/bugzilla/show_bug.cgi?id=14898");

size_t gNumCodeObjects = 0;
CodeProtectionInfoListEntry* gCodeObjects = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/trap-handler/trap-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline bool UseTrapHandler() {
return FLAG_wasm_trap_handler && V8_TRAP_HANDLER_SUPPORTED;
}

extern THREAD_LOCAL bool g_thread_in_wasm_code;
extern THREAD_LOCAL int g_thread_in_wasm_code;

inline bool IsThreadInWasm() { return g_thread_in_wasm_code; }

Expand Down

0 comments on commit e020aae

Please sign in to comment.