Skip to content

GC info in webassembly R2R files was not found/decoded properly - #128860

Merged
davidwrighton merged 6 commits into
dotnet:mainfrom
davidwrighton:gcissues
Jun 4, 2026
Merged

davidwrighton merged 6 commits into
dotnet:mainfrom
davidwrighton:gcissues

Conversation

@davidwrighton

Copy link
Copy Markdown
Member
  • The writer was aligning the gc format, which isn't necessary, and the readers in R2RDump/runtime were not expecting
  • R2RDump was assuming HAS_FIXED_STACK_PARAMETER_SCRATCH_AREA was set to true when it wasn't

Drive-by work

  • R2RDump handling of debug data in WebAssembly isn't correct, and is attempting to print data about debug data that is incorrect. This was causing an exception in R2RDump that interfered with making further progress on this work. Changed to simply return "NYI". We should fix this later/disable debug data in WebAssembly R2R files.
  • Added new DumpRva switch to R2RDump to allow easier diagnostics of issues in WebAssembly R2R files. This allows viewing the data portion of the WebAssembly file much more like a hex dump, which is helpful.

Copilot AI review requested due to automatic review settings June 1, 2026 17:08
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label Jun 1, 2026
@davidwrighton
davidwrighton requested a review from kg June 1, 2026 17:14

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 the ReadyToRun toolchain (R2RDump and ILCompiler ReadyToRun/Reflection readers) to better handle WebAssembly R2R payloads, particularly around GC-info encoding/decoding and diagnostics.

Changes:

  • Add a new --dump-rva switch to R2RDump to dump raw bytes at a specified RVA:Size.
  • Adjust WebAssembly-specific GC-info handling (skip fixed stack parameter scratch area decoding; remove 4-byte alignment/padding in the writer path).
  • Avoid throwing for Wasm32 debug register name decoding by returning a placeholder string.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/tools/r2rdump/TextDumper.cs Changes raw byte dumping behavior for unwind info (now attempts dump on all platforms).
src/coreclr/tools/r2rdump/R2RDumpRootCommand.cs Introduces the --dump-rva CLI option.
src/coreclr/tools/r2rdump/Program.cs Implements parsing/handling for --dump-rva.
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs Adds a per-target flag controlling whether fixed stack parameter scratch area is encoded/decoded.
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs Returns a placeholder register name for Wasm32 instead of throwing.
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs Conditions decoding of stack outgoing/scratch area on the new GC-info trait flag.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodGCInfoNode.cs Skips 4-byte alignment/padding for Wasm32 when laying out / emitting runtime function GC-info blobs.
Comments suppressed due to low confidence (2)

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodGCInfoNode.cs:67

  • CalculateFuncletOffsets still reserves 4 bytes for the personality routine on Wasm (if (arch != X86) offset += sizeof(uint)), but EncodeDataCore explicitly does not emit a personality routine component for TargetArchitecture.Wasm32. This makes the offsets inconsistent with the actual encoded layout and risks emitting incorrect runtime function GC-info pointers for Wasm. The personality routine size reservation should match the EncodeDataCore condition (!= X86 && != Wasm32).
                if (factory.Target.Architecture != TargetArchitecture.Wasm32)
                {
                    offset += (-offset & 3); // 4-alignment for the personality routine
                }
                if (factory.Target.Architecture != TargetArchitecture.X86)
                {
                    offset += sizeof(uint); // personality routine
                }

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodGCInfoNode.cs:95

  • Same offset/layout mismatch for cold funclets: CalculateFuncletOffsets reserves 4 bytes for a personality routine on Wasm, but EncodeDataCore doesn’t emit one for TargetArchitecture.Wasm32. Adjust the condition here as well so cold funclet offsets match the encoded data.
                        if (factory.Target.Architecture != TargetArchitecture.Wasm32)
                        {
                            offset += (-offset & 3); // 4-alignment for the personality routine
                        }
                        if (factory.Target.Architecture != TargetArchitecture.X86)
                        {
                            offset += sizeof(uint); // personality routine
                        }

Comment thread src/coreclr/tools/r2rdump/Program.cs Resolved
Comment thread src/coreclr/tools/r2rdump/TextDumper.cs Resolved
@kg

kg commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Testing locally with the latest version of this PR, the GC has lit up and is trying to decode our gc information with some degree of success. Currently chasing down a GetRegisterSlot assert (GetStackSlot is trying to read the FP so it can locate FP-relative slots).

Copilot AI review requested due to automatic review settings June 3, 2026 22:15

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/tools/r2rdump/Program.cs Resolved
@davidwrighton

Copy link
Copy Markdown
Member Author

/ba-g known infra issue with the osx x64 queue

@davidwrighton
davidwrighton merged commit becd5e3 into dotnet:main Jun 4, 2026
111 of 113 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 5, 2026
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jun 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
)

- The writer was aligning the gc format, which isn't necessary, and the
readers in R2RDump/runtime were not expecting
- R2RDump was assuming HAS_FIXED_STACK_PARAMETER_SCRATCH_AREA was set to
true when it wasn't

Drive-by work
- R2RDump handling of debug data in WebAssembly isn't correct, and is
attempting to print data about debug data that is incorrect. This was
causing an exception in R2RDump that interfered with making further
progress on this work. Changed to simply return "NYI". We should fix
this later/disable debug data in WebAssembly R2R files.
- Added new DumpRva switch to R2RDump to allow easier diagnostics of
issues in WebAssembly R2R files. This allows viewing the data portion of
the WebAssembly file much more like a hex dump, which is helpful.
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-crossgen2-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants