Skip to content

Fix argument extension on riscv64 for Wasmtime builtins#10069

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:fix-riscv64-sext
Jan 23, 2025
Merged

Fix argument extension on riscv64 for Wasmtime builtins#10069
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:fix-riscv64-sext

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit fixes a crash found in the CI of #10040. That PR itself isn't the fault per-se but rather uncovered a preexisting issue on riscv64. According to riscv64's ABI docs it looks like arguments are all expected to be sign-extended, whereas currently in Wasmtime all host signatures are zero-extended on all platforms. This commit applies two changes to fix this:

  • A new TargetIsa::default_argument_extension method was added which is now used instead of unconditionally using uext to apply to all arguments/results.

  • While I was here I went ahead and split apart things where the wasm signature of a builtin doesn't use uext or sext. The host signature still does, however, which means that any extension necessary happens in the trampoline we generate per-libcall as opposed to at all callsites.

I'm not certain that all platforms require uext but I've left the TargetIsa implementation as uext for now with a comment explaining why. Currently the only non-uext platforms are riscv64, which is sext to fix the issue from #10040, and Pulley which is "none" as things work differently there.

This commit fixes a crash found in the CI of bytecodealliance#10040. That PR itself
isn't the fault per-se but rather uncovered a preexisting issue on
riscv64. According to riscv64's ABI docs it looks like arguments are all
expected to be sign-extended, whereas currently in Wasmtime all host
signatures are zero-extended on all platforms. This commit applies two
changes to fix this:

* A new `TargetIsa::default_argument_extension` method was added which
  is now used instead of unconditionally using `uext` to apply to all
  arguments/results.

* While I was here I went ahead and split apart things where the wasm
  signature of a builtin doesn't use `uext` or `sext`. The host
  signature still does, however, which means that any extension
  necessary happens in the trampoline we generate per-libcall as opposed
  to at all callsites.

I'm not certain that all platforms require `uext` but I've left the
`TargetIsa` implementation as `uext` for now with a comment explaining
why. Currently the only non-`uext` platforms are riscv64, which is
`sext` to fix the issue from bytecodealliance#10040, and Pulley which is "none" as
things work differently there.
@alexcrichton alexcrichton requested review from a team as code owners January 21, 2025 21:18
@alexcrichton alexcrichton requested review from abrown and pchickey and removed request for a team January 21, 2025 21:18
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels Jan 21, 2025
Copy link
Copy Markdown
Member

@abrown abrown left a comment

Choose a reason for hiding this comment

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

Thanks for the comments!

@alexcrichton alexcrichton added this pull request to the merge queue Jan 23, 2025
Merged via the queue into bytecodealliance:main with commit 1e6d533 Jan 23, 2025
@alexcrichton alexcrichton deleted the fix-riscv64-sext branch January 23, 2025 15:42
JonasKruckenberg pushed a commit to JonasKruckenberg/wasmtime that referenced this pull request Apr 4, 2025
…ance#10069)

* Fix argument extension on riscv64 for Wasmtime builtins

This commit fixes a crash found in the CI of bytecodealliance#10040. That PR itself
isn't the fault per-se but rather uncovered a preexisting issue on
riscv64. According to riscv64's ABI docs it looks like arguments are all
expected to be sign-extended, whereas currently in Wasmtime all host
signatures are zero-extended on all platforms. This commit applies two
changes to fix this:

* A new `TargetIsa::default_argument_extension` method was added which
  is now used instead of unconditionally using `uext` to apply to all
  arguments/results.

* While I was here I went ahead and split apart things where the wasm
  signature of a builtin doesn't use `uext` or `sext`. The host
  signature still does, however, which means that any extension
  necessary happens in the trampoline we generate per-libcall as opposed
  to at all callsites.

I'm not certain that all platforms require `uext` but I've left the
`TargetIsa` implementation as `uext` for now with a comment explaining
why. Currently the only non-`uext` platforms are riscv64, which is
`sext` to fix the issue from bytecodealliance#10040, and Pulley which is "none" as
things work differently there.

* Update test expectations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants