Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate libcalls to checking for traps #9710

Merged

Conversation

alexcrichton
Copy link
Member

This PR is the equivalent of #9675 for libcalls used in core wasm and components.
All libcalls now communicate whether or not they trapped through their
return value instead of implicitly calling longjmp to exit from the
libcall. This is to make integration with Pulley easier to avoid the
need to longjmp over Pulley execution.

Libcall definitions have changed where appropriate and the
catch_unwind_and_record_trap function introduced in #9675 was
refactored to better support multiple types of values being returned
from libcalls (instead of just Result<()>).

Note that changes have been made to both the Cranelift translation layer
and the Winch translation layer for this as the ABI of various libcalls
are all changing.

@alexcrichton alexcrichton requested review from a team as code owners December 2, 2024 22:48
@alexcrichton alexcrichton requested review from abrown and pchickey and removed request for a team December 2, 2024 22:48
// Under fuel limits branch.
self.masm.bind(continuation);
self.context.free_reg(fuel_var);
Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly @saulecabrera I had to move this up since fuel_var was assigned rax but rax was needed as the return value of the hostcall, so this was needed to fix some panics during compilation.

@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime labels Dec 3, 2024
Copy link

github-actions bot commented Dec 3, 2024

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "wasmtime:api", "wasmtime:ref-types"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: wasmtime:ref-types

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton alexcrichton requested review from fitzgen and removed request for pchickey December 4, 2024 01:25
@sunfishcode
Copy link
Member

Does this significantly change overall code size of Cranelift-generated code, due to needing inline trap check code at each libcall callsite?

@alexcrichton
Copy link
Member Author

Yes as-is all libcalls that can trap have a check after them, so it's inflating code by at least that much.

In thinking though this can be pretty easily optimized. We already generate a trampoline-per-libcall so I'll move the check-for-trap logic to the trampoline instead of the callsite of the trampoline.

@alexcrichton
Copy link
Member Author

Ok I've updated this where the trampoline itself now checks for a trap, so the code size impact on wasm itself should be minimal.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

LGTM modulo one comment below

crates/cranelift/src/gc/enabled/drc.rs Show resolved Hide resolved
This commit is the equivalent of bytecodealliance#9675 for libcalls used in core wasm.
All libcalls now communicate whether or not they trapped through their
return value instead of implicitly calling `longjmp` to exit from the
libcall. This is to make integration with Pulley easier to avoid the
need to `longjmp` over Pulley execution.

Libcall definitions have changed where appropriate and the
`catch_unwind_and_record_trap` function introduced in bytecodealliance#9675 was
refactored to better support multiple types of values being returned
from libcalls (instead of just `Result<()>`).

Note that changes have been made to both the Cranelift translation layer
and the Winch translation layer for this as the ABI of various libcalls
are all changing.
@alexcrichton alexcrichton added this pull request to the merge queue Dec 5, 2024
Merged via the queue into bytecodealliance:main with commit 7783579 Dec 5, 2024
42 checks passed
@alexcrichton alexcrichton deleted the libcall-manual-trap branch December 5, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:ref-types Issues related to reference types and GC in Wasmtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants