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

iwasm: WASM module load failed: struct or array as field is not supported in constant expr

Open bashor opened this issue 1 year ago • 6 comments

Steps to reproduce

  1. Unpack zip kotlin-wasm-wasi-example-wasm-wasi-prod.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-prod.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:

iwasm: WASM module load failed: struct or array as field is not supported in constant expr

bashor avatar May 09 '24 21:05 bashor

I took a look at this case, it's due to the current implement limitation, we don't allow to init the global with references. The #3411 is also due to this limitation.

TianlongLiang avatar May 13 '24 06:05 TianlongLiang

Any chance they will be fixed in the foreseeable future?

bashor avatar May 13 '24 11:05 bashor

We plan to take on that and will try our best to support this syntax, it could be a while through

TianlongLiang avatar May 14 '24 10:05 TianlongLiang

@bashor I submitted PR #3447, and now it should be able to run this case successfully in interpreter mode. But it only supports the nested constant initializer expression like struct.new struct.new (a struct's field is a struct), ref.func struct.new (a struct's field is a func obj). Just want to know is there requirement from you like array.new struct.new (a struct's field is an array), struct.new array.new (an array's element is a struct)? If yes, is there any case from you? Thanks.

wenyongh avatar May 17 '24 14:05 wenyongh

@wenyongh Hi! Thanks for the fix! Could you please also check it on #3411? It's an unoptimized version and should contain more cases.

bashor avatar May 19 '24 14:05 bashor

@bashor Welcome, I looked into this case and fixed several issues in wasm loader, now iwasm can run this case successfully, please try PR #3447 again.

wenyongh avatar May 20 '24 08:05 wenyongh