Skip to content

[Wasm RyuJit] Type Index Relocation Support in Wasm Object Writer#124685

Merged
adamperlin merged 27 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-object-writer-type-relocs
Feb 27, 2026
Merged

[Wasm RyuJit] Type Index Relocation Support in Wasm Object Writer#124685
adamperlin merged 27 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-object-writer-type-relocs

Conversation

@adamperlin
Copy link
Contributor

@adamperlin adamperlin commented Feb 21, 2026

This PR adds type index relocation support to the crossgen wasm object writer.

In particular,

  • The new WasmTypeNode symbol now uses the WasmFuncType originally defined in the object writer, now moved to ILCompiler.DependencyAnalysis.Wasm. This type already contains code for encoding signatures
  • The object writer now collects WasmTypeNodes and assigns them an index in the resulting module, and will resolve any references to a particular type node to its index (resolving WASM_TYPE_INDEX_LEB relocations).

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 a void static managed method.

…er for common use in crossgen, use WasmFuncType as backing data for WasmTypeNode
…jectWriter and add support for resolving type index relocations
…, remove unnecessary array copy when creating WasmTypeNode
Copy link
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 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 WasmFuncType and related type infrastructure by moving it from ILCompiler.ObjectWriter to ILCompiler.DependencyAnalysis.Wasm namespace
  • Implements relocation resolution in WasmObjectWriter to handle type index relocations
  • Refactors WasmTypeNode to use the new WasmFuncType and 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

Copilot AI review requested due to automatic review settings February 21, 2026 01:56
Copy link
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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings February 21, 2026 02:05
Copy link
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

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

…after lifetime ends, and make lifetime of reloc resolution buffer more explicit (also avoid re-use reloc buffer for each reloc)
@adamperlin adamperlin marked this pull request as ready for review February 23, 2026 20:06
Copilot AI review requested due to automatic review settings February 23, 2026 20:06
Copilot AI review requested due to automatic review settings February 24, 2026 01:05
Copy link
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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings February 25, 2026 22:21
@adamperlin
Copy link
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!

Copy link
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.

…sm/WasmTypeNode.cs


Avoids unnecessary copy of `data` when constructing the `ObjectData` in WasmTypeNode.GetData`

Co-authored-by: Michal Strehovský <[email protected]>
Copilot AI review requested due to automatic review settings February 26, 2026 19:46
Copy link
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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings February 26, 2026 20:58
Copy link
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

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

@adamperlin
Copy link
Contributor Author

/ba-g infrastructure failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-crossgen2-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants