WebAssembly / WebAssembly/wabt

wat2wasm: data section memory index

Open
#2,518 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
8.1k
Forks
827
Avg merge
4d 6h
Merged PRs (30d)
18

Description

Take the following code:

(module
  (memory $n 1)
  (memory $m 1)
  (data (memory $m) (i32.const 0))
)

Compile.

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).

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 by reproducing the example with the wat2wasm entry point and inspect the emitted data section bytes for the segment using memory $m. Compare the encoding with the WebAssembly data-section specification and validate the result by compiling the output in JavaScript; done means the memory index is emitted and the module compiles successfully.

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
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.