diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1679f2e79..68ecc9d998 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -107,6 +107,16 @@ jobs: | shuf \ | head -n 100 \ | xargs cargo fuzz run differential --release --debug-assertions + - run: | + find fuzz/corpus/reader_parse_test -type f \ + | shuf \ + | head -n 100 \ + | xargs cargo fuzz run reader_parse_test --release --debug-assertions + - run: | + find fuzz/corpus/translate_module -type f \ + | shuf \ + | head -n 100 \ + | xargs cargo fuzz run translate_module --release --debug-assertions # Install wasm32-unknown-emscripten target, and ensure `crates/wasi-common` # compiles to Emscripten. diff --git a/Cargo.lock b/Cargo.lock index 3a4b15a1f8..debe8fbd6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -420,6 +420,14 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-reader" +version = "0.59.0" +dependencies = [ + "cranelift-codegen", + "target-lexicon", +] + [[package]] name = "cranelift-wasm" version = "0.59.0" @@ -2114,7 +2122,11 @@ name = "wasmtime-fuzz" version = "0.12.0" dependencies = [ "arbitrary 0.2.0", + "cranelift-codegen", + "cranelift-reader", + "cranelift-wasm", "libfuzzer-sys", + "target-lexicon", "wasmtime", "wasmtime-fuzzing", ] diff --git a/cranelift/.github/workflows/main.yml b/cranelift/.github/workflows/main.yml index ac1fffb5dc..529c16f2c3 100644 --- a/cranelift/.github/workflows/main.yml +++ b/cranelift/.github/workflows/main.yml @@ -14,17 +14,6 @@ jobs: - run: find ./target/doc -maxdepth 1 -type d -name "cranelift*" | xargs -I{} cargo deadlinks --dir {} name: Run cargo-deadlinks - # Ensure fuzzer works by running it with a single input - - run: cargo install cargo-fuzz - if: matrix.rust == 'nightly' - - run: | - fuzz_module="ffaefab69523eb11935a9b420d58826c8ea65c4c" - cargo fuzz run fuzz_translate_module fuzz/corpus/fuzz_translate_module/$fuzz_module - env: - RUST_BACKTRACE: 1 - if: matrix.rust == 'nightly' - continue-on-error: true - meta_determinist_check: name: Meta deterministic check runs-on: ubuntu-latest diff --git a/cranelift/fuzz/Cargo.toml b/cranelift/fuzz/Cargo.toml deleted file mode 100644 index 948a07abc9..0000000000 --- a/cranelift/fuzz/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "clif-wasm-fuzz" -version = "0.0.1" -authors = ["foote@fastly.com"] -publish = false -edition = "2018" - -[package.metadata] -cargo-fuzz = true - -[dependencies] -cargo-fuzz = "*" -binaryen = { git = "https://github.com/pepyakin/binaryen-rs.git" } -libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } -cranelift-codegen = { path = "../codegen" } -cranelift-wasm = { path = "../wasm" } -cranelift-reader = { path = "../reader" } -target-lexicon = "0.10" - -# Prevent this from interfering with workspaces -[workspace] -members = ["."] - -[[bin]] -name = "fuzz_translate_module" -path = "fuzz_translate_module.rs" - -[[bin]] -name = "fuzz_reader_parse_test" -path = "fuzz_reader_parse_test.rs" diff --git a/cranelift/fuzz/corpus/fuzz_translate_module/ffaefab69523eb11935a9b420d58826c8ea65c4c b/cranelift/fuzz/corpus/fuzz_translate_module/ffaefab69523eb11935a9b420d58826c8ea65c4c deleted file mode 100644 index 1fa4159954..0000000000 Binary files a/cranelift/fuzz/corpus/fuzz_translate_module/ffaefab69523eb11935a9b420d58826c8ea65c4c and /dev/null differ diff --git a/cranelift/fuzz/fuzz_translate_module.rs b/cranelift/fuzz/fuzz_translate_module.rs deleted file mode 100644 index 27854f329f..0000000000 --- a/cranelift/fuzz/fuzz_translate_module.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![no_main] - -#[macro_use] -extern crate libfuzzer_sys; -extern crate binaryen; -extern crate cranelift_codegen; -extern crate cranelift_wasm; -#[macro_use] -extern crate target_lexicon; - -use cranelift_codegen::{isa, settings}; -use cranelift_wasm::{translate_module, DummyEnvironment, ReturnMode}; -use std::str::FromStr; - -fuzz_target!(|data: &[u8]| { - let binaryen_module = binaryen::tools::translate_to_fuzz_mvp(data); - - let wasm = binaryen_module.write(); - - let flags = settings::Flags::new(settings::builder()); - let triple = triple!("x86_64"); - let isa = isa::lookup(triple).unwrap().finish(flags); - let mut dummy_environ = DummyEnvironment::new(isa.frontend_config(), ReturnMode::NormalReturns, false); - translate_module(&wasm, &mut dummy_environ).unwrap(); -}); diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index ec70d6c695..6a24baa0d8 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -10,9 +10,13 @@ cargo-fuzz = true [dependencies] arbitrary = "0.2.0" -wasmtime-fuzzing = { path = "../crates/fuzzing" } -wasmtime = { path = "../crates/api" } +cranelift-codegen = { path = "../cranelift/codegen" } +cranelift-reader = { path = "../cranelift/reader" } +cranelift-wasm = { path = "../cranelift/wasm" } libfuzzer-sys = "0.2.1" +target-lexicon = "0.10" +wasmtime = { path = "../crates/api" } +wasmtime-fuzzing = { path = "../crates/fuzzing" } [[bin]] name = "compile" @@ -43,3 +47,15 @@ name = "differential" path = "fuzz_targets/differential.rs" test = false doc = false + +[[bin]] +name = "translate_module" +path = "fuzz_targets/translate_module.rs" +test = false +doc = false + +[[bin]] +name = "reader_parse_test" +path = "fuzz_targets/reader_parse_test.rs" +test = false +doc = false diff --git a/cranelift/fuzz/fuzz_reader_parse_test.rs b/fuzz/fuzz_targets/reader_parse_test.rs similarity index 76% rename from cranelift/fuzz/fuzz_reader_parse_test.rs rename to fuzz/fuzz_targets/reader_parse_test.rs index 4f17898264..9770606f13 100644 --- a/cranelift/fuzz/fuzz_reader_parse_test.rs +++ b/fuzz/fuzz_targets/reader_parse_test.rs @@ -1,7 +1,7 @@ #![no_main] -#[macro_use] -extern crate libfuzzer_sys; -extern crate cranelift_reader; + +use libfuzzer_sys::fuzz_target; + use std::str; fuzz_target!(|data: &[u8]| { diff --git a/fuzz/fuzz_targets/translate_module.rs b/fuzz/fuzz_targets/translate_module.rs new file mode 100644 index 0000000000..2965c63c4c --- /dev/null +++ b/fuzz/fuzz_targets/translate_module.rs @@ -0,0 +1,17 @@ +#![no_main] + +use cranelift_codegen::{isa, settings}; +use cranelift_wasm::{translate_module, DummyEnvironment, ReturnMode}; +use libfuzzer_sys::fuzz_target; +use std::str::FromStr; +use target_lexicon::triple; +use wasmtime_fuzzing::generators; + +fuzz_target!(|data: generators::WasmOptTtf| { + let flags = settings::Flags::new(settings::builder()); + let triple = triple!("x86_64"); + let isa = isa::lookup(triple).unwrap().finish(flags); + let mut dummy_environ = + DummyEnvironment::new(isa.frontend_config(), ReturnMode::NormalReturns, false); + translate_module(&data.wasm, &mut dummy_environ).unwrap(); +});