You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is unfortunately a bit of a difficult issue to reproduce, but the gist of the issue is that wasm2wat will normalize an elem segment when printing, so the text format isn't necessarily faithful to how the binary format was written down.
The general idea is with an element segment that looks like (elem (;0;) funcref (ref.func 0)). This is normalized to (elem (;0;) func 0) when printing. An easy test case for this isn't available because wat2wasm will also do this normalization on encoding.
This issue cropped up with one of the upstream spec tests, looking like this:
(module binary
"\00asm" "\01\00\00\00"
"\01\04\01\60\00\00" ;; Type section
"\03\02\01\00" ;; Function section
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\05\03\01\00\00" ;; Memory section
"\09\07\01" ;; Element section with one segment
"\05\70" ;; Passive, funcref
"\01" ;; 1 element
"\d2\00\0b" ;; ref.func, index 0, end
"\0a\04\01" ;; Code section
;; function 0
"\02\00"
"\0b") ;; end
The text parser that I'm working with doesn't attempt to interpret the bytes and serializes them out, but wat2wasm in wabt will parse these bytes and, even with this module, encode a binary module that uses the (elem (;0;) func 0) encoding. A binary version of this module that reproduces the issue is here: foo.wasm.gz
I'm not really sure whether this is an issue per-se. It's a harmless difference but it does seem a bit odd that when printing the segments are normalized. I think it makes sense when encoding to be MVP-friendly where possible, though! If y'all think this isn't a major issue feel free to close!
The text was updated successfully, but these errors were encountered:
This is a good point. Currently the wabt IR doesn't distinguish between element expressions and element indexes internally, so it can't know what the original encoding was. But you're right, it probably should when reading a binary file.
This is unfortunately a bit of a difficult issue to reproduce, but the gist of the issue is that
wasm2wat
will normalize an elem segment when printing, so the text format isn't necessarily faithful to how the binary format was written down.The general idea is with an element segment that looks like
(elem (;0;) funcref (ref.func 0))
. This is normalized to(elem (;0;) func 0)
when printing. An easy test case for this isn't available becausewat2wasm
will also do this normalization on encoding.This issue cropped up with one of the upstream spec tests, looking like this:
The text parser that I'm working with doesn't attempt to interpret the bytes and serializes them out, but
wat2wasm
in wabt will parse these bytes and, even with this module, encode a binary module that uses the(elem (;0;) func 0)
encoding. A binary version of this module that reproduces the issue is here:foo.wasm.gz
I'm not really sure whether this is an issue per-se. It's a harmless difference but it does seem a bit odd that when printing the segments are normalized. I think it makes sense when encoding to be MVP-friendly where possible, though! If y'all think this isn't a major issue feel free to close!
The text was updated successfully, but these errors were encountered: