Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor WASM AOT segfault in wasm-opt on linux-musl-x64 when FSharp.Core is referenced #44933

Open
zotanmew opened this issue Nov 18, 2024 · 2 comments
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@zotanmew
Copy link

zotanmew commented Nov 18, 2024

Describe the bug

Publish fails at the wasm-opt stage of blazor WASM AOT compilation with error message:

emcc : error : '/usr/share/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.56.Sdk.linux-musl-x64/9.0.0/tools/bin/wasm-opt --strip-target-features --post-emscripten -O2 --low-memory-unused --zero-filled-memory --pass-arg=directize-initial-contents-immutable /test/iceshrimp.net/Iceshrimp.Frontend/obj/Release/net9.0/wasm/for-publish/dotnet.native.wasm -o /test/iceshrimp.net/Iceshrimp.Frontend/obj/Release/net9.0/wasm/for-publish/dotnet.native.wasm -g --mvp-features --enable-bulk-memory --enable-exception-handling --enable-multivalue --enable-mutable-globals --enable-reference-types --enable-sign-ext --enable-simd' failed (received SIGSEGV (-11))
    /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/9.0.0/Sdk/BrowserWasmApp.targets(494,5): error MSB3073: The command "emcc "@/usr/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/9.0.0/runtimes/browser-wasm/native/src/emcc-default.rsp" -msimd128 "@/usr/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.browser-wasm/9.0.0/runtimes/browser-wasm/native/src/emcc-link.rsp" "@/test/iceshrimp.net/Iceshrimp.Frontend/obj/Release/net9.0/wasm/for-publish/emcc-link.rsp"" exited with code 1.

Workaround: publish with -p:EmccLinkOptimizationFlag="-O0"

This problem does not occur on glibc-based linux-x64 systems.

Copying the dotnet.native.wasm from the failed build on a musl system to a glibc system & invoking wasm-opt manually also does not reproduce the issue.

To Reproduce

docker run --rm -it mcr.microsoft.com/dotnet/sdk:9.0-alpine
dotnet workload install wasm-tools
apk add python3
mkdir test
cd test
dotnet new blazorwasm
dotnet add package FSharp.Core
dotnet publish -p:RunAOTCompilation=true

To prove it works on glibc:

docker run --rm -it mcr.microsoft.com/dotnet/sdk:9.0
dotnet workload install wasm-tools
apt update && apt install python3 -y
mkdir test
cd test
dotnet new blazorwasm
dotnet add package FSharp.Core
dotnet publish -p:RunAOTCompilation=true

Further technical details

dotnet --info
.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.c6f19616
 MSBuild version:   17.12.7+5b8665660

Runtime Environment:
 OS Name:     alpine
 OS Version:  3.20
 OS Platform: Linux
 RID:         linux-musl-x64
 Base Path:   /usr/share/dotnet/sdk/9.0.100/

.NET workloads installed:
 [wasm-tools]
   Installation Source: SDK 9.0.100
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       /usr/share/dotnet/sdk-manifests/9.0.100/microsoft.net.workload.mono.toolchain.current/9.0.0/WorkloadManifest.json
   Install Type:        FileBased

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  9.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Nov 18, 2024
@zotanmew
Copy link
Author

Problem seems to be stack size. Running https://github.com/yaegashi/muslstack on wasm-opt seems to solve the issue:

apk add go
go install github.com/yaegashi/muslstack@latest
~/go/bin/muslstack -s 0x800000 /usr/share/dotnet/packs/Microsoft.NET.Runtime.Emscripten.3.1.56.Sdk.linux-musl-x64/9.0.0/tools/bin/wasm-opt

# rerun publish

@zotanmew
Copy link
Author

I've patched this in our downstream dotnet-sdk dockerfile: https://iceshrimp.dev/iceshrimp/Iceshrimp.NET/commit/1511692b1e7c113e2448c1eabe39848e4c7aab2d

Might be a good idea to build emscripten with a higher stack-size=, so this is not necessary anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

1 participant