Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Makes cfg flags consistent with the ones of jit. (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso authored May 1, 2024
1 parent 0f4e75c commit 0270240
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 66 deletions.
2 changes: 1 addition & 1 deletion benches/jit_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn bench_init_vm(bencher: &mut Bencher) {
});
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_compile(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/relative_call.so").unwrap();
Expand Down
26 changes: 12 additions & 14 deletions benches/vm_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
extern crate solana_rbpf;
extern crate test;

#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
use solana_rbpf::{ebpf, memory_region::MemoryRegion, program::FunctionRegistry, vm::Config};
use solana_rbpf::{
ebpf,
elf::Executable,
memory_region::MemoryRegion,
program::{BuiltinProgram, FunctionRegistry},
verifier::RequisiteVerifier,
vm::{Config, TestContextObject},
elf::Executable, program::BuiltinProgram, verifier::RequisiteVerifier, vm::TestContextObject,
};
use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;
Expand Down Expand Up @@ -46,7 +43,7 @@ fn bench_init_interpreter_start(bencher: &mut Bencher) {
});
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_init_jit_start(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/rodata_section.so").unwrap();
Expand All @@ -73,7 +70,7 @@ fn bench_init_jit_start(bencher: &mut Bencher) {
});
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
fn bench_jit_vs_interpreter(
bencher: &mut Bencher,
assembly: &str,
Expand Down Expand Up @@ -132,7 +129,7 @@ fn bench_jit_vs_interpreter(
);
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_vs_interpreter_address_translation(bencher: &mut Bencher) {
bench_jit_vs_interpreter(
Expand All @@ -150,6 +147,7 @@ fn bench_jit_vs_interpreter_address_translation(bencher: &mut Bencher) {
);
}

#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
static ADDRESS_TRANSLATION_STACK_CODE: &str = "
mov r1, r2
and r1, 4095
Expand All @@ -161,7 +159,7 @@ static ADDRESS_TRANSLATION_STACK_CODE: &str = "
jlt r2, 0x10000, -8
exit";

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_vs_interpreter_address_translation_stack_fixed(bencher: &mut Bencher) {
bench_jit_vs_interpreter(
Expand All @@ -176,7 +174,7 @@ fn bench_jit_vs_interpreter_address_translation_stack_fixed(bencher: &mut Benche
);
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_vs_interpreter_address_translation_stack_dynamic(bencher: &mut Bencher) {
bench_jit_vs_interpreter(
Expand All @@ -191,7 +189,7 @@ fn bench_jit_vs_interpreter_address_translation_stack_dynamic(bencher: &mut Benc
);
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_vs_interpreter_empty_for_loop(bencher: &mut Bencher) {
bench_jit_vs_interpreter(
Expand All @@ -208,7 +206,7 @@ fn bench_jit_vs_interpreter_empty_for_loop(bencher: &mut Bencher) {
);
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_vs_interpreter_call_depth_fixed(bencher: &mut Bencher) {
bench_jit_vs_interpreter(
Expand Down Expand Up @@ -238,7 +236,7 @@ fn bench_jit_vs_interpreter_call_depth_fixed(bencher: &mut Bencher) {
);
}

#[cfg(not(windows))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_vs_interpreter_call_depth_dynamic(bencher: &mut Bencher) {
bench_jit_vs_interpreter(
Expand Down
35 changes: 19 additions & 16 deletions fuzz/fuzz_targets/smart_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ fuzz_target!(|data: FuzzData| {
// verify please
return;
}
let mut interp_mem = data.mem.clone();
let mut jit_mem = data.mem;

#[allow(unused_mut)]
let mut executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(
Expand All @@ -63,19 +63,24 @@ fuzz_target!(|data: FuzzData| {
function_registry,
)
.unwrap();
if executable.jit_compile().is_ok() {
let mut interp_context_object = TestContextObject::new(1 << 16);
let interp_mem_region = MemoryRegion::new_writable(&mut interp_mem, ebpf::MM_INPUT_START);
create_vm!(
interp_vm,
&executable,
&mut interp_context_object,
interp_stack,
interp_heap,
vec![interp_mem_region],
None
);
let mut interp_mem = data.mem.clone();
let mut interp_context_object = TestContextObject::new(1 << 16);
let interp_mem_region = MemoryRegion::new_writable(&mut interp_mem, ebpf::MM_INPUT_START);
create_vm!(
interp_vm,
&executable,
&mut interp_context_object,
interp_stack,
interp_heap,
vec![interp_mem_region],
None
);
#[allow(unused)]
let (_interp_ins_count, interp_res) = interp_vm.execute_program(&executable, true);

#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
if executable.jit_compile().is_ok() {
let mut jit_mem = data.mem;
let mut jit_context_object = TestContextObject::new(1 << 16);
let jit_mem_region = MemoryRegion::new_writable(&mut jit_mem, ebpf::MM_INPUT_START);
create_vm!(
Expand All @@ -87,8 +92,6 @@ fuzz_target!(|data: FuzzData| {
vec![jit_mem_region],
None
);

let (_interp_ins_count, interp_res) = interp_vm.execute_program(&executable, true);
let (_jit_ins_count, jit_res) = jit_vm.execute_program(&executable, false);
if format!("{:?}", interp_res) != format!("{:?}", jit_res) {
panic!("Expected {:?}, but got {:?}", interp_res, jit_res);
Expand Down
53 changes: 22 additions & 31 deletions fuzz/fuzz_targets/smarter_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use solana_rbpf::{
insn_builder::IntoBytes,
memory_region::MemoryRegion,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
static_analysis::Analysis,
verifier::{RequisiteVerifier, Verifier},
vm::{ContextObject, TestContextObject},
vm::TestContextObject,
};
use test_utils::create_vm;

Expand All @@ -27,12 +26,6 @@ struct FuzzData {
mem: Vec<u8>,
}

fn dump_insns<C: ContextObject>(executable: &Executable<C>) {
let analysis = Analysis::from_executable(executable).unwrap();
eprint!("Using the following disassembly");
analysis.disassemble(&mut std::io::stderr().lock()).unwrap();
}

fuzz_target!(|data: FuzzData| {
let prog = make_program(&data.prog);
let config = data.template.into();
Expand All @@ -48,8 +41,8 @@ fuzz_target!(|data: FuzzData| {
// verify please
return;
}
let mut interp_mem = data.mem.clone();
let mut jit_mem = data.mem;

#[allow(unused_mut)]
let mut executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(
Expand All @@ -60,19 +53,24 @@ fuzz_target!(|data: FuzzData| {
function_registry,
)
.unwrap();
if executable.jit_compile().is_ok() {
let mut interp_context_object = TestContextObject::new(1 << 16);
let interp_mem_region = MemoryRegion::new_writable(&mut interp_mem, ebpf::MM_INPUT_START);
create_vm!(
interp_vm,
&executable,
&mut interp_context_object,
interp_stack,
interp_heap,
vec![interp_mem_region],
None
);
let mut interp_mem = data.mem.clone();
let mut interp_context_object = TestContextObject::new(1 << 16);
let interp_mem_region = MemoryRegion::new_writable(&mut interp_mem, ebpf::MM_INPUT_START);
create_vm!(
interp_vm,
&executable,
&mut interp_context_object,
interp_stack,
interp_heap,
vec![interp_mem_region],
None
);
#[allow(unused)]
let (_interp_ins_count, interp_res) = interp_vm.execute_program(&executable, true);

#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
if executable.jit_compile().is_ok() {
let mut jit_mem = data.mem;
let mut jit_context_object = TestContextObject::new(1 << 16);
let jit_mem_region = MemoryRegion::new_writable(&mut jit_mem, ebpf::MM_INPUT_START);
create_vm!(
Expand All @@ -84,33 +82,26 @@ fuzz_target!(|data: FuzzData| {
vec![jit_mem_region],
None
);

let (_interp_ins_count, interp_res) = interp_vm.execute_program(&executable, true);
let (_jit_ins_count, jit_res) = jit_vm.execute_program(&executable, false);
let interp_res_str = format!("{:?}", interp_res);
let jit_res_str = format!("{:?}", jit_res);
if interp_res_str != jit_res_str {
if format!("{:?}", interp_res) != format!("{:?}", jit_res) {
// spot check: there's a meaningless bug where ExceededMaxInstructions is different due to jump calculations
if interp_res_str.contains("ExceededMaxInstructions")
&& jit_res_str.contains("ExceededMaxInstructions")
{
return;
}
eprintln!("{:#?}", &data.prog);
dump_insns(&executable);
panic!("Expected {}, but got {}", interp_res_str, jit_res_str);
panic!("Expected {:?}, but got {:?}", interp_res, jit_res);
}
if interp_res.is_ok() {
// we know jit res must be ok if interp res is by this point
if interp_context_object.remaining != jit_context_object.remaining {
dump_insns(&executable);
panic!(
"Expected {} insts remaining, but got {}",
interp_context_object.remaining, jit_context_object.remaining
);
}
if interp_mem != jit_mem {
dump_insns(&executable);
panic!(
"Expected different memory. From interpreter: {:?}\nFrom JIT: {:?}",
interp_mem, jit_mem
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod insn_builder;
pub mod interpreter;
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
mod jit;
#[cfg(feature = "jit")]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
mod memory_management;
pub mod memory_region;
pub mod program;
Expand Down
4 changes: 2 additions & 2 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ macro_rules! test_interpreter_and_jit {
vm.context_object_pointer.clone(),
)
};
#[cfg(all(not(windows), target_arch = "x86_64"))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
{
#[allow(unused_mut)]
let compilation_result = $executable.jit_compile();
Expand Down Expand Up @@ -3270,7 +3270,7 @@ fn test_struct_func_pointer() {

// Fuzzy

#[cfg(all(not(windows), target_arch = "x86_64"))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
fn execute_generated_program(prog: &[u8]) -> bool {
let max_instruction_count = 1024;
let mem_size = 1024 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion tests/exercise_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ macro_rules! test_interpreter_and_jit {
mem,
)
};
#[cfg(all(not(windows), target_arch = "x86_64"))]
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
{
#[allow(unused_mut)]
$executable.jit_compile().unwrap();
Expand Down

0 comments on commit 0270240

Please sign in to comment.