Wasm: encode struct arg alignment in wasm signature strings - #132244
Open
AndyAyersMS wants to merge 1 commit into
Open
Wasm: encode struct arg alignment in wasm signature strings#132244AndyAyersMS wants to merge 1 commit into
AndyAyersMS wants to merge 1 commit into
Conversation
Thunks are keyed globally by signature string, but S<N> encoded only the struct size, so structs of the same size with different alignments shared a thunk and disagreed on argument offsets. Fixes dotnet#131639 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AndyAyersMS
requested review from
MichalStrehovsky,
akoeplinger and
maraf
as code owners
August 12, 2026 23:18
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Member
Author
|
@davidwrighton PTAL This supplants the just-introduced return caching. Happy to put that back if desired. Likewise unsure if this warranted a GUID bump. It has one currently. |
Contributor
|
Tagging @dotnet/jit-contrib for JIT-EE GUID update |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the WebAssembly ReadyToRun “signature string” encoding to incorporate a struct argument’s required transition-block alignment, distinguishing same-sized structs with different alignment requirements (e.g., 8 vs 16). This addresses the thunk-sharing/layout mismatch described in #131639.
Changes:
- Introduces
A<N>alongsideS<N>to represent byref-passed structs whose transition-block slot requires 16-byte alignment. - Keys the struct-type cache by
(size, alignment)and updates signature parsing/raising logic to roundtrip the new encoding. - Updates native signature key generation, tests, and the ReadyToRun format documentation; bumps the JIT/EE versioning GUID.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tasks/WasmAppBuilder/coreclr/SignatureMapper.cs | Extends interop signature-string generation/parsing to accept A<N> and tracks known struct size+alignment. |
| src/coreclr/vm/wasm/helpers.cpp | Encodes S<N> vs A<N> in runtime signature keys based on clamped struct alignment. |
| src/coreclr/tools/Common/JitInterface/WasmLowering.cs | Adds struct-token alignment handling (A<N>), updates raising/lowering logic and struct-token caching. |
| src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Wasm.cs | Reworks struct cache to be keyed by (size, alignment) for signature raising. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmR2RToInterpreterThunkNode.cs | Updates return-struct-token detection to include A<N>. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmInterpreterToR2RThunkNode.cs | Updates return-struct-token detection to include A<N>. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunk.cs | Updates return-struct-token detection to include A<N>. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/WasmArgumentLayoutTests.cs | Adds/updates tests validating A<N> behavior and alignment-sensitive tokenization. |
| src/coreclr/inc/jiteeversionguid.h | Updates the JIT/EE versioning GUID for the signature-encoding change. |
| docs/design/coreclr/botr/readytorun-format.md | Documents the new A<N> token and rationale (alignment-sensitive thunk sharing). |
Comment on lines
353
to
356
| /// <summary> | ||
| /// Returns the number of INTERP_STACK_SLOT_SIZE slots consumed by a token. | ||
| /// Struct tokens (S<N>) consume max((size + 7) / 8, 1) slots; all others consume 1. | ||
| /// </summary> |
Comment on lines
+451
to
+455
| int alignment = GetStructArgAlignment(type); | ||
| sigBuilder.Append(alignment == WideStructArgAlignment ? 'A' : 'S'); | ||
| sigBuilder.Append(type.GetElementSize().AsInt); | ||
| ((CompilerTypeSystemContext)type.Context).CacheStructBySize(type, alignment); | ||
| } |
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.
Support structs with 16 byte alignment requirements via
A<N>signature string.Fixes #131639
Note
Portions of this change and this description were generated with GitHub Copilot.