Skip to content

[WASM] Jiterpreter crash using System.Text.JSON and WasmNativeStrip usage. #94939

@nickwinder

Description

@nickwinder

Description

Crash in the Jiterpreter using System.Text.JSON serialization or deserialization when native WASM is stripped or a high Emscripten optimization level is chosen.

Setting WasmNativeStrip to false rectifies the issue, so it seems the strip command is too aggressive, or is disobeying the EMSCRIPTEN_KEEP_ALIVE annotation on the mono_wasm_copy_managed_pointer symbol.

Reproduction Steps

Minimal repo highlighting the issue can be found at https://github.com/nickwinder/dotnet-8-webassembly-bug

Basically, use System.Text.JSON using WasmNativeStrip and Emscripten optimization of O3.

I've found other mixtures of settings cause the same issue, but this was the simplest and easiest to reproduce.

Expected behavior

Calling System.Text.JSON serialization/deserialization should not crash, even when native binary is stripped, or highly optimized.

Actual behavior

Crashes with the following error log.

raw cwrap mono_wasm_copy_managed_pointer not found

      at Ja (../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/https:/raw.githubusercontent.com/dotnet/runtime/5535e31a712343a63f5d7d796cd874e563e5ac14/src/mono/wasm/runtime/jiterpreter-support.ts:1862:15)
      at Ja (../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/https:/raw.githubusercontent.com/dotnet/runtime/5535e31a712343a63f5d7d796cd874e563e5ac14/src/mono/wasm/runtime/jiterpreter.ts:264:31)
      at $i (../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/https:/raw.githubusercontent.com/dotnet/runtime/5535e31a712343a63f5d7d796cd874e563e5ac14/src/mono/wasm/runtime/jiterpreter.ts:703:26)
      at ../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/https:/raw.githubusercontent.com/dotnet/runtime/5535e31a712343a63f5d7d796cd874e563e5ac14/src/mono/wasm/runtime/jiterpreter.ts:736:9
      at Ul (../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/https:/raw.githubusercontent.com/dotnet/runtime/5535e31a712343a63f5d7d796cd874e563e5ac14/src/mono/wasm/runtime/jiterpreter.ts:1049:19)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:322624)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:1589606)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:1548333)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:791465)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:122212)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:85466)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:66234)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:301784)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:1589606)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:1548333)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:791465)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:122212)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:85466)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:241702)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:791302)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:324116)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:1589606)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:1548333)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:791465)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:122212)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:622449)
      at null.<anonymous> (wasm:/wasm/00a3bc76:1:1525334)
      at Object.apply [as mono_wasm_invoke_method_bound] (../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/dotnet.native.js:8:96257)
      at mono_wasm_invoke_method_bound (../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/https:/raw.githubusercontent.com/dotnet/runtime/5535e31a712343a63f5d7d796cd874e563e5ac14/src/mono/wasm/runtime/invoke-cs.ts:273:29)
      at Object.kr (../WasmStripBug/WasmStripBug/bin/Release/net8.0/browser-wasm/AppBundle/https:/raw.githubusercontent.com/dotnet/runtime/5535e31a712343a63f5d7d796cd874e563e5ac14/src/mono/wasm/runtime/invoke-cs.ts:184:13)
      at Object.DoSomething (tests/init-test.js:5:40)

Regression?

.NET7 still allows this combination of optimization and features.

Known Workarounds

No response

Configuration

.NET8
Env : Chrome browser (likely others) and Node.js environments.
Arch : WASM

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions