Chaos mode MVP: Skip branch optimization in MachBuffer (#6039)

* fuzz: Add chaos mode control plane

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* fuzz: Skip branch optimization with chaos mode

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* fuzz: Rename chaos engine -> control plane

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* chaos mode: refactoring ControlPlane to be passed through the call stack by reference

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Remo Senekowitsch <contact@remsle.dev>

* fuzz: annotate chaos todos

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* fuzz: cleanup control plane

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* fuzz: remove control plane from compiler context

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* fuzz: move control plane into emit state

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* fuzz: fix remaining compiler errors

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* fix tests

* refactor emission state ctrl plane accessors

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* centralize conditional compilation of chaos mode

Also cleanup a few straggling dependencies on cranelift-control
that aren't needed anymore.

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* add cranelift-control to published crates

prtest:full

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

* add cranelift-control to public crates

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>

---------

Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com>
Co-authored-by: Moritz Waser <mzrw.dev@pm.me>
Co-authored-by: Remo Senekowitsch <contact@remsle.dev>
This commit is contained in:
Remo Senekowitsch
2023-04-05 21:28:46 +02:00
committed by GitHub
parent 064968b01d
commit 7eb8914090
61 changed files with 815 additions and 245 deletions

View File

@@ -17,6 +17,7 @@ cranelift-filetests = { workspace = true }
cranelift-interpreter = { workspace = true }
cranelift-fuzzgen = { workspace = true }
cranelift-native = { workspace = true }
cranelift-control = { workspace = true }
libfuzzer-sys = { version = "0.4.0", features = ["arbitrary-derive"] }
target-lexicon = { workspace = true }
smallvec = { workspace = true }
@@ -36,6 +37,7 @@ component-fuzz-util = { workspace = true }
[features]
default = ['fuzz-spec-interpreter']
fuzz-spec-interpreter = ['wasmtime-fuzzing/fuzz-spec-interpreter']
chaos = ["cranelift-control/chaos"]
[[bin]]
name = "compile"

View File

@@ -5,6 +5,7 @@ use cranelift_codegen::ir::Signature;
use cranelift_codegen::ir::UserExternalName;
use cranelift_codegen::ir::UserFuncName;
use cranelift_codegen::Context;
use cranelift_control::ControlPlane;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::arbitrary::Unstructured;
@@ -146,6 +147,9 @@ pub struct TestCase {
/// Functions under test
/// By convention the first function is the main function.
pub functions: Vec<Function>,
/// Control planes for function compilation.
/// There should be an equal amount as functions to compile.
pub ctrl_planes: Vec<ControlPlane>,
/// Generate multiple test inputs for each test case.
/// This allows us to get more coverage per compilation, which may be somewhat expensive.
pub inputs: Vec<TestCaseInput>,
@@ -191,6 +195,7 @@ impl TestCase {
// the start.
let func_count = gen.u.int_in_range(gen.config.testcase_funcs.clone())?;
let mut functions: Vec<Function> = Vec::with_capacity(func_count);
let mut ctrl_planes: Vec<ControlPlane> = Vec::with_capacity(func_count);
for i in (0..func_count).rev() {
// Function name must be in a different namespace than TESTFILE_NAMESPACE (0)
let fname = UserFuncName::user(1, i as u32);
@@ -212,6 +217,8 @@ impl TestCase {
ALLOWED_LIBCALLS.to_vec(),
)?;
functions.push(func);
ctrl_planes.push(ControlPlane::arbitrary(gen.u)?);
}
// Now reverse the functions so that the main function is at the start.
functions.reverse();
@@ -222,6 +229,7 @@ impl TestCase {
Ok(TestCase {
isa,
functions,
ctrl_planes,
inputs,
compare_against_host,
})
@@ -241,6 +249,7 @@ impl TestCase {
TestCase {
isa: self.isa.clone(),
functions: optimized_functions,
ctrl_planes: self.ctrl_planes.clone(),
inputs: self.inputs.clone(),
compare_against_host: false,
}
@@ -368,7 +377,9 @@ fuzz_target!(|testcase: TestCase| {
});
} else {
let mut compiler = TestFileCompiler::new(testcase.isa.clone());
compiler.add_functions(&testcase.functions[..]).unwrap();
compiler
.add_functions(&testcase.functions[..], testcase.ctrl_planes.clone())
.unwrap();
let compiled = compiler.compile().unwrap();
let trampoline = compiled.get_trampoline(testcase.main()).unwrap();

View File

@@ -108,7 +108,7 @@ fuzz_target!(|func: FunctionWithIsa| {
let cache_key_hash = icache::compute_cache_key(&*isa, &func);
let mut context = Context::for_function(func.clone());
let prev_stencil = match context.compile_stencil(&*isa) {
let prev_stencil = match context.compile_stencil(&*isa, &mut Default::default()) {
Ok(stencil) => stencil,
Err(_) => return,
};
@@ -199,7 +199,7 @@ fuzz_target!(|func: FunctionWithIsa| {
context = Context::for_function(func.clone());
let after_mutation_result = match context.compile(&*isa) {
let after_mutation_result = match context.compile(&*isa, &mut Default::default()) {
Ok(info) => info,
Err(_) => return,
};