llvm-project
577e9a7c - [WebAssembly] WASIP3 Library Call Thread Context Support (#175800)

Commit
43 days ago
[WebAssembly] WASIP3 Library Call Thread Context Support (#175800) The [WebAssembly Component Model](https://component-model.bytecodealliance.org/) has added support for [cooperative multithreading](https://github.com/WebAssembly/component-model/pull/557). This has been implemented in the [Wasmtime engine](https://github.com/bytecodealliance/wasmtime/pull/11751) and is part of the wider project of [WASI preview 3](https://wasi.dev/roadmap#upcoming-wasi-03-releases), which is currently tracked [here](https://github.com/orgs/bytecodealliance/projects/16). These changes require updating the way that `__stack_pointer` and `__tls_base` work purely for a new `wasm32-wasip3` target; other targets will not be touched. Specifically, rather than using a Wasm global for tracking the stack pointer and TLS base, the new [`context.get/set`](https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#-canon-contextget) component model builtin functions will be used (the intention being that runtimes will need to aggressively optimize these calls into single load/stores). For justification on this choice rather than switching out the global at context-switch boundaries, see [this comment](https://github.com/WebAssembly/wasi-libc/issues/691#issuecomment-3716405618) and [this comment](https://github.com/WebAssembly/wasi-libc/issues/691#issuecomment-3716916730). This PR adds support for using library calls instead of globals for holding the stack pointer and TLS base. When used, this thread context ABI emits calls to `__wasm_{get,set}_{stack_pointer,tls_base}` when needed. These functions can then be implemented in `libc`. This is enabled only for the WASIp3 target. There is a temporary macro define for `__wasm_libcall_thread_context__` which can be removed once `wasi-libc` has fully migrated to the new ABI for the WASIp3 target.
Author
Parents
Loading