marxin opened PR #13586 from marxin:macho-eh-main to bytecodealliance:main:
This change is motivated by a compatibility difference between LLVM and the Cranelift compiler. The PR enables Cranelift to emit proper compact unwind information for the Mach-O AArch64 platform, based on
UnwindInstandFinalizedMachCallSite.The change has two parts:
- Unwind instructions only describe which pairs of callee-save registers are saved and restored. The canonical stack frame layout is still expected: nonvolatile registers must be placed near the top of the frame, immediately below the return address.
- The unwind encoding only supports register pairs emitted with
stp; it cannot encode individual registers. This results in slightly larger stack frames, but the increase should hopefully be manageable.Collected statistics for a larger WASM module (total function count: ~37K):
function count: diff: newly spilled registers 9828 diff=+0: newly spilled=0 1958 diff=+0: newly spilled=10 3457 diff=+0: newly spilled=2 3828 diff=+0: newly spilled=4 1038 diff=+0: newly spilled=6 552 diff=+0: newly spilled=8 639 diff=+1: newly spilled=10 882 diff=+1: newly spilled=2 6639 diff=+1: newly spilled=4 2393 diff=+1: newly spilled=6 1072 diff=+1: newly spilled=8 359 diff=+2: newly spilled=10 2229 diff=+2: newly spilled=4 1062 diff=+2: newly spilled=6 523 diff=+2: newly spilled=8 118 diff=+3: newly spilled=10 505 diff=+3: newly spilled=6 226 diff=+3: newly spilled=8 54 diff=+4: newly spilled=10 68 diff=+4: newly spilled=8 7 diff=+5: newly spilled=10Pair-register encoding constant defined in LLVM:
https://github.com/llvm/llvm-project/blob/main/libunwind/include/mach-o/compact_unwind_encoding.h?utm_source=chatgpt.com#L292-L300
marxin requested alexcrichton for a review on PR #13586.
marxin requested wasmtime-compiler-reviewers for a review on PR #13586.
:speech_balloon: bjorn3 created PR review comment:
Instead of unconditionally doing this on Mach-O, maybe add a flag for it? rustc_codegen_cranelift will not use compact unwind info (it only allows 3 distinct personality functions, but non-rust languages on apple platforms already use 3 personality functions combined, so rustc has to use dwarf debuginfo to ensure it can always use its own personality function), so there is no reason it has to incur the code quality hit.
:memo: bjorn3 submitted PR review.
marxin updated PR #13586.
:memo: marxin submitted PR review.
:speech_balloon: marxin created PR review comment:
Sure - makes fully sense to me. The new flag has been added, with the default value being
false.
marxin requested wasmtime-core-reviewers for a review on PR #13586.
marxin updated PR #13586.
github-actions[bot] added the label cranelift:area:aarch64 on PR #13586.
github-actions[bot] added the label wasmtime:api on PR #13586.
github-actions[bot] added the label cranelift:meta on PR #13586.
github-actions[bot] added the label cranelift on PR #13586.
:memo: cfallin submitted PR review:
This seems reasonable to me -- thanks a bunch for the contribution!
In addition to the nit below, could you add a compile filetest showing the assembly (including cases where the logic adds a new clobber) as well?
:speech_balloon: cfallin created PR review comment:
We generally use
crate::FxHashSetthroughoutcranelift-codegen-- could you switch to that?
marxin updated PR #13586.
:memo: marxin submitted PR review.
:speech_balloon: marxin created PR review comment:
Sure!
:thumbs_up: cfallin submitted PR review.
alexcrichton requested cfallin for a review on PR #13586.
cfallin has enabled auto merge for PR #13586.
alexcrichton unassigned alexcrichton from PR #13586 feat(MachO): Cranelift: align stack prologue/epilogue with compact unwind format.
marxin commented on PR #13586:
In addition to the nit below, could you add a compile filetest showing the assembly (including cases where the logic adds a new clobber) as well?
Included a test-case, where switching
set enable_compact_unwind_abi=truetofalseleads to the following diff:--- expected +++ actual @@ -1,8 +1,8 @@ VCode: stp fp, lr, [sp, #-16]! mov fp, sp - stp x20, x19, [sp, #-16]! - stp x22, x21, [sp, #-16]! + str x21, [sp, #-16]! + stp x19, x20, [sp, #-16]! block0: mov x19, x2 mov x20, x1 @@ -13,8 +13,8 @@ add x6, x0, x1 mov x2, x19 add x0, x6, x2 - ldp x22, x21, [sp], #16 - ldp x20, x19, [sp], #16 + ldp x19, x20, [sp], #16 + ldr x21, [sp], #16 ldp fp, lr, [sp], #16 ret
cfallin added PR #13586 feat(MachO): Cranelift: align stack prologue/epilogue with compact unwind format to the merge queue.
:check: cfallin merged PR #13586.
cfallin removed PR #13586 feat(MachO): Cranelift: align stack prologue/epilogue with compact unwind format from the merge queue.
marxin commented on PR #13586:
Given the nature of the change and that it's opt-in, can we please cherry pick it into the upcoming
0.133version?
Thank you.
alexcrichton commented on PR #13586:
That seems reasonable yeah, can you send a cherry-pick to the release-46.0.0 branch for that?
Last updated: Jul 29 2026 at 05:03 UTC