Skip to content

Fix stackwalking handling of FP on Wasm in R2R code#130010

Open
davidwrighton wants to merge 3 commits into
dotnet:mainfrom
davidwrighton:FixR2RGenericContextsAndAssociatedIssues
Open

Fix stackwalking handling of FP on Wasm in R2R code#130010
davidwrighton wants to merge 3 commits into
dotnet:mainfrom
davidwrighton:FixR2RGenericContextsAndAssociatedIssues

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

This fixes the behavior of Generic Context lookups (and thus pairs with the JIT changes in #130000 to fix some tests)

Add setting of the various InstructionSets so that R2R code is used

Adjust CLRTest.CrossGen.targets to specify the JitWasmNyi flags so that tests generally pass

  • We should revert this part of the change once everything is in place

Add setting of the various InstructionSets so that R2R code is used

Adjust CLRTest.CrossGen.targets to specify the JitWasmNyi flags so that tests generally pass

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.

Pull request overview

Updates CoreCLR Wasm stack unwinding / stackwalking to reliably recover and propagate a frame pointer in R2R scenarios, and adjusts test CrossGen2 invocation to treat certain Wasm NYIs as R2R-unsupported so the existing test suite can run with Wasm R2R enabled.

Changes:

  • Populate InterpreterFP from the current stack pointer for Wasm stackwalking (transition frames + unwind paths + software exception frames).
  • Mark Wasm instruction sets as available for compilation so R2R code paths are selected.
  • Add Wasm-specific CrossGen2 --codegenopt flags in CLRTest script generation to reduce NYI-related test failures.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/tests/Common/CLRTest.CrossGen.targets Adds Wasm-only CrossGen2 --codegenopt flags to treat NYIs as R2R-unsupported during test compilation.
src/coreclr/vm/wasm/helpers.cpp Recovers and sets InterpreterFP in transition frame regdisplay updates; also propagates FP during virtual unwind.
src/coreclr/vm/excep.cpp Sets InterpreterFP for Wasm SoftwareExceptionFrame from the transition block stack pointer.
src/coreclr/vm/codeman.cpp Sets Wasm instruction set flags in EEJitManager::SetCpuInfo to enable R2R selection/usage.

Comment on lines 529 to 533
pRD->pCurrentContext->InterpreterIP = GetReturnAddress();
pRD->pCurrentContext->InterpreterSP = GetSP();
// Recover the frame pointer so GC-info readers can locate frame slots.
pRD->pCurrentContext->InterpreterFP = GetWasmFramePointerFromStackPointer(GetSP());

Comment thread src/coreclr/vm/excep.cpp
davidwrighton and others added 2 commits June 30, 2026 14:54
The R2R FP stackwalking change started decoding the frame pointer from
TransitionFrame::GetSP() unconditionally. For transitions out of interpreted
code GetSP() returns the address just past the TransitionBlock (the outgoing
argument area) rather than a real R2R stack pointer, so feeding it into
GetWasmFramePointerFromStackPointer followed a garbage chained pointer and
trapped with 'memory access out of bounds' during exception dispatch.

Only decode InterpreterFP when the TransitionBlock records a trusted R2R
stack pointer (both m_ReturnAddress and m_StackPointer set), mirroring the
trusted-SP condition in TransitionFrame::GetSP. Otherwise leave it 0, which
restores the previous safe behavior for interpreter transitions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants