Skip to content

[Wasm RyuJIT] Start generating relocations for call_indirect#124205

Merged
kg merged 29 commits into
dotnet:mainfrom
kg:wasm-call-relocs
Feb 13, 2026
Merged

[Wasm RyuJIT] Start generating relocations for call_indirect#124205
kg merged 29 commits into
dotnet:mainfrom
kg:wasm-call-relocs

Conversation

@kg

@kg kg commented Feb 10, 2026

Copy link
Copy Markdown
Contributor
  • Add various relocation types from the wasm linking spec to CorInfoReloc and RelocType
  • Add new instruction formats for relocated constant payloads like IF_CALL and IF_MEMADDR
  • Use relocations in emitIns_Call
  • Add pseudo-instructions for relocated i32_const
  • Make WasmTypeNode an ISymbolNode so it can be a reloc target

Copilot AI review requested due to automatic review settings February 10, 2026 00:09
@kg kg added arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Feb 10, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 WASM JIT emitter to begin supporting relocatable immediates for call_indirect, by representing certain immediates as “padded reloc” placeholders and centralizing constant emission logic.

Changes:

  • Use getWasmTypeSymbol and store the returned handle in the call_indirect immediate as a relocatable constant.
  • Teach instrDesc::idCodeSize() to account for padded reloc sizes for call_indirect immediates.
  • Add helper routines to emit either normal (S)LEB128 constants or fixed-size padded relocation placeholders.

Reviewed changes

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

File Description
src/coreclr/jit/emitwasm.h Declares new helper APIs for emitting padded relocations/constants.
src/coreclr/jit/emitwasm.cpp Implements padded-reloc emission and switches call_indirect immediate handling to use a relocatable constant path.

Comment thread src/coreclr/jit/emitwasm.cpp Outdated
Comment thread src/coreclr/jit/emitwasm.cpp Outdated
Comment thread src/coreclr/jit/emitwasm.cpp Outdated
@kg

kg commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

Current status:

Generating: N003 (???,???) [000001] --CXG+-----                         *  CALL r2r_ind void   Program:voidFunc()
Added IP mapping: 0x0001 STACK_EMPTY CALL_INSTRUCTION (G_M45341_IG02,ins#4,ofs#8)
IN0005:             i32.const 0
IN0006:             i32.load 0 0
IN0007:             call_indirect 4611686018431713352 0      ;; Program:voidFunc()

~~~ snip ~~~

IN0005: 00001E      i32.const 0
IN0006: 000020      i32.load 0 0
recordRelocation: 000001D2A75F2E7C (rw: 000001D2A75F2E7C) => 4000000000420048, type 28 (relocType), delta 0
Unhandled exception. ILCompiler.CodeGenerationFailedException: Code generation failed for method '[wasm-test]Program.callVoidFunc()'
 ---> System.ArgumentException: Unsupported relocation type: R_WASM_TYPE_INDEX_LEB
   at Internal.JitInterface.CorInfoImpl.GetRelocType(CorInfoReloc)
   at Internal.JitInterface.CorInfoImpl.recordRelocation(Void*, Void*, Void*, CorInfoReloc, Int32)
   at Internal.JitInterface.CorInfoImpl._recordRelocation(IntPtr, IntPtr*, Void*, Void*, Void*, CorInfoReloc, Int32)
   --- End of inner exception stack trace ---
   at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode, MethodIL)

Copilot AI review requested due to automatic review settings February 10, 2026 17:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 9 out of 9 changed files in this pull request and generated 5 comments.

Comment thread src/coreclr/jit/emitwasm.cpp
Comment thread src/coreclr/jit/emitwasm.cpp Outdated
Comment thread src/coreclr/jit/emitwasm.cpp Outdated
Comment thread src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs
Comment thread src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmTypeNode.cs Outdated
Copilot AI review requested due to automatic review settings February 10, 2026 17:33
Comment thread src/coreclr/inc/corinfo.h Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/emitwasm.cpp Outdated
@kg kg marked this pull request as ready for review February 10, 2026 17:51
@kg kg requested a review from MichalStrehovsky as a code owner February 10, 2026 17:51
Copilot AI review requested due to automatic review settings February 10, 2026 17:51
@kg

kg commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

cc @dotnet/jit-contrib

I'm not sure we need to actually generate a valid ULEB/SLEB fill pattern here because R2R is going to be replacing the fill pattern with the real value.
I'm also not sure we need to pad relocations in the first place, since we care about code size ideally when R2R replaces the placeholders with the relocated values it should be shrinking the relocations as necessary.

Copilot AI review requested due to automatic review settings February 11, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs
Comment thread src/coreclr/jit/emitwasm.cpp
Comment thread src/coreclr/jit/codegenwasm.cpp Outdated
Comment thread src/coreclr/jit/emitwasm.cpp
Comment thread src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs
Copilot AI review requested due to automatic review settings February 11, 2026 23:55
@kg

kg commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

It pads the (U|S)LEB values to 5 bytes now using the algorithm from runtimelab. For completeness's sake I'm manually validating them for the whole 32-bit space right now since I can't manually test them inside of crossgen yet (we're not generating that type of reloc anywhere.)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/codegenwasm.cpp Outdated

@SingleAccretion SingleAccretion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor comments.

Comment thread src/coreclr/jit/codegenwasm.cpp
Comment thread src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs Outdated

@AndyAyersMS AndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI review requested due to automatic review settings February 13, 2026 02:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 11 out of 11 changed files in this pull request and generated 4 comments.

Comment thread src/coreclr/tools/Common/Compiler/ObjectWriter/Dwarf/DwarfHelper.cs
Comment thread src/coreclr/tools/Common/Compiler/ObjectWriter/Dwarf/DwarfHelper.cs
Comment thread src/coreclr/tools/Common/Compiler/ObjectWriter/Dwarf/DwarfHelper.cs
Comment thread src/coreclr/jit/emitwasm.cpp
@kg kg enabled auto-merge (squash) February 13, 2026 03:42
@kg kg merged commit 0efcb73 into dotnet:main Feb 13, 2026
130 of 132 checks passed
iremyux pushed a commit to iremyux/dotnet-runtime that referenced this pull request Mar 2, 2026
…124205)

* Add various relocation types from the wasm linking spec to CorInfoReloc and RelocType
* Add new instruction formats for relocated constant payloads like IF_FUNCIDX and IF_MEMADDR
* Use relocations in emitIns_Call
* Add pseudo-instructions for relocated i32_const
* Make WasmTypeNode an ISymbolNode so it can be a reloc target
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants