Skip to content

[Wasm] Add missing return buffer argument in wasm import thunks#128104

Merged
kg merged 4 commits into
dotnet:mainfrom
kg:wasm-import-thunk-retbuff-arg
May 14, 2026
Merged

[Wasm] Add missing return buffer argument in wasm import thunks#128104
kg merged 4 commits into
dotnet:mainfrom
kg:wasm-import-thunk-retbuff-arg

Conversation

@kg
Copy link
Copy Markdown
Member

@kg kg commented May 12, 2026

Fixes errors like

Failed to construct WebAssembly module for Webcil image: {
  wasmPath: '/Users/kg/AppData/Local/Temp/wasm-ryujit-runner/sandbox/IL/test-module.wasm',
  errorMessage: 'WebAssembly.Module(): Compiling function #39 failed: not enough arguments on the stack for call_indirect (need 3, got 2) @+8418'
}
Unhandled exception. System.BadImageFormatException: Bad IL format. The format of the file '/Users/kg/AppData/Local/Temp/wasm-ryujit-runner/sandbox/IL/test-module.wasm' is invalid.

#39 WasmDelayLoadHelper->EagerImports->SignaturePointer_ReadyToRunHelper_DelayLoad_MethodCall(ImportSection:MethodImports,Kind:DelayLoadHelper,Sig:S16p) ( i32, i32, i32 ) -> none (75 byte(s))

cc @davidwrighton @AndyAyersMS

Copilot AI review requested due to automatic review settings May 12, 2026 22:58
@kg kg added the arch-wasm WebAssembly architecture label May 12, 2026
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label May 12, 2026
Copy link
Copy Markdown
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 WebAssembly import thunk emitter in the ReadyToRun AOT toolchain to account for signatures that require a hidden return-buffer (struct return) argument, preventing invalid wasm codegen at indirect call sites.

Changes:

  • Detect struct-return signatures that require a hidden return buffer argument.
  • Attempt to push the return buffer argument before the final call_indirect dispatch in the import thunk.

Copy link
Copy Markdown
Member

@davidwrighton davidwrighton left a comment

Choose a reason for hiding this comment

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

LGTM, just remove the FIXME.

Copilot AI review requested due to automatic review settings May 13, 2026 17:39
@kg kg marked this pull request as ready for review May 13, 2026 17:42
Copy link
Copy Markdown
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 1 out of 1 changed files in this pull request and generated 1 comment.

@kg
Copy link
Copy Markdown
Member Author

kg commented May 14, 2026

/ba-g os x flakes

@kg kg merged commit ea32e27 into dotnet:main May 14, 2026
109 of 112 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-crossgen2-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants