WebAssembly / WebAssembly/binaryen

wasm-opt: tables cannot be declared after functions

Open
#1,108 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

wasm-opt appears to expect tables in textual wast to be declared before any function bodies, but some utilities such as wabt's wasm2wast always places it after, near the bottom of the file.

[parse exception: no table]Fatal: error in parsing input

https://github.com/WebAssembly/binaryen/blob/b2c17a105e9fbe86c059793032ee0be676245a8a/src/wasm/wasm-s-parser.cpp#L1356

If I move the table text above the functions, the issue resolves.

 (module
   (type $t0 (func))
+  (table 1 anyfunc)
   (func $f0 (type $t0))
   (func $f1 (type $t0)
     (call_indirect $t0
       (i32.const 0)
     )
   )
-  (table 1 anyfunc)
   (elem (i32.const 0) $f0)
 )

I recall seeing a rough spec for the textual format but can't seem to find it right now to see whether binaryen or wabt is at fault or if this is just undefined behavior. I only see the super high level Text Format page.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/wasm/wasm-s-parser.cpp around line 1356 and reproduce the failure using wasm-opt with the textual module shown in the issue. Compare parsing when the table follows the function bodies versus when it precedes them, and check the WebAssembly text-format expectations. Done means valid input from wabt's wasm2wast is accepted without requiring the table to be moved.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.