DePasqualeOrg opened PR #12997 from DePasqualeOrg:aarch64-apple-exception-handling to bytecodealliance:main:
This PR adds
AppleAarch64to the exception handling code paths in the Cranelift backend so that Wasm modules using the exception handling proposal can be compiled on Apple AArch64 targets.Problem
When compiling a Wasm module that uses the exception handling proposal (e.g., CPython compiled to WASI) with the
AppleAarch64calling convention, Cranelift panics:unimplemented clobbers for exn abi of AppleAarch64and
assertion `left == right` failed: left: 0, right: 2This is because
AppleAarch64is missing from four match arms in the Cranelift backend. Without the fix,AppleAarch64exception handling is either rejected by the verifier or panics later in lowering, depending on the pipeline:
supports_exceptions: returnsfalse, causing the verifier to rejecttry_callwithapple_aarch64calleesget_regs_clobbered_by_call: falls through to the(_, true) => panic!(...)arm for exception callsexception_payload_regs: falls through to_ => &[], returning no payload registersexception_payload_types: falls through to_ => &[], returning no payload typesThe
AppleAarch64calling convention uses the same AAPCS general-purpose register layout asSystemVfor exception handling purposes (x0–x7 for arguments, same caller-saved set), though it differs in other aspects such as argument extension behavior.Changes
cranelift/codegen/src/isa/call_conv.rsAdd
AppleAarch64alongsideSystemVin:
supports_exceptions: returnstrueso the verifier acceptstry_callwithapple_aarch64calleesexception_payload_types: returns[I64, I64](or[I32, I32]for 32-bit) as payload types
cranelift/codegen/src/isa/aarch64/abi.rsAdd
AppleAarch64alongsideSystemVin:
get_regs_clobbered_by_call: usesDEFAULT_AAPCS_CLOBBERSfor both normal and exception callsexception_payload_regs: returns[x0, x1]as payload registers
cranelift/filetests/filetests/isa/aarch64/exceptions-apple-aarch64.clifAdd a compile-only filetest that exercises
try_callandtry_call_indirectwith theapple_aarch64calling convention, to prevent regressions.Testing
Validated by compiling and running CPython (from the Wasmer Registry's
python/pythonpackage) on macOS aarch64. Without the fix, compilation panics. With the fix,python -c "print('hello')"runs successfully.Also validated that existing tools using simpler exception handling (grep, sed) continue to work.
DePasqualeOrg requested fitzgen for a review on PR #12997.
DePasqualeOrg requested wasmtime-compiler-reviewers for a review on PR #12997.
cfallin commented on PR #12997:
@DePasqualeOrg thanks for the PR. Could you clarify how you ran into this issue? At a high level, Wasmtime supports exception-handling on macOS just fine; this works because Wasm modules' functions are compiled using our internal calling convention (
tail) so we don't actually need exception-handling in the system ABI. We avoided that because it comes with other pitfalls, e.g. the need to restore clobbers at every frame using unwind info in the unwinder as well.So when you say
When compiling a Wasm module that uses the exception handling proposal (e.g., CPython compiled to WASI) with the AppleAarch64 calling convention, Cranelift panics:
How are you compiling a Wasm module in a way that requires this?
DePasqualeOrg closed without merge PR #12997.
DePasqualeOrg commented on PR #12997:
Sorry, I should have tried to reproduce this before submitting. Whatever crash I was encountering happened a week ago, and I documented it then, but something must have changed since then, and I must not have documented it correctly. I'll close this for now.
cfallin commented on PR #12997:
No worries; thanks. I'm still curious what your overall workflow is: did you encounter this issue in Wasmtime running a Wasm module? We'd like to know if so.
DePasqualeOrg commented on PR #12997:
I'm building a Swift library that uses the Wasmtime C API to run WASI tools (coreutils, sed, jq, Python, etc.) on macOS and iOS. On macOS it uses Cranelift JIT, and on iOS it targets Pulley.
cfallin commented on PR #12997:
That's very odd then. As noted above, Wasmtime doesn't use the system ABI to compile exceptions internally, and is extensively tested (including with exceptions) on macOS. If you have any documentation on how you hit an error, please do file a detailed issue.
Last updated: Apr 12 2026 at 23:10 UTC