Skip to content

[Wasm RyuJIT] Start generating relocations for call_indirect#124205

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

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

Conversation

@kg
Copy link
Member

@kg kg commented Feb 10, 2026

  • 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
Contributor

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

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 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.

@kg
Copy link
Member Author

kg commented Feb 10, 2026

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

Copilot AI review requested due to automatic review settings February 10, 2026 17:33
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 9 out of 9 changed files in this pull request and generated 1 comment.

@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
Copy link
Member Author

kg commented Feb 10, 2026

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.

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Feb 11, 2026

int32 ... what do you think?

I don't see any strong reason to do hacks here. The relocation write support will also likely be used in the object writer to actually resolve the relocations (similar to e. g. https://github.com/dotnet/runtimelab/blob/c1a9777ae47f937d4e1a5484247ce73c86f45030/src/coreclr/tools/aot/ILCompiler.LLVM/CodeGen/WasmObjectWriter.cs#L310-L318). That needs proper [S|U]LEBs.

Edit: for that kind of use case, all relocs (not just those with addends) will need WriteValue implemented.

Copy link
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

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

LGTM module a few comments and the proper LEB management in Relocation.cs.

Copilot AI review requested due to automatic review settings February 11, 2026 20:38
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 11 out of 11 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings February 11, 2026 23:55
@kg
Copy link
Member Author

kg commented Feb 11, 2026

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.)

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

Copy link
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

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

LGTM with minor comments.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

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

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

5 participants