Skip to content

rust: preserve WASIp3 TLS for no-std task context - #1745

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
macovedj:wasip3-task-context-tls
Oct 12, 2026
Merged

alexcrichton merged 2 commits into
bytecodealliance:mainfrom
macovedj:wasip3-task-context-tls

Conversation

@macovedj

Copy link
Copy Markdown
Contributor

Overlapping async exports on wasm32-wasip3 can panic when wit-bindgen/std is disabled. The existing C fallback declares task_context as _Thread_local, but its prebuilt object is compiled for the SDK’s default WASIp1 target with -mcpu=mvp. This produces a shared global, so a second export task sees the suspended task’s state and fails the assertion in start_task.

This was found while testing a standard-library-using HTTP handler with wasip3 0.9.0, whose dependency configuration leaves wit-bindgen/std disabled. A second export starting before the first completes sees the first task’s state and fails the assertion in start_task.

This was found while testing concurrent requests to an HTTP handler built with Rust’s standard library and wasip3 0.9.0, whose dependency configuration leaves wit-bindgen/std disabled. The resulting panics cause the server to return HTTP 500 responses.

The prebuilt task-context helper was compiled with -mcpu=mvp, which
lowers its _Thread_local storage to a plain global. Overlapping async
exports on WASIp3 then share the same task state and panic in start_task.

Keep wasip3_task_set in the MVP archive used by every wasm32 target.
Move the versioned context accessors into a separate archive compiled
for wasm32-wasip3 and link it only for that target. Regenerate the C,
object, and archive files and check the TLS-base import during rebuilds.

Validation:
- Stock nightly-2026-10-12 and Wasmtime 47.0.2: the unpatched HTTP
  handler returns 20/20 concurrent 500s; the fix returns 20/20 200s.
- Rust 1.99.0 builds binaries and cdylibs for WASIp1, WASIp2, and
  wasm32-unknown-unknown without introducing TLS-base imports.
- WASIp1/WASIp2 binaries and the unknown-target probe run successfully;
  native unit tests and the generated doctest pass.
- SDK 34 and wasm-tools 1.258.0 regenerate artifacts identically on
  macOS arm64. Reintroducing the MVP flag makes the rebuild guard fail.
- cargo fmt --all --check and git diff --check pass.

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread crates/guest-rust/build.rs
@alexcrichton
alexcrichton added this pull request to the merge queue Oct 12, 2026
Merged via the queue into bytecodealliance:main with commit 3e8e729 Oct 12, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants