diff --git a/benches/elf_loader.rs b/benches/elf_loader.rs index f0c94d7d7..323be403d 100644 --- a/benches/elf_loader.rs +++ b/benches/elf_loader.rs @@ -32,7 +32,7 @@ fn loader() -> Arc> { #[bench] fn bench_load_sbpfv1(bencher: &mut Bencher) { - let mut file = File::open("tests/elfs/syscall_reloc_64_32.so").unwrap(); + let mut file = File::open("tests/elfs/syscall_reloc_64_32_sbpfv1.so").unwrap(); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); let loader = loader(); diff --git a/benches/jit_compile.rs b/benches/jit_compile.rs index 9b6cc3a6d..48b224840 100644 --- a/benches/jit_compile.rs +++ b/benches/jit_compile.rs @@ -18,7 +18,7 @@ use test_utils::create_vm; #[bench] fn bench_init_vm(bencher: &mut Bencher) { - let mut file = File::open("tests/elfs/relative_call.so").unwrap(); + let mut file = File::open("tests/elfs/relative_call_sbpfv1.so").unwrap(); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); let executable = @@ -42,7 +42,7 @@ fn bench_init_vm(bencher: &mut Bencher) { #[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(); + let mut file = File::open("tests/elfs/relative_call_sbpfv1.so").unwrap(); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); let mut executable = diff --git a/src/elf.rs b/src/elf.rs index 9a16affa4..b306a3790 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -1182,7 +1182,7 @@ mod test { #[test] fn test_validate() { - let elf_bytes = std::fs::read("tests/elfs/relative_call.so").unwrap(); + let elf_bytes = std::fs::read("tests/elfs/relative_call_sbpfv1.so").unwrap(); let elf = Elf64::parse(&elf_bytes).unwrap(); let mut header = elf.file_header().clone(); @@ -1244,7 +1244,7 @@ mod test { #[test] fn test_load() { - let mut file = File::open("tests/elfs/relative_call.so").expect("file open failed"); + let mut file = File::open("tests/elfs/relative_call_sbpfv1.so").expect("file open failed"); let mut elf_bytes = Vec::new(); file.read_to_end(&mut elf_bytes) .expect("failed to read elf file"); @@ -1254,7 +1254,7 @@ mod test { #[test] fn test_load_unaligned() { let mut elf_bytes = - std::fs::read("tests/elfs/relative_call.so").expect("failed to read elf file"); + std::fs::read("tests/elfs/relative_call_sbpfv1.so").expect("failed to read elf file"); // The default allocator allocates aligned memory. Move the ELF slice to // elf_bytes.as_ptr() + 1 to make it unaligned and test unaligned // parsing. @@ -1266,14 +1266,14 @@ mod test { fn test_entrypoint() { let loader = loader(); - let mut file = File::open("tests/elfs/syscall_static.so").expect("file open failed"); + let mut file = File::open("tests/elfs/relative_call_sbpfv1.so").expect("file open failed"); let mut elf_bytes = Vec::new(); file.read_to_end(&mut elf_bytes) .expect("failed to read elf file"); let elf = ElfExecutable::load(&elf_bytes, loader.clone()).expect("validation failed"); let parsed_elf = Elf64::parse(&elf_bytes).unwrap(); let executable: &Executable = &elf; - assert_eq!(0, executable.get_entrypoint_instruction_offset()); + assert_eq!(4, executable.get_entrypoint_instruction_offset()); let write_header = |header: Elf64Ehdr| unsafe { let mut bytes = elf_bytes.clone(); @@ -1288,7 +1288,7 @@ mod test { let elf_bytes = write_header(header.clone()); let elf = ElfExecutable::load(&elf_bytes, loader.clone()).expect("validation failed"); let executable: &Executable = &elf; - assert_eq!(1, executable.get_entrypoint_instruction_offset()); + assert_eq!(5, executable.get_entrypoint_instruction_offset()); header.e_entry = 1; let elf_bytes = write_header(header.clone()); @@ -1315,7 +1315,7 @@ mod test { let elf_bytes = write_header(header); let elf = ElfExecutable::load(&elf_bytes, loader).expect("validation failed"); let executable: &Executable = &elf; - assert_eq!(0, executable.get_entrypoint_instruction_offset()); + assert_eq!(4, executable.get_entrypoint_instruction_offset()); } #[test] @@ -1878,7 +1878,7 @@ mod test { #[should_panic(expected = r#"validation failed: WritableSectionNotSupported(".data")"#)] fn test_writable_data_section() { let elf_bytes = - std::fs::read("tests/elfs/data_section.so").expect("failed to read elf file"); + std::fs::read("tests/elfs/data_section_sbpfv1.so").expect("failed to read elf file"); ElfExecutable::load(&elf_bytes, loader()).expect("validation failed"); } @@ -1886,7 +1886,7 @@ mod test { #[should_panic(expected = r#"validation failed: WritableSectionNotSupported(".bss")"#)] fn test_bss_section() { let elf_bytes = - std::fs::read("tests/elfs/bss_section.so").expect("failed to read elf file"); + std::fs::read("tests/elfs/bss_section_sbpfv1.so").expect("failed to read elf file"); ElfExecutable::load(&elf_bytes, loader()).expect("validation failed"); } @@ -1899,20 +1899,20 @@ mod test { } #[test] - #[should_panic(expected = "validation failed: RelativeJumpOutOfBounds(9)")] + #[should_panic(expected = "validation failed: RelativeJumpOutOfBounds(8)")] fn test_relative_call_oob_backward() { let mut elf_bytes = - std::fs::read("tests/elfs/relative_call.so").expect("failed to read elf file"); - LittleEndian::write_i32(&mut elf_bytes[0x104C..0x1050], -11i32); + std::fs::read("tests/elfs/relative_call_sbpfv1.so").expect("failed to read elf file"); + LittleEndian::write_i32(&mut elf_bytes[0x1044..0x1048], -11i32); ElfExecutable::load(&elf_bytes, loader()).expect("validation failed"); } #[test] - #[should_panic(expected = "validation failed: RelativeJumpOutOfBounds(12)")] + #[should_panic(expected = "validation failed: RelativeJumpOutOfBounds(11)")] fn test_relative_call_oob_forward() { let mut elf_bytes = - std::fs::read("tests/elfs/relative_call.so").expect("failed to read elf file"); - LittleEndian::write_i32(&mut elf_bytes[0x1064..0x1068], 5); + std::fs::read("tests/elfs/relative_call_sbpfv1.so").expect("failed to read elf file"); + LittleEndian::write_i32(&mut elf_bytes[0x105C..0x1060], 5); ElfExecutable::load(&elf_bytes, loader()).expect("validation failed"); } diff --git a/tests/elfs/bss_section_sbpfv1.so b/tests/elfs/bss_section_sbpfv1.so new file mode 100755 index 000000000..0eec1ea1c Binary files /dev/null and b/tests/elfs/bss_section_sbpfv1.so differ diff --git a/tests/elfs/data_section.so b/tests/elfs/data_section_sbpfv1.so similarity index 98% rename from tests/elfs/data_section.so rename to tests/elfs/data_section_sbpfv1.so index 8c85d2403..3a633107d 100755 Binary files a/tests/elfs/data_section.so and b/tests/elfs/data_section_sbpfv1.so differ diff --git a/tests/elfs/elfs.sh b/tests/elfs/elfs.sh index c6158f75f..5f02e69ba 100755 --- a/tests/elfs/elfs.sh +++ b/tests/elfs/elfs.sh @@ -11,17 +11,17 @@ LD_COMMON="$TOOLCHAIN/llvm/bin/ld.lld -z notext -shared --Bdynamic -entry entryp LD="$LD_COMMON --section-start=.text=0x100000000" LD_V1=$LD_COMMON -$RC -o relative_call.o relative_call.rs -$LD -o relative_call.so relative_call.o +$RC_V1 -o relative_call.o relative_call.rs +$LD_V1 -o relative_call_sbpfv1.so relative_call.o $RC_V1 -o syscall_reloc_64_32.o syscall_reloc_64_32.rs -$LD_V1 -o syscall_reloc_64_32.so syscall_reloc_64_32.o +$LD_V1 -o syscall_reloc_64_32_sbpfv1.so syscall_reloc_64_32.o -$RC -o bss_section.o bss_section.rs -$LD -o bss_section.so bss_section.o +$RC_V1 -o bss_section.o bss_section.rs +$LD_V1 -o bss_section_sbpfv1.so bss_section.o -$RC -o data_section.o data_section.rs -$LD -o data_section.so data_section.o +$RC_V1 -o data_section.o data_section.rs +$LD_V1 -o data_section_sbpfv1.so data_section.o $RC_V1 -o rodata_section.o rodata_section.rs $LD_V1 -o rodata_section_sbpfv1.so rodata_section.o @@ -29,8 +29,8 @@ $LD_V1 -o rodata_section_sbpfv1.so rodata_section.o $RC -o program_headers_overflow.o rodata_section.rs "$TOOLCHAIN"/llvm/bin/ld.lld -z notext -shared --Bdynamic -entry entrypoint --script program_headers_overflow.ld --noinhibit-exec -o program_headers_overflow.so program_headers_overflow.o -$RC -o struct_func_pointer.o struct_func_pointer.rs -$LD -o struct_func_pointer.so struct_func_pointer.o +$RC_V1 -o struct_func_pointer.o struct_func_pointer.rs +$LD_V1 -o struct_func_pointer_sbpfv1.so struct_func_pointer.o $RC_V1 -o reloc_64_64.o reloc_64_64.rs $LD_V1 -o reloc_64_64_sbpfv1.so reloc_64_64.o @@ -38,8 +38,8 @@ $LD_V1 -o reloc_64_64_sbpfv1.so reloc_64_64.o $RC_V1 -o reloc_64_relative.o reloc_64_relative.rs $LD_V1 -o reloc_64_relative_sbpfv1.so reloc_64_relative.o -# $RC_V1 -o reloc_64_relative_data.o reloc_64_relative_data.rs -# $LD_V1 -o reloc_64_relative_data_sbpfv1.so reloc_64_relative_data.o +$RC_V1 -o reloc_64_relative_data.o reloc_64_relative_data.rs +$LD_V1 -o reloc_64_relative_data_sbpfv1.so reloc_64_relative_data.o # $RC_V1 -o callx_unaligned.o callx_unaligned.rs # $LD_V1 -o callx_unaligned.so callx_unaligned.o diff --git a/tests/elfs/relative_call.so b/tests/elfs/relative_call.so deleted file mode 100755 index 9f24730e2..000000000 Binary files a/tests/elfs/relative_call.so and /dev/null differ diff --git a/tests/elfs/bss_section.so b/tests/elfs/relative_call_sbpfv1.so old mode 100755 new mode 100644 similarity index 71% rename from tests/elfs/bss_section.so rename to tests/elfs/relative_call_sbpfv1.so index 48c14f7c1..0c56eeb81 Binary files a/tests/elfs/bss_section.so and b/tests/elfs/relative_call_sbpfv1.so differ diff --git a/tests/elfs/struct_func_pointer.so b/tests/elfs/struct_func_pointer_sbpfv1.so similarity index 97% rename from tests/elfs/struct_func_pointer.so rename to tests/elfs/struct_func_pointer_sbpfv1.so index 333e12409..acd9bfdaf 100755 Binary files a/tests/elfs/struct_func_pointer.so and b/tests/elfs/struct_func_pointer_sbpfv1.so differ diff --git a/tests/elfs/syscall_reloc_64_32.so b/tests/elfs/syscall_reloc_64_32_sbpfv1.so similarity index 100% rename from tests/elfs/syscall_reloc_64_32.so rename to tests/elfs/syscall_reloc_64_32_sbpfv1.so diff --git a/tests/execution.rs b/tests/execution.rs index db7fa6887..00259f110 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -2315,11 +2315,16 @@ fn test_err_mem_access_out_of_bound() { #[test] fn test_relative_call() { + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; test_interpreter_and_jit_elf!( - "tests/elfs/relative_call.so", + "tests/elfs/relative_call_sbpfv1.so", + config, [1], (), - TestContextObject::new(18), + TestContextObject::new(16), ProgramResult::Ok(3), ); } @@ -2994,7 +2999,6 @@ fn test_err_call_unresolved() { enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, ..Config::default() }; - test_interpreter_and_jit_asm!( " mov r1, 1 @@ -3015,8 +3019,13 @@ fn test_err_call_unresolved() { #[test] fn test_syscall_reloc_64_32() { + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; test_interpreter_and_jit_elf!( - "tests/elfs/syscall_reloc_64_32.so", + "tests/elfs/syscall_reloc_64_32_sbpfv1.so", + config, [], ( "log" => syscalls::SyscallString::vm, @@ -3030,12 +3039,13 @@ fn test_syscall_reloc_64_32() { fn test_err_unresolved_syscall_reloc_64_32() { let loader = BuiltinProgram::new_loader( Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, reject_broken_elfs: true, ..Config::default() }, FunctionRegistry::default(), ); - let mut file = File::open("tests/elfs/syscall_reloc_64_32.so").unwrap(); + let mut file = File::open("tests/elfs/syscall_reloc_64_32_sbpfv1.so").unwrap(); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); assert_error!( @@ -3064,8 +3074,13 @@ fn test_reloc_64_relative_sbpfv1() { // returns the address of the first .rodata byte. // [ 1] .text PROGBITS 0000000000000120 000120 000018 00 AX 0 0 8 // [ 2] .rodata PROGBITS 0000000000000138 000138 00000a 01 AMS 0 0 1 + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; test_interpreter_and_jit_elf!( "tests/elfs/reloc_64_relative_sbpfv1.so", + config, [], (), TestContextObject::new(2), @@ -3082,8 +3097,13 @@ fn test_reloc_64_relative_data_sbfv1() { // // 00000000000001f8 : // 63: 08 01 00 00 00 00 00 00 + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; test_interpreter_and_jit_elf!( "tests/elfs/reloc_64_relative_data_sbpfv1.so", + config, [], (), TestContextObject::new(3), @@ -3106,8 +3126,13 @@ fn test_reloc_64_relative_data_sbpfv1() { // // 00000000000001f8 : // 63: 00 00 00 00 08 01 00 00 + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; test_interpreter_and_jit_elf!( "tests/elfs/reloc_64_relative_data_sbpfv1.so", + config, [], (), TestContextObject::new(3), @@ -3118,6 +3143,7 @@ fn test_reloc_64_relative_data_sbpfv1() { #[test] fn test_load_elf_rodata_sbpfv1() { let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, optimize_rodata: false, ..Config::default() }; @@ -3136,11 +3162,16 @@ fn test_struct_func_pointer() { // This tests checks that a struct field adjacent to another field // which is a relocatable function pointer is not overwritten when // the function pointer is relocated at load time. + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; test_interpreter_and_jit_elf!( - "tests/elfs/struct_func_pointer.so", + "tests/elfs/struct_func_pointer_sbpfv1.so", + config, [], (), - TestContextObject::new(3), + TestContextObject::new(2), ProgramResult::Ok(0x102030405060708), ); }