Skip to content

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

Open
davidwrighton wants to merge 3 commits into
dotnet:mainfrom
davidwrighton:gcissues
Open

GC info in webassembly R2R files was not found/decoded properly#128860
davidwrighton wants to merge 3 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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 on lines +205 to +212
string[] parts = rvaSpec.Split(':');
if (parts.Length != 2)
{
throw new ArgumentException($"Invalid --dump-rva format '{rvaSpec}'. Expected RVA:Size (e.g. 0x1234:0x20)");
}

int rva = Convert.ToInt32(parts[0].Trim(), 16);
uint size = Convert.ToUInt32(parts[1].Trim(), 16);
Comment on lines 261 to 266
_writer.WriteLine("UnwindInfo:");
_writer.Write(rtf.UnwindInfo);
if (_model.Raw && !isWasm)
if (_model.Raw)
{
DumpBytes(rtf.UnwindRVA, (uint)rtf.UnwindInfo.Size);
}
Comment on lines 87 to 92
case Machine.RiscV64:
return ((RiscV64.Registers)regnum).ToString();
case WasmMachine.Wasm32:
throw new NotImplementedException($"No implementation for machine type {machine}.");
return "NYI";
default:
throw new NotImplementedException($"No implementation for machine type {machine}.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-crossgen2-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants