wat2wasm: data section memory index
Take the following code:
(module
(memory $n 1)
(memory $m 1)
(data (memory $m) (i32.const 0))
)
The data section has bytes:
; data segment header 0
0000012: 02 ; segment flags
0000013: 41 ; i32.const
0000014: 00 ; i32 literal
0000015: 0b ; end
As you can see from spec, flag == 2 expects memory index u32, but wabt omits it.
If you try to compile that code in JS, you'll see the error:
CompileError: WebAssembly.Module(): invalid memory index 65 for data section (having 2 memories) @+18
Adding memory index after segment flag solves the issue (watr has that fixed).
Hmm, I can't speak to the web demo, but this seems to work fine in the actual main branch of the codebase. Are you able to bisect and identify when this was fixed in the code? We might just need to update the demo.
It seems have been fixed for at least 2 years - I could not compile past 1.0.32. I guess demo only needs to update the libwabt.js.
@keithw that's weird: I've rebuilt the libwabt.js (see PR), but it still has same issue! Whereas bin/wat2wasm compiles just fine. It makes me wonder if issue is in some js include or something like that.
I assume you enabled the multi-memory feature (which is still off by default)?
Without that feature wabt throws error on validation stage.