metadce errors when data or element section is initalized with a global variable
Hello!
When you run metadce on the following wasm code:
(module
(import "host" "element_offset" (global $element_offset i32))
(func $main (export "main")
nop)
(table $table 1 funcref)
(elem $table (global.get $element_offset) $main)
)
and try to get the new reachability graph with the --dump flag, metadce crashes and gives you
=== graph ===
root:
as output. The graph input that I supplied was,
[
{
"name": "main",
"root": true,
"export": "main"
}
]
It seems to be that this happens every time you try to initialize a data or element section with a global variable, which is allowed by WebAssembly.
I can't reproduce a crash with that. But the wat file you mention doesn't load in binaryen, so maybe there was another tool in the middle? I edited your file slightly to this so it loads:
(module
(import "host" "element_offset" (global $element_offset i32))
(func $main (export "main")
(nop)
)
(table $table 1 funcref)
(elem $table (global.get $element_offset) $main)
)
Then bin/wasm-metadce a.wat -f=a --dump (where a is that JSON you provided) does not crash, and prints
=== graph ===
root: func$main$0
root: main
node: func$main$0
is function main
node: main
is export main, main
reaches: func$main$0
=============
I load the .wat file through wat2wasm using wat2wasm foo.wat -o foo.wasm and then run wasm-metadce --dump -f graph foo.wasm -o foo-dce.wasm, which still crashes with the example you provided.
Can you get a stack trace of the crash in a debug build? That might help.