Add reference types R32 and R64
-Add resumable_trap, safepoint, isnull, and null instructions -Add Stackmap struct and StackmapSink trait Co-authored-by: Mir Ahmed <mirahmed753@gmail.com> Co-authored-by: Dan Gohman <sunfish@mozilla.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! CLI tool to reduce Cranelift IR files crashing during compilation.
|
||||
|
||||
use crate::disasm::{PrintRelocs, PrintTraps};
|
||||
use crate::disasm::{PrintRelocs, PrintStackmaps, PrintTraps};
|
||||
use crate::utils::{parse_sets_and_triple, read_to_string};
|
||||
use cranelift_codegen::ir::{
|
||||
Ebb, FuncRef, Function, GlobalValueData, Inst, InstBuilder, InstructionData, StackSlots,
|
||||
@@ -730,11 +730,16 @@ impl<'a> CrashCheckContext<'a> {
|
||||
let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
let mut relocs = PrintRelocs::new(false);
|
||||
let mut traps = PrintTraps::new(false);
|
||||
let mut stackmaps = PrintStackmaps::new(false);
|
||||
let mut mem = vec![];
|
||||
|
||||
let _ = self
|
||||
.context
|
||||
.compile_and_emit(self.isa, &mut mem, &mut relocs, &mut traps);
|
||||
let _ = self.context.compile_and_emit(
|
||||
self.isa,
|
||||
&mut mem,
|
||||
&mut relocs,
|
||||
&mut traps,
|
||||
&mut stackmaps,
|
||||
);
|
||||
})) {
|
||||
Ok(()) => CheckResult::Succeed,
|
||||
Err(err) => CheckResult::Crash(get_panic_string(err)),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! CLI tool to read Cranelift IR files and compile them into native code.
|
||||
|
||||
use crate::disasm::{print_all, PrintRelocs, PrintTraps};
|
||||
use crate::disasm::{print_all, PrintRelocs, PrintStackmaps, PrintTraps};
|
||||
use crate::utils::{parse_sets_and_triple, read_to_string};
|
||||
use cranelift_codegen::print_errors::pretty_error;
|
||||
use cranelift_codegen::settings::FlagsOrIsa;
|
||||
@@ -62,11 +62,12 @@ fn handle_module(
|
||||
|
||||
let mut relocs = PrintRelocs::new(flag_print);
|
||||
let mut traps = PrintTraps::new(flag_print);
|
||||
let mut stackmaps = PrintStackmaps::new(flag_print);
|
||||
let mut mem = vec![];
|
||||
|
||||
// Compile and encode the result to machine code.
|
||||
let code_info = context
|
||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps)
|
||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stackmaps)
|
||||
.map_err(|err| pretty_error(&context.func, Some(isa), err))?;
|
||||
|
||||
if flag_print {
|
||||
@@ -81,6 +82,7 @@ fn handle_module(
|
||||
code_info.jumptables_size + code_info.rodata_size,
|
||||
&relocs,
|
||||
&traps,
|
||||
&stackmaps,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,28 @@ impl binemit::TrapSink for PrintTraps {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PrintStackmaps {
|
||||
pub flag_print: bool,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
impl PrintStackmaps {
|
||||
pub fn new(flag_print: bool) -> PrintStackmaps {
|
||||
Self {
|
||||
flag_print,
|
||||
text: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl binemit::StackmapSink for PrintStackmaps {
|
||||
fn add_stackmap(&mut self, offset: binemit::CodeOffset, _: binemit::Stackmap) {
|
||||
if self.flag_print {
|
||||
write!(&mut self.text, "add_stackmap at {}\n", offset).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "disas")] {
|
||||
use capstone::prelude::*;
|
||||
@@ -170,11 +192,12 @@ pub fn print_all(
|
||||
rodata_size: u32,
|
||||
relocs: &PrintRelocs,
|
||||
traps: &PrintTraps,
|
||||
stackmaps: &PrintStackmaps,
|
||||
) -> Result<(), String> {
|
||||
print_bytes(&mem);
|
||||
print_disassembly(isa, &mem[0..code_size as usize])?;
|
||||
print_readonly_data(&mem[code_size as usize..(code_size + rodata_size) as usize]);
|
||||
println!("\n{}\n{}", &relocs.text, &traps.text);
|
||||
println!("\n{}\n{}\n{}", &relocs.text, &traps.text, &stackmaps.text);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
allow(clippy::too_many_arguments, clippy::cyclomatic_complexity)
|
||||
)]
|
||||
|
||||
use crate::disasm::{print_all, PrintRelocs, PrintTraps};
|
||||
use crate::disasm::{print_all, PrintRelocs, PrintTraps, PrintStackmaps};
|
||||
use crate::utils::{parse_sets_and_triple, read_to_end};
|
||||
use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error};
|
||||
use cranelift_codegen::settings::FlagsOrIsa;
|
||||
@@ -171,13 +171,14 @@ fn handle_module(
|
||||
let mut mem = vec![];
|
||||
let mut relocs = PrintRelocs::new(flag_print);
|
||||
let mut traps = PrintTraps::new(flag_print);
|
||||
let mut stackmaps = PrintStackmaps::new(flag_print);
|
||||
if flag_check_translation {
|
||||
if let Err(errors) = context.verify(fisa) {
|
||||
return Err(pretty_verifier_error(&context.func, fisa.isa, None, errors));
|
||||
}
|
||||
} else {
|
||||
let code_info = context
|
||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps)
|
||||
.compile_and_emit(isa, &mut mem, &mut relocs, &mut traps, &mut stackmaps)
|
||||
.map_err(|err| pretty_error(&context.func, fisa.isa, err))?;
|
||||
|
||||
if flag_print_size {
|
||||
@@ -223,7 +224,7 @@ fn handle_module(
|
||||
}
|
||||
|
||||
if let Some((code_size, rodata_size)) = saved_sizes {
|
||||
print_all(isa, &mem, code_size, rodata_size, &relocs, &traps)?;
|
||||
print_all(isa, &mem, code_size, rodata_size, &relocs, &traps, &stackmaps)?;
|
||||
}
|
||||
|
||||
context.clear();
|
||||
|
||||
Reference in New Issue
Block a user