Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

wasm-opt fails to run on our binary #136

@tanishiking

Description

@tanishiking
$ bin/wasm-opt --version
wasm-opt version 117 (version_117-203-g5999c996c)

wasm-opt build on 2024-05-24 WebAssembly/binaryen@5999c99

$ bin/wasm-opt sample/target/scala-2.12/sample-fastopt/main.wasm
[parse exception: bad section size, started at 7633 plus payload 61 not being equal to new position 7663 (at 0:7663)]
Fatal: error parsing wasm (try --debug for more info)
$ wasm-objdump -h sample/target/scala-2.12/sample-fastopt/main.wasm

main.wasm:      file format wasm 0x1
0000011: error: expected valid field type (got -0x8)
000090f: error: invalid global type: 0xffffffe4
0001738: error: invalid global type: 0xffffffe4
0001e22: error: expected valid local type
00050b6: warning: invalid function index: 186

Sections:

     Type start=0x0000000d end=0x000008d6 (size=0x000008c9) count: 136
   Import start=0x000008db end=0x000015f2 (size=0x00000d17) count: 112
 Function start=0x000015f7 end=0x0000172b (size=0x00000134) count: 186
      Tag start=0x00001730 end=0x00001731 (size=0x00000001) count: 0
   Global start=0x00001736 end=0x00001dbf (size=0x00000689) count: 63
   Export start=0x00001dc4 end=0x00001dc5 (size=0x00000001) count: 0
    Start start=0x00001dca end=0x00001dcc (size=0x00000002) start: 291
     Elem start=0x00001dd1 end=0x00001e0e (size=0x0000003d) count: 1
DataCount start=0x00001e13 end=0x00001e14 (size=0x00000001) count: 1
     Code start=0x00001e19 end=0x000038d5 (size=0x00001abc) count: 186
     Data start=0x000038da end=0x00003f2e (size=0x00000654) count: 1
   Custom start=0x00003f33 end=0x00006116 (size=0x000021e3) "name"
   Custom start=0x0000611b end=0x0000613c (size=0x00000021) "sourceMappingURL"

Since 0x00001dd1 = 7633, it looks like binaryen fails to parse Elem Section (more precisely, binaryen couldn't find the enough content of 61 bytes in the elem section) and failed at the validation https://github.com/WebAssembly/binaryen/blob/5999c996c36abeba912599b5fba83d0b2989ed4c/src/wasm/wasm-binary.cpp#L1829-L1834

$ wasm-objdump -s --section=elem sample/target/scala-2.12/sample-fastopt/main.wasm

...

Contents of section Elem:
0001dd1: 0107 7011 d270 0bd2 710b d273 0bd2 740b  ..p..p..q..s..t.
0001de1: d275 0bd2 7a0b d27b 0bd2 7c0b d27d 0bd2  .u..z..{..|..}..
0001df1: 7e0b d27f 0bd2 8001 0bd2 8101 0bd2 8201  ~...............
0001e01: 0bd2 8701 0bd2 8901 0bd2 a202 0b         .............

It seems binaryen stopped reading at

0001dd1: 0107 7011 d270 0bd2 710b d273 0bd2 740b  ..p..p..q..s..t.
0001de1: d275 0bd2 7a0b d27b 0bd2 7c0b d27d

?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions