Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm2c: Cleanup TLS: check for __thread and declare TLS vars only when needed #2488

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wasm2c/wasm-rt-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ WASM_RT_THREAD_LOCAL uint32_t wasm_rt_saved_call_stack_depth;
static WASM_RT_THREAD_LOCAL void* g_alt_stack = NULL;
#endif

#ifndef WASM_RT_TRAP_HANDLER
WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf g_wasm_rt_jmp_buf;
#endif

#ifdef WASM_RT_TRAP_HANDLER
extern void WASM_RT_TRAP_HANDLER(wasm_rt_trap_t code);
Expand Down
2 changes: 2 additions & 0 deletions wasm2c/wasm-rt-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
extern "C" {
#endif

#ifndef WASM_RT_TRAP_HANDLER
/** A setjmp buffer used for handling traps. */
extern WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf g_wasm_rt_jmp_buf;
#endif

#if WASM_RT_STACK_DEPTH_COUNT
/** Saved call stack depth that will be restored in case a trap occurs. */
Expand Down
9 changes: 6 additions & 3 deletions wasm2c/wasm-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ extern "C" {

#endif

#ifdef _MSC_VER
#define WASM_RT_THREAD_LOCAL __declspec(thread)
#elif defined(WASM_RT_C11_AVAILABLE)
#ifdef WASM_RT_C11_AVAILABLE
#define WASM_RT_THREAD_LOCAL _Thread_local
#elif defined(_MSC_VER)
#define WASM_RT_THREAD_LOCAL __declspec(thread)
#elif (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__)
// Disabled on Apple systems due to sporadic test failures.
#define WASM_RT_THREAD_LOCAL __thread
#else
#define WASM_RT_THREAD_LOCAL
#endif
Expand Down
Loading