Skip to content

[Wasm R2R] Report tracked GC vars as untracked in GC info#129100

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:wasm-gc-untracked
Jun 7, 2026
Merged

[Wasm R2R] Report tracked GC vars as untracked in GC info#129100
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:wasm-gc-untracked

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

The wasm JIT does not emit tracked GC slot lifetimes (noTrackedGCSlots is true on wasm). Ensure any (liveness) tracked GC vars get reported as untracked for GC purposes, and also get properly zero initialized.

Fixes some more cases in #128234.

The wasm JIT does not emit tracked GC slot lifetimes (noTrackedGCSlots is
true on wasm), but the untracked-vars encoding loop in gcMakeRegPtrTable
was still skipping any lvTracked local. Those vars therefore fell through
both encoding paths and were never reported to the runtime, leaving the
shadow-stack slots that hold their values invisible to the precise GC
scan. A GC during a method that kept GC refs in tracked locals would
collect or move those objects without updating the slots, producing
spurious IndexOutOfRangeException, AV, or silent corruption on R2R.

Fix:

- gcencode.cpp: gate the 'skip tracked vars' branches in
  gcMakeRegPtrTable on !noTrackedGCSlots, so on wasm tracked on-frame GC
  locals and tracked register-arg GC params are reported as untracked
  (live for the whole method).

- codegencommon.cpp: force lvMustInit for any on-frame GC ptr local on
  wasm, so the wasm prolog zero-inits those slots. Without this, a GC
  reached before the first assignment would scan stale shadow-stack
  memory as a GC root.

Fixes dotnet#128234.
Copilot AI review requested due to automatic review settings June 7, 2026 17:08
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 7, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@kg PTAL
fyi @dotnet/wasm-contrib @dotnet/jit-contrib

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

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

This PR updates CoreCLR JIT GC-info emission for TARGET_WASM R2R scenarios where tracked GC stack-slot lifetimes are not emitted, ensuring any GC locals/arg homes that would otherwise be “tracked” are instead represented as untracked GC slots and therefore conservatively reported to the runtime. It also updates prolog init heuristics so those newly-untracked GC stack slots are reliably zero-initialized on Wasm.

Changes:

  • Adjust GCInfo::gcMakeRegPtrTable to include tracked-on-frame GC locals (and tracked reg-arg stack homes) in the “untracked stack pointers” section when noTrackedGCSlots is in effect (Wasm).
  • Update CodeGen::genCheckUseBlockInit on Wasm to force lvMustInit for on-frame GC-pointer locals so shadow-stack slots get zero-inited even when liveness says they don’t need init.

Reviewed changes

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

File Description
src/coreclr/jit/gcencode.cpp Reports tracked on-frame GC vars / tracked reg-arg homes as untracked when Wasm isn’t emitting tracked GC slot lifetimes.
src/coreclr/jit/codegencommon.cpp Ensures Wasm prolog init accounts for GC vars that will now be treated as untracked roots (forces zero-init).

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Failure is probably SPMI timing skew...??

@AndyAyersMS AndyAyersMS merged commit ea282a9 into dotnet:main Jun 7, 2026
139 of 141 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants