summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShravan Narayan <shravanrn@gmail.com>2024-10-15 00:29:43 -0500
committerShravan Narayan <shravanrn@gmail.com>2024-10-28 16:17:12 -0500
commit1af95898e523a92f962c100db82a55a1a80632e7 (patch)
tree63d218a89fb3665ad94e271608ca0d5d2c1976bf
parentb8d82acf6189a563830b0b76d89c4640c6310b33 (diff)
downloadwabt-1af95898e523a92f962c100db82a55a1a80632e7.tar.gz
wabt-1af95898e523a92f962c100db82a55a1a80632e7.tar.bz2
wabt-1af95898e523a92f962c100db82a55a1a80632e7.zip
wasm2c: Cleanup TLS: check for __thread and declare TLS vars only when needed
-rw-r--r--wasm2c/wasm-rt-impl.c2
-rw-r--r--wasm2c/wasm-rt-impl.h2
-rw-r--r--wasm2c/wasm-rt.h9
3 files changed, 10 insertions, 3 deletions
diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c
index 456c3025..92616351 100644
--- a/wasm2c/wasm-rt-impl.c
+++ b/wasm2c/wasm-rt-impl.c
@@ -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);
diff --git a/wasm2c/wasm-rt-impl.h b/wasm2c/wasm-rt-impl.h
index aa6f46d9..ed46b097 100644
--- a/wasm2c/wasm-rt-impl.h
+++ b/wasm2c/wasm-rt-impl.h
@@ -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. */
diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h
index 3274a15d..c5bad614 100644
--- a/wasm2c/wasm-rt.h
+++ b/wasm2c/wasm-rt.h
@@ -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