Repository navigation
GC info in webassembly R2R files was not found/decoded properly - #128860
Conversation
There was a problem hiding this comment.
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-rvaswitch to R2RDump to dump raw bytes at a specifiedRVA: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
CalculateFuncletOffsetsstill reserves 4 bytes for the personality routine on Wasm (if (arch != X86) offset += sizeof(uint)), butEncodeDataCoreexplicitly does not emit a personality routine component forTargetArchitecture.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 theEncodeDataCorecondition (!= 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:
CalculateFuncletOffsetsreserves 4 bytes for a personality routine on Wasm, butEncodeDataCoredoesn’t emit one forTargetArchitecture.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
}
|
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). |
|
/ba-g known infra issue with the osx x64 queue |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
) - 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.
Drive-by work