[lld] [WebAssembly] Export TLS symbols by default on wasip3 (PR #215413)
Alex Crichton via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 15:46:36 PDT 2026
https://github.com/alexcrichton updated https://github.com/llvm/llvm-project/pull/215413
>From 3e8a39ef42f9a59580e6ad4cc7ef1300d28ef4af Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex at alexcrichton.com>
Date: Mon, 10 Aug 2026 14:23:52 -0700
Subject: [PATCH] [WebAssembly] Export TLS symbols by default on wasip3
This commit is a change to `wasm-ld` to export a number of TLS-related
symbols by default on wasip3 targets. Specifically `__tls_base`,
`__tls_align`, and `__wasm_init_tls` are all exported by default now.
This is required for dynamic linking in wasip3 in `wasm-tools component
link` as otherwise there's no way to learn about the TLS
size/align/initialization of dynamically linked libraries. For
non-dynamic use cases these will still be used internally and it's just
that the exports will be dead, but that's a pretty minor cost for now.
An eventual component-optimizer would be able to remove these pretty
easily.
---
lld/test/wasm/cooperative-threading.s | 14 +++++++++++++-
lld/wasm/Driver.cpp | 3 +++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/lld/test/wasm/cooperative-threading.s b/lld/test/wasm/cooperative-threading.s
index a4afb01dc2264..5756b41015f88 100644
--- a/lld/test/wasm/cooperative-threading.s
+++ b/lld/test/wasm/cooperative-threading.s
@@ -87,8 +87,20 @@ foo:
# CHECK-NEXT: - Minimum: 0x2
# CHECK-NOT: Shared
-# The function table is exported by default.
+# For wasip3 these symbols are unconditionally exported since they're required
+# when dynamic linking.
# CHECK: - Type: EXPORT
+# CHECK: - Name: __tls_size
+# CHECK-NEXT: Kind: GLOBAL
+# CHECK-NEXT: Index: 2
+# CHECK-NEXT: - Name: __tls_align
+# CHECK-NEXT: Kind: GLOBAL
+# CHECK-NEXT: Index: 3
+# CHECK-NEXT: - Name: __wasm_init_tls
+# CHECK-NEXT: Kind: FUNCTION
+# CHECK-NEXT: Index: 2
+
+# The function table is exported by default.
# CHECK: - Name: __indirect_function_table
# CHECK-NEXT: Kind: TABLE
# CHECK-NEXT: Index: 0
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 740e8878c6e03..34d965412b88a 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -1004,6 +1004,9 @@ static void createSyntheticSymbols() {
ctx.sym.getTLSBase =
createUndefinedFunction("__wasm_get_tls_base", &getTLSBaseSignature);
ctx.sym.getTLSBase->markLive();
+ ctx.sym.tlsSize->forceExport = true;
+ ctx.sym.tlsAlign->forceExport = true;
+ ctx.sym.initTLS->forceExport = true;
}
}
}
More information about the llvm-commits
mailing list