Skip to content

Commit bf564b5

Browse files
authored
[wasm-dis] Enable all features for printing (#7802)
This enables all features for wasm-dis for printing. wasm-dis currently enables all features at parsing time and restores the originally enabled features at printing time, but doesn't do any validation, so there's no point restoring the original features: https://github.com/WebAssembly/binaryen/blob/e81f964d9cc70c71c4339e6558f57ebe8eb5cc32/src/tools/wasm-dis.cpp#L70-L73 https://github.com/WebAssembly/binaryen/blob/e81f964d9cc70c71c4339e6558f57ebe8eb5cc32/src/tools/wasm-dis.cpp#L94-L100 And even if we do validation, I'm not sure how many people would use wasm-dis for validation anyway. And it's easy to be misused. For example, running `wasm-dis` without any options on a binary that has reference types enabled and has multiple tables will not print any indices for `call_indirect`s and does not even error out, happily producing a wast file that has incorrect semantics, because without table references they will all mean whatever table at index 0. https://github.com/WebAssembly/binaryen/blob/21464e7533ef235634c8d62442a8a10cafff6568/src/passes/Print.cpp#L506-L509 Note that without `-all` you can even disassemble GC binaries with `struct`s, because there's no validation. But we still don't print table references for `call_indirect`s. This PR removes that restoring and validation and enables all features at all times for wasm-dis. The test changes are two kinds: - We now have a table reference for all `call_indirect`s - We now have a type index for all `func`s At least the first change is not compatible with MVP. (Not sure about the second one.) But our wast parser doesn't seem to have any problems with parsing these without `-all` of `--enable-reference-types` at the moment. Companion change: emscripten-core/emscripten#24876
1 parent 9181f9f commit bf564b5

32 files changed

+139
-137
lines changed

src/tools/wasm-dis.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ int main(int argc, const char* argv[]) {
6767
}
6868
Module wasm;
6969
options.applyOptionsBeforeParse(wasm);
70-
// Temporarily apply all features during parsing to avoid any errors. See note
71-
// below on skipping validation.
72-
auto enabledFeatures = wasm.features;
7370
wasm.features = FeatureSet::All;
7471

7572
try {
@@ -91,13 +88,6 @@ int main(int argc, const char* argv[]) {
9188

9289
options.applyOptionsAfterParse(wasm);
9390

94-
// TODO: Validation. However, validating would mean that users are forced to
95-
// run with wasm-dis -all or such, to enable the features (unless the
96-
// features section is present, but that's rare in general). It would be
97-
// better to have an "autodetect" code path that enables used features
98-
// eventually.
99-
100-
wasm.features = enabledFeatures;
10191
if (options.debug) {
10292
std::cerr << "Printing..." << std::endl;
10393
}

test/br_to_exit.wasm.fromBinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(module
22
(type $0 (func))
3-
(func $0
3+
(func $0 (type $0)
44
(block $label
55
(br $label)
66
)

test/br_to_try.wasm.fromBinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(type $0 (func (param i32)))
33
(type $1 (func))
44
(tag $tag$0 (type $0) (param i32))
5-
(func $0
5+
(func $0 (type $1)
66
(block $label
77
(try
88
(do

test/break-to-return.wasm.fromBinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(type $0 (func (param i32 i32) (result i32)))
33
(memory $0 256 256)
44
(export "add" (func $0))
5-
(func $0 (param $0 i32) (param $1 i32) (result i32)
5+
(func $0 (type $0) (param $0 i32) (param $1 i32) (result i32)
66
(block $label (result i32)
77
(br $label
88
(i32.add

test/break-within-catch.wasm.fromBinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(type $0 (func (param i32)))
33
(type $1 (func))
44
(tag $tag$0 (type $0) (param i32))
5-
(func $0
5+
(func $0 (type $1)
66
(block $label
77
(try
88
(do

test/complexBinaryNames.wasm.fromBinary

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(module
22
(type $0 (func))
33
(export "$zoo (.bar)" (func $1))
4-
(func $foo\20\28.bar\29
4+
(func $foo\20\28.bar\29 (type $0)
55
(nop)
66
)
7-
(func $1
7+
(func $1 (type $0)
88
(call $foo\20\28.bar\29)
99
)
1010
)

test/consume-stacky.wasm.fromBinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(module
22
(type $0 (func (result i32)))
33
(memory $0 1 1)
4-
(func $0 (result i32)
4+
(func $0 (type $0) (result i32)
55
(local $scratch i32)
66
(local.set $scratch
77
(i32.const 1)

test/dylib.wasm.fromBinary

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
(type $3 (func (param i32 i32) (result i32)))
66
(import "env" "memory" (memory $mimport$0 0))
77
(import "env" "__memory_base" (global $gimport$0 i32))
8-
(import "env" "g$waka_mine" (func $fimport$0 (result i32)))
9-
(import "env" "g$waka_others" (func $fimport$1 (result i32)))
10-
(import "env" "fp$_Z16waka_func_theirsi$ii" (func $fimport$2 (result i32)))
11-
(import "env" "fp$_Z14waka_func_minei$ii" (func $fimport$3 (result i32)))
8+
(import "env" "g$waka_mine" (func $fimport$0 (type $0) (result i32)))
9+
(import "env" "g$waka_others" (func $fimport$1 (type $0) (result i32)))
10+
(import "env" "fp$_Z16waka_func_theirsi$ii" (func $fimport$2 (type $0) (result i32)))
11+
(import "env" "fp$_Z14waka_func_minei$ii" (func $fimport$3 (type $0) (result i32)))
1212
(global $global$0 (mut i32) (i32.const 0))
1313
(global $global$1 (mut i32) (i32.const 0))
1414
(global $global$2 (mut i32) (i32.const 0))
@@ -23,16 +23,16 @@
2323
(export "main" (func $3))
2424
(export "__dso_handle" (global $global$5))
2525
(export "__post_instantiate" (func $4))
26-
(func $0
26+
(func $0 (type $1)
2727
(nop)
2828
)
29-
(func $1 (param $0 i32) (result i32)
29+
(func $1 (type $2) (param $0 i32) (result i32)
3030
(i32.add
3131
(local.get $0)
3232
(i32.const 1)
3333
)
3434
)
35-
(func $2 (result i32)
35+
(func $2 (type $0) (result i32)
3636
(i32.add
3737
(i32.load
3838
(global.get $global$3)
@@ -48,7 +48,7 @@
4848
)
4949
)
5050
)
51-
(func $3 (param $0 i32) (param $1 i32) (result i32)
51+
(func $3 (type $3) (param $0 i32) (param $1 i32) (result i32)
5252
(i32.add
5353
(i32.load
5454
(global.get $global$3)
@@ -64,7 +64,7 @@
6464
)
6565
)
6666
)
67-
(func $4
67+
(func $4 (type $1)
6868
(global.set $global$2
6969
(call $fimport$0)
7070
)

test/elided-br.wasm.fromBinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(module
22
(type $0 (func))
3-
(func $0
3+
(func $0 (type $0)
44
(block $block
55
(unreachable)
66
(block

test/fib-dbg.wasm.fromBinary

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
(export "stackRestore" (func $stackRestore))
4949
(export "_fib" (func $_fib))
5050
(export "stackAlloc" (func $stackAlloc))
51-
(func $stackAlloc (param $0 i32) (result i32)
51+
(func $stackAlloc (type $0) (param $0 i32) (result i32)
5252
(local $1 i32)
5353
(block
5454
(local.set $1
@@ -76,25 +76,25 @@
7676
)
7777
(unreachable)
7878
)
79-
(func $stackSave (result i32)
79+
(func $stackSave (type $2) (result i32)
8080
(return
8181
(global.get $global$3)
8282
)
8383
)
84-
(func $stackRestore (param $0 i32)
84+
(func $stackRestore (type $3) (param $0 i32)
8585
(global.set $global$3
8686
(local.get $0)
8787
)
8888
)
89-
(func $establishStackSpace (param $0 i32) (param $1 i32)
89+
(func $establishStackSpace (type $1) (param $0 i32) (param $1 i32)
9090
(global.set $global$3
9191
(local.get $0)
9292
)
9393
(global.set $global$4
9494
(local.get $1)
9595
)
9696
)
97-
(func $setThrew (param $0 i32) (param $1 i32)
97+
(func $setThrew (type $1) (param $0 i32) (param $1 i32)
9898
(if
9999
(i32.eq
100100
(global.get $global$7)
@@ -110,7 +110,7 @@
110110
)
111111
)
112112
)
113-
(func $_fib (param $0 i32) (result i32)
113+
(func $_fib (type $0) (param $0 i32) (result i32)
114114
(local $1 i32)
115115
(local $2 i32)
116116
(local $3 i32)
@@ -222,7 +222,7 @@
222222
(unreachable)
223223
;;@ fib.c:8:0
224224
)
225-
(func $runPostSets
225+
(func $runPostSets (type $4)
226226
(local $0 i32)
227227
(nop)
228228
)

0 commit comments

Comments
 (0)