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

[mono] [wasi][wasm] Wasm AOT breaks wasm export functions #101276

Open
ReneeGA2020 opened this issue Apr 19, 2024 · 2 comments
Open

[mono] [wasi][wasm] Wasm AOT breaks wasm export functions #101276

ReneeGA2020 opened this issue Apr 19, 2024 · 2 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono os-wasi Related to WASI variant of arch-wasm
Milestone

Comments

@ReneeGA2020
Copy link

ReneeGA2020 commented Apr 19, 2024

Description

After a recent fix, wasm interpreter no longer require a unmanaged delegate as workaround to initialize exports. But it looks like the AOT version still get the uninitialized element error.

Reproduction Steps

  1. Clone the runtime https://github.com/dotnet/runtime/
  2. git pull with the leastest (was testing with a344abd of april)
  3. Follow the steps here to build wasi runtime https://github.com/dotnet/runtime/blob/main/src/mono/wasi/README.md
  4. Test the wasi native sample with RunAOTCompilation, the samaple features import and export functions to native:
  5. ./dotnet.cmd publish /p:RunAOTCompilation=true /p:TargetOS=wasi /p:Configuration=Release /t:RunSample src/mono/sample/wasi/native

Expected behavior

The console prints:

main: 0
UnmanagedFunc calling ManagedFunc
MyExport(123) -> 42
ManagedFunc returned 42

Actual behavior

The console prints:

main: 0
UnmanagedFunc calling ManagedFunc
EXEC : error : failed to run main module Wasi.Native.Sample.wasm [E:\runtime\src\mono\sample\wasi\native\Wasi.Native.
Sample.csproj]

Caused by:
0: failed to invoke command default
1: error while executing at wasm backtrace:
2: wasm trap: uninitialized element

Regression?

No response

Known Workarounds

No response

Configuration

NET9 + Windows + Wasmtime + WASI SDK 21
Tested with .NET 9 alpha local build with latest commit a344abd
Tested with .NET 9 Preview 3 installed from the official website

Other information

Directly export function to Wasmtime lead to the same issue.
It worked fine with no RunAOTCompilation

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 19, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 19, 2024
@jeffschwMSFT jeffschwMSFT added arch-wasm WebAssembly architecture area-Codegen-AOT-mono labels Apr 19, 2024
@vcsjones vcsjones removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 19, 2024
@maraf maraf added this to the 9.0.0 milestone Apr 25, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Apr 25, 2024
@maraf maraf added the os-wasi Related to WASI variant of arch-wasm label Apr 25, 2024
@lewing
Copy link
Member

lewing commented Apr 26, 2024

main: 0
UnmanagedFunc calling ManagedFunc
Error: failed to run main module `.\testwasinative.wasm`

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
           0: 0xd956 - <unknown>!<wasm function 33>
           1: 0xca2d5e - <unknown>!<wasm function 17873>
           2: 0x5e3a9c - <unknown>!<wasm function 7396>
           3: 0x5e3944 - <unknown>!<wasm function 7394>
           4: 0x957886 - <unknown>!<wasm function 11235>
           5: 0x935521 - <unknown>!<wasm function 11156>
           6: 0xc7f0a9 - <unknown>!<wasm function 17326>
           7: 0xc7df17 - <unknown>!<wasm function 17306>
           8: 0xc44e0e - <unknown>!<wasm function 16337>
           9: 0xc4587c - <unknown>!<wasm function 16346>
          10: 0xc49dff - <unknown>!<wasm function 16415>
          11: 0xc498de - <unknown>!<wasm function 16412>
          12: 0x108b9 - <unknown>!<wasm function 80>
          13: 0xca6a39 - <unknown>!<wasm function 17901>
          14: 0xd6c5 - <unknown>!<wasm function 28>
    2: wasm trap: uninitialized element

I can reproduce this. Works with trimming but no aot, does not work with /p:RunAotCompilation=true

@pavelsavara
Copy link
Member

I also have a repro

Caused by:
0: failed to invoke `run` function
1: error while executing at wasm backtrace:
0: 0x18a33 - ManagedFunc
                at C:\Dev\runtime\artifacts\bin\Wasi.Build.Tests\Debug\net9.0\win-x64\wbt artifacts\Release_nsxhe3qu_k4m\C:/Dev/runtime/artifacts/bin/Wasi.Build.Tests/Debug/net9.0/win-x64/wbt artifacts/Release_nsxhe3qu_k4m/obj/Release/net9.0/wasi-wasm/wasm/for-publish\pinvoke-table.h:262:3
1: 0x2fb8360 - UnmanagedFunc
                at C:\Dev\runtime\artifacts\bin\Wasi.Build.Tests\Debug\net9.0\win-x64\wbt artifacts\Release_nsxhe3qu_k4m\native.c:9:11
2: 0xb8b983 - .tmpnwLnie!aot_wrapper_Wasi_dot_Native_dot_Test_pinvoke_Wasi_dot_Native_dot_Test_Sample_Sample_dot_Test__MyImport_pinvoke_void_void_
3: 0xb8b815 - .tmpnwLnie!Wasi_Native_Test_Sample_Test_Main_string__
4: 0x2230d49 - .tmpnwLnie!aot_instances_aot_wrapper_gsharedvt_out_sig_pinvoke_i4_obj
5: 0x220e21d - .tmpnwLnie!aot_instances_wrapper_runtime_invoke_object_runtime_invoke_sig_void_intptr_intptr_intptr_object_intptr_intptr_intptr
6: 0x2de5908 - mono_llvmonly_runtime_invoke
                at C:\Dev\runtime\artifacts\obj\mono\wasi.wasm.Debug\C:/Dev/runtime/src/mono/mono/mini\mini-runtime.c:3424:2
7: 0x2de0938 - mono_jit_runtime_invoke
                at C:\Dev\runtime\artifacts\obj\mono\wasi.wasm.Debug\C:/Dev/runtime/src/mono/mono/mini\mini-runtime.c:3688:12
8: 0x2d1389c - do_runtime_invoke
                at C:\Dev\runtime\artifacts\obj\mono\wasi.wasm.Debug\C:/Dev/runtime/src/mono/mono/metadata\object.c:2572:11
9: 0x2d15a7d - mono_runtime_try_invoke
                at C:\Dev\runtime\artifacts\obj\mono\wasi.wasm.Debug\C:/Dev/runtime/src/mono/mono/metadata\object.c:2729:9
10: 0x2d2539f - do_try_exec_main
                at C:\Dev\runtime\artifacts\obj\mono\wasi.wasm.Debug\C:/Dev/runtime/src/mono/mono/metadata\object.c:4739:9
11: 0x2d24c14 - mono_runtime_try_exec_main
                at C:\Dev\runtime\artifacts\obj\mono\wasi.wasm.Debug\C:/Dev/runtime/src/mono/mono/metadata\object.c:4821:9
12: 0x2d23ec7 - mono_runtime_run_main
                at C:\Dev\runtime\artifacts\obj\mono\wasi.wasm.Debug\C:/Dev/runtime/src/mono/mono/metadata\object.c:4343:9
13: 0x1bf91 - __main_argc_argv
                at C:\Dev\runtime\artifacts\bin\dotnet-latest\packs\Microsoft.NETCore.App.Runtime.Mono.wasi-wasm\9.0.0-dev\runtimes\wasi-wasm\native\src\main.c:108:12
14: 0x2fbc571 - .tmpnwLnie!__main_void
15: 0x1867c - _start
                at C:\wasi-sdk\sysroot\wasi-libc-wasm32-wasip2\libc-bottom-half/crt\crt1-command.c:43:13
16: 0x3d73efa - wit-component:adapter:wasi_snapshot_preview1!wasi:cli/run@0.2.0#run

2: wasm trap: uninitialized element

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono os-wasi Related to WASI variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

8 participants