Skip to content

Fix NativeAOT WASM math helper calling conventions - #136208

Merged
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasm-math-abi
Oct 22, 2026
Merged

MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasm-math-abi

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Wasm was running into linker warnings (visible in our first CI results!):

##[warning]wasm-ld(0,0): warning : function signature mismatch: sin [/__w/1/s/src/tests/nativeaot/nativeaot.csproj]
    >>> defined as (i32, f64) -> f64 in /__w/1/s/artifacts/tests/coreclr/obj/wasi.wasm.Checked/Managed/nativeaot/nativeaot/native/nativeaot.o
    >>> defined as (f64) -> f64 in /__w/1/s/.dotnet/wasm-tools/wasi-sdk/34.0-linux-x64//share/wasi-sysroot/lib/wasm32-wasip2/libc.a(sin.c.obj)

Route x86 and WASM math calls through distinct runtime wrappers, including floating-point remainder helpers, while preserving direct libc imports on other architectures.

x86 used some /alternatename linker tricks to keep the names as their C library function, but I don't think it's possible on WASM because WASM doesn't do the x86 Windows symbol name manglings and sin is sin.

Route x86 and WASM math calls through distinct runtime wrappers, including floating-point remainder helpers, while preserving direct libc imports on other architectures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 50455c2b-3074-4f0c-a48f-2486534e5002
@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.

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.

🔵 Needs a closer look

Cross-architecture calling-convention changes need x86 and WASM link-and-run validation, which was not performed during this review.

No open issues 🎉

What changed in this PR

Fixes NativeAOT math calling-convention mismatches by routing x86 and WASM calls through dedicated runtime wrappers.

Changes:

  • Renames math wrappers with the Rhp prefix and enables them for WASM.
  • Updates managed imports and remainder helper mappings while preserving direct libc calls on other architectures.
File Description
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​DependencyAnalysis/​KnownExternFunctions.cs Routes x86/WASM remainder helpers through wrappers.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Runtime/​RuntimeImports.cs Selects architecture-specific math imports.
src/​coreclr/​nativeaot/​Runtime/​MathHelpers.cpp Renames wrappers and enables WASM support.

Review effort: Balanced

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8bd8db78-9e93-4d8e-a82f-9456de1c8328
@MichalStrehovsky
MichalStrehovsky merged commit bc980bc into dotnet:main Oct 22, 2026
103 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the nativeaot-wasm-math-abi branch October 22, 2026 07:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 23, 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.

3 participants