[Wasm R2R] Report tracked GC vars as untracked in GC info#129100
Conversation
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.
|
@kg PTAL |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
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::gcMakeRegPtrTableto include tracked-on-frame GC locals (and tracked reg-arg stack homes) in the “untracked stack pointers” section whennoTrackedGCSlotsis in effect (Wasm). - Update
CodeGen::genCheckUseBlockIniton Wasm to forcelvMustInitfor 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). |
|
Failure is probably SPMI timing skew...?? |
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.