diff --git a/benches/elf_loader.rs b/benches/elf_loader.rs index ea621400..323be403 100644 --- a/benches/elf_loader.rs +++ b/benches/elf_loader.rs @@ -32,16 +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 elf = Vec::new(); - file.read_to_end(&mut elf).unwrap(); - let loader = loader(); - bencher.iter(|| Executable::::from_elf(&elf, loader.clone()).unwrap()); -} - -#[bench] -fn bench_load_sbpfv2(bencher: &mut Bencher) { - let mut file = File::open("tests/elfs/syscall_static.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 9b6cc3a6..48b22484 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/benches/vm_execution.rs b/benches/vm_execution.rs index e3c6ebc1..4404c927 100644 --- a/benches/vm_execution.rs +++ b/benches/vm_execution.rs @@ -25,7 +25,7 @@ use test_utils::create_vm; #[bench] fn bench_init_interpreter_start(bencher: &mut Bencher) { - let mut file = File::open("tests/elfs/rodata_section.so").unwrap(); + let mut file = File::open("tests/elfs/rodata_section_sbpfv1.so").unwrap(); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); let executable = @@ -51,7 +51,7 @@ fn bench_init_interpreter_start(bencher: &mut Bencher) { #[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(); + let mut file = File::open("tests/elfs/rodata_section_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 9a16affa..375c8040 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,23 +1899,39 @@ 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"); } + #[test] + #[should_panic(expected = "validation failed: UnresolvedSymbol(\"log\", 39, 312)")] + 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 elf_bytes = std::fs::read("tests/elfs/syscall_reloc_64_32_sbpfv1.so") + .expect("failed to read elf file"); + ElfExecutable::load(&elf_bytes, Arc::new(loader)).expect("validation failed"); + } + #[test] fn test_long_section_name() { let elf_bytes = std::fs::read("tests/elfs/long_section_name.so").unwrap(); diff --git a/src/elf_parser/mod.rs b/src/elf_parser/mod.rs index d81e8879..12e13766 100644 --- a/src/elf_parser/mod.rs +++ b/src/elf_parser/mod.rs @@ -552,7 +552,7 @@ impl<'a> Elf64<'a> { } } -impl<'a> fmt::Debug for Elf64<'a> { +impl fmt::Debug for Elf64<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "{:#X?}", self.file_header)?; for program_header in self.program_header_table.iter() { diff --git a/src/insn_builder.rs b/src/insn_builder.rs index 179276f9..411e9b88 100644 --- a/src/insn_builder.rs +++ b/src/insn_builder.rs @@ -80,7 +80,7 @@ pub trait IntoBytes { } /// General implementation of `IntoBytes` for `Instruction` -impl<'i, I: Instruction> IntoBytes for &'i I { +impl IntoBytes for &I { type Bytes = Vec; /// transform immutable reference of `Instruction` into `Vec` with size of 8 @@ -310,7 +310,7 @@ impl<'i> Move<'i> { } } -impl<'i> Instruction for Move<'i> { +impl Instruction for Move<'_> { fn opt_code_byte(&self) -> u8 { let op_bits = self.op_bits as u8; let src_bit = self.src_bit as u8; @@ -386,7 +386,7 @@ impl<'i> SwapBytes<'i> { } } -impl<'i> Instruction for SwapBytes<'i> { +impl Instruction for SwapBytes<'_> { fn opt_code_byte(&self) -> u8 { self.endian as u8 } @@ -431,7 +431,7 @@ impl<'i> Load<'i> { } } -impl<'i> Instruction for Load<'i> { +impl Instruction for Load<'_> { fn opt_code_byte(&self) -> u8 { let size = self.mem_size as u8; let addressing = self.addressing as u8; @@ -464,7 +464,7 @@ impl<'i> Store<'i> { } } -impl<'i> Instruction for Store<'i> { +impl Instruction for Store<'_> { fn opt_code_byte(&self) -> u8 { let size = self.mem_size as u8; BPF_MEM | BPF_ST | size | self.source @@ -521,7 +521,7 @@ impl<'i> Jump<'i> { } } -impl<'i> Instruction for Jump<'i> { +impl Instruction for Jump<'_> { fn opt_code_byte(&self) -> u8 { let cmp: u8 = self.cond as u8; let src_bit = self.src_bit as u8; @@ -585,7 +585,7 @@ impl<'i> FunctionCall<'i> { } } -impl<'i> Instruction for FunctionCall<'i> { +impl Instruction for FunctionCall<'_> { fn opt_code_byte(&self) -> u8 { BPF_CALL | BPF_JMP } @@ -614,7 +614,7 @@ impl<'i> Exit<'i> { } } -impl<'i> Instruction for Exit<'i> { +impl Instruction for Exit<'_> { fn opt_code_byte(&self) -> u8 { BPF_EXIT | BPF_JMP } diff --git a/src/memory_region.rs b/src/memory_region.rs index e8648557..6b03216b 100644 --- a/src/memory_region.rs +++ b/src/memory_region.rs @@ -195,7 +195,7 @@ pub struct UnalignedMemoryMapping<'a> { cow_cb: Option, } -impl<'a> fmt::Debug for UnalignedMemoryMapping<'a> { +impl fmt::Debug for UnalignedMemoryMapping<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("UnalignedMemoryMapping") .field("regions", &self.regions) @@ -559,7 +559,7 @@ pub struct AlignedMemoryMapping<'a> { cow_cb: Option, } -impl<'a> fmt::Debug for AlignedMemoryMapping<'a> { +impl fmt::Debug for AlignedMemoryMapping<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("AlignedMemoryMapping") .field("regions", &self.regions) diff --git a/tests/elfs/bss_section.so b/tests/elfs/bss_section.so deleted file mode 100755 index 48c14f7c..00000000 Binary files a/tests/elfs/bss_section.so and /dev/null differ diff --git a/tests/elfs/bss_section_sbpfv1.so b/tests/elfs/bss_section_sbpfv1.so new file mode 100755 index 00000000..0eec1ea1 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 8c85d240..3a633107 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 419cc427..5f02e69b 100755 --- a/tests/elfs/elfs.sh +++ b/tests/elfs/elfs.sh @@ -11,50 +11,35 @@ 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 syscall_static.o syscall_static.rs -$LD -o syscall_static.so syscall_static.o +$RC_V1 -o bss_section.o bss_section.rs +$LD_V1 -o bss_section_sbpfv1.so bss_section.o -$RC -o bss_section.o bss_section.rs -$LD -o bss_section.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 -$RC -o rodata_section.o rodata_section.rs -$LD -o rodata_section.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 -o reloc_64_64.o reloc_64_64.rs -$LD -o reloc_64_64.so reloc_64_64.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 -$RC -o reloc_64_relative.o reloc_64_relative.rs -$LD -o reloc_64_relative.so reloc_64_relative.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 -o reloc_64_relative_data.o reloc_64_relative_data.rs -# $LD -o reloc_64_relative_data.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 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 9f24730e..00000000 Binary files a/tests/elfs/relative_call.so and /dev/null differ diff --git a/tests/elfs/syscall_static.so b/tests/elfs/relative_call_sbpfv1.so old mode 100755 new mode 100644 similarity index 72% rename from tests/elfs/syscall_static.so rename to tests/elfs/relative_call_sbpfv1.so index 0667af4f..0c56eeb8 Binary files a/tests/elfs/syscall_static.so and b/tests/elfs/relative_call_sbpfv1.so differ diff --git a/tests/elfs/reloc_64_64.so b/tests/elfs/reloc_64_64.so deleted file mode 100755 index 95e03f54..00000000 Binary files a/tests/elfs/reloc_64_64.so and /dev/null differ diff --git a/tests/elfs/reloc_64_relative.so b/tests/elfs/reloc_64_relative.so deleted file mode 100755 index 0ebd7ccc..00000000 Binary files a/tests/elfs/reloc_64_relative.so and /dev/null differ diff --git a/tests/elfs/reloc_64_relative_data.so b/tests/elfs/reloc_64_relative_data.so deleted file mode 100755 index fe2e0db3..00000000 Binary files a/tests/elfs/reloc_64_relative_data.so and /dev/null differ diff --git a/tests/elfs/rodata_section.so b/tests/elfs/rodata_section.so deleted file mode 100755 index 8868f7e6..00000000 Binary files a/tests/elfs/rodata_section.so and /dev/null 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 333e1240..acd9bfda 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 59c769dc..3eea021a 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, @@ -3026,55 +3035,6 @@ fn test_syscall_reloc_64_32() { ); } -#[test] -fn test_syscall_static() { - test_interpreter_and_jit_elf!( - "tests/elfs/syscall_static.so", - [], - ( - "log" => syscalls::SyscallString::vm, - ), - TestContextObject::new(6), - ProgramResult::Ok(0), - ); -} - -#[test] -fn test_err_unresolved_syscall_reloc_64_32() { - let loader = BuiltinProgram::new_loader( - Config { - reject_broken_elfs: true, - ..Config::default() - }, - FunctionRegistry::default(), - ); - let mut file = File::open("tests/elfs/syscall_reloc_64_32.so").unwrap(); - let mut elf = Vec::new(); - file.read_to_end(&mut elf).unwrap(); - assert_error!( - Executable::::from_elf(&elf, Arc::new(loader)), - "UnresolvedSymbol(\"log\", 39, 312)" - ); -} - -#[test] -fn test_err_unresolved_syscall_static() { - let config = Config { - enable_instruction_tracing: true, - ..Config::default() - }; - // This case only works if we skip verification. - test_interpreter_and_jit_elf!( - false, - "tests/elfs/syscall_static.so", - config, - [], - (), - TestContextObject::new(4), - ProgramResult::Err(EbpfError::UnsupportedInstruction), - ); -} - #[test] fn test_reloc_64_64_sbpfv1() { // Tests the correctness of R_BPF_64_64 relocations. The program returns the @@ -3089,28 +3049,19 @@ fn test_reloc_64_64_sbpfv1() { ); } -#[test] -fn test_reloc_64_64() { - // Same as test_reloc_64_64, but with .text already alinged to - // MM_PROGRAM_START by the linker - // [ 1] .text PROGBITS 0000000100000000 001000 000018 00 AX 0 0 8 - test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_64.so", - [], - (), - TestContextObject::new(3), - ProgramResult::Ok(ebpf::MM_PROGRAM_START), - ); -} - #[test] fn test_reloc_64_relative_sbpfv1() { // Tests the correctness of R_BPF_64_RELATIVE relocations. The program // 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), @@ -3118,21 +3069,6 @@ fn test_reloc_64_relative_sbpfv1() { ); } -#[test] -fn test_reloc_64_relative() { - // Same as test_reloc_64_relative, but with .text placed already within - // MM_PROGRAM_START by the linker - // [ 1] .text PROGBITS 0000000100000000 001000 000018 00 AX 0 0 8 - // [ 2] .rodata PROGBITS 0000000100000018 001018 00000b 01 AMS 0 0 1 - test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_relative.so", - [], - (), - TestContextObject::new(3), - ProgramResult::Ok(ebpf::MM_PROGRAM_START + 0x18), - ); -} - #[test] fn test_reloc_64_relative_data_sbfv1() { // Tests the correctness of R_BPF_64_RELATIVE relocations in sections other @@ -3142,8 +3078,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), @@ -3151,24 +3092,6 @@ fn test_reloc_64_relative_data_sbfv1() { ); } -#[test] -fn test_reloc_64_relative_data() { - // Same as test_reloc_64_relative_data, but with rodata already placed - // within MM_PROGRAM_START by the linker - // [ 1] .text PROGBITS 0000000100000000 001000 000020 00 AX 0 0 8 - // [ 2] .rodata PROGBITS 0000000100000020 001020 000019 01 AMS 0 0 1 - // - // 0000000100000110 : - // 536870946: 20 00 00 00 01 00 00 00 - test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_relative_data.so", - [], - (), - TestContextObject::new(4), - ProgramResult::Ok(ebpf::MM_PROGRAM_START + 0x20), - ); -} - #[test] fn test_reloc_64_relative_data_sbpfv1() { // Before https://github.com/solana-labs/llvm-project/pull/35, we used to @@ -3184,8 +3107,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), @@ -3194,34 +3122,38 @@ fn test_reloc_64_relative_data_sbpfv1() { } #[test] -fn test_load_elf_rodata() { +fn test_load_elf_rodata_sbpfv1() { let config = Config { - optimize_rodata: true, + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + optimize_rodata: false, ..Config::default() }; test_interpreter_and_jit_elf!( - "tests/elfs/rodata_section.so", + "tests/elfs/rodata_section_sbpfv1.so", config, [], (), - TestContextObject::new(4), + TestContextObject::new(3), ProgramResult::Ok(42), ); } #[test] -fn test_load_elf_rodata_sbpfv1() { +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 { - optimize_rodata: false, + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, ..Config::default() }; test_interpreter_and_jit_elf!( - "tests/elfs/rodata_section_sbpfv1.so", + "tests/elfs/struct_func_pointer_sbpfv1.so", config, [], (), - TestContextObject::new(3), - ProgramResult::Ok(42), + TestContextObject::new(2), + ProgramResult::Ok(0x102030405060708), ); } @@ -3433,20 +3365,6 @@ fn test_tcp_sack_nomatch() { ); } -#[test] -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. - test_interpreter_and_jit_elf!( - "tests/elfs/struct_func_pointer.so", - [], - (), - TestContextObject::new(3), - ProgramResult::Ok(0x102030405060708), - ); -} - // Fuzzy #[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]