diff --git a/cranelift/faerie/src/backend.rs b/cranelift/faerie/src/backend.rs index 87df38d899..91ffc265e4 100644 --- a/cranelift/faerie/src/backend.rs +++ b/cranelift/faerie/src/backend.rs @@ -1,38 +1,25 @@ //! Defines `FaerieBackend`. use crate::container; -use crate::traps::{FaerieTrapManifest, FaerieTrapSink}; use anyhow::anyhow; use cranelift_codegen::binemit::{ - Addend, CodeOffset, NullStackmapSink, NullTrapSink, Reloc, RelocSink, Stackmap, StackmapSink, + Addend, CodeOffset, NullStackmapSink, Reloc, RelocSink, Stackmap, StackmapSink, TrapSink, }; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::{self, binemit, ir}; use cranelift_module::{ Backend, DataContext, DataDescription, DataId, FuncId, Init, Linkage, ModuleError, - ModuleNamespace, ModuleResult, TrapSite, + ModuleNamespace, ModuleResult, }; use faerie; use std::convert::TryInto; use std::fs::File; use target_lexicon::Triple; -#[derive(Debug)] -/// Setting to enable collection of traps. Setting this to `Enabled` in -/// `FaerieBuilder` means that a `FaerieTrapManifest` will be present -/// in the `FaerieProduct`. -pub enum FaerieTrapCollection { - /// `FaerieProduct::trap_manifest` will be `None` - Disabled, - /// `FaerieProduct::trap_manifest` will be `Some` - Enabled, -} - /// A builder for `FaerieBackend`. pub struct FaerieBuilder { isa: Box, name: String, - collect_traps: FaerieTrapCollection, libcall_names: Box String>, } @@ -43,9 +30,6 @@ impl FaerieBuilder { /// /// Faerie output requires that TargetIsa have PIC (Position Independent Code) enabled. /// - /// `collect_traps` setting determines whether trap information is collected in a - /// `FaerieTrapManifest` available in the `FaerieProduct`. - /// /// The `libcall_names` function provides a way to translate `cranelift_codegen`'s `ir::LibCall` /// enum to symbols. LibCalls are inserted in the IR as part of the legalization for certain /// floating point instructions, and for stack probes. If you don't know what to use for this @@ -53,7 +37,6 @@ impl FaerieBuilder { pub fn new( isa: Box, name: String, - collect_traps: FaerieTrapCollection, libcall_names: Box String>, ) -> ModuleResult { if !isa.flags().is_pic() { @@ -64,7 +47,6 @@ impl FaerieBuilder { Ok(Self { isa, name, - collect_traps, libcall_names, }) } @@ -76,7 +58,6 @@ impl FaerieBuilder { pub struct FaerieBackend { isa: Box, artifact: faerie::Artifact, - trap_manifest: Option, libcall_names: Box String>, } @@ -112,10 +93,6 @@ impl Backend for FaerieBackend { Self { artifact: faerie::Artifact::new(builder.isa.triple().clone(), builder.name), isa: builder.isa, - trap_manifest: match builder.collect_traps { - FaerieTrapCollection::Enabled => Some(FaerieTrapManifest::new()), - FaerieTrapCollection::Disabled => None, - }, libcall_names: builder.libcall_names, } } @@ -145,18 +122,21 @@ impl Backend for FaerieBackend { .expect("inconsistent declarations"); } - fn define_function( + fn define_function( &mut self, _id: FuncId, name: &str, ctx: &cranelift_codegen::Context, namespace: &ModuleNamespace, total_size: u32, - ) -> ModuleResult<(FaerieCompiledFunction, &[TrapSite])> { + trap_sink: &mut TS, + ) -> ModuleResult + where + TS: TrapSink, + { let mut code: Vec = vec![0; total_size as usize]; // TODO: Replace this with FaerieStackmapSink once it is implemented. let mut stackmap_sink = NullStackmapSink {}; - let mut traps: &[TrapSite] = &[]; // Non-lexical lifetimes would obviate the braces here. { @@ -168,30 +148,15 @@ impl Backend for FaerieBackend { libcall_names: &*self.libcall_names, }; - if let Some(ref mut trap_manifest) = self.trap_manifest { - let mut trap_sink = FaerieTrapSink::new(name, total_size); - unsafe { - ctx.emit_to_memory( - &*self.isa, - code.as_mut_ptr(), - &mut reloc_sink, - &mut trap_sink, - &mut stackmap_sink, - ) - }; - traps = trap_manifest.add_sink(trap_sink); - } else { - let mut trap_sink = NullTrapSink {}; - unsafe { - ctx.emit_to_memory( - &*self.isa, - code.as_mut_ptr(), - &mut reloc_sink, - &mut trap_sink, - &mut stackmap_sink, - ) - }; - } + unsafe { + ctx.emit_to_memory( + &*self.isa, + code.as_mut_ptr(), + &mut reloc_sink, + trap_sink, + &mut stackmap_sink, + ) + }; } // because `define` will take ownership of code, this is our last chance @@ -201,7 +166,7 @@ impl Backend for FaerieBackend { .define(name, code) .expect("inconsistent declaration"); - Ok((FaerieCompiledFunction { code_length }, traps)) + Ok(FaerieCompiledFunction { code_length }) } fn define_function_bytes( @@ -210,24 +175,17 @@ impl Backend for FaerieBackend { name: &str, bytes: &[u8], _namespace: &ModuleNamespace, - traps: Vec, - ) -> ModuleResult<(FaerieCompiledFunction, &[TrapSite])> { + ) -> ModuleResult { let code_length: u32 = match bytes.len().try_into() { Ok(code_length) => code_length, _ => Err(ModuleError::FunctionTooLarge(name.to_string()))?, }; - let mut ret_traps: &[TrapSite] = &[]; - - if let Some(ref mut trap_manifest) = self.trap_manifest { - let trap_sink = FaerieTrapSink::new_with_sites(name, code_length, traps); - ret_traps = trap_manifest.add_sink(trap_sink); - } self.artifact .define(name, bytes.to_vec()) .expect("inconsistent declaration"); - Ok((FaerieCompiledFunction { code_length }, ret_traps)) + Ok(FaerieCompiledFunction { code_length }) } fn define_data( @@ -345,7 +303,6 @@ impl Backend for FaerieBackend { fn finish(self, _namespace: &ModuleNamespace) -> FaerieProduct { FaerieProduct { artifact: self.artifact, - trap_manifest: self.trap_manifest, } } } @@ -357,9 +314,6 @@ impl Backend for FaerieBackend { pub struct FaerieProduct { /// Faerie artifact with all functions, data, and links from the module defined pub artifact: faerie::Artifact, - /// Optional trap manifest. Contains `FaerieTrapManifest` when `FaerieBuilder.collect_traps` is - /// set to `FaerieTrapCollection::Enabled`. - pub trap_manifest: Option, } impl FaerieProduct { diff --git a/cranelift/faerie/src/lib.rs b/cranelift/faerie/src/lib.rs index a6098ff8f7..67da33565b 100644 --- a/cranelift/faerie/src/lib.rs +++ b/cranelift/faerie/src/lib.rs @@ -27,9 +27,8 @@ mod backend; mod container; -pub mod traps; -pub use crate::backend::{FaerieBackend, FaerieBuilder, FaerieProduct, FaerieTrapCollection}; +pub use crate::backend::{FaerieBackend, FaerieBuilder, FaerieProduct}; pub use crate::container::Format; /// Version number of this crate. diff --git a/cranelift/faerie/src/traps.rs b/cranelift/faerie/src/traps.rs deleted file mode 100644 index d3bd041d94..0000000000 --- a/cranelift/faerie/src/traps.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! Faerie trap manifests record every `TrapCode` that cranelift outputs during code generation, -//! for every function in the module. This data may be useful at runtime. - -use cranelift_codegen::{binemit, ir}; -use cranelift_module::TrapSite; - -/// Record of the trap sites for a given function -#[derive(Debug)] -pub struct FaerieTrapSink { - /// Name of function - pub name: String, - /// Total code size of function - pub code_size: u32, - /// All trap sites collected in function - pub sites: Vec, -} - -impl FaerieTrapSink { - /// Create an empty `FaerieTrapSink` - pub fn new(name: &str, code_size: u32) -> Self { - Self { - sites: Vec::new(), - name: name.to_owned(), - code_size, - } - } - - /// Create a `FaerieTrapSink` pre-populated with `traps` - pub fn new_with_sites(name: &str, code_size: u32, traps: Vec) -> Self { - Self { - sites: traps, - name: name.to_owned(), - code_size, - } - } -} - -impl binemit::TrapSink for FaerieTrapSink { - fn trap(&mut self, offset: binemit::CodeOffset, srcloc: ir::SourceLoc, code: ir::TrapCode) { - self.sites.push(TrapSite { - offset, - srcloc, - code, - }); - } -} - -/// Collection of all `FaerieTrapSink`s for the module -#[derive(Debug)] -pub struct FaerieTrapManifest { - /// All `FaerieTrapSink` for the module - pub sinks: Vec, -} - -impl FaerieTrapManifest { - /// Create an empty `FaerieTrapManifest` - pub fn new() -> Self { - Self { sinks: Vec::new() } - } - - /// Put a `FaerieTrapSink` into manifest - pub fn add_sink(&mut self, sink: FaerieTrapSink) -> &[TrapSite] { - self.sinks.push(sink); - &self.sinks.last().unwrap().sites - } -} diff --git a/cranelift/module/src/backend.rs b/cranelift/module/src/backend.rs index 9333e5f570..4616791e92 100644 --- a/cranelift/module/src/backend.rs +++ b/cranelift/module/src/backend.rs @@ -6,7 +6,6 @@ use crate::FuncId; use crate::Linkage; use crate::ModuleNamespace; use crate::ModuleResult; -use crate::TrapSite; use core::marker; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::Context; @@ -15,7 +14,6 @@ use cranelift_codegen::{binemit, ir}; use std::borrow::ToOwned; use std::boxed::Box; use std::string::String; -use std::vec::Vec; /// A `Backend` implements the functionality needed to support a `Module`. /// @@ -79,14 +77,17 @@ where /// Define a function, producing the function body from the given `Context`. /// /// Functions must be declared before being defined. - fn define_function( + fn define_function( &mut self, id: FuncId, name: &str, ctx: &Context, namespace: &ModuleNamespace, code_size: u32, - ) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])>; + trap_sink: &mut TS, + ) -> ModuleResult + where + TS: binemit::TrapSink; /// Define a function, taking the function body from the given `bytes`. /// @@ -97,8 +98,7 @@ where name: &str, bytes: &[u8], namespace: &ModuleNamespace, - traps: Vec, - ) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])>; + ) -> ModuleResult; /// Define a zero-initialized data object of the given size. /// diff --git a/cranelift/module/src/module.rs b/cranelift/module/src/module.rs index 543b23b160..3a6f90fc88 100644 --- a/cranelift/module/src/module.rs +++ b/cranelift/module/src/module.rs @@ -7,7 +7,6 @@ use super::HashMap; use crate::data_context::DataContext; -use crate::traps::TrapSite; use crate::Backend; use cranelift_codegen::binemit::{self, CodeInfo}; use cranelift_codegen::entity::{entity_impl, PrimaryMap}; @@ -363,9 +362,8 @@ where backend: B, } -pub struct ModuleCompiledFunction<'a> { +pub struct ModuleCompiledFunction { pub size: binemit::CodeOffset, - pub traps: &'a [TrapSite], } impl Module @@ -569,11 +567,15 @@ where /// Returns the size of the function's code and constant data. /// /// Note: After calling this function the given `Context` will contain the compiled function. - pub fn define_function( + pub fn define_function( &mut self, func: FuncId, ctx: &mut Context, - ) -> ModuleResult { + trap_sink: &mut TS, + ) -> ModuleResult + where + TS: binemit::TrapSink, + { info!( "defining function {}: {}", func, @@ -588,7 +590,7 @@ where return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone())); } - let (compiled, traps) = self.backend.define_function( + let compiled = self.backend.define_function( func, &info.decl.name, ctx, @@ -596,14 +598,12 @@ where contents: &self.contents, }, total_size, + trap_sink, )?; self.contents.functions[func].compiled = Some(compiled); self.functions_to_finalize.push(func); - Ok(ModuleCompiledFunction { - size: total_size, - traps, - }) + Ok(ModuleCompiledFunction { size: total_size }) } /// Define a function, taking the function body from the given `bytes`. @@ -617,7 +617,6 @@ where &mut self, func: FuncId, bytes: &[u8], - traps: Vec, ) -> ModuleResult { info!("defining function {} with bytes", func); let info = &self.contents.functions[func]; @@ -633,22 +632,18 @@ where _ => Err(ModuleError::FunctionTooLarge(info.decl.name.clone()))?, }; - let (compiled, traps) = self.backend.define_function_bytes( + let compiled = self.backend.define_function_bytes( func, &info.decl.name, bytes, &ModuleNamespace:: { contents: &self.contents, }, - traps, )?; self.contents.functions[func].compiled = Some(compiled); self.functions_to_finalize.push(func); - Ok(ModuleCompiledFunction { - size: total_size, - traps, - }) + Ok(ModuleCompiledFunction { size: total_size }) } /// Define a data object, producing the data contents from the given `DataContext`. diff --git a/cranelift/object/src/backend.rs b/cranelift/object/src/backend.rs index 6191b27695..f651ad69b4 100644 --- a/cranelift/object/src/backend.rs +++ b/cranelift/object/src/backend.rs @@ -1,15 +1,14 @@ //! Defines `ObjectBackend`. -use crate::traps::ObjectTrapSink; use cranelift_codegen::binemit::{ - Addend, CodeOffset, NullStackmapSink, NullTrapSink, Reloc, RelocSink, + Addend, CodeOffset, NullStackmapSink, Reloc, RelocSink, TrapSink, }; use cranelift_codegen::entity::SecondaryMap; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::{self, binemit, ir}; use cranelift_module::{ Backend, DataContext, DataDescription, DataId, FuncId, Init, Linkage, ModuleNamespace, - ModuleResult, TrapSite, + ModuleResult, }; use object::write::{ Object, Relocation, SectionId, StandardSection, Symbol, SymbolId, SymbolSection, @@ -17,24 +16,12 @@ use object::write::{ use object::{RelocationEncoding, RelocationKind, SymbolFlags, SymbolKind, SymbolScope}; use std::collections::HashMap; use std::mem; -use std::ops::IndexMut; use target_lexicon::{BinaryFormat, PointerWidth}; -#[derive(Debug)] -/// Setting to enable collection of traps. Setting this to `Enabled` in -/// `ObjectBuilder` means that `ObjectProduct` will contains trap sites. -pub enum ObjectTrapCollection { - /// `ObjectProduct::traps` will be empty - Disabled, - /// `ObjectProduct::traps` will contain trap sites - Enabled, -} - /// A builder for `ObjectBackend`. pub struct ObjectBuilder { isa: Box, name: Vec, - collect_traps: ObjectTrapCollection, libcall_names: Box String>, function_alignment: u64, } @@ -43,9 +30,6 @@ impl ObjectBuilder { /// Create a new `ObjectBuilder` using the given Cranelift target, that /// can be passed to [`Module::new`](cranelift_module::Module::new). /// - /// `collect_traps` setting determines whether trap information is collected in the - /// `ObjectProduct`. - /// /// The `libcall_names` function provides a way to translate `cranelift_codegen`'s `ir::LibCall` /// enum to symbols. LibCalls are inserted in the IR as part of the legalization for certain /// floating point instructions, and for stack probes. If you don't know what to use for this @@ -53,13 +37,11 @@ impl ObjectBuilder { pub fn new>>( isa: Box, name: V, - collect_traps: ObjectTrapCollection, libcall_names: Box String>, ) -> Self { Self { isa, name: name.into(), - collect_traps, libcall_names, function_alignment: 1, } @@ -80,11 +62,9 @@ pub struct ObjectBackend { object: Object, functions: SecondaryMap>, data_objects: SecondaryMap>, - traps: SecondaryMap>, relocs: Vec, libcalls: HashMap, libcall_names: Box String>, - collect_traps: ObjectTrapCollection, function_alignment: u64, } @@ -111,11 +91,9 @@ impl Backend for ObjectBackend { object, functions: SecondaryMap::new(), data_objects: SecondaryMap::new(), - traps: SecondaryMap::new(), relocs: Vec::new(), libcalls: HashMap::new(), libcall_names: builder.libcall_names, - collect_traps: builder.collect_traps, function_alignment: builder.function_alignment, } } @@ -182,41 +160,31 @@ impl Backend for ObjectBackend { } } - fn define_function( + fn define_function( &mut self, func_id: FuncId, _name: &str, ctx: &cranelift_codegen::Context, _namespace: &ModuleNamespace, code_size: u32, - ) -> ModuleResult<(ObjectCompiledFunction, &[TrapSite])> { + trap_sink: &mut TS, + ) -> ModuleResult + where + TS: TrapSink, + { let mut code: Vec = vec![0; code_size as usize]; let mut reloc_sink = ObjectRelocSink::new(self.object.format()); - let mut trap_sink = ObjectTrapSink::default(); let mut stackmap_sink = NullStackmapSink {}; - if let ObjectTrapCollection::Enabled = self.collect_traps { - unsafe { - ctx.emit_to_memory( - &*self.isa, - code.as_mut_ptr(), - &mut reloc_sink, - &mut trap_sink, - &mut stackmap_sink, - ) - }; - } else { - let mut trap_sink = NullTrapSink {}; - unsafe { - ctx.emit_to_memory( - &*self.isa, - code.as_mut_ptr(), - &mut reloc_sink, - &mut trap_sink, - &mut stackmap_sink, - ) - }; - } + unsafe { + ctx.emit_to_memory( + &*self.isa, + code.as_mut_ptr(), + &mut reloc_sink, + trap_sink, + &mut stackmap_sink, + ) + }; let symbol = self.functions[func_id].unwrap(); let section = self.object.section_id(StandardSection::Text); @@ -230,9 +198,7 @@ impl Backend for ObjectBackend { relocs: reloc_sink.relocs, }); } - let trapref = self.traps.index_mut(func_id); - *trapref = trap_sink.sites; - Ok((ObjectCompiledFunction, trapref)) + Ok(ObjectCompiledFunction) } fn define_function_bytes( @@ -241,16 +207,13 @@ impl Backend for ObjectBackend { _name: &str, bytes: &[u8], _namespace: &ModuleNamespace, - traps: Vec, - ) -> ModuleResult<(ObjectCompiledFunction, &[TrapSite])> { + ) -> ModuleResult { let symbol = self.functions[func_id].unwrap(); let section = self.object.section_id(StandardSection::Text); let _offset = self .object .add_symbol_data(symbol, section, bytes, self.function_alignment); - let trapref = self.traps.index_mut(func_id); - *trapref = traps; - Ok((ObjectCompiledFunction, trapref)) + Ok(ObjectCompiledFunction) } fn define_data( @@ -421,7 +384,6 @@ impl Backend for ObjectBackend { object: self.object, functions: self.functions, data_objects: self.data_objects, - traps: self.traps, } } } @@ -496,8 +458,6 @@ pub struct ObjectProduct { pub functions: SecondaryMap>, /// Symbol IDs for data objects (both declared and defined). pub data_objects: SecondaryMap>, - /// Trap sites for defined functions. - pub traps: SecondaryMap>, } impl ObjectProduct { diff --git a/cranelift/object/src/lib.rs b/cranelift/object/src/lib.rs index 1542c0a191..31033927c9 100644 --- a/cranelift/object/src/lib.rs +++ b/cranelift/object/src/lib.rs @@ -26,10 +26,8 @@ )] mod backend; -mod traps; -pub use crate::backend::{ObjectBackend, ObjectBuilder, ObjectProduct, ObjectTrapCollection}; -pub use crate::traps::ObjectTrapSink; +pub use crate::backend::{ObjectBackend, ObjectBuilder, ObjectProduct}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/cranelift/object/src/traps.rs b/cranelift/object/src/traps.rs deleted file mode 100644 index 2fabfc626d..0000000000 --- a/cranelift/object/src/traps.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Records every `TrapCode` that cranelift outputs during code generation, -//! for every function in the module. This data may be useful at runtime. - -use cranelift_codegen::{binemit, ir}; -use cranelift_module::TrapSite; - -/// Record of the trap sites for a given function -#[derive(Default, Clone)] -pub struct ObjectTrapSink { - /// All trap sites collected in function - pub sites: Vec, -} - -impl binemit::TrapSink for ObjectTrapSink { - fn trap(&mut self, offset: binemit::CodeOffset, srcloc: ir::SourceLoc, code: ir::TrapCode) { - self.sites.push(TrapSite { - offset, - srcloc, - code, - }); - } -} diff --git a/cranelift/simplejit/examples/simplejit-minimal.rs b/cranelift/simplejit/examples/simplejit-minimal.rs index ade2cd3422..1534e144de 100644 --- a/cranelift/simplejit/examples/simplejit-minimal.rs +++ b/cranelift/simplejit/examples/simplejit-minimal.rs @@ -1,4 +1,5 @@ use cranelift::prelude::*; +use cranelift_codegen::binemit::NullTrapSink; use cranelift_module::{default_libcall_names, Linkage, Module}; use cranelift_simplejit::{SimpleJITBackend, SimpleJITBuilder}; use std::mem; @@ -38,7 +39,10 @@ fn main() { bcx.seal_all_blocks(); bcx.finalize(); } - module.define_function(func_a, &mut ctx).unwrap(); + let mut trap_sink = NullTrapSink {}; + module + .define_function(func_a, &mut ctx, &mut trap_sink) + .unwrap(); module.clear_context(&mut ctx); ctx.func.signature = sig_b; @@ -60,7 +64,9 @@ fn main() { bcx.seal_all_blocks(); bcx.finalize(); } - module.define_function(func_b, &mut ctx).unwrap(); + module + .define_function(func_b, &mut ctx, &mut trap_sink) + .unwrap(); module.clear_context(&mut ctx); // Perform linking. diff --git a/cranelift/simplejit/src/backend.rs b/cranelift/simplejit/src/backend.rs index 22a7c4b36b..a5d0150904 100644 --- a/cranelift/simplejit/src/backend.rs +++ b/cranelift/simplejit/src/backend.rs @@ -2,13 +2,13 @@ use crate::memory::Memory; use cranelift_codegen::binemit::{ - Addend, CodeOffset, NullTrapSink, Reloc, RelocSink, Stackmap, StackmapSink, + Addend, CodeOffset, Reloc, RelocSink, Stackmap, StackmapSink, TrapSink, }; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::{self, ir, settings}; use cranelift_module::{ Backend, DataContext, DataDescription, DataId, FuncId, Init, Linkage, ModuleNamespace, - ModuleResult, TrapSite, + ModuleResult, }; use cranelift_native; #[cfg(not(windows))] @@ -271,14 +271,18 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend { // Nothing to do. } - fn define_function( + fn define_function( &mut self, _id: FuncId, name: &str, ctx: &cranelift_codegen::Context, _namespace: &ModuleNamespace, code_size: u32, - ) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])> { + trap_sink: &mut TS, + ) -> ModuleResult + where + TS: TrapSink, + { let size = code_size as usize; let ptr = self .memory @@ -289,28 +293,22 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend { self.record_function_for_perf(ptr, size, name); let mut reloc_sink = SimpleJITRelocSink::new(); - // Ignore traps for now. For now, frontends should just avoid generating code - // that traps. - let mut trap_sink = NullTrapSink {}; let mut stackmap_sink = SimpleJITStackmapSink::new(); unsafe { ctx.emit_to_memory( &*self.isa, ptr, &mut reloc_sink, - &mut trap_sink, + trap_sink, &mut stackmap_sink, ) }; - Ok(( - Self::CompiledFunction { - code: ptr, - size, - relocs: reloc_sink.relocs, - }, - &[], - )) + Ok(Self::CompiledFunction { + code: ptr, + size, + relocs: reloc_sink.relocs, + }) } fn define_function_bytes( @@ -319,8 +317,7 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend { name: &str, bytes: &[u8], _namespace: &ModuleNamespace, - _traps: Vec, - ) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])> { + ) -> ModuleResult { let size = bytes.len(); let ptr = self .memory @@ -334,14 +331,11 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend { ptr::copy_nonoverlapping(bytes.as_ptr(), ptr, size); } - Ok(( - Self::CompiledFunction { - code: ptr, - size, - relocs: vec![], - }, - &[], - )) + Ok(Self::CompiledFunction { + code: ptr, + size, + relocs: vec![], + }) } fn define_data( diff --git a/cranelift/simplejit/tests/basic.rs b/cranelift/simplejit/tests/basic.rs index 0e8ea0aa9d..31d19fa97a 100644 --- a/cranelift/simplejit/tests/basic.rs +++ b/cranelift/simplejit/tests/basic.rs @@ -1,3 +1,4 @@ +use cranelift_codegen::binemit::NullTrapSink; use cranelift_codegen::ir::*; use cranelift_codegen::isa::CallConv; use cranelift_codegen::{ir::types::I16, Context}; @@ -46,7 +47,10 @@ fn define_simple_function(module: &mut Module) -> FuncId { bcx.ins().return_(&[]); } - module.define_function(func_id, &mut ctx).unwrap(); + let mut trap_sink = NullTrapSink {}; + module + .define_function(func_id, &mut ctx, &mut trap_sink) + .unwrap(); func_id } @@ -191,7 +195,10 @@ fn libcall_function() { bcx.ins().return_(&[]); } - module.define_function(func_id, &mut ctx).unwrap(); + let mut trap_sink = NullTrapSink {}; + module + .define_function(func_id, &mut ctx, &mut trap_sink) + .unwrap(); module.finalize_definitions(); }