Skip to content

[wasm] Encode struct alignment in thunk signatures - #132248

Draft
davidwrighton wants to merge 2 commits into
dotnet:mainfrom
davidwrighton:fix-wasm-struct-alignment
Draft

[wasm] Encode struct alignment in thunk signatures#132248
davidwrighton wants to merge 2 commits into
dotnet:mainfrom
davidwrighton:fix-wasm-struct-alignment

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

Supports structs with 16 byte alignment. Alternative PR to #132244

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b1af492e-7431-46af-b519-dcc504b62300
Copilot AI lite review requested due to automatic review settings August 12, 2026 23:24
@azure-pipelines

Copy link
Copy Markdown
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.

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

Updates the Wasm thunk signature-string encoding to preserve by-reference struct alignment requirements (notably 16-byte alignment) so that signature raising and transition-block layout remain correct when two same-sized structs differ in alignment.

Changes:

  • Extends struct tokens from S<N> to optionally include alignment for parameters: S!<N>:<A> (while keeping struct returns as S<N>).
  • Threads alignment through signature generation/parsing paths (runtime, WasmAppBuilder thunk generator, and crossgen2 tooling) and updates caching to disambiguate same-sized structs by (size, alignment) when needed.
  • Adds ReadyToRun tests and updates design documentation for the extended encoding.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/tasks/WasmAppBuilder/coreclr/SignatureMapper.cs Adds parsing/formatting support for alignment-qualified struct tokens and exposes helpers to extract size/alignment.
src/tasks/WasmAppBuilder/coreclr/InterpToNativeGenerator.cs Aligns interpreter-stack slot offsets for indirect struct args when token alignment exceeds 8, and normalizes struct-return typedef naming.
src/coreclr/vm/wasm/helpers.cpp Encodes parameter struct alignment into thunk signature keys while forcing return structs to remain size-only.
src/coreclr/vm/jitinterface.cpp Adjusts Wasm alignment requirement computation to account for explicit layout and elevated field alignment in auto-layout structs.
src/coreclr/tools/Common/JitInterface/WasmLowering.cs Implements parsing/emission for S!<N>:<A>, raises signatures using cached structs keyed by layout, and emits alignment only for parameters.
src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Mirrors Wasm alignment requirement logic in the tool-side JIT interface implementation.
src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Wasm.cs Changes struct caching to key by (size, alignment) when alignment is part of the signature encoding.
src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/WasmArgumentLayoutTests.cs Adds/updates tests ensuring signatures and computed offsets remain correct for same-sized structs with different alignment.
docs/design/coreclr/botr/readytorun-format.md Documents S!<N>:<A> encoding rules and clarifies slot sizing for struct tokens.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b1af492e-7431-46af-b519-dcc504b62300
Copilot AI review requested due to automatic review settings August 13, 2026 00:25

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

Suppressed comments (1)

src/coreclr/vm/jitinterface.cpp:1964

  • The comment mentions "beyond the pointer size", but the logic only adjusts the alignment when fieldAlignment > 8. On Wasm32 the pointer size is 4, so this is misleading and makes it harder to reason about why the threshold is 8.
        // Auto-layout structs can contain fields aligned beyond the pointer size on Wasm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants