Skip to content

Conversation

@alexcrichton
Copy link
Collaborator

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/run@0.2.0#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.

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/run@0.2.0#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`.
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.

1 participant