webassemblyjs icon indicating copy to clipboard operation
webassemblyjs copied to clipboard

globals should not support multiple initialisation instructions

Open ColinEberhardt opened this issue 7 years ago • 3 comments

I can't find this documented in the official specification, however the 'unofficial' specification indicates that the init field of globals (and data sections), is an 'instantiation-time initializer'

https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#global-section

These are single instructions, therefore the way we handle globals is currently incorrect, as illustrated by this test:

https://github.com/xtuc/js-webassembly-interpreter/blob/master/test/compiler/parsing/fixtures/watf/global/with-multiple-instrs-in-init/actual.wast

I've verified this by using the wat2wasm tool on the acbove actual.wast file, and it fails with the message:

error: invalid global initializer expression, must be a constant expression; either *.const or get_global.
  (global i32

ColinEberhardt avatar Feb 15 '18 11:02 ColinEberhardt

I added a note here about that https://github.com/xtuc/js-webassembly-interpreter/blob/431caff0cb1debecd7c3b864103f78d3debc1ac6/src/interpreter/runtime/values/global.js#L19-L23. Might be worth opening an issue on the spec to clarify this?

The test you mentioned is only for parsing, since it's an 'instantiation-time initializer' it should still parse, right? My implementation of global initialization passes the spec tests tho.

xtuc avatar Feb 15 '18 11:02 xtuc

raised an issue with the spec here: https://github.com/WebAssembly/spec/issues/694

ColinEberhardt avatar Feb 15 '18 11:02 ColinEberhardt

Thanks!

xtuc avatar Feb 15 '18 11:02 xtuc