Skip to content

R2RDump: decode all GC info versions with the shared cDAC decoders - #137959

Merged
davidwrighton merged 2 commits into
dotnet:mainfrom
davidwrighton:r2rdump-cdac-gcinfo
Nov 23, 2026
Merged

davidwrighton merged 2 commits into
dotnet:mainfrom
davidwrighton:r2rdump-cdac-gcinfo

Conversation

@davidwrighton

@davidwrighton davidwrighton commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

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

  • Shared source instead of a DLL reference. ILCompiler.Reflection.ReadyToRun.csproj links the decoder closure from src/native/managed/cdac (abstractions, GCInfoDecoder.cs, platform traits, and the x86 decoder).
  • Cdac/CdacTarget.cs supplies small stand-ins for the parts of the cDAC Target/TargetStream that the decoders use, plus an ImageTarget over the image NativeReader. Addresses are image offsets, and the highest offset read gives the blob size.
    • The cDAC decoder reads through a fixed 10000-byte window. R2RDump decodes the whole blob, which can be larger, so the R2R TargetStream extends to the end of the image.
  • Cdac/CdacGcInfo.cs and Cdac/CdacX86GcInfo.cs provide BaseGcInfo implementations (header, safepoints, interruptible ranges, slot table, lifetimes, and transitions). CdacGcInfo also exposes the legacy ReturnKind and SecurityObjectStackSlot fields.
  • Legacy format support is version-gated in the shared cDAC decoder: v1 uses 9 flag bits; v2–3 include 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.
  • x86 support starts at version 1. Versions 1–4 share the x86 encoding.
  • x86 fix: for R2R major version 14 and later, a 4-byte UNWIND_INFO { FunctionLength } precedes the x86 GC info (see codeman.cpp's GetUnwindDataBlob). 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 ReturnKind and WantsReportOnlyLeaf as 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:

  • The ReturnKind line is removed.
  • WantsReportOnlyLeaf now matches native (True for v4+).
  • New StackBaseRegister and GenericsInstContextKind lines.
  • Slot and stack-base formatting differs.

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 Release and dotnet build src/coreclr/tools/dotnet-pgo -c Release: succeeded with no warnings.
  • R2RDump --gc --sc over 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.

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

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

@jkotas

jkotas commented Nov 20, 2026

Copy link
Copy Markdown
Member

because the cDAC decoders assume v4+.

Should we fix that? The GCInfo format deltas have been fairly small.

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

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]>
@davidwrighton

Copy link
Copy Markdown
Member Author

@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.

@davidwrighton
davidwrighton marked this pull request as ready for review November 20, 2026 01:23
@davidwrighton
davidwrighton requested a balanced review from Copilot November 20, 2026 01:23
@davidwrighton davidwrighton changed the title R2RDump: decode GC info v4+ with the shared cDAC decoders R2RDump: decode all GC info versions with the shared cDAC decoders Nov 20, 2026

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

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

@davidwrighton

Copy link
Copy Markdown
Member Author

/ba-g failures unrelated.

@davidwrighton
davidwrighton merged commit 6433d42 into dotnet:main Nov 23, 2026
145 of 150 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 24, 2026
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.

4 participants