Implement struct return thunks in CoreCLR WASM InterpToNativeGenerator#130379
Merged
Conversation
Remove the PORTABILITY_ASSERT for indirect struct returns in the CoreCLR WASM interp-to-native thunk generator. For struct return types (S<N> tokens), emit C typedefs of the correct size so emcc generates the proper sret ABI calling convention. This fixes the runtime crash when CoreCLR WASM code calls native functions that return structs. Also remove the native-mono test category filter from EnsureWasmAbiRulesAreFollowedInInterpreter since it now works on CoreCLR. Fixes dotnet#120897 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the CoreCLR WASM interp-to-native thunk generator to support P/Invokes that return structs, removing the prior assert-only behavior and enabling CoreCLR interpreter scenarios that involve indirect struct returns. It also updates a WASM build test to run on CoreCLR now that this ABI shape is supported.
Changes:
- Collect unique
S<N>struct return sizes up-front and emit correspondingtypedef struct { char d[N]; } wasm_ret_S<N>;definitions in generated code. - Generate call-thunks that use the emitted typedef as the native function’s return type (instead of asserting), allowing the toolchain to apply the correct hidden-return-buffer calling convention.
- Remove the
native-monotest category restriction fromEnsureWasmAbiRulesAreFollowedInInterpreter, allowing the interpreter ABI test to run on CoreCLR.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/tasks/WasmAppBuilder/coreclr/InterpToNativeGenerator.cs | Adds struct-return typedef emission and uses those types for S<N> return thunks to avoid the previous portability assert. |
| src/mono/wasm/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs | Enables the interpreter ABI validation test to run on CoreCLR by removing the mono-only category gate. |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
3 tasks
The CoreCLR WASM pipeline generates callhelpers-pinvoke.cpp, not pinvoke-table.cpp. This was already fixed in the workload PR but needs to be included here since the test now runs on CoreCLR after removing the native-mono category. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Member
|
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
|
The EnsureWasmAbiRulesAreFollowedInInterpreter test requires the native build pipeline (NativeFileReference for wasm-abi.c) which is only available in the workload enablement PR. Re-add native-mono category so this test is skipped on CoreCLR until the pipeline is available. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Member
Author
Member
|
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
steveisok
approved these changes
Jul 14, 2026
This was referenced Jul 15, 2026
maraf
reviewed
Jul 15, 2026
| [Theory] | ||
| [BuildAndRun(aot: false)] | ||
| [TestCategory("native-mono")] // coreclr ActiveIssue: https://github.com/dotnet/runtime/issues/120897 | ||
| [TestCategory("native-mono")] |
Member
There was a problem hiding this comment.
The native-mono runs only on mono. The native runs on both.
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.
Summary
Implements struct return support in the CoreCLR WASM interp-to-native thunk generator, fixing #120897.
Problem
InterpToNativeGenerator.csemitted aPORTABILITY_ASSERT("Indirect struct return is not yet implemented.")for any PInvoke signature with a struct return type. This caused a runtime crash when CoreCLR WASM apps called native functions returning structs.Fix
typedef struct { char d[N]; } wasm_ret_SN;) for each unique sizeCallFunc_*thunks instead of assertingThe fix works for both browser-wasm and wasi-wasm (same generator, same wasm32 ABI).
Test Changes
native-monotest category fromEnsureWasmAbiRulesAreFollowedInInterpreter— this test now passes on CoreCLR tooNote
This PR was generated with the assistance of GitHub Copilot.