bytecodealliance / wasm-micro-runtime

WebAssembly Micro Runtime (WAMR)
Apache License 2.0
4.98k stars 627 forks source link

iwasm: WASM module load failed: type mismatch: expect (ref null ht) but got other1 unknown type #3411

Open bashor opened 6 months ago

bashor commented 6 months ago

Steps to reproduce

  1. Unpack zip kotlin-wasm-wasi-example-wasm-wasi-dev.wasm.zip

  2. Build iwasm with the following command

    cmake .. -DWAMR_BUILD_GC=1 -DWAMR_BUILD_BULK_MEMORY=1 -DWAMR_BUILD_EXCE_HANDLING=1 -DWAMR_BUILD_TAIL_CALL=1 -DWAMR_BUILD_CUSTOM_NAME_SECTION=1 -DWAMR_BUILD_EXCE_HANDLING=0 && make
  3. Run ./iwasm kotlin-wasm-wasi-example-wasm-wasi-dev.wasm

Expected behavior

It should print something like:

Hello from Kotlin via WASI
Current 'realtime' timestamp is: 1715281633864118000
Current 'monotonic' timestamp is: 210424654558083

Actual behavior

It prints:

WASM module load failed: type mismatch: expect (ref null ht) but got other1 unknown type
TianlongLiang commented 6 months ago

Hi, would you mind telling me which toolchain you are using? I wasn't aware that Kotlin has standalone support for wasm, I would love to give it a try if it's publicly accessible

bashor commented 6 months ago

@TianlongLiang Hi! Kotlin Multiplatform toolchain supports wasm out of the box. Check out https://kotl.in/wasm or https://kotl.in/wasm-examples.

bashor commented 6 months ago

I'm working on Kotlin/Wasm (with other folks), so feel free to reach out if you have any questions.

TianlongLiang commented 6 months ago

Thanks, I will definitely check it out!

wenyongh commented 6 months ago

Please try #3447.

bashor commented 5 months ago

Hi, @wenyongh @TianlongLiang! Thanks for fixes, it really helped with attached examples.

Previous binaries was compiled with disabled EH on Kotlin side, after turning it on I got the a similar error. Here is a new binary --kotlin-wasm-wasi-example-wasm-wasi.wasm.zip

wenyongh commented 5 months ago

@bashor Welcome. Could you upload the wast file also? It is a little complex to analyze the wasm file without wast info, I used the tool compiled from wasm GC MVP spec proposal, but it reports: decoding error: malformed section id.

bashor commented 5 months ago

@wenyongh Here is a wat file I got using Binaryen's wasm-dis -- kotlin-wasm-wasi-example-wasm-wasi.wasm.wat.zip

$ wasm-dis --enable-gc --enable-reference-types --enable-exception-handling --enable-bulk-memory kotlin-wasm-wasi-example-wasm-wasi.wasm -o  kotlin-wasm-wasi-example-wasm-wasi.wasm.wat
wenyongh commented 5 months ago

@bashor I tried to debug it but since I am not familiar with the exception handling, I am not sure whether it is caused by the case itself, or by exception handling, or by the GC implementation. And the wasm file is really big and there are too many GC types, I need more time to try.

bashor commented 5 months ago

@wenyongh Hi! Here is a smaller version -- kotlin-wasm-wasi-example-wasm-wasi.wasm-prod.zip. Hope it will be easier to inspect.

-- Also, you can find a version optimized with Binaryen here. kotlin-wasm-wasi-example-wasm-wasi.wasm-prod-opt.zip

With the optimized version, wami fails differently:

iwasm(872,0x1f55e8c00) malloc: *** error for object 0x600000000003: pointer being freed was not allocated
iwasm(872,0x1f55e8c00) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort 
wenyongh commented 4 months ago

@bashor thanks for the wat files and the new samples, there are several issues in the handling of exception handling and GC, I submitted PR #3586 to fix them and now all the files run successfully. Please try again.

bashor commented 4 months ago

@wenyongh Nice, thanks! I'll try it and let you know.

bashor commented 4 months ago

@wenyongh confirm, with #3586, the simple example works. Thanks! I found some other bugs and am going to file separate issues for them.

wenyongh commented 4 months ago

@bashor welcome, please feel free to file issues, we will try to fix them.

bashor commented 4 months ago

@wenyongh JFYI I've just filed #3598 and #3599