Skip to content

Align NativeAOT Vector<T> to 16 bytes on WASM - #135948

Merged
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasm-vector-alignment
Oct 16, 2026
Merged

MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasm-vector-alignment

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Summary

Give NativeAOT System.Numerics.Vector<T> the 16-byte alignment required by its WASM v128 ABI.

The metadata layout contains two ulong fields, giving alignment 8. NativeAOT adjusts the vector size for the target but previously retained that metadata alignment. Shared WASM ABI lowering consequently asserts that the 16-byte vector must be 16-byte aligned.

Override the field alignment on WASM only. Keep the ABI assertion and preserve other architectures' layouts. This matches the earlier crossgen2/VM correction in #131328, which did not update NativeAOT's separate layout algorithm.

Validation

On the combined local NativeAOT WASI bringup tree, including other unmerged enablement:

  • Before the fix, Preinitialization and Reflection_FromUsage both failed with the WasmLowering.IsWasmV128Type alignment assertion.
  • .\build.cmd clr.tools -rc Checked -lc Release -os wasi -arch wasm passed after the fix.
  • .\src\tests\build.cmd nativeaot checked tree nativeaot wasm wasi compiled and linked both affected projects. The tree still failed on the existing UnitTests lowering assertion; C math ABI warnings remain.
  • Freshly rebuilt AttributeTrimming and Determinism both returned 100 under Wasmtime.

This branch contains only this cherry-picked commit from main; it was not built independently. The affected vector tests were not executed.

Note

This PR description was generated by GitHub Copilot.

Use the alignment required by the v128 ABI instead of preserving the 8-byte metadata alignment. Leave other architectures unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a6f3a617-acae-4f4f-95d3-20b2a0bac43c
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@tannergooding tannergooding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks correct for WASM. Left a question above though because this seems like possibly a gap for other types or architectures as well

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g widespread mutex failures; this change is not covered by CI

@MichalStrehovsky
MichalStrehovsky merged commit 7de32fa into dotnet:main Oct 16, 2026
118 of 120 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the nativeaot-wasm-vector-alignment branch October 16, 2026 22:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-NativeAOT-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants