Remove sink arguments from compile_and_emit
The data can be accessed after the fact using context.mach_compile_result
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
//! contexts concurrently. Typically, you would have one context per compilation thread and only a
|
//! contexts concurrently. Typically, you would have one context per compilation thread and only a
|
||||||
//! single ISA instance.
|
//! single ISA instance.
|
||||||
|
|
||||||
use crate::binemit::{CodeInfo, RelocSink, StackMapSink, TrapSink};
|
use crate::binemit::CodeInfo;
|
||||||
use crate::dce::do_dce;
|
use crate::dce::do_dce;
|
||||||
use crate::dominator_tree::DominatorTree;
|
use crate::dominator_tree::DominatorTree;
|
||||||
use crate::flowgraph::ControlFlowGraph;
|
use crate::flowgraph::ControlFlowGraph;
|
||||||
@@ -18,7 +18,7 @@ use crate::isa::TargetIsa;
|
|||||||
use crate::legalizer::simple_legalize;
|
use crate::legalizer::simple_legalize;
|
||||||
use crate::licm::do_licm;
|
use crate::licm::do_licm;
|
||||||
use crate::loop_analysis::LoopAnalysis;
|
use crate::loop_analysis::LoopAnalysis;
|
||||||
use crate::machinst::{MachCompileResult, MachReloc, MachStackMap, MachTrap};
|
use crate::machinst::MachCompileResult;
|
||||||
use crate::nan_canonicalization::do_nan_canonicalization;
|
use crate::nan_canonicalization::do_nan_canonicalization;
|
||||||
use crate::remove_constant_phis::do_remove_constant_phis;
|
use crate::remove_constant_phis::do_remove_constant_phis;
|
||||||
use crate::result::CodegenResult;
|
use crate::result::CodegenResult;
|
||||||
@@ -111,16 +111,11 @@ impl Context {
|
|||||||
&mut self,
|
&mut self,
|
||||||
isa: &dyn TargetIsa,
|
isa: &dyn TargetIsa,
|
||||||
mem: &mut Vec<u8>,
|
mem: &mut Vec<u8>,
|
||||||
relocs: &mut dyn RelocSink,
|
|
||||||
traps: &mut dyn TrapSink,
|
|
||||||
stack_maps: &mut dyn StackMapSink,
|
|
||||||
) -> CodegenResult<()> {
|
) -> CodegenResult<()> {
|
||||||
let info = self.compile(isa)?;
|
let info = self.compile(isa)?;
|
||||||
let old_len = mem.len();
|
let old_len = mem.len();
|
||||||
mem.resize(old_len + info.total_size as usize, 0);
|
mem.resize(old_len + info.total_size as usize, 0);
|
||||||
let new_info = unsafe {
|
let new_info = unsafe { self.emit_to_memory(mem.as_mut_ptr().add(old_len)) };
|
||||||
self.emit_to_memory(mem.as_mut_ptr().add(old_len), relocs, traps, stack_maps)
|
|
||||||
};
|
|
||||||
debug_assert!(new_info == info);
|
debug_assert!(new_info == info);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -187,13 +182,7 @@ impl Context {
|
|||||||
///
|
///
|
||||||
/// Returns information about the emitted code and data.
|
/// Returns information about the emitted code and data.
|
||||||
#[deny(unsafe_op_in_unsafe_fn)]
|
#[deny(unsafe_op_in_unsafe_fn)]
|
||||||
pub unsafe fn emit_to_memory(
|
pub unsafe fn emit_to_memory(&self, mem: *mut u8) -> CodeInfo {
|
||||||
&self,
|
|
||||||
mem: *mut u8,
|
|
||||||
relocs: &mut dyn RelocSink,
|
|
||||||
traps: &mut dyn TrapSink,
|
|
||||||
stack_maps: &mut dyn StackMapSink,
|
|
||||||
) -> CodeInfo {
|
|
||||||
let _tt = timing::binemit();
|
let _tt = timing::binemit();
|
||||||
let result = self
|
let result = self
|
||||||
.mach_compile_result
|
.mach_compile_result
|
||||||
@@ -204,32 +193,6 @@ impl Context {
|
|||||||
let mem = unsafe { std::slice::from_raw_parts_mut(mem, info.total_size as usize) };
|
let mem = unsafe { std::slice::from_raw_parts_mut(mem, info.total_size as usize) };
|
||||||
mem.copy_from_slice(result.buffer.data());
|
mem.copy_from_slice(result.buffer.data());
|
||||||
|
|
||||||
for &MachReloc {
|
|
||||||
offset,
|
|
||||||
srcloc,
|
|
||||||
kind,
|
|
||||||
ref name,
|
|
||||||
addend,
|
|
||||||
} in result.buffer.relocs()
|
|
||||||
{
|
|
||||||
relocs.reloc_external(offset, srcloc, kind, name, addend);
|
|
||||||
}
|
|
||||||
for &MachTrap {
|
|
||||||
offset,
|
|
||||||
srcloc,
|
|
||||||
code,
|
|
||||||
} in result.buffer.traps()
|
|
||||||
{
|
|
||||||
traps.trap(offset, srcloc, code);
|
|
||||||
}
|
|
||||||
for &MachStackMap {
|
|
||||||
offset_end,
|
|
||||||
ref stack_map,
|
|
||||||
..
|
|
||||||
} in result.buffer.stack_maps()
|
|
||||||
{
|
|
||||||
stack_maps.add_stack_map(offset_end, stack_map.clone());
|
|
||||||
}
|
|
||||||
info
|
info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub mod verifier;
|
|||||||
pub mod write;
|
pub mod write;
|
||||||
|
|
||||||
pub use crate::entity::packed_option;
|
pub use crate::entity::packed_option;
|
||||||
pub use crate::machinst::buffer::{MachCallSite, MachReloc, MachSrcLoc, MachTrap};
|
pub use crate::machinst::buffer::{MachCallSite, MachReloc, MachSrcLoc, MachStackMap, MachTrap};
|
||||||
pub use crate::machinst::TextSectionBuilder;
|
pub use crate::machinst::TextSectionBuilder;
|
||||||
|
|
||||||
mod bitset;
|
mod bitset;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
//! Provides functionality for compiling and running CLIF IR for `run` tests.
|
//! Provides functionality for compiling and running CLIF IR for `run` tests.
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use cranelift_codegen::binemit::{NullRelocSink, NullStackMapSink, NullTrapSink};
|
|
||||||
use cranelift_codegen::data_value::DataValue;
|
use cranelift_codegen::data_value::DataValue;
|
||||||
use cranelift_codegen::ir::{condcodes::IntCC, Function, InstBuilder, Signature};
|
use cranelift_codegen::ir::{condcodes::IntCC, Function, InstBuilder, Signature};
|
||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
@@ -241,14 +240,11 @@ fn compile(function: Function, isa: &dyn TargetIsa) -> Result<Mmap, CompilationE
|
|||||||
context.func = function;
|
context.func = function;
|
||||||
|
|
||||||
// Compile and encode the result to machine code.
|
// Compile and encode the result to machine code.
|
||||||
let relocs = &mut NullRelocSink {};
|
|
||||||
let traps = &mut NullTrapSink {};
|
|
||||||
let stack_maps = &mut NullStackMapSink {};
|
|
||||||
let code_info = context.compile(isa)?;
|
let code_info = context.compile(isa)?;
|
||||||
let mut code_page = MmapMut::map_anon(code_info.total_size as usize)?;
|
let mut code_page = MmapMut::map_anon(code_info.total_size as usize)?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
context.emit_to_memory(code_page.as_mut_ptr(), relocs, traps, stack_maps);
|
context.emit_to_memory(code_page.as_mut_ptr());
|
||||||
};
|
};
|
||||||
|
|
||||||
let code_page = code_page.make_exec()?;
|
let code_page = code_page.make_exec()?;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use cranelift::prelude::*;
|
use cranelift::prelude::*;
|
||||||
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
|
|
||||||
use cranelift_codegen::settings::{self, Configurable};
|
use cranelift_codegen::settings::{self, Configurable};
|
||||||
use cranelift_jit::{JITBuilder, JITModule};
|
use cranelift_jit::{JITBuilder, JITModule};
|
||||||
use cranelift_module::{default_libcall_names, Linkage, Module};
|
use cranelift_module::{default_libcall_names, Linkage, Module};
|
||||||
@@ -48,11 +47,7 @@ fn main() {
|
|||||||
bcx.seal_all_blocks();
|
bcx.seal_all_blocks();
|
||||||
bcx.finalize();
|
bcx.finalize();
|
||||||
}
|
}
|
||||||
let mut trap_sink = NullTrapSink {};
|
module.define_function(func_a, &mut ctx).unwrap();
|
||||||
let mut stack_map_sink = NullStackMapSink {};
|
|
||||||
module
|
|
||||||
.define_function(func_a, &mut ctx, &mut trap_sink, &mut stack_map_sink)
|
|
||||||
.unwrap();
|
|
||||||
module.clear_context(&mut ctx);
|
module.clear_context(&mut ctx);
|
||||||
|
|
||||||
ctx.func.signature = sig_b;
|
ctx.func.signature = sig_b;
|
||||||
@@ -74,9 +69,7 @@ fn main() {
|
|||||||
bcx.seal_all_blocks();
|
bcx.seal_all_blocks();
|
||||||
bcx.finalize();
|
bcx.finalize();
|
||||||
}
|
}
|
||||||
module
|
module.define_function(func_b, &mut ctx).unwrap();
|
||||||
.define_function(func_b, &mut ctx, &mut trap_sink, &mut stack_map_sink)
|
|
||||||
.unwrap();
|
|
||||||
module.clear_context(&mut ctx);
|
module.clear_context(&mut ctx);
|
||||||
|
|
||||||
// Perform linking.
|
// Perform linking.
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
use crate::{compiled_blob::CompiledBlob, memory::Memory};
|
use crate::{compiled_blob::CompiledBlob, memory::Memory};
|
||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
use cranelift_codegen::settings::Configurable;
|
use cranelift_codegen::settings::Configurable;
|
||||||
use cranelift_codegen::{self, ir, settings};
|
use cranelift_codegen::{self, ir, settings, MachReloc};
|
||||||
use cranelift_codegen::{
|
use cranelift_codegen::{
|
||||||
binemit::{Addend, CodeInfo, CodeOffset, Reloc, RelocSink, StackMapSink, TrapSink},
|
binemit::{Addend, CodeInfo, CodeOffset, Reloc, RelocSink},
|
||||||
CodegenError,
|
CodegenError,
|
||||||
};
|
};
|
||||||
use cranelift_entity::SecondaryMap;
|
use cranelift_entity::SecondaryMap;
|
||||||
@@ -648,8 +648,6 @@ impl Module for JITModule {
|
|||||||
&mut self,
|
&mut self,
|
||||||
id: FuncId,
|
id: FuncId,
|
||||||
ctx: &mut cranelift_codegen::Context,
|
ctx: &mut cranelift_codegen::Context,
|
||||||
trap_sink: &mut dyn TrapSink,
|
|
||||||
stack_map_sink: &mut dyn StackMapSink,
|
|
||||||
) -> ModuleResult<ModuleCompiledFunction> {
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
info!("defining function {}: {}", id, ctx.func.display());
|
info!("defining function {}: {}", id, ctx.func.display());
|
||||||
let decl = self.declarations.get_function_decl(id);
|
let decl = self.declarations.get_function_decl(id);
|
||||||
@@ -674,7 +672,17 @@ impl Module for JITModule {
|
|||||||
.expect("TODO: handle OOM etc.");
|
.expect("TODO: handle OOM etc.");
|
||||||
|
|
||||||
let mut reloc_sink = JITRelocSink::default();
|
let mut reloc_sink = JITRelocSink::default();
|
||||||
unsafe { ctx.emit_to_memory(ptr, &mut reloc_sink, trap_sink, stack_map_sink) };
|
unsafe { ctx.emit_to_memory(ptr) };
|
||||||
|
for &MachReloc {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
kind,
|
||||||
|
ref name,
|
||||||
|
addend,
|
||||||
|
} in ctx.mach_compile_result.as_ref().unwrap().buffer.relocs()
|
||||||
|
{
|
||||||
|
reloc_sink.reloc_external(offset, srcloc, kind, name, addend);
|
||||||
|
}
|
||||||
|
|
||||||
self.record_function_for_perf(ptr, size, &decl.name);
|
self.record_function_for_perf(ptr, size, &decl.name);
|
||||||
self.compiled_functions[id] = Some(CompiledBlob {
|
self.compiled_functions[id] = Some(CompiledBlob {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
|
|
||||||
use cranelift_codegen::ir::*;
|
use cranelift_codegen::ir::*;
|
||||||
use cranelift_codegen::isa::CallConv;
|
use cranelift_codegen::isa::CallConv;
|
||||||
use cranelift_codegen::settings::{self, Configurable};
|
use cranelift_codegen::settings::{self, Configurable};
|
||||||
@@ -56,11 +55,7 @@ fn define_simple_function(module: &mut JITModule) -> FuncId {
|
|||||||
bcx.ins().return_(&[]);
|
bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut trap_sink = NullTrapSink {};
|
module.define_function(func_id, &mut ctx).unwrap();
|
||||||
let mut stack_map_sink = NullStackMapSink {};
|
|
||||||
module
|
|
||||||
.define_function(func_id, &mut ctx, &mut trap_sink, &mut stack_map_sink)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
func_id
|
func_id
|
||||||
}
|
}
|
||||||
@@ -205,11 +200,7 @@ fn libcall_function() {
|
|||||||
bcx.ins().return_(&[]);
|
bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut trap_sink = NullTrapSink {};
|
module.define_function(func_id, &mut ctx).unwrap();
|
||||||
let mut stack_map_sink = NullStackMapSink {};
|
|
||||||
module
|
|
||||||
.define_function(func_id, &mut ctx, &mut trap_sink, &mut stack_map_sink)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
module.finalize_definitions();
|
module.finalize_definitions();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -554,8 +554,6 @@ pub trait Module {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func: FuncId,
|
func: FuncId,
|
||||||
ctx: &mut Context,
|
ctx: &mut Context,
|
||||||
trap_sink: &mut dyn binemit::TrapSink,
|
|
||||||
stack_map_sink: &mut dyn binemit::StackMapSink,
|
|
||||||
) -> ModuleResult<ModuleCompiledFunction>;
|
) -> ModuleResult<ModuleCompiledFunction>;
|
||||||
|
|
||||||
/// Define a function, taking the function body from the given `bytes`.
|
/// Define a function, taking the function body from the given `bytes`.
|
||||||
@@ -656,10 +654,8 @@ impl<M: Module> Module for &mut M {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func: FuncId,
|
func: FuncId,
|
||||||
ctx: &mut Context,
|
ctx: &mut Context,
|
||||||
trap_sink: &mut dyn binemit::TrapSink,
|
|
||||||
stack_map_sink: &mut dyn binemit::StackMapSink,
|
|
||||||
) -> ModuleResult<ModuleCompiledFunction> {
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
(**self).define_function(func, ctx, trap_sink, stack_map_sink)
|
(**self).define_function(func, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn define_function_bytes(
|
fn define_function_bytes(
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use cranelift_codegen::entity::SecondaryMap;
|
use cranelift_codegen::entity::SecondaryMap;
|
||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
use cranelift_codegen::{self, ir};
|
use cranelift_codegen::{self, ir, MachReloc};
|
||||||
use cranelift_codegen::{
|
use cranelift_codegen::{
|
||||||
binemit::{Addend, CodeOffset, Reloc, RelocSink, StackMapSink, TrapSink},
|
binemit::{Addend, CodeOffset, Reloc, RelocSink},
|
||||||
CodegenError,
|
CodegenError,
|
||||||
};
|
};
|
||||||
use cranelift_module::{
|
use cranelift_module::{
|
||||||
@@ -307,20 +307,23 @@ impl Module for ObjectModule {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func_id: FuncId,
|
func_id: FuncId,
|
||||||
ctx: &mut cranelift_codegen::Context,
|
ctx: &mut cranelift_codegen::Context,
|
||||||
trap_sink: &mut dyn TrapSink,
|
|
||||||
stack_map_sink: &mut dyn StackMapSink,
|
|
||||||
) -> ModuleResult<ModuleCompiledFunction> {
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
info!("defining function {}: {}", func_id, ctx.func.display());
|
info!("defining function {}: {}", func_id, ctx.func.display());
|
||||||
let mut code: Vec<u8> = Vec::new();
|
let mut code: Vec<u8> = Vec::new();
|
||||||
let mut reloc_sink = ObjectRelocSink::default();
|
let mut reloc_sink = ObjectRelocSink::default();
|
||||||
|
|
||||||
ctx.compile_and_emit(
|
ctx.compile_and_emit(self.isa(), &mut code)?;
|
||||||
self.isa(),
|
|
||||||
&mut code,
|
for &MachReloc {
|
||||||
&mut reloc_sink,
|
offset,
|
||||||
trap_sink,
|
srcloc,
|
||||||
stack_map_sink,
|
kind,
|
||||||
)?;
|
ref name,
|
||||||
|
addend,
|
||||||
|
} in ctx.mach_compile_result.as_ref().unwrap().buffer.relocs()
|
||||||
|
{
|
||||||
|
reloc_sink.reloc_external(offset, srcloc, kind, name, addend);
|
||||||
|
}
|
||||||
|
|
||||||
self.define_function_bytes(func_id, &code, &reloc_sink.relocs)
|
self.define_function_bytes(func_id, &code, &reloc_sink.relocs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
use cranelift_codegen::ir::*;
|
use cranelift_codegen::ir::*;
|
||||||
use cranelift_codegen::isa::CallConv;
|
use cranelift_codegen::isa::CallConv;
|
||||||
use cranelift_codegen::{
|
use cranelift_codegen::settings;
|
||||||
binemit::{NullStackMapSink, NullTrapSink},
|
|
||||||
settings,
|
|
||||||
};
|
|
||||||
use cranelift_codegen::{ir::types::I16, Context};
|
use cranelift_codegen::{ir::types::I16, Context};
|
||||||
use cranelift_entity::EntityRef;
|
use cranelift_entity::EntityRef;
|
||||||
use cranelift_frontend::*;
|
use cranelift_frontend::*;
|
||||||
@@ -53,11 +50,7 @@ fn define_simple_function(module: &mut ObjectModule) -> FuncId {
|
|||||||
bcx.ins().return_(&[]);
|
bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut trap_sink = NullTrapSink {};
|
module.define_function(func_id, &mut ctx).unwrap();
|
||||||
let mut stack_map_sink = NullStackMapSink {};
|
|
||||||
module
|
|
||||||
.define_function(func_id, &mut ctx, &mut trap_sink, &mut stack_map_sink)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
func_id
|
func_id
|
||||||
}
|
}
|
||||||
@@ -194,11 +187,7 @@ fn libcall_function() {
|
|||||||
bcx.ins().return_(&[]);
|
bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut trap_sink = NullTrapSink {};
|
module.define_function(func_id, &mut ctx).unwrap();
|
||||||
let mut stack_map_sink = NullStackMapSink {};
|
|
||||||
module
|
|
||||||
.define_function(func_id, &mut ctx, &mut trap_sink, &mut stack_map_sink)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
module.finish();
|
module.finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
//! CLI tool to reduce Cranelift IR files crashing during compilation.
|
//! CLI tool to reduce Cranelift IR files crashing during compilation.
|
||||||
|
|
||||||
use crate::disasm::{PrintRelocs, PrintStackMaps, PrintTraps};
|
|
||||||
use crate::utils::{parse_sets_and_triple, read_to_string};
|
use crate::utils::{parse_sets_and_triple, read_to_string};
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||||
@@ -1029,17 +1028,9 @@ impl<'a> CrashCheckContext<'a> {
|
|||||||
std::panic::set_hook(Box::new(|_| {})); // silence panics
|
std::panic::set_hook(Box::new(|_| {})); // silence panics
|
||||||
|
|
||||||
let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||||
let mut relocs = PrintRelocs::new(false);
|
let _ = self
|
||||||
let mut traps = PrintTraps::new(false);
|
.context
|
||||||
let mut stack_maps = PrintStackMaps::new(false);
|
.compile_and_emit(self.isa, &mut self.code_memory);
|
||||||
|
|
||||||
let _ = self.context.compile_and_emit(
|
|
||||||
self.isa,
|
|
||||||
&mut self.code_memory,
|
|
||||||
&mut relocs,
|
|
||||||
&mut traps,
|
|
||||||
&mut stack_maps,
|
|
||||||
);
|
|
||||||
})) {
|
})) {
|
||||||
Ok(()) => CheckResult::Succeed,
|
Ok(()) => CheckResult::Succeed,
|
||||||
Err(err) => CheckResult::Crash(get_panic_string(err)),
|
Err(err) => CheckResult::Crash(get_panic_string(err)),
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
use crate::disasm::{print_all, PrintRelocs, PrintStackMaps, PrintTraps};
|
use crate::disasm::{print_all, PrintRelocs, PrintStackMaps, PrintTraps};
|
||||||
use crate::utils::{parse_sets_and_triple, read_to_string};
|
use crate::utils::{parse_sets_and_triple, read_to_string};
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
|
use cranelift_codegen::binemit::{RelocSink, StackMapSink, TrapSink};
|
||||||
use cranelift_codegen::print_errors::pretty_error;
|
use cranelift_codegen::print_errors::pretty_error;
|
||||||
use cranelift_codegen::settings::FlagsOrIsa;
|
use cranelift_codegen::settings::FlagsOrIsa;
|
||||||
use cranelift_codegen::timing;
|
|
||||||
use cranelift_codegen::Context;
|
use cranelift_codegen::Context;
|
||||||
|
use cranelift_codegen::{timing, MachReloc, MachStackMap, MachTrap};
|
||||||
use cranelift_reader::{parse_test, ParseOptions};
|
use cranelift_reader::{parse_test, ParseOptions};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -79,9 +80,36 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
|
|
||||||
// Compile and encode the result to machine code.
|
// Compile and encode the result to machine code.
|
||||||
context
|
context
|
||||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
|
.compile_and_emit(isa, &mut mem)
|
||||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
||||||
let code_info = context.mach_compile_result.as_ref().unwrap().code_info();
|
let result = context.mach_compile_result.as_ref().unwrap();
|
||||||
|
let code_info = result.code_info();
|
||||||
|
for &MachReloc {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
kind,
|
||||||
|
ref name,
|
||||||
|
addend,
|
||||||
|
} in result.buffer.relocs()
|
||||||
|
{
|
||||||
|
relocs.reloc_external(offset, srcloc, kind, name, addend);
|
||||||
|
}
|
||||||
|
for &MachTrap {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
code,
|
||||||
|
} in result.buffer.traps()
|
||||||
|
{
|
||||||
|
traps.trap(offset, srcloc, code);
|
||||||
|
}
|
||||||
|
for &MachStackMap {
|
||||||
|
offset_end,
|
||||||
|
ref stack_map,
|
||||||
|
..
|
||||||
|
} in result.buffer.stack_maps()
|
||||||
|
{
|
||||||
|
stack_maps.add_stack_map(offset_end, stack_map.clone());
|
||||||
|
}
|
||||||
|
|
||||||
if options.print {
|
if options.print {
|
||||||
println!("{}", context.func.display());
|
println!("{}", context.func.display());
|
||||||
|
|||||||
@@ -10,11 +10,12 @@
|
|||||||
use crate::disasm::{print_all, PrintRelocs, PrintStackMaps, PrintTraps};
|
use crate::disasm::{print_all, PrintRelocs, PrintStackMaps, PrintTraps};
|
||||||
use crate::utils::parse_sets_and_triple;
|
use crate::utils::parse_sets_and_triple;
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
|
use cranelift_codegen::binemit::{RelocSink, StackMapSink, TrapSink};
|
||||||
use cranelift_codegen::ir::DisplayFunctionAnnotations;
|
use cranelift_codegen::ir::DisplayFunctionAnnotations;
|
||||||
use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error};
|
use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error};
|
||||||
use cranelift_codegen::settings::FlagsOrIsa;
|
use cranelift_codegen::settings::FlagsOrIsa;
|
||||||
use cranelift_codegen::timing;
|
|
||||||
use cranelift_codegen::Context;
|
use cranelift_codegen::Context;
|
||||||
|
use cranelift_codegen::{timing, MachReloc, MachStackMap, MachTrap};
|
||||||
use cranelift_entity::EntityRef;
|
use cranelift_entity::EntityRef;
|
||||||
use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex, ReturnMode};
|
use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex, ReturnMode};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
@@ -267,9 +268,36 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context
|
context
|
||||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stack_maps)
|
.compile_and_emit(isa, &mut mem)
|
||||||
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
.map_err(|err| anyhow::anyhow!("{}", pretty_error(&context.func, err)))?;
|
||||||
let code_info = context.mach_compile_result.as_ref().unwrap().code_info();
|
let result = context.mach_compile_result.as_ref().unwrap();
|
||||||
|
let code_info = result.code_info();
|
||||||
|
for &MachReloc {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
kind,
|
||||||
|
ref name,
|
||||||
|
addend,
|
||||||
|
} in result.buffer.relocs()
|
||||||
|
{
|
||||||
|
relocs.reloc_external(offset, srcloc, kind, name, addend);
|
||||||
|
}
|
||||||
|
for &MachTrap {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
code,
|
||||||
|
} in result.buffer.traps()
|
||||||
|
{
|
||||||
|
traps.trap(offset, srcloc, code);
|
||||||
|
}
|
||||||
|
for &MachStackMap {
|
||||||
|
offset_end,
|
||||||
|
ref stack_map,
|
||||||
|
..
|
||||||
|
} in result.buffer.stack_maps()
|
||||||
|
{
|
||||||
|
stack_maps.add_stack_map(offset_end, stack_map.clone());
|
||||||
|
}
|
||||||
|
|
||||||
if options.print_size {
|
if options.print_size {
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ use crate::{
|
|||||||
CompiledFunction, FunctionAddressMap, Relocation, RelocationTarget,
|
CompiledFunction, FunctionAddressMap, Relocation, RelocationTarget,
|
||||||
};
|
};
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
|
use cranelift_codegen::binemit::{RelocSink as _, StackMapSink as _, TrapSink as _};
|
||||||
use cranelift_codegen::ir::{self, ExternalName, InstBuilder, MemFlags};
|
use cranelift_codegen::ir::{self, ExternalName, InstBuilder, MemFlags};
|
||||||
use cranelift_codegen::isa::TargetIsa;
|
use cranelift_codegen::isa::TargetIsa;
|
||||||
use cranelift_codegen::print_errors::pretty_error;
|
use cranelift_codegen::print_errors::pretty_error;
|
||||||
use cranelift_codegen::settings;
|
|
||||||
use cranelift_codegen::MachSrcLoc;
|
|
||||||
use cranelift_codegen::{binemit, Context};
|
use cranelift_codegen::{binemit, Context};
|
||||||
|
use cranelift_codegen::{settings, MachReloc, MachTrap};
|
||||||
|
use cranelift_codegen::{MachSrcLoc, MachStackMap};
|
||||||
use cranelift_entity::{EntityRef, PrimaryMap};
|
use cranelift_entity::{EntityRef, PrimaryMap};
|
||||||
use cranelift_frontend::FunctionBuilder;
|
use cranelift_frontend::FunctionBuilder;
|
||||||
use cranelift_wasm::{
|
use cranelift_wasm::{
|
||||||
@@ -170,15 +171,37 @@ impl wasmtime_environ::Compiler for Compiler {
|
|||||||
let mut trap_sink = TrapSink::new();
|
let mut trap_sink = TrapSink::new();
|
||||||
let mut stack_map_sink = StackMapSink::default();
|
let mut stack_map_sink = StackMapSink::default();
|
||||||
context
|
context
|
||||||
.compile_and_emit(
|
.compile_and_emit(isa, &mut code_buf)
|
||||||
isa,
|
|
||||||
&mut code_buf,
|
|
||||||
&mut reloc_sink,
|
|
||||||
&mut trap_sink,
|
|
||||||
&mut stack_map_sink,
|
|
||||||
)
|
|
||||||
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
||||||
|
|
||||||
|
let result = context.mach_compile_result.as_ref().unwrap();
|
||||||
|
for &MachReloc {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
kind,
|
||||||
|
ref name,
|
||||||
|
addend,
|
||||||
|
} in result.buffer.relocs()
|
||||||
|
{
|
||||||
|
reloc_sink.reloc_external(offset, srcloc, kind, name, addend);
|
||||||
|
}
|
||||||
|
for &MachTrap {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
code,
|
||||||
|
} in result.buffer.traps()
|
||||||
|
{
|
||||||
|
trap_sink.trap(offset, srcloc, code);
|
||||||
|
}
|
||||||
|
for &MachStackMap {
|
||||||
|
offset_end,
|
||||||
|
ref stack_map,
|
||||||
|
..
|
||||||
|
} in result.buffer.stack_maps()
|
||||||
|
{
|
||||||
|
stack_map_sink.add_stack_map(offset_end, stack_map.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let unwind_info = context
|
let unwind_info = context
|
||||||
.create_unwind_info(isa)
|
.create_unwind_info(isa)
|
||||||
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
||||||
@@ -535,18 +558,26 @@ impl Compiler {
|
|||||||
) -> Result<CompiledFunction, CompileError> {
|
) -> Result<CompiledFunction, CompileError> {
|
||||||
let mut code_buf = Vec::new();
|
let mut code_buf = Vec::new();
|
||||||
let mut reloc_sink = TrampolineRelocSink::default();
|
let mut reloc_sink = TrampolineRelocSink::default();
|
||||||
let mut trap_sink = binemit::NullTrapSink {};
|
|
||||||
let mut stack_map_sink = binemit::NullStackMapSink {};
|
|
||||||
context
|
context
|
||||||
.compile_and_emit(
|
.compile_and_emit(isa, &mut code_buf)
|
||||||
isa,
|
|
||||||
&mut code_buf,
|
|
||||||
&mut reloc_sink,
|
|
||||||
&mut trap_sink,
|
|
||||||
&mut stack_map_sink,
|
|
||||||
)
|
|
||||||
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
||||||
|
|
||||||
|
for &MachReloc {
|
||||||
|
offset,
|
||||||
|
srcloc,
|
||||||
|
kind,
|
||||||
|
ref name,
|
||||||
|
addend,
|
||||||
|
} in context
|
||||||
|
.mach_compile_result
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.buffer
|
||||||
|
.relocs()
|
||||||
|
{
|
||||||
|
reloc_sink.reloc_external(offset, srcloc, kind, name, addend);
|
||||||
|
}
|
||||||
|
|
||||||
let unwind_info = context
|
let unwind_info = context
|
||||||
.create_unwind_info(isa)
|
.create_unwind_info(isa)
|
||||||
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user