Wrap component function exports in functions that call `__wasm_init_task` by TartanLlama · Pull Request #2417 · bytecodealliance/wasm-tools

Exports need their stack pointer and thread-local storage set up. For this, in wasip3, wasi-libc can export __wasilibc_init_task(_async) functions that should be called before the real component exports are called. This PR introduces a new module into components generated by wit-component when it detects __wasilibc_init_task(_async) functions exported from the main module.

This new module is called wasilibc-init-wrappers. For every function the component exports, it imports that function, and exports a wrapper that calls the relevant task initialization function before calling the original export. I did this with a separate module to cleanly separate out the logic, but could dump the wrappers into the original module or the shim if desired.