Description
A minimal Microsoft.NET.Sdk.WebAssembly project fails to link when a native C file referenced with NativeFileReference uses <setjmp.h> / setjmp / longjmp.
The project explicitly passes Emscripten's wasm longjmp mode:
<EmccFlags>-sSUPPORT_LONGJMP=wasm</EmccFlags>
A standalone compile with the bundled Emscripten toolchain succeeds for the same C file using -fwasm-exceptions -sSUPPORT_LONGJMP=wasm, but the .NET WebAssembly SDK build fails with unresolved __wasm_setjmp symbols.
Reproduction Steps
Either download JumpTest.zip or:
- Create a new WASM browser project:
dotnet new wasmbrowser -n JumpTest
cd JumpTest
- Add this to the project file:
<EmccFlags>-sSUPPORT_LONGJMP=wasm</EmccFlags>
and reference the native C file:
<NativeFileReference Include="jump_test.c" />
- Add
jump_test.c:
#include <setjmp.h>
int setjmp_roundtrip(void)
{
jmp_buf buffer;
int result = setjmp(buffer);
if (result == 0)
longjmp(buffer, 42);
return result;
}
- Call it from
Program.cs:
using System;
using System.Runtime.InteropServices;
Console.WriteLine($"setjmp_roundtrip() = {NativeMethods.SetjmpRoundtrip()}");
internal static partial class NativeMethods
{
[LibraryImport("__Internal", EntryPoint = "setjmp_roundtrip")]
internal static partial int SetjmpRoundtrip();
}
- Build:
Expected behavior
The project should compile and link successfully, or the SDK should document/report that native setjmp/longjmp is unsupported for this target.
Since the project passes -sSUPPORT_LONGJMP=wasm, Emscripten's wasm SjLj support should be included during linking.
Actual behavior
The build fails during the native link step:
undefined symbol: __wasm_setjmp
undefined symbol: __wasm_setjmp_test
The failure occurs even with:
<EmccFlags>-sSUPPORT_LONGJMP=wasm</EmccFlags>
Allowing undefined symbols lets the build finish, but the produced wasm still imports env.__wasm_setjmp and env.__wasm_setjmp_test, so that is not a valid workaround.
Regression?
Unknown
Known Workarounds
Unknown
Configuration
.NET configuration:
.NET SDK:
Version: 10.0.301
Commit: 96856fd726
Workload version: 10.0.301.1
MSBuild version: 18.6.4+96856fd72
Host:
Version: 10.0.9
Architecture: x64
Commit: 901ca94124
Installed workloads:
wasm-tools 10.0.109/10.0.100
wasm-experimental 10.0.109/10.0.100
Which version of .NET is the code running on?
TargetFramework: net10.0
Microsoft.NETCore.App: 10.0.9
SDK: 10.0.301
OS and version:
Windows 10.0.26200
RID: win-x64
Other information
No response
Description
A minimal
Microsoft.NET.Sdk.WebAssemblyproject fails to link when a native C file referenced withNativeFileReferenceuses<setjmp.h>/setjmp/longjmp.The project explicitly passes Emscripten's wasm longjmp mode:
A standalone compile with the bundled Emscripten toolchain succeeds for the same C file using
-fwasm-exceptions -sSUPPORT_LONGJMP=wasm, but the .NET WebAssembly SDK build fails with unresolved__wasm_setjmpsymbols.Reproduction Steps
Either download JumpTest.zip or:
dotnet new wasmbrowser -n JumpTest cd JumpTestand reference the native C file:
jump_test.c:Program.cs:Expected behavior
The project should compile and link successfully, or the SDK should document/report that native
setjmp/longjmpis unsupported for this target.Since the project passes
-sSUPPORT_LONGJMP=wasm, Emscripten's wasm SjLj support should be included during linking.Actual behavior
The build fails during the native link step:
The failure occurs even with:
Allowing undefined symbols lets the build finish, but the produced wasm still imports
env.__wasm_setjmpandenv.__wasm_setjmp_test, so that is not a valid workaround.Regression?
Unknown
Known Workarounds
Unknown
Configuration
.NET configuration:
Which version of .NET is the code running on?
OS and version:
Other information
No response