Skip to content

[cDAC] Fix riscv64/loongarch64 gaps and interpreter stack walking - #137365

Merged
max-charlamb merged 10 commits into
dotnet:mainfrom
am11:cdac-rv64-la64-parity
Nov 22, 2026
Merged

max-charlamb merged 10 commits into
dotnet:mainfrom
am11:cdac-rv64-la64-parity

Conversation

@am11

@am11 am11 commented Nov 11, 2026

Copy link
Copy Markdown
Member

Brings the riscv64/loongarch64 cDAC on par with arm64 and fixes interpreter stack walking found while running the cDAC stress tests (DOTNET_CdacStress=0x101/0x201) on riscv64 hardware.

riscv64/loongarch64:

  • RISCV64Context was missing R0, so every GPR and Pc was read 8 bytes off the native CONTEXT (all GCREFS stress runs failed).
  • Implement RISC-V/LoongArch64 FP struct classification (TryGetFpStructInRegistersClassification in RuntimeTypeSystem, mirroring MethodTable::GetFpStructInRegistersInfo) instead of throwing NotImplementedException from the calling convention.
  • Set the first-arg register to the next InterpreterFrame in InlinedCallFrame handling, null unwind info check in the unwinders, and SP register numbers in ClrDataFrame.

Interpreter (all architectures):

  • Decode interpreted code with the interpreter GC info encoding, with frame-relative slots and skipping slots in an active callee's frame.
  • Report InterpreterFrame's continuation (new Continuation data descriptor field).
  • Recognize interpreted funclets (handler/filter ranges of EH clauses) and compute interpreted caller contexts like VirtualUnwindInterpreterCallFrame, so funclet parents and unwound frames are skipped as in the runtime.

With these, all cDAC stress debuggees pass on riscv64 in both JIT and DOTNET_Interpreter=* modes, and the cDAC dump tests pass on riscv64 dumps.

Depends on microsoft/clrmd#1527 (for dump tests on riscv64/loongarch64) and #137337 (for interpreter on riscv64/loongarch64).

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 11, 2026
@am11 am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Nov 11, 2026
@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.

@am11
am11 temporarily deployed to copilot-pat-pool November 11, 2026 17:33 — with GitHub Actions Inactive
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@am11
am11 temporarily deployed to copilot-pat-pool November 11, 2026 17:33 — with GitHub Actions Inactive
@am11

am11 commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

osx-x64 leg dead-lettered.

@am11

am11 commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@jkotas, @steveisok, I've tested this and microsoft/clrmd#1527 on linux-riscv64 device and all tests in both repos are now passing. Could you please take a look. Thanks!

cc @shushanhf (LA64 tests of both PRs were ran under QEMU)

@jkotas
jkotas requested review from max-charlamb and a balanced review from Copilot November 19, 2026 04:32

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

GC scanning skips a non-null continuation when starting from an interpreted context, risking a missed root, while the new classification and slot-resolution paths lack focused regression coverage.

3 open issues
What changed in this PR

This PR improves cDAC’s diagnostic support for RISC-V and LoongArch64 and aligns interpreter stack walking and GC-root reporting with native runtime behavior.

Changes:

  • Corrects RISC-V context offsets and fills architecture-specific register, unwinding, and floating-point struct classification gaps.
  • Adds interpreter-aware GC decoding, continuation-root reporting, funclet detection, and caller-context handling.
  • Updates contract documentation and adds context-layout regression tests.

Validation was limited to source inspection; no builds or tests were run.

File Description
PlatformContextTests.cs Tests RISC-V context field offsets.
ClrDataFrame.cs Adds architecture-specific stack-pointer register numbers.
InterpreterFrame.cs Exposes the continuation field address.
StackWalk_1.ExceptionHandling.cs Uses interpreter-aware caller contexts during exception handling.
StackWalk_1.cs Integrates interpreter decoding and caller-context unwinding.
GcScanner.cs Adds interpreter slot filtering and continuation scanning.
RISCV64FrameHandler.cs Records the interpreter owner in A0.
LoongArch64FrameHandler.cs Records the interpreter owner in A0.
FrameHelpers.cs Computes complete interpreted caller contexts.
RISCV64Context.cs Adds R0 and corrects register offsets.
RISCV64Unwinder.cs Handles missing unwind information.
LoongArch64Unwinder.cs Handles missing unwind information.
RuntimeTypeSystem_1.cs Implements floating-point struct classification.
ExecutionManagerCore.cs Identifies interpreted funclets through exception-clause ranges.
CdacTypeHandle.cs Maps classification results to calling-convention data.
IRuntimeTypeSystem.cs Defines the classification contract and result types.
frames.h Exposes the native continuation field offset.
datadescriptor.inc Publishes the continuation data descriptor.
StackWalk.md Documents interpreter unwinding and root scanning.
RuntimeTypeSystem.md Specifies floating-point struct classification.
data-descriptor-meanings.json Describes the continuation descriptor.

Review effort: Balanced

FpStructClassificationTests covers TryGetFpStructInRegistersClassification on
RISC-V and LoongArch64: one and two floating-point fields, mixed integer and
reference fields in both orders, ordering by offset, nested structs, fixed
buffers and inline arrays, and the fallbacks to the integer calling convention
(no floating-point field, too many fields, larger than 16 bytes, overlapping
fields, too many array elements, other architectures).

The StackWalk tests cover GC reporting of an interpreted frame: decoding with
the interpreter GC info encoding, frame-relative slot addresses, and excluding
slots at and above the stack of an active callee while keeping them when the
callee's ip is null.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@am11

am11 commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

ios-arm64 failures are unrelated.

am11 and others added 2 commits November 19, 2026 22:04
- Make InterpreterFrame.Continuation optional: runtimes that support
  StackWalk version 1 but predate the descriptor entry no longer fail the
  GC scan; the continuation root is skipped for them.
- Route StackWalkData's cached caller context through the interpreter-aware
  GetCallerContext helper so CheckForSkippedFrames unwinds interpreted
  frames the same way as the other caller-context paths.
- Document FpStructMaxSize and FpStructMaxNestingDepth in
  RuntimeTypeSystem.md and use them in the pseudocode.
- Note in StackWalk.md that Continuation is optional and what happens
  when it is absent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
am11 and others added 2 commits November 20, 2026 19:38
The nesting guard is a cDAC implementation detail, not a contract constant.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-charlamb
max-charlamb merged commit 3a35e8d into dotnet:main Nov 22, 2026
147 of 150 checks passed
@am11
am11 deleted the cdac-rv64-la64-parity branch November 22, 2026 21:47
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 23, 2026
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-Diagnostics-cdac 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