Repository navigation
R2RDump: decode all GC info versions with the shared cDAC decoders - #137959
Conversation
ILCompiler.Reflection.ReadyToRun now compiles the cDAC GC info decoders (GcInfoDecoder<TTraits> and X86GCInfo) as shared source and uses them for GC info version 4 and later. Older versions keep the legacy decoders. - Cdac/CdacTarget.cs: minimal Target/TargetStream stand-ins plus an ImageTarget over the image NativeReader. - Cdac/CdacGcInfo.cs, Cdac/CdacX86GcInfo.cs: BaseGcInfo implementations over the shared decoders. - cDAC: additive internal accessors (unused by the cDAC) for header fields and the slot table; X86GCInfo.NoGCRegions made internal. - Fix x86 GC info location for R2R major >= 14, where a 4-byte UNWIND_INFO precedes the GC info. This fixes several legacy decoding defects: reverse P/Invoke slot not denormalized, transitions at adjacent interruptible range starts, stack slot base names, unsigned stack slot deltas, x86 EBP-frame call offset accumulation, x86 this/iptr argument flags, and x86 tracked EBP slot offsets. Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
Should we fix that? The GCInfo format deltas have been fairly small. |
There was a problem hiding this comment.
🟡 Changes recommended
Tracked-slot decoding performs quadratic safepoint searches that the large-blob test misses, and x86 R2R v14 layout-boundary handling lacks regression coverage.
2 open issues
What changed in this PR
This PR moves R2RDump’s GC-info v4+ decoding to shared cDAC decoders while retaining legacy decoders for older formats. It also corrects x86 GC-info offsets for R2R v14+ images.
Changes:
- Adds image-backed adapters and GC-info display models for shared decoding.
- Exposes cDAC header and slot-table data without changing cDAC decoding behavior.
- Adds decoding regressions and updates existing tests for the new models.
| File | Description |
|---|---|
| src/native/managed/cdac/tests/UnitTests/GCInfoTests.cs | Checks the exposed x86 no-GC region table. |
| src/native/managed/cdac/tests/UnitTests/GCInfoHeaderTests.cs | Tests new header and slot-table accessors. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/X86/GCInfo.cs | Exposes no-GC regions internally. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfoDecoder.cs | Adds accessors needed by R2RDump. |
| src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/x86/UnwindInfo.cs | Supports fixed-width x86 funclet unwind headers. |
| src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs | Selects shared decoders and adjusts x86 GC-info offsets. |
| src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/NativeReader.cs | Exposes image length for decoder streams. |
| src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ILCompiler.Reflection.ReadyToRun.csproj | Links the shared cDAC decoder sources. |
| src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Cdac/CdacX86GcInfo.cs | Adapts x86 decoding results for display. |
| src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Cdac/CdacTarget.cs | Provides image-backed target and stream adapters. |
| src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Cdac/CdacGcInfo.cs | Adapts non-x86 decoding results for display. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs | Updates slot assertions to use the new model. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/GcInfoRegressionTests.cs | Adds shared-decoder and large-blob regression cases. |
Review effort: Balanced
…R2RDump decoders Teach the shared cDAC GCInfo decoder the pre-v4 formats (gated on version < 4 so cDAC behavior is unchanged): 9-bit flags for v1, ReturnKind for v2-3, identity code-offset normalization, the legacy security object and PSPSym slots, and the safepoint offset-1 encoding. Lower the x86 decoder minimum version to 1, since v1-v4 share the encoding. R2RDump now always uses the cDAC decoders, and the legacy Amd64/x86 GcInfo decoders are deleted. CdacGcInfo exposes ReturnKind and SecurityObjectStackSlot. Co-authored-by: Copilot <[email protected]>
|
@jkotas I've asked copilot to look into supporting it all with the cDAC reader. Looks not too bad to me. We'll have to see what @max-charlamb thinks. |
There was a problem hiding this comment.
🟡 Changes recommended
Pre-v4 AMD64 methods with a PSPSym slot are reported relative to caller.sp instead of initial.sp, identifying the wrong stack location and requiring a decoder correction and architecture-specific test assertions.
1 open issue
2 resolved since last review
Review effort: Balanced
|
/ba-g failures unrelated. |


Summary
R2RDump now uses the cDAC GCInfo decoders for every supported GC info version. The cDAC decoder source is compiled into
ILCompiler.Reflection.ReadyToRun; no cDAC DLL reference is added. The shared decoder now handles the pre-v4 formats as well as v4+, and the R2RDump-specific legacy decoders have been removed. The cDAC's existing v4+ decoding behavior is unchanged.Approach
ILCompiler.Reflection.ReadyToRun.csprojlinks the decoder closure fromsrc/native/managed/cdac(abstractions,GCInfoDecoder.cs, platform traits, and the x86 decoder).Cdac/CdacTarget.cssupplies small stand-ins for the parts of the cDACTarget/TargetStreamthat the decoders use, plus anImageTargetover the imageNativeReader. Addresses are image offsets, and the highest offset read gives the blob size.TargetStreamextends to the end of the image.Cdac/CdacGcInfo.csandCdac/CdacX86GcInfo.csprovideBaseGcInfoimplementations (header, safepoints, interruptible ranges, slot table, lifetimes, and transitions).CdacGcInfoalso exposes the legacyReturnKindandSecurityObjectStackSlotfields.ReturnKind; pre-v4 code offsets are not normalized; and the legacy security-object and PSPSym slots and safepoint offset convention are decoded. These paths are used by R2RDump, while existing cDAC v4+ behavior remains unchanged.UNWIND_INFO { FunctionLength }precedes the x86 GC info (seecodeman.cpp'sGetUnwindDataBlob). R2RDump was reading the GC info at the wrong offset for every x86 method. This PR fixes that offset.R2RDump decoder issues addressed
Regression coverage exercises the corrected GCInfo decoding, including normalized frame slots, transitions at range boundaries, stack-slot bases, x86 call offsets and argument-push flags, x86 tracked EBP slots, signed stack-slot deltas, no-GC regions, and ESP-based VarPtr offsets. The source-linked decoder also avoids reporting
ReturnKindandWantsReportOnlyLeafas though v4+ encoded them in the legacy format.Legacy versions
The new tests cover synthetic v1, v2, and v3 headers on x64, ARM, and ARM64, along with legacy safepoint offset and x86 slot behavior. The old-format logic follows the native C++ decoder; a real pre-v4 ReadyToRun image has not yet been validated. Issues specific to .NET 10 preview formats are out of scope.
Expected R2RDump output changes
For v4+ GC info:
ReturnKindline is removed.WantsReportOnlyLeafnow matches native (True for v4+).StackBaseRegisterandGenericsInstContextKindlines.For pre-v4 GC info, R2RDump now uses the shared decoder's legacy-format decoding rather than the deleted R2RDump-specific decoder. Any R2RDiff or r2rtest baselines that include GC info may need updating.
Validation
dotnet build src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests -c Release: succeeded.dotnet test src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests -c Release --no-build: 410 passed, 21 skipped, 0 failed.dotnet test src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests -c Release --no-build --filter "FullyQualifiedName~GcInfoRegressionTests": 48 passed, 0 failed after restoring the source following a mutation check. Removing the legacy safepoint +1 adjustment made both legacy safepoint tests fail.dotnet test src/native/managed/cdac/tests/UnitTests: 4178 passed, 0 failed.dotnet build src/coreclr/tools/r2rdump/R2RDump.csproj -c Releaseanddotnet build src/coreclr/tools/dotnet-pgo -c Release: succeeded with no warnings.R2RDump --gc --scover x64 System.Private.CoreLib produced byte-identical output to the previous commit (3,874,378 lines).Note
This PR description and the changes were generated with GitHub Copilot.