Skip to content

Preserve NativeAOT WASI numeric exit codes - #135954

Merged
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasi-exit-codes
Oct 19, 2026
Merged

MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasi-exit-codes

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Summary

Preserve the managed entry point's numeric exit code in NativeAOT WASI applications.

WASI Preview 2 libc's normal startup calls main and returns r != 0 through the CLI run interface. A test returning 100 consequently produces host exit code 1, even with Wasmtime's exit-with-code option: libc has already discarded the number.

Call exit(__managed__Main(...)) on WASI so libc can use the numeric exit-with-code interface. Other platforms' bootstrap paths are unchanged. Wasmtime still needs -S cli-exit-with-code=y to enable that interface.

Validation

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

  • .\build.cmd clr.nativeaotruntime -rc Checked -lc Release -os wasi -arch wasm passed.
  • .\src\tests\build.cmd nativeaot checked test nativeaot\SmokeTests\AttributeTrimming\AttributeTrimming.csproj wasm wasi passed.
  • wasmtime run -W exceptions=y -S cli-exit-with-code=y .\artifacts\tests\coreclr\wasi.wasm.Checked\nativeaot\SmokeTests\AttributeTrimming\AttributeTrimming\native\AttributeTrimming.wasm returned 100.

The SDK libc startup source and installed CRT disassembly were inspected to confirm the boolean conversion. This branch contains only this cherry-picked commit from main; it was not built independently.

Note

This PR description was generated by GitHub Copilot.

WASI Preview 2 libc startup calls main and returns r != 0 through the
CLI run interface. Returning 100 therefore produces host exit code 1,
even with Wasmtime's -S cli-exit-with-code=y: the number is already lost.

Call exit explicitly so libc's _Exit uses the exit-with-code interface
for statuses 0-255. The Wasmtime option is still needed to enable that
interface; it does not change libc's normal-main return path. Preview 1
startup instead forwards nonzero main results to __wasi_proc_exit.

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.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

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

@MichalStrehovsky
MichalStrehovsky enabled auto-merge (squash) October 16, 2026 22:47
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

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

2 similar comments
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

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

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

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

@MichalStrehovsky
MichalStrehovsky merged commit 17730e8 into dotnet:main Oct 19, 2026
100 of 102 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the nativeaot-wasi-exit-codes branch October 19, 2026 04:41
@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