WebAssembly / WebAssembly/wabt
wasm2wat normalizes element segments when printing
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.1k
- Forks
- 827
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 18
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing wasm2wat's output using the supplied foo.wasm.gz binary and compare it with the element-segment example in the issue. Check wat2wasm's corresponding normalization for context. Done should be demonstrated by a clear decision and regression coverage for whether printing preserves the original funcref/ref.func representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, wasm
- Domain
- cli, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100