Skip to content

Conversation

@TartanLlama
Copy link

Adds pthread support for wasip3 based on the component model's cooperative threading builtins.

Currently a draft for progress tracking.

alexcrichton and others added 22 commits January 6, 2026 11:25
Almost all functions are stubbed out to return errors. This is all done
in preparation for eventually filling out these functions, but the goal
of this commit is to lay down the scaffolding of the target rather than
actually implement anything.

CI jobs are added to build and test this target. Most tests are expected
to fail, but all tests are still run as usual. Once tests are passing
they'll be updated in `CMakeLists.txt` to flag the test as expected to
pass instead of expected to fail.

This is a very large PR line-wise, but all the major changes with large
chunks of code are generated code and are expected to be easy to review.
The actual changes here in the source are primarily:

* Adding `#elif defined(__wasip3__)` cases
* Sometimes using the WASIp2 definitions of functions for WASIp3
* Shuffling naming in the network utilities to support both WASIp2 and
  WASIp3 which have the same types, just renamed.
* Generated bindings for WASIp3 are now vendored like WASIp2 bindings.
* Wasmtime is updated for testing to be able to run generated WASIp3
  binaries.
This commit is an improvement to the WASIp2 target which changes how the
interface `wasi:cli/run` is defined and exported. Previously the
`wasm32-wasip2` target would define a `_start` wasm export which
required the use of the WASIp1-to-WASIp2 adapter to hook it up to
`wasi:cli/run`. This meant that despite libc not actually using any
WASIp2 APIs the adapter was still used. The purpose of this commit is to
change this.

The changes made here are:

* The linker-level `_start` symbol now has a wasm-level export name of
  `wasi:cli/[email protected]#run`. This means that `_start` isn't a wasm-level
  export any more, meaning there's nothing for the adapter to import.
* The signature of the C-level `_start` function is now different based
  on WASI version (returns an `int` in WASIp2, nothing on WASIp1)
* The `crt1-command.o` object file now contains type information for
  `wasi:cli/run` (which previously wasn't present anywhere in
  wasi-libc). This means that when this object is linked in
  `wit-component` will know what to do after linking.

The end result is that binaries are now produced entirely without the
WASIp1-to-WASIp2 adapter and linking with `-Wl,--wasi-adapter=none`,
for example, produces a working binary.

Another minor change made in this commit is that the `crt1-*.c` files
are now included in `clang-format` like all other source files.

Build-wise this requires the usage of `wasm-tools` at build-time to
embed type information in the clang-produced object file for
`crt1-command.o`.
@cpetig
Copy link
Contributor

cpetig commented Jan 15, 2026

I think your assembly code to set the initial context from the globals got lost when the new run implementation was integrated. At least for me the initial context 0 (stack pointer) is zero and results in traps.

@TartanLlama
Copy link
Author

@cpetig that code is planned to be called by wasm-tools, so that all exports are handled the same way: bytecodealliance/wasm-tools#2417

@TartanLlama
Copy link
Author

To try it out, you'd need to build wasm-component-ld against my wasm-tools branch, and use that as the linker for the executable you're building

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.

3 participants