[lld] [WebAssembly] Default export tables with `--cooperative-threading` (PR #208263)
Alex Crichton via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 17:01:11 PDT 2026
================
@@ -759,6 +759,14 @@ static void setConfigs() {
if (ctx.arg.sharedMemory)
error("--cooperative-threading is incompatible with --shared-memory");
ctx.arg.libcallThreadContext = true;
+
+ // Cooperative threading requires the table is either imported or exported
+ // or otherwise there's no way for embedders to read spawned functions from
+ // the table. If we've gotten this far and the table isn't otherwise
+ // imported (e.g in `isPic` mode) then export the table instead to ensure
+ // that it's visible to the outside world.
+ if (!ctx.arg.importTable)
+ ctx.arg.exportTable = true;
----------------
alexcrichton wrote:
I thought about putting in the driver, yeah, but I feel that here in wasm-ld is the best place. One consequence of a driver is that `--export-table` as a flag is incompatible with `-shared`, `--import-table`, and `--relocatable`. For all of these flags the driver would have to figure out what's going on and whether `--export-table` otherwise needs to be passed. Given that I don't think the `*.cfg` file will work, and while the driver in theory could work it'd also be something I'd have to replicate in rustc, too. Given all that it's how I figured that here in `wasm-ld` was probably the best place to put this since it's got the most context.
For a different scheme, that's theoretically possible, yeah, but the current definition of the threading intrinsics is that the new-thread intrinsic takes a table + index and spawns the thread based on that. This is intended to be somewhat future-compatible with a world where an intrinsic takes a `funcref` directly, but that's not possible to call from C right now hence the interim table+index intrinsic.
https://github.com/llvm/llvm-project/pull/208263
More information about the llvm-commits
mailing list