wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

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

Open bashor opened this issue 1 year ago • 17 comments

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
  1. 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

bashor avatar May 09 '24 21:05 bashor

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

TianlongLiang avatar May 10 '24 11:05 TianlongLiang

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

bashor avatar May 10 '24 13:05 bashor

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

bashor avatar May 10 '24 13:05 bashor

Thanks, I will definitely check it out!

TianlongLiang avatar May 13 '24 06:05 TianlongLiang

Please try #3447.

wenyongh avatar May 20 '24 08:05 wenyongh

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

bashor avatar Jun 04 '24 20:06 bashor

@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.

wenyongh avatar Jun 06 '24 07:06 wenyongh

@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

bashor avatar Jun 07 '24 14:06 bashor

@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.

wenyongh avatar Jun 18 '24 07:06 wenyongh

@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 

bashor avatar Jun 19 '24 00:06 bashor

@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.

wenyongh avatar Jul 02 '24 01:07 wenyongh

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

bashor avatar Jul 02 '24 11:07 bashor

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

bashor avatar Jul 02 '24 15:07 bashor

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

wenyongh avatar Jul 05 '24 06:07 wenyongh

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

bashor avatar Jul 05 '24 15:07 bashor