Skip to content

Share arm64 EH funclet call helpers and align arm64 funclet ABI with x64 - #137168

Merged
jkotas merged 12 commits into
dotnet:mainfrom
am11:chore/share-eh-funclet-helpers-arm64
Nov 10, 2026
Merged

jkotas merged 12 commits into
dotnet:mainfrom
am11:chore/share-eh-funclet-helpers-arm64

Conversation

@am11

@am11 am11 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #136639 for arm64. As discussed in #136639 (comment), this also aligns the funclet calling convention produced by the JIT on arm64 with x64 (https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/clr-abi.md#registers-on-entry-to-a-funclet), which is the second item of #114893.

JIT

  • arm64 funclets save only LR. The runtime calls funclets with FP set to the parent frame's FP, which funclets do not change, and preserves the callee-saved registers around the funclets it calls; the main method already saves every callee-saved register used by its funclets, and call-to-finally sites do not keep values in registers across the call (same as x64).
  • The funclet frame is LR plus the outgoing argument space: str lr, [sp, #-16]! followed by sub sp, sp, #outsz if needed. This deletes the five funclet frame types and the varargs/MonitorAcquired/async padding that kept funclet frames in sync with the main frame (the first item of Improve codegen of funclet prologs #114893), along with the JitSaveFpLrWithCalleeSavedRegisters=3 stress mode that only forced funclet frame type 5.

Runtime

  • CallEHFunclet and CallEHFilterFunclet move to src/coreclr/runtime/arm64/EHHelpers.{S,asm} and are shared by CoreCLR and NativeAOT, using the x64 template: per-runtime LOAD_FUNCLET_REGISTERS / LOAD_FUNCLET_FRAME_POINTER / STORE_FUNCLET_REGISTERS macros in each runtime's AsmMacros_Shared.h load from the CONTEXT on CoreCLR and through the REGDISPLAY on NativeAOT, and the TSF_DoNotTriggerGc toggle and register write-back are under FEATURE_NATIVEAOT.
  • Both helpers now save x19-x28 and d8-d15 with unwind info (CoreCLR's CallEHFunclet did not save d8-d15, and CallEHFilterFunclet saved only fp/lr). The frame is SP-based on both runtimes; NativeAOT's old helpers used an FP-based CFA and then overwrote FP, which broke native backtraces through them.
  • NativeAOT: RhpCallCatchFunclet/RhpCallFinallyFunclet/RhpCallFilterFunclet are removed, catch resume goes through RhpResumeAfterCatch after RhpPopExInfo in arch-neutral code, RhpCallPropagateExceptionCallback no longer pops ExInfos, and UnwindFuncletInvokeThunk follows the new frame layout.
  • ReadyToRun major version 34: an older runtime would not preserve the callee-saved registers around filter funclets compiled with the new convention.

Funclets on arm64 now save only FP and LR, like funclets on x64 do not save any callee-saved
registers. The runtime helpers that call funclets save all callee-saved registers instead.

- JIT: the arm64 funclet frame is FP/LR plus the outgoing argument space. This removes the five
  funclet frame types and the padding that kept funclet frames in sync with the main frame.
- CallEHFunclet and CallEHFilterFunclet live in runtime/arm64/EHHelpers.{S,asm} and are shared
  by CoreCLR and NativeAOT, following the x64 template.
- NativeAOT pops the ExInfos in arch-neutral code and resumes after a catch through
  RhpResumeAfterCatch, like x64.
- ReadyToRun major version 34, since older runtimes do not preserve the callee-saved registers
  around filter funclets.

Co-authored-by: Cursor <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 7 pipeline(s).
8 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 9, 2026
@am11

am11 commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

SuperPMI asm diffs for linux-arm64 (x64-hosted checked arm64 JIT, dotnet/main 0ca316a as base) on 1,168,786 contexts, with no replay failures:

Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
benchmarks.run 37,291,804 -288,228 -0.21%
coreclr_tests.run 557,972,624 -1,021,728 -0.24%
libraries.crossgen2 63,730,836 -412,480 -0.29%

There are no size regressions; for example, libraries.crossgen2 has 13,049 contexts with diffs, of which 13,046 are smaller and 3 are the same size. A typical funclet that used to save a callee-saved register pair:

 G_M42448_IG07:        ; funclet prolog
-            stp     fp, lr, [sp, #-0x20]!
-            stp     x19, x20, [sp, #0x10]
+            stp     fp, lr, [sp, #-0x10]!
 ...
 G_M42448_IG09:        ; funclet epilog
-            ldp     x19, x20, [sp, #0x10]
-            ldp     fp, lr, [sp], #0x20
+            ldp     fp, lr, [sp], #0x10
             ret     lr

Comment thread src/coreclr/jit/codegenarm64.cpp Resolved
@am11
am11 marked this pull request as ready for review November 9, 2026 07:39
@am11

am11 commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

WASI SDK download failure is #135025.

Comment thread src/coreclr/jit/codegen.h Resolved
Comment thread src/coreclr/jit/codegenarm64.cpp Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The coupled ARM64 funclet ABI, GC, and unwind changes require Windows and Unix EH/GC-stress and native-unwind validation beyond the static review performed.

No open issues 🎉

What changed in this PR

Extends the shared exception-handling helpers from #136639 to ARM64 and aligns ARM64 funclets with the x64 calling convention, addressing the frame-layout simplifications tracked in #114893.

Changes:

  • Simplifies JIT-generated funclet frames to save only LR plus outgoing argument space, removing obsolete frame variants and stress-mode support.
  • Shares ARM64 funclet helpers between CoreCLR and NativeAOT, updating register preservation, stack unwinding, and NativeAOT catch resumption.
  • Advances ReadyToRun to version 34.0 for the changed calling convention.
File Description
src/​coreclr/​vm/​eetwain.cpp Passes the ARM64 context to the filter helper.
src/​coreclr/​vm/​CMakeLists.txt Includes shared ARM64 exception helpers.
src/​coreclr/​vm/​arm64/​AsmMacros_Shared.h Adds context-based register-loading macros.
src/​coreclr/​vm/​arm64/​asmhelpers.S Removes superseded Unix funclet helpers.
src/​coreclr/​vm/​arm64/​asmhelpers.asm Removes superseded Windows funclet helpers.
src/​coreclr/​tools/​Common/​Internal/​Runtime/​ModuleHeaders.cs Updates managed ReadyToRun constants to 34.0.
src/​coreclr/​runtime/​arm64/​EHHelpers.S Adds shared Unix funclet helpers with register preservation.
src/​coreclr/​runtime/​arm64/​EHHelpers.asm Adds shared Windows funclet helpers with register preservation.
src/​coreclr/​nativeaot/​Runtime/​StackFrameIterator.cpp Updates helper recognition and frame unwinding.
src/​coreclr/​nativeaot/​Runtime/​inc/​ModuleHeaders.h Updates NativeAOT ReadyToRun constants to 34.0.
src/​coreclr/​nativeaot/​Runtime/​CMakeLists.txt Includes shared ARM64 helpers in NativeAOT.
src/​coreclr/​nativeaot/​Runtime/​arm64/​ExceptionHandling.S Replaces Unix funclet helpers with catch resumption and simplifies propagation.
src/​coreclr/​nativeaot/​Runtime/​arm64/​ExceptionHandling.asm Replaces Windows funclet helpers with catch resumption.
src/​coreclr/​nativeaot/​Runtime/​arm64/​AsmMacros_Shared.h Adds register load/store macros using NativeAOT’s register display.
src/​coreclr/​nativeaot/​Runtime.Base/​src/​System/​Runtime/​InternalCalls.cs Updates ARM64 helper imports and propagation signature.
src/​coreclr/​nativeaot/​Runtime.Base/​src/​System/​Runtime/​ExceptionHandling.cs Routes ARM64 dispatch through shared helpers and explicit exception-record cleanup.
src/​coreclr/​jit/​lclvars.cpp Removes handling for the obsolete stress mode.
src/​coreclr/​jit/​jitconfigvalues.h Removes documentation for stress mode 3.
src/​coreclr/​jit/​codegencommon.cpp Removes obsolete funclet-frame initialization.
src/​coreclr/​jit/​codegenarm64.cpp Simplifies funclet prologs, epilogs, and frame calculations.
src/​coreclr/​jit/​codegen.h Reduces funclet frame metadata and removes obsolete state.
src/​coreclr/​inc/​readytorun.h Raises current and minimum major versions to 34 and documents the ABI change.

Review effort: Balanced

Comment thread src/coreclr/jit/codegenarm64.cpp Resolved
@am11

am11 commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

#137200 sits on top of these changes and ports riscv64 and loongarch64 on the same plan (and unifies JIT a bit more).

@AndyAyersMS AndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

JIT changes LGTM. Much simpler.

@jakobbotsch maybe you can also take a look.

@jkotas
jkotas requested a review from jakobbotsch November 10, 2026 05:59

@jakobbotsch jakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

JIT side looks great to me as well.

@jkotas
jkotas merged commit 82716fe into dotnet:main Nov 10, 2026
132 checks passed
jkotas added a commit that referenced this pull request Nov 11, 2026
Built on top of #137168.

Funclets on riscv64 and loongarch64 now save only RA, like arm64. The
runtime helpers that call
funclets save all callee-saved registers instead.

- JIT: the funclet frame is RA plus the outgoing argument space, shared
with arm64.
- CallEHFunclet and CallEHFilterFunclet live in
runtime/{riscv64,loongarch64}/EHHelpers.S and are
  shared by CoreCLR and NativeAOT, following the arm64 template.
- NativeAOT pops the ExInfos in arch-neutral code and resumes after a
catch through
RhpResumeAfterCatch. The unused RhpCallPropagateExceptionCallback is
removed from these
  architectures since FEATURE_OBJCMARSHAL is Apple-only.
- With all 64-bit targets on the shared helpers, the AMD64/ARM64
conditions become TARGET_64BIT.

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 11, 2026
@am11
am11 deleted the chore/share-eh-funclet-helpers-arm64 branch November 13, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-arm64 area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants