Files
wasmtime/crates/fuzzing/wasm-spec-interpreter
Alex Crichton fd98814b96 Port v8 fuzzer to the new framework (#4739)
* Port v8 fuzzer to the new framework

This commit aims to improve the support for the new "meta" differential
fuzzer added in #4515 by ensuring that all existing differential fuzzing
is migrated to this new fuzzer. This PR includes features such as:

* The V8 differential execution is migrated to the new framework.
* `Config::set_differential_config` no longer force-disables wasm
  features, instead allowing them to be enabled as per the fuzz input.
* `DiffInstance::{hash, hash}` was replaced with
  `DiffInstance::get_{memory,global}` to allow more fine-grained
  assertions.
* Support for `FuncRef` and `ExternRef` have been added to `DiffValue`
  and `DiffValueType`. For now though generating an arbitrary
  `ExternRef` and `FuncRef` simply generates a null value.
* Arbitrary `DiffValue::{F32,F64}` values are guaranteed to use
  canonical NaN representations to fix an issue with v8 where with the
  v8 engine we can't communicate non-canonical NaN values through JS.
* `DiffEngine::evaluate` allows "successful failure" for cases where
  engines can't support that particular invocation, for example v8 can't
  support `v128` arguments or return values.
* Smoke tests were added for each engine to ensure that a simple wasm
  module works at PR-time.
* Statistics printed from the main fuzzer now include percentage-rates
  for chosen engines as well as percentage rates for styles-of-module.

There's also a few small refactorings here and there but mostly just
things I saw along the way.

* Update the fuzzing README
2022-08-19 19:19:00 +00:00
..

wasm-spec-interpreter

This project shows how to use ocaml-interop to call into the Wasm spec interpreter. There are several steps to making this work:

  • building the OCaml Wasm spec interpreter as a static library
  • building a Rust-to-OCaml FFI bridge using ocaml-interop and a custom OCaml wrapper
  • linking both things into a Rust crate

Dependencies

This crate only builds in an environment with:

  • make (the Wasm spec interpreter uses a Makefile)
  • ocamlopt, ocamlbuild (available with, e.g., dnf install ocaml)
  • Linux tools (e.g. ar); currently it is easiest to build the static libraries in a single environment but this could be fixed in the future (TODO)
  • libgmp, for the OCaml zarith package
  • git is used by build.rs to retrieve the repository containing the Wasm spec interpreter; it is safe to completely remove ocaml/spec to get a new copy

Build

cargo build --features build-libinterpret

Use FFI_LIB_DIR=path/to/lib/... to specify a different location for the static library (this is mainly for debugging). If the build-libinterpret feature is not provided, this crate will build successfully but fail at runtime.

Test

cargo test --features build-libinterpret