Skip to content

Bring RV64 and LA64 EH helpers to x64/arm64 plan - #137200

Merged
jkotas merged 4 commits into
dotnet:mainfrom
am11:chore/share-eh-funclet-helpers-rv64-la64
Nov 11, 2026
Merged

jkotas merged 4 commits into
dotnet:mainfrom
am11:chore/share-eh-funclet-helpers-rv64-la64

Conversation

@am11

@am11 am11 commented Nov 9, 2026

Copy link
Copy Markdown
Member

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.

@am11 am11 changed the title Chore/share eh funclet helpers rv64 la64 Share eh funclet helpers rv64 la64 Nov 9, 2026
@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
@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

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@am11
am11 force-pushed the chore/share-eh-funclet-helpers-rv64-la64 branch from 8167f2f to 5ae7e2f Compare November 9, 2026 16:22
@am11 am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Nov 9, 2026
@am11 am11 changed the title Share eh funclet helpers rv64 la64 Bring RV64 and LA64 EH helpers to x64/arm64 plan Nov 9, 2026
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, and the funclet frame info is shared
  by all 64-bit targets.
- 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]>
@am11
am11 force-pushed the chore/share-eh-funclet-helpers-rv64-la64 branch from d9bd953 to 5501160 Compare November 10, 2026 13:42
@am11
am11 marked this pull request as ready for review November 10, 2026 13:42
@jkotas

jkotas commented Nov 10, 2026

Copy link
Copy Markdown
Member

Could you please update the comment at the R2R version bump to apply to all platforms https://github.com/dotnet/runtime/pull/137168/changes#diff-629b3f51fac4e86af46c243083bf13c2bae37e0f11fa23b2958ad86535d9c557R89 ? I think it is fine to piggyback on the one R2R version bump even though the work is split into multiple PRs.

@jkotas

jkotas commented Nov 10, 2026

Copy link
Copy Markdown
Member

Have you done any testing on this?

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.

🟡 Changes recommended

LoongArch64 funclet restores can load unrelated or uninitialized floating-point values by assuming a LASX context layout, while NativeAOT TLS helpers on both architectures lack required unwind metadata.

3 open issues
What changed in this PR

Extends the ARM64 funclet model from #137168 to RISC-V64 and LoongArch64, sharing exception-handling helpers between CoreCLR and NativeAOT.

Changes:

  • Simplifies funclet frames to the return address and outgoing argument space, moving register preservation into runtime helpers.
  • Updates NativeAOT catch resumption and stack unwinding for the shared helpers.
  • Consolidates 64-bit conditions and expands the ReadyToRun version 34 ABI comment.
File Description
src/​coreclr/​vm/​riscv64/​AsmMacros_Shared.h Adds parent-context register loads.
src/​coreclr/​vm/​riscv64/​asmhelpers.S Removes superseded funclet helpers.
src/​coreclr/​vm/​riscv64/​asmconstants.h Defines the floating-point context offset.
src/​coreclr/​vm/​loongarch64/​AsmMacros_Shared.h Adds parent-context register loads.
src/​coreclr/​vm/​loongarch64/​asmhelpers.S Removes superseded funclet helpers.
src/​coreclr/​vm/​loongarch64/​asmconstants.h Defines the floating-point context offset.
src/​coreclr/​vm/​eetwain.cpp Uses context-based filter calls on all 64-bit targets.
src/​coreclr/​vm/​CMakeLists.txt Includes the shared helpers in CoreCLR builds.
src/​coreclr/​runtime/​riscv64/​EHHelpers.S Adds shared RISC-V64 funclet helpers.
src/​coreclr/​runtime/​loongarch64/​EHHelpers.S Adds shared LoongArch64 funclet helpers.
src/​coreclr/​nativeaot/​Runtime/​StackFrameIterator.cpp Adapts unwinding to the new helper frames.
src/​coreclr/​nativeaot/​Runtime/​riscv64/​ExceptionHandling.S Replaces legacy helpers with catch resumption.
src/​coreclr/​nativeaot/​Runtime/​riscv64/​AsmMacros_Shared.h Adds register-display loads and write-back.
src/​coreclr/​nativeaot/​Runtime/​loongarch64/​ExceptionHandling.S Replaces legacy helpers with catch resumption.
src/​coreclr/​nativeaot/​Runtime/​loongarch64/​AsmMacros_Shared.h Adds register-display loads and write-back.
src/​coreclr/​nativeaot/​Runtime/​CMakeLists.txt Includes shared helpers for both architectures.
src/​coreclr/​nativeaot/​Runtime.Base/​src/​System/​Runtime/​InternalCalls.cs Extends shared helper imports to all 64-bit targets.
src/​coreclr/​nativeaot/​Runtime.Base/​src/​System/​Runtime/​ExceptionHandling.cs Routes 64-bit dispatch through shared helpers.
src/​coreclr/​jit/​codegenriscv64.cpp Simplifies funclet prologs, epilogs, and frame sizing.
src/​coreclr/​jit/​codegenloongarch64.cpp Simplifies funclet prologs, epilogs, and frame sizing.
src/​coreclr/​jit/​codegenarm64.cpp Adopts the common frame-size field name.
src/​coreclr/​jit/​codegen.h Consolidates 64-bit funclet frame information.
src/​coreclr/​inc/​readytorun.h Expands the ABI comment to include both architectures.

Review effort: Balanced

Comment thread src/coreclr/runtime/riscv64/EHHelpers.S Resolved
Comment thread src/coreclr/inc/readytorun.h 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.

🟡 Changes recommended

Reusing ReadyToRun major version 34 lets older RV64/LA64 runtimes accept ABI-incompatible images and risk callee-saved register corruption, requiring a fresh major version synchronized across all three version constants.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment thread src/coreclr/inc/readytorun.h Resolved
@jkotas

jkotas commented Nov 11, 2026

Copy link
Copy Markdown
Member

/ba-g osx deadletter

@jkotas
jkotas merged commit f838d6e into dotnet:main Nov 11, 2026
126 of 132 checks passed
@shushanhf

Copy link
Copy Markdown
Contributor

Thanks very much!
We will test it again on our local mackine right now.

@am11

am11 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member Author

@jkotas, with a checked runtime, I ran these suites on riscv64 hardware:

  • libraries: System.Runtime.Tests, System.Threading.Tasks.Tests, System.Diagnostics.StackTrace.Tests
  • runtime: JIT/Methodical/eh, JIT/jit64/eh, baseservices/exceptions

With #137318, they all passed. That PR fixes a pre-existing JIT bug in the riscv64 CAS codegen that isn't related to the EH changes; the Lock assertions in checked builds caught it.

@am11
am11 deleted the chore/share-eh-funclet-helpers-rv64-la64 branch November 11, 2026 01:41
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 11, 2026
jkotas pushed a commit that referenced this pull request Nov 11, 2026
Fix the building error for cfi_rel_offset by #137200.
@shushanhf

shushanhf commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Thanks very much! We will test it again on our local mackine right now.

LoongArch64-Debian-OS:
Release-mode:
TOTAL PASSED FAILED SKIPPED UNKNOWN
15897 15541 0 356 0

Checked-mode:
TOTAL PASSED FAILED SKIPPED UNKNOWN
15897 15541 0 356 0

Debug-mode:
TOTAL PASSED FAILED SKIPPED UNKNOWN
15786 15433 1 352 0

LoongArch64-Alpine-OS:
Release-mode:
TOTAL PASSED FAILED SKIPPED UNKNOWN
15962 15604 0 358 0

Checked-mode:
TOTAL PASSED FAILED SKIPPED UNKNOWN
15962 15604 0 358 0

Debug-mode:
TOTAL PASSED FAILED SKIPPED UNKNOWN
15961 15601 2 358 0

The failed cases are:
JIT/opt/GuardedDevirtualization/badinlinee/badinlinee.cmd (also failed on other CPU archs before this PR)
JIT/Regression/JitBlue/Runtime_135557/Runtime_135557/Runtime_135557.cmd (also failed on other CPU archs before this PR)

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

Labels

arch-loongarch64 arch-riscv Related to the RISC-V architecture 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.

4 participants