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

run-native: assemblyscript hello world fails with 'WASM error: only one memory per module is supported ()' #740

Open
nycki93 opened this issue Jul 7, 2024 · 5 comments

Comments

@nycki93
Copy link

nycki93 commented Jul 7, 2024

steps to reproduce:

w4 version 2.7.0
node version 20.1.0

w4 new --assemblyscript hello-world
cd hello-world
npm run build
w4 run-native build/cart.wasm

output:

WASM error: only one memory per module is supported ()

tested: the cart works in browser with w4 run cart.wasm.

tested: if the cart is bundled for windows with w4 bundle cart.wasm --windows cart.exe then the exe produces the same error as before.

tested: removing "importMemory": true in asconfig.json seems to fix the issue. is this flag needed?

@yamt
Copy link
Contributor

yamt commented Aug 14, 2024

fwiw, it seems wasm3-specifc as it doesn't happen with toywasm. #749
i haven't tried wasmer.

@easeway
Copy link

easeway commented Sep 5, 2024

This was caused by wasm3 bug, the wasm3 runtime requires exactly one memory section: https://github.com/wasm3/wasm3/blob/main/source/m3_parse.c#L460, however, it's legal to have wasm declare 0 memory sections. The fix will be >1 versus !=1 in the above code.

Or build wasm4 using wasmer as runtime (not tried).

@peter-jerry-ye
Copy link

It may be related to how the memory is imported, i.e.

(import "env" "memory" (memory 1))

vs

(memory (import "env" "memory") 1)

The former one will fail due to the fact that @easeway mentioned: there will be no memory in memory section

@yamt
Copy link
Contributor

yamt commented Sep 15, 2024

(import "env" "memory" (memory 1))

vs

(memory (import "env" "memory") 1)

these two are exactly same.

@yamt
Copy link
Contributor

yamt commented Sep 15, 2024

assemblyscript seems to produce an empty memory section, which makes wasm3 unhappy.

other toolchains usually just omits the memory section if a module has no memory defined. wasm3 wrongly assumes this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants