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

@@ -12,6 +12,7 @@ edition.workspace = true
anyhow = { workspace = true }
wasmtime-environ = { workspace = true }
cranelift-codegen = { workspace = true }
cranelift-control = { workspace = true }
cranelift-native = { workspace = true }
target-lexicon = { workspace = true }
gimli = { workspace = true }

View File

@@ -19,6 +19,7 @@ use cranelift_codegen::binemit::Reloc;
use cranelift_codegen::ir::LibCall;
use cranelift_codegen::isa::unwind::{systemv, UnwindInfo};
use cranelift_codegen::TextSectionBuilder;
use cranelift_control::ControlPlane;
use gimli::write::{Address, EhFrame, EndianVec, FrameTable, Writer};
use gimli::RunTimeEndian;
use object::write::{Object, SectionId, StandardSegment, Symbol, SymbolId, SymbolSection};
@@ -59,6 +60,8 @@ pub struct ModuleTextBuilder<'a> {
/// Note that this isn't typically used. It's only used for SSE-disabled
/// builds without SIMD on x86_64 right now.
libcall_symbols: HashMap<LibCall, SymbolId>,
ctrl_plane: ControlPlane,
}
impl<'a> ModuleTextBuilder<'a> {
@@ -88,6 +91,7 @@ impl<'a> ModuleTextBuilder<'a> {
unwind_info: Default::default(),
text,
libcall_symbols: HashMap::default(),
ctrl_plane: ControlPlane::default(),
}
}
@@ -115,6 +119,7 @@ impl<'a> ModuleTextBuilder<'a> {
true,
&body,
self.compiler.function_alignment().max(alignment),
&mut self.ctrl_plane,
);
let symbol_id = self.obj.add_symbol(Symbol {
@@ -227,7 +232,8 @@ impl<'a> ModuleTextBuilder<'a> {
if padding == 0 {
return;
}
self.text.append(false, &vec![0; padding], 1);
self.text
.append(false, &vec![0; padding], 1, &mut self.ctrl_plane);
}
/// Indicates that the text section has been written completely and this
@@ -237,7 +243,7 @@ impl<'a> ModuleTextBuilder<'a> {
/// necessary.
pub fn finish(mut self) {
// Finish up the text section now that we're done adding functions.
let text = self.text.finish();
let text = self.text.finish(&mut self.ctrl_plane);
self.obj
.section_mut(self.text_section)
.set_data(text, self.compiler.page_size_align());

View File

@@ -19,6 +19,7 @@ cranelift-codegen = { workspace = true }
cranelift-frontend = { workspace = true }
cranelift-entity = { workspace = true }
cranelift-native = { workspace = true }
cranelift-control = { workspace = true }
wasmtime-cranelift-shared = { workspace = true }
wasmparser = { workspace = true }
target-lexicon = { workspace = true }

View File

@@ -612,7 +612,7 @@ fn compile_uncached<'a>(
) -> Result<(&'a CompiledCode, Vec<u8>), CompileError> {
let mut code_buf = Vec::new();
let compiled_code = context
.compile_and_emit(isa, &mut code_buf)
.compile_and_emit(isa, &mut code_buf, &mut Default::default())
.map_err(|error| CompileError::Codegen(pretty_error(&error.func, error.inner)))?;
Ok((compiled_code, code_buf))
}