Uh oh!
There was an error while loading. Please reload this page.
Crossgen2: Support Writing R2R Metadata into Wasm Data Sections in Wasm Object Writer - #122878
Conversation
…nd begin internally sorting non-code R2R nodes into WasmData type sections
…py R2R data into these segments
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Pull request overview
This PR implements support for writing R2R metadata into WebAssembly data sections by extending the WasmObjectWriter class. The changes enable crossgen2 to emit Wasm object files with proper data section support, which is critical for R2R compilation targeting WebAssembly.
Key changes:
- Introduced a
CodeDataLayoutModeenum to distinguish between platforms that require unified vs. separate code/data address spaces (Wasm32 requires separate) - Refactored
WasmObjectWriterto use the baseObjectWriterclass's methods for processing DependencyNodes instead of fully overriding EmitObject - Implemented WebAssembly data segment support, where each data section is represented as a segment that gets merged into a single data section per Wasm format requirements
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| ILCompiler.ReadyToRun.csproj | Added reference to CodeDataLayoutMode.cs for R2R compiler |
| ILCompiler.Compiler.csproj | Added reference to CodeDataLayoutMode.cs for AOT compiler |
| CodeDataLayoutMode.cs | New file defining the CodeDataLayout enum (Unified/Separate) for platform-specific code/data layout requirements |
| WasmObjectWriter.cs | Major refactor to support data sections: added RecordMethod, EmitSymbolTable, EmitRelocations, EmitObjectFile overrides; implemented WasmDataSection and WasmDataSegment classes for proper Wasm binary format encoding |
| WasmNative.cs | Added WasmConstExpr and WasmExprKind for encoding constant expressions in data segments (used for memory offset calculations) |
| SectionWriter.cs | Exposed Buffer property to allow direct access to underlying buffer writer for Wasm encoding |
| ObjectWriter.cs | Added CodeDataLayout support, made _insPaddingByte nullable for Wasm, added RecordMethod virtual method, updated EmitRelocations and EmitObjectFile signatures to include Logger parameter |
| PEObjectWriter.cs | Updated method signatures to match base class changes (Logger parameter) |
| MachObjectWriter.cs | Updated method signatures to match base class changes (Logger parameter) |
| ElfObjectWriter.cs | Updated method signatures to match base class changes (Logger parameter) |
| CoffObjectWriter.cs | Updated method signatures to match base class changes (Logger parameter) |
| ObjectNodeSection.cs | Added NeedsAlignment property and new constructor; added Wasm-specific section definitions (WasmCodeSection, WasmDataSection, etc.) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…-object-writer-v0.2
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…r.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…r.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…erlin/runtime into adamperlin/wasm-object-writer-v0.2
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
kg
commented
Jan 20, 2026
LGTM overall, thanks for working on this! |
adamperlin
commented
Jan 21, 2026
@kg Thanks for the detailed feedback! Whenever you are able, please feel free to take another look! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This PR implements support for a data section in crossgen emitted wasm r2r output files.
As part of this goal, the WasmObjectWriter class has been adapted to better conform to the base
ObjectWriterinterface, so that the base class's method can be used to process DependencyNodes.Each separate data-like is represented as a single data segment, and the segments are then merged into a single
datasection as is required by the Wasm format.