dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.18k stars 4.72k forks source link

[wasm] Specific PInvoke call works with AOT but fails on Interp #61156

Closed TheSpydog closed 2 years ago

TheSpydog commented 2 years ago

Description

I'm attempting to run a basic FNA app with the interpreter mode of BlazorWebAssembly, and it almost works, except for one particular PInvoke call, which produces an error. When running in AOT mode, the program runs correctly.

Reproduction Steps

I have isolated the problematic PInvoke call and written a small sample project to demonstrate the bug. Clone the repo, run dotnet publish without any changes, then open the page on a local server to see the error appear. If you change the .csproj so that RunAOTCompilation is true, then running the page will print "Survived!" instead.

Expected behavior

In both Interp and AOT modes, the program should print "Survived!" with no errors.

Actual behavior

This error appears in the browser console:

console.trace() /__w/1/s/src/mono/mono/mini/aot-runtime-wasm.c:113 <disabled> dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1:17700
    573339 http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1
    _emscripten_asm_const_int http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:1366317
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:1789101
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:860323
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:171148
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:20830
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:429713
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:1556460
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:1519821
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:739925
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:91490
    <anonymous> http://127.0.0.1:8080/_framework/dotnet.wasm:1506065
    _mono_wasm_invoke_method http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1
    _call_method_with_converted_args http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1
    call_method http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1
    bind_assembly_entry_point http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1
    call_assembly_entry_point http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1
    callEntryPoint http://127.0.0.1:8080/_framework/blazor.webassembly.js:1
    Ct http://127.0.0.1:8080/_framework/blazor.webassembly.js:1

Regression?

Probably not, given that NativeFileReference is new to RC2.

Known Workarounds

None that I have found.

Configuration

.NET Version: .NET 6 rc2 OS: Windows 10 x64 Browsers: Chrome, Firefox

Other information

The file/line that the error points to is this: https://github.com/dotnet/runtime/blob/main/src/mono/mono/mini/aot-runtime-wasm.c#L113, which seems to imply this error is "CANNOT HANDLE INTERP ICALL SIG". (I don't know why this string isn't printed to the console, it would be helpful information.)

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 2 years ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

Issue Details
### Description I'm attempting to run a basic FNA app with the interpreter mode of BlazorWebAssembly, and it almost works, except for one particular PInvoke call, which produces an error. When running in AOT mode, the program runs correctly. ### Reproduction Steps I have isolated the problematic PInvoke call and written a [small sample project](https://github.com/TheSpydog/wasm-pinvoketest) to demonstrate the bug. Clone the repo, run `dotnet publish` without any changes, then open the page on a local server to see the error appear. If you change the .csproj so that RunAOTCompilation is true, then running the page will print "Survived!" instead. ### Expected behavior In both Interp and AOT modes, the program should print "Survived!" with no errors. ### Actual behavior This error appears in the browser console: ``` console.trace() /__w/1/s/src/mono/mono/mini/aot-runtime-wasm.c:113 dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1:17700 573339 http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 _emscripten_asm_const_int http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 http://127.0.0.1:8080/_framework/dotnet.wasm:1366317 http://127.0.0.1:8080/_framework/dotnet.wasm:1789101 http://127.0.0.1:8080/_framework/dotnet.wasm:860323 http://127.0.0.1:8080/_framework/dotnet.wasm:171148 http://127.0.0.1:8080/_framework/dotnet.wasm:20830 http://127.0.0.1:8080/_framework/dotnet.wasm:429713 http://127.0.0.1:8080/_framework/dotnet.wasm:1556460 http://127.0.0.1:8080/_framework/dotnet.wasm:1519821 http://127.0.0.1:8080/_framework/dotnet.wasm:739925 http://127.0.0.1:8080/_framework/dotnet.wasm:91490 http://127.0.0.1:8080/_framework/dotnet.wasm:1506065 _mono_wasm_invoke_method http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 _call_method_with_converted_args http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 call_method http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 bind_assembly_entry_point http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 call_assembly_entry_point http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 callEntryPoint http://127.0.0.1:8080/_framework/blazor.webassembly.js:1 Ct http://127.0.0.1:8080/_framework/blazor.webassembly.js:1 ``` ### Regression? Probably not, given that NativeFileReference is new to RC2. ### Known Workarounds None that I have found. ### Configuration **.NET Version:** .NET 6 rc2 **OS:** Windows 10 x64 **Browsers:** Chrome, Firefox ### Other information The file/line that the error points to is this: https://github.com/dotnet/runtime/blob/main/src/mono/mono/mini/aot-runtime-wasm.c#L113, which seems to imply this error is "CANNOT HANDLE INTERP ICALL SIG". (I don't know why this string isn't printed to the console, it would be helpful information.)
Author: TheSpydog
Assignees: -
Labels: `arch-wasm`, `untriaged`
Milestone: -
ghost commented 2 years ago

Tagging subscribers to this area: @brzvlad See info in area-owners.md if you want to be subscribed.

Issue Details
### Description I'm attempting to run a basic FNA app with the interpreter mode of BlazorWebAssembly, and it almost works, except for one particular PInvoke call, which produces an error. When running in AOT mode, the program runs correctly. ### Reproduction Steps I have isolated the problematic PInvoke call and written a [small sample project](https://github.com/TheSpydog/wasm-pinvoketest) to demonstrate the bug. Clone the repo, run `dotnet publish` without any changes, then open the page on a local server to see the error appear. If you change the .csproj so that RunAOTCompilation is true, then running the page will print "Survived!" instead. ### Expected behavior In both Interp and AOT modes, the program should print "Survived!" with no errors. ### Actual behavior This error appears in the browser console: ``` console.trace() /__w/1/s/src/mono/mono/mini/aot-runtime-wasm.c:113 dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1:17700 573339 http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 _emscripten_asm_const_int http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 http://127.0.0.1:8080/_framework/dotnet.wasm:1366317 http://127.0.0.1:8080/_framework/dotnet.wasm:1789101 http://127.0.0.1:8080/_framework/dotnet.wasm:860323 http://127.0.0.1:8080/_framework/dotnet.wasm:171148 http://127.0.0.1:8080/_framework/dotnet.wasm:20830 http://127.0.0.1:8080/_framework/dotnet.wasm:429713 http://127.0.0.1:8080/_framework/dotnet.wasm:1556460 http://127.0.0.1:8080/_framework/dotnet.wasm:1519821 http://127.0.0.1:8080/_framework/dotnet.wasm:739925 http://127.0.0.1:8080/_framework/dotnet.wasm:91490 http://127.0.0.1:8080/_framework/dotnet.wasm:1506065 _mono_wasm_invoke_method http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 _call_method_with_converted_args http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 call_method http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 bind_assembly_entry_point http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 call_assembly_entry_point http://127.0.0.1:8080/_framework/dotnet.6.0.0-rc.2.21480.5.idrh62rvaw.js:1 callEntryPoint http://127.0.0.1:8080/_framework/blazor.webassembly.js:1 Ct http://127.0.0.1:8080/_framework/blazor.webassembly.js:1 ``` ### Regression? Probably not, given that NativeFileReference is new to RC2. ### Known Workarounds None that I have found. ### Configuration **.NET Version:** .NET 6 rc2 **OS:** Windows 10 x64 **Browsers:** Chrome, Firefox ### Other information The file/line that the error points to is this: https://github.com/dotnet/runtime/blob/main/src/mono/mono/mini/aot-runtime-wasm.c#L113, which seems to imply this error is "CANNOT HANDLE INTERP ICALL SIG". (I don't know why this string isn't printed to the console, it would be helpful information.)
Author: TheSpydog
Assignees: -
Labels: `arch-wasm`, `untriaged`, `area-Codegen-Interpreter-mono`
Milestone: -
lewing commented 2 years ago

cc @BrzVlad @vargaz

PogoRollo commented 2 years ago

Will this eventually be solved at compile time?
I just hit a roadblock on a project where a simple signature (IDD) is not available.
Is forking and editing wasm_m2n_invoke.g.h really the only way to go here?