Skip to content

Converge NativeAOT transition and throw helpers - #137436

Open
am11 wants to merge 7 commits into
dotnet:mainfrom
am11:chore/converge-transition-throw
Open

am11 wants to merge 7 commits into
dotnet:mainfrom
am11:chore/converge-transition-throw

Conversation

@am11

@am11 am11 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member
  • RhpUniversalTransitionTailCall becomes RhpInterfaceDispatchSlow, like in CoreCLR. It is built with the PROLOG_WITH_TRANSITION_BLOCK/EPILOG_WITH_TRANSITION_BLOCK_TAILCALL macros, which move from CoreCLR to the shared runtime/<arch> macro files, and calls RhpCidResolve directly. The arguments are still reported conservatively.
  • The throw helpers set up and link their ExInfo with RhpPushExInfo instead of doing it in assembly. The unhijack in RhpThrowEx is removed, since it is not tail called.

Also removes leftovers of the old funclet ABI: DWORD_PTR in EECodeManager::CallFunclet and a stale PSPSym comment.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 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 12, 2026
@am11
am11 requested review from janvorli and jkotas November 12, 2026 17:40
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@am11
am11 force-pushed the chore/converge-transition-throw branch 3 times, most recently from 09249cd to 548f7c9 Compare November 12, 2026 18:32
@am11
am11 marked this pull request as ready for review November 12, 2026 18:32
@jkotas
jkotas requested a balanced review from Copilot November 13, 2026 03:42

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

NativeAOT exception-handling and frame ABI changes across six architectures require runtime validation beyond static review to establish GC relocation, hijack recovery, unwind behavior, and Windows CET/CFG correctness.

No open issues 🎉

What changed in this PR

This PR reduces duplication between NativeAOT and CoreCLR by sharing transition-frame assembly macros and centralizing NativeAOT exception setup in C++ workers.

Changes:

  • Moves transition-block macros into shared architecture files and updates NativeAOT interface dispatch to call RhpCidResolve directly.
  • Refactors throw helpers to capture the throw-site context, with shared workers managing ExInfo and dedicated assembly helpers entering managed exception dispatch.
  • Simplifies managed transition-block offsets, replaces funclet-related DWORD_PTR types with UINT_PTR, and corrects stale comments.
File Description
src/​coreclr/​vm/​exceptionhandling.cpp Uses UINT_PTR for funclet results.
src/​coreclr/​vm/​eetwain.cpp Updates funclet result types and comments.
src/​coreclr/​vm/​arm64/​asmmacros.h Removes macros moved to shared ARM64 code.
src/​coreclr/​vm/​amd64/​AsmMacros.inc Removes macros moved to shared AMD64 code.
src/​coreclr/​runtime/​riscv64/​AsmMacros_Unix.inc Hosts shared RISC-V transition-block macros.
src/​coreclr/​runtime/​loongarch64/​AsmMacros_Unix.inc Hosts shared LoongArch transition-block macros.
src/​coreclr/​runtime/​arm64/​AsmMacros_Windows.h Hosts shared Windows ARM64 transition-block macros.
src/​coreclr/​runtime/​arm64/​AsmMacros_Unix.inc Hosts shared Unix ARM64 transition-block macros.
src/​coreclr/​runtime/​arm/​AsmMacros_Unix.inc Hosts shared ARM transition-block macros.
src/​coreclr/​runtime/​amd64/​AsmMacros_Windows.inc Hosts shared Windows AMD64 transition-block macros.
src/​coreclr/​runtime/​amd64/​AsmMacros_Unix.inc Hosts shared Unix AMD64 transition-block macros.
src/​coreclr/​pal/​inc/​unixasmmacrosriscv64.inc Removes relocated RISC-V macros.
src/​coreclr/​pal/​inc/​unixasmmacrosloongarch64.inc Removes relocated LoongArch macros.
src/​coreclr/​pal/​inc/​unixasmmacrosarm64.inc Removes relocated ARM64 macros.
src/​coreclr/​pal/​inc/​unixasmmacrosarm.inc Removes relocated ARM macros.
src/​coreclr/​pal/​inc/​unixasmmacrosamd64.inc Removes relocated AMD64 macros.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosriscv64.inc Defines floating-point argument save-area size.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosloongarch64.inc Defines floating-point argument save-area size.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosarm64.inc Defines the q0–q7 save-area size.
src/​coreclr/​nativeaot/​Runtime/​thread.h Declares throw-site unhijacking helper.
src/​coreclr/​nativeaot/​Runtime/​thread.cpp Centralizes throw-site unhijacking logic.
src/​coreclr/​nativeaot/​Runtime/​riscv64/​UniversalTransition.S Uses shared macros and direct dispatch resolution.
src/​coreclr/​nativeaot/​Runtime/​riscv64/​ExceptionHandling.S Delegates exception setup to shared workers.
src/​coreclr/​nativeaot/​Runtime/​riscv64/​DispatchResolve.S Simplifies transition handoff using t5.
src/​coreclr/​nativeaot/​Runtime/​loongarch64/​UniversalTransition.S Uses shared macros and direct dispatch resolution.
src/​coreclr/​nativeaot/​Runtime/​loongarch64/​ExceptionHandling.S Delegates exception setup to shared workers.
src/​coreclr/​nativeaot/​Runtime/​loongarch64/​DispatchResolve.S Removes obsolete resolver-address setup.
src/​coreclr/​nativeaot/​Runtime/​i386/​ExceptionHandling.asm Uses shared workers and new dispatcher-call helpers.
src/​coreclr/​nativeaot/​Runtime/​i386/​AsmMacros.inc Declares decorated exception-worker symbols.
src/​coreclr/​nativeaot/​Runtime/​EHHelpers.cpp Adds shared exception setup and dispatch workers.
src/​coreclr/​nativeaot/​Runtime/​arm64/​UniversalTransition.S Uses shared macros and direct dispatch resolution.
src/​coreclr/​nativeaot/​Runtime/​arm64/​UniversalTransition.asm Shares transition layout while retaining guarded dispatch.
src/​coreclr/​nativeaot/​Runtime/​arm64/​ExceptionHandling.S Uses shared workers and dispatcher-call frames.
src/​coreclr/​nativeaot/​Runtime/​arm64/​ExceptionHandling.asm Updates Windows throw helpers to use shared workers.
src/​coreclr/​nativeaot/​Runtime/​arm64/​DispatchResolve.S Passes the dispatch cell directly in x11.
src/​coreclr/​nativeaot/​Runtime/​arm64/​DispatchResolve.asm Removes obsolete transition argument setup.
src/​coreclr/​nativeaot/​Runtime/​arm64/​AsmMacros.h Adds save-area size and worker declarations.
src/​coreclr/​nativeaot/​Runtime/​arm/​UniversalTransition.S Uses shared transition macros and r12 dispatch cell.
src/​coreclr/​nativeaot/​Runtime/​arm/​ExceptionHandling.S Uses shared workers and dispatcher-call frames.
src/​coreclr/​nativeaot/​Runtime/​arm/​DispatchResolve.S Removes hidden stack arguments for transition calls.
src/​coreclr/​nativeaot/​Runtime/​amd64/​UniversalTransition.S Uses shared macros and direct dispatch resolution.
src/​coreclr/​nativeaot/​Runtime/​amd64/​UniversalTransition.asm Shares transition layout while retaining guarded dispatch.
src/​coreclr/​nativeaot/​Runtime/​amd64/​ExceptionHandling.S Shares context capture and delegates exception setup.
src/​coreclr/​nativeaot/​Runtime/​amd64/​ExceptionHandling.asm Uses shared workers and dispatcher-call frames.
src/​coreclr/​nativeaot/​Runtime/​amd64/​DispatchResolve.S Removes obsolete resolver-address setup.
src/​coreclr/​nativeaot/​Runtime/​amd64/​DispatchResolve.asm Removes obsolete resolver-address setup.
src/​coreclr/​nativeaot/​Runtime/​amd64/​AsmMacros.inc Adds outgoing argument-space size and worker declarations.
src/​coreclr/​nativeaot/​Common/​src/​Internal/​Runtime/​TransitionBlock.cs Replaces unused layout abstractions with this offsets.
src/​coreclr/​jit/​codegenarmarch.cpp Corrects a varargs comment; no code behavior change.
src/​coreclr/​inc/​eetwain.h Aligns funclet declarations on UINT_PTR.

Review effort: Balanced

@jkotas jkotas 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.

This is again a type of change that would be easier to review and polish for a single arch first.

Comment thread src/coreclr/vm/amd64/AsmMacros.inc Resolved
- RhpUniversalTransitionTailCall becomes RhpInterfaceDispatchSlow, like
  in CoreCLR. It is built with the PROLOG_WITH_TRANSITION_BLOCK and
  EPILOG_WITH_TRANSITION_BLOCK_TAILCALL macros, which move from CoreCLR
  to the shared runtime/<arch> macro files, and calls RhpCidResolve
  directly. The arguments are still reported conservatively.
- The throw helpers set up and link their ExInfo with RhpPushExInfo
  instead of doing it in assembly. The unhijack in RhpThrowEx is
  removed, since it is not tail called.

Also removes leftovers of the old funclet ABI: DWORD_PTR in
EECodeManager::CallFunclet and a stale PSPSym comment.

Co-authored-by: Cursor <[email protected]>
@am11
am11 force-pushed the chore/converge-transition-throw branch from 548f7c9 to 7b5cac0 Compare November 13, 2026 11:16
am11 and others added 4 commits November 13, 2026 13:46
The hijack code passes the return address from the stack, which has
the Thumb bit set on arm, so the return address of a thunk such as
RhpInterfaceDispatchSlow did not match its label.

Co-authored-by: Cursor <[email protected]>
`INLINE_GETTHREAD` saves `x0` and `lr` around the TLS lookup, and the
`EPILOG_RESTORE_REG_PAIR_INDEXED` that pops them emits `.cfi_restore`
for both. That resets `lr` to its rule at function entry, which is wrong
in functions that saved `lr` in their prologue before using the macro,
such as `CallEHFunclet`. For the rest of such a function the CFI claims
that `lr` holds the caller's return address, so after the call into a
funclet lldb computes `CallEHFunclet` as its own caller and stops
unwinding.

Wrap the macro in `.cfi_remember_state` / `.cfi_restore_state` so the
caller's unwind rules are restored as they were.

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

am11 commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

This is again a type of change that would be easier to review and polish for a single arch first.

@jkotas, I can split it in four parts: x64, arm64, {RV,LA}64 and 32-bit if that's preferred.

@jkotas

jkotas commented Nov 16, 2026

Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

`ReturnAddressToCanonicalPC` in `IsValidReturnAddress` also strips the
PAC signature on arm64, but its callers pass either an already stripped
return address or an unsigned context IP. Only arm needed a change, so
clear the Thumb bit at the hijack call site instead, the same way arm64
calls `PacStripPtr` there.

Co-authored-by: Cursor <[email protected]>
The hijack code passes the return address from the stack, so let
IsValidReturnAddress canonicalize it instead of duplicating
ReturnAddressToCanonicalPC at the call site.

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

This branch has not been deployed

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

Labels

area-NativeAOT-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.

3 participants