[Wasm RyuJit] Type Index Relocation Support in Wasm Object Writer#124685
Merged
adamperlin merged 27 commits intodotnet:mainfrom Feb 27, 2026
Merged
[Wasm RyuJit] Type Index Relocation Support in Wasm Object Writer#124685adamperlin merged 27 commits intodotnet:mainfrom
adamperlin merged 27 commits intodotnet:mainfrom
Conversation
…er for common use in crossgen, use WasmFuncType as backing data for WasmTypeNode
…jectWriter and add support for resolving type index relocations
…-object-writer-type-relocs
…, remove unnecessary array copy when creating WasmTypeNode
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds type index relocation support to the WebAssembly (Wasm) object writer for crossgen compilation. The implementation enables the object writer to collect Wasm type signatures, assign them indices, and resolve WASM_TYPE_INDEX_LEB relocations without requiring a separate linker.
Changes:
- Introduces
WasmFuncTypeand related type infrastructure by moving it fromILCompiler.ObjectWritertoILCompiler.DependencyAnalysis.Wasmnamespace - Implements relocation resolution in
WasmObjectWriterto handle type index relocations - Refactors
WasmTypeNodeto use the newWasmFuncTypeand emit proper object data with symbols
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypes.cs | New file containing WasmValueType, WasmResultType, and WasmFuncType moved from ObjectWriter namespace with additional comparison and mangling support |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs | Updated to use WasmFuncType instead of raw CorInfoWasmType[], implements ISymbolDefinitionNode, and emits encoded type data |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Adds relocation resolution logic, separates signature recording from method declaration, and implements section-level relocation handling |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.cs | Removes moved type definitions (WasmValueType, WasmResultType, WasmFuncType) |
| src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs | Splits RecordMethodSignature into two methods for signatures and declarations, adjusts relocation offsets for length prefixes |
| src/coreclr/tools/Common/Compiler/ObjectWriter/SectionWriter.cs | Adds HasLengthPrefix property and LengthPrefixSize method for relocation offset calculations |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs | Updates WriteValue and GetSize to handle Wasm relocation types including WASM_TYPE_INDEX_LEB |
| src/coreclr/tools/Common/JitInterface/WasmLowering.cs | Refactors to use ArrayBuilder for cleaner signature construction and updates namespace references |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Updates namespace import from ILCompiler.ObjectWriter to ILCompiler.DependencyAnalysis.Wasm |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs | Adds blank line for readability in getWasmTypeSymbol method |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs | Updates to use WasmFuncType and implements proper equality/hashing via the type |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj | Adds WasmTypes.cs to compilation |
| src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj | Adds WasmTypeNode.cs and WasmTypes.cs to compilation |
| src/coreclr/jit/emitwasm.cpp | Updates test code to use a void (i32, i32) signature for testing the type symbol interface |
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs
Outdated
Show resolved
Hide resolved
.../tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypes.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypes.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypes.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…yAnalysis/ReadyToRunCodegenNodeFactory.cs Co-authored-by: Copilot <[email protected]>
…r.cs Co-authored-by: Copilot <[email protected]>
…sm/WasmTypes.cs Co-authored-by: Copilot <[email protected]>
…sm/WasmTypes.cs Co-authored-by: Copilot <[email protected]>
…sm/WasmTypes.cs Co-authored-by: Copilot <[email protected]>
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypes.cs
Show resolved
Hide resolved
…sm/WasmTypeNode.cs Co-authored-by: Copilot <[email protected]>
…after lifetime ends, and make lifetime of reloc resolution buffer more explicit (also avoid re-use reloc buffer for each reloc)
…gth explicitly; jit-format
adamperlin
commented
Feb 23, 2026
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
.../tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs
Outdated
Show resolved
Hide resolved
This was referenced Feb 24, 2026
…r.cs Co-authored-by: Copilot <[email protected]>
Contributor
Author
|
@MichalStrehovsky thanks for the feedback, I've implemented your suggestions! Please feel free to give this another look if you have a moment! |
MichalStrehovsky
approved these changes
Feb 26, 2026
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs
Outdated
Show resolved
Hide resolved
…sm/WasmTypeNode.cs Avoids unnecessary copy of `data` when constructing the `ObjectData` in WasmTypeNode.GetData` Co-authored-by: Michal Strehovský <[email protected]>
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs
Show resolved
Hide resolved
…sm/WasmTypes.cs Co-authored-by: Copilot <[email protected]>
…r.cs Co-authored-by: Copilot <[email protected]>
Contributor
Author
|
/ba-g infrastructure failures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds type index relocation support to the crossgen wasm object writer.
In particular,
ILCompiler.DependencyAnalysis.Wasm. This type already contains code for encoding signaturesWasmTypeNodes and assigns them an index in the resulting module, and will resolve any references to a particular type node to its index (resolvingWASM_TYPE_INDEX_LEBrelocations).The signatures that the JIT requests are still hardcoded. To test the interface and relocation resolution, the JIT currently requests a signature of
void (int, int)which is the lowered version of avoidstatic managed method.