Skip to content

Commit

Permalink
wasm-smith: restrict which kinds of instructions can be generated
Browse files Browse the repository at this point in the history
In looking into
bytecodealliance/wasmtime#3251, I created a
mechanism for restricting what kinds of instructions wasm-smith can
generate. The [WebAssembly
specification](https://webassembly.github.io/spec/core/syntax/instructions.html)
organizes its instructions into several categories (e.g., numeric,
vector, reference, control, etc.) and this change allows the user to
configure the module generation based on these categories:

```
head -c 10000 /dev/urandom | cargo run --bin wasm-smith -- --allowed-instructions memory,parametric -o test.wasm && wasm2wat test.wasm
```

There is some related configuration in wasm-smith to restrict what
instructions are available. Currently, the wasm-smith configuration is
organized around "proposals," which can be enabled or disabled. In
theory, a user could be confused if the proposal was disabled and they
explicitly enabled an instruction kind (e.g. reference)--"why aren't
reference instructions being generated?" But this accident seems
unlikely: `--allowed-instructions` defaults to enabling all kinds, so
the user would have to explicitly filter out some kind, deliberately
shooting themselves in the foot.

Despite some risk of confusion (mitigated by the documentation in this
PR), this filtering of instructions kinds ends up being useful in a
general way: not only is it a start at fixing the issue above, it is
useful for work I am doing to generate fuzz only parts of the spec.
  • Loading branch information
abrown committed Nov 30, 2021
1 parent 9e8d43d commit 8c1747c
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 465 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = ['fuzz', 'crates/wasm-encoder', 'crates/fuzz-stats', 'crates/wasm-muta
anyhow = "1.0"
arbitrary = "1.0.0"
env_logger = "0.8"
flagset = "0.4"
getopts = "0.2"
log = "0.4"
rayon = "1.0"
Expand Down
1 change: 1 addition & 0 deletions crates/wasm-smith/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ harness = false

[dependencies]
arbitrary = { version = "1.0.0", features = ["derive"] }
flagset = { version = "0.4", features = ["serde"] }
leb128 = "0.2.4"
wasm-encoder = { version = "0.8.0", path = "../wasm-encoder" }
indexmap = "1.6"
Expand Down
Loading

0 comments on commit 8c1747c

Please sign in to comment.