From c06f051ef76f195cced72bacff9d411391d76e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 7 Oct 2024 20:54:23 +0200 Subject: [PATCH] Cleanup - test ELFs (#604) * Makes cargo fmt happy. * Remove SBPF-v2 only test ELFs. * Move test_struct_func_pointer. * Explicitly marks SBPF-v1 ELF tests as such. * Moves test_err_unresolved_syscall_reloc_64_32. --- benches/elf_loader.rs | 11 +- benches/jit_compile.rs | 4 +- benches/vm_execution.rs | 4 +- src/elf.rs | 46 +++-- src/elf_parser/mod.rs | 2 +- src/insn_builder.rs | 16 +- src/memory_region.rs | 4 +- tests/elfs/bss_section.so | Bin 5424 -> 0 bytes tests/elfs/bss_section_sbpfv1.so | Bin 0 -> 2128 bytes ...data_section.so => data_section_sbpfv1.so} | Bin 5432 -> 5432 bytes tests/elfs/elfs.sh | 37 ++-- tests/elfs/relative_call.so | Bin 5384 -> 0 bytes ...call_static.so => relative_call_sbpfv1.so} | Bin 5368 -> 5376 bytes tests/elfs/reloc_64_64.so | Bin 5248 -> 0 bytes tests/elfs/reloc_64_relative.so | Bin 5424 -> 0 bytes tests/elfs/reloc_64_relative_data.so | Bin 5784 -> 0 bytes tests/elfs/rodata_section.so | Bin 5424 -> 0 bytes ...inter.so => struct_func_pointer_sbpfv1.so} | Bin 5112 -> 5112 bytes ...64_32.so => syscall_reloc_64_32_sbpfv1.so} | Bin tests/execution.rs | 164 +++++------------- 20 files changed, 99 insertions(+), 189 deletions(-) delete mode 100755 tests/elfs/bss_section.so create mode 100755 tests/elfs/bss_section_sbpfv1.so rename tests/elfs/{data_section.so => data_section_sbpfv1.so} (98%) delete mode 100755 tests/elfs/relative_call.so rename tests/elfs/{syscall_static.so => relative_call_sbpfv1.so} (72%) mode change 100755 => 100644 delete mode 100755 tests/elfs/reloc_64_64.so delete mode 100755 tests/elfs/reloc_64_relative.so delete mode 100755 tests/elfs/reloc_64_relative_data.so delete mode 100755 tests/elfs/rodata_section.so rename tests/elfs/{struct_func_pointer.so => struct_func_pointer_sbpfv1.so} (97%) rename tests/elfs/{syscall_reloc_64_32.so => syscall_reloc_64_32_sbpfv1.so} (100%) diff --git a/benches/elf_loader.rs b/benches/elf_loader.rs index ea6214001..323be403d 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 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/benches/vm_execution.rs b/benches/vm_execution.rs index e3c6ebc11..4404c9271 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 9a16affa4..375c80404 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 d81e8879f..12e13766e 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 179276f93..411e9b88e 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 e86485572..6b03216b2 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 48c14f7c1099d76eb5d8d4197248280483bbb388..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5424 zcmeHLO>0v@6rCj1TI(XMAYF(&mkJIqG$D-}TWrKaEOjH+O~`wFwLz1VmnSs1@K^Xh zx^wGK$zO2mCf+l1&m)9x#HDj#-nnz{x$|+D1ZKW+Zci;o!bM10tL59Rn(>7y>zI*iMCfY;Js z#5=wlzCnSYKu{nk5EKXs1OdoQ&;mC+Re^^W<6j@r#X3|HE;kv6SC^ zchGCJFVbe(8lN!#Hg$9 z8M7`9YHJz*AN71sy4E<)H|uqHcdl_p@eT!>OG7>1u{b~K5obNmGZ1sLp69x*KO~-O zp*VAUV@EKOwjqu6kr2R%w4Uqa{y0D5PlSsY^E`jC){`$3XRCcHQOw7EdY1IHp1*g- z!G#gq;&bgTp`X`Uf2Do=&Y>aar+zOa#4wm9Fg2oLQZ;hpM7Fytt!{TocOmqoM-E=S z_fOzrxNjmbg`1DZ+oT0?yca`nYf+>V>Z$BNae*CaIE+y15X0dt{%<2fD zwA0;;TTx2eZkUnSU)GWM88HUNK9hHO?#&u#>Yq`>wRorg^Ev%xoddod^<%MDG#+_{I!7F^-ilraouy*EzFeGlEZee+x0-3X znJkq`8?Cgt)v&y{T}tB6joi7=Z6u{I+-}cpcH&ooms%WC^s9ckycjrs!?zcLitSfz zCvd!Kd7;v9=BpLYU3}>~)!;TZJq4xgBlNYOcV+b*I!m}m@Ly!(wEmIaIIVxk^1D&e zZIiVTZCOn>X_Ed6pLWRV1fj%`l?FR$7VfrN9$AefA*n%|yN4`ZB6S;#O%@r;AaUG! z!X;_Nk>ydY)z+8Sp51@?Oy!STy1_$)u#4lRBGw91h&Er4=@x9Pv|0?^1gC6f(PYLLBnUi;4iF=Ha ze?Cv>BM22y2jFAoQM$ literal 0 HcmV?d00001 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 8c85d2403758761667d493358dc4a8e16d4b5710..3a633107ddede29fa5876404b4fff39c25a09c82 100755 GIT binary patch delta 12 Tcmdm?wL@!y0VBgkLv~RB9CQPO delta 12 Tcmdm?wL@!y0i(i3Lv~RB9TWqk diff --git a/tests/elfs/elfs.sh b/tests/elfs/elfs.sh index 419cc4277..5f02e69ba 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 9f24730e209597b7bb901191dc47dca8bd3a6887..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5384 zcmeHLzi-n}5PnSx=9fe%5@JG@m>96^rb!HRD560^3Kb(|i5$nFp|KMj2Q})z#EP;o zFv35Ql|O@jfrT~P_ugFzrbtMPypvwOdw2KUJzx9=-`iIEab;~yiBy%NcP<%V-K7Qj zvT4vI*j1sb((gs(=$LbGZQ#dCfbD?ofbD?ofbD?ofbD?ofbD?ofbGD4-GSMLd3=We-_a-fBV4Hu z+!g0CDa+;Z^$lYxWBN#2EP{8zcY*l!uL znGKMRZ+$JqMQR)ea?^m)vj@_B_FrQA6-GWb@BSW8Ym+LvgwUVU(voCFJ{yk)S)tm4 z>?q0ayY2R#8`M4D+m@i;5job?H{H8cFP^ueE0{ViI}g}?ObD(#???D6mD70#wvhL< z&OEPIB*%sFdb2D_2eDQrv(#XbD=!|UDLs?&$XY~Q!ox|C8_l4~lVMa0-Xxtk8V`_n8g2BWMqDWdqOlPCS4c^HKCFziKJ{d%)etA$DH zEb7)z>NF)%t-0Os{a)nvlX@cxqLy0ee`oJt|KZaok8}h6@drJ|I(^@GFLS4PDSvsc zg!=<-mE#bPd@`pRvt7@;NEbf8{<;j_ZQKe`Paq3sLw{a;2qMX_G;)e=Fi!PbK}mI&mWLYddHy}zB0f3 VCre$4eeehVZJt|xmO#cb{|AeCfu;Ze 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 0667af4f1144c07c987ca60f13687924b798b0ae..0c56eeb818b63a8d0e958e140d2f2d0a44b3dae2 GIT binary patch literal 5376 zcmeHLJ8u&~5Z*Wj^O6FIgs9L}NJwzHvq|m@jS(>d$wZ=r#@c%rAFaU`(kfFia) zQ9i93#I_|uQHA!bsOgwf=)8!H5uOckMm|Q4d;CQuRT}$K_?x^66gdq#E3I>l3L}0b zoAC_wEm#ID1C{~HfMvikU>UFsSOzQumI2FvW#E5cU`qGl8f*sd>-%(he@B~paoHIA z&&2|*`Jw68FmAC}yn*~9z&Yj3BQuVEbn!fM$N1N%9{aBvH@qhp!8IO}S}yf|A8@Vfuwn-g?FXP*(p(kOy-}7c(aG}Nw7BhbI@^vP zy1pB5(9ei-RK+*VS$XstbSk=nspHU~B!3?eb9ujqI9|cm3$tHsK=U5-#Pzx=eWiq( zOmjKRVr`74LxZXiZaf+eVNb#ZuaXg9f2;~)85Bi2kScqbc4IjhxU%5|QMj4NpdLnB zUU)NpHgP@CeY)c}eu(tL-XxDzHp;tWCF9+0k@ozc-{|#Z6&}Hz9n=gEP?!Quir?X8yu8Z^ed>~?N&OZPf>pPdA0pb6` z^k{F~0dzodUakYCmK&76!45*r4cLs=!RFfK&=%#tB`2;M|J~*F``{~cN8#c#%E1@d@a>q z)hD*NSb4+|=gNbK*Sr|sp#q@-p#q@-p#q@-p#q@-p#q@-p#q@-p#uL!1-|GIJkXQ; zP{cfZs)I6S?oays`uhFoR1x&qgB%vcb+C6$=6rt3P+ulT;IOV4?fYF1_Gc)VBDX+6rK{f*&ao<52n zWbZyk136cTy`49&9>09?l)LJKQuQz`;Ph7Opm@qkK$el#J=Ud6!(vK*s+G#IImRxV*GE>30sK( diff --git a/tests/elfs/reloc_64_64.so b/tests/elfs/reloc_64_64.so deleted file mode 100755 index 95e03f5468190a7c219a10d1b0cc34b0884896a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5248 zcmeHLyG|QH6usEILQ?RMB8n*54yDLwjZBEBK$u98HW6(q9*z|(u#MImDX!or==~8C zd_+EkmMZSTJu~-gtQ8GPJ6E1LckW{zXUE0dtAp%QZDvL&by+A!uAMbUDuNf%bYr}j?+90n2$ZNyrLf9Mne{}&r==6(xbUEnu3qPbE zk!V@Bf8NP=k}PW_jV+hDW*PRRf}B}-_*->uz)-9Cx<}YWhQ}1l%N3npg}Cpd z{z*Uo z_K%+~m8s(&wZ47b`|^1|Z0tXK@`suX#h-hsK0`aOT8~*!8*=M#s+9E{%O87ds1-qF zKJOV2cMEkP2=5!~N@+0rS`+rgeBMJK)@DBMVpEBZXQIv{SU&b1i>Of3J{jMyX2$@O{u9kW|l3D=gNm6o7z UU7A~}@Y~S_{B8Nwb5-*n0eve>s{jB1 diff --git a/tests/elfs/reloc_64_relative.so b/tests/elfs/reloc_64_relative.so deleted file mode 100755 index 0ebd7ccc662179f98896601362798131f9fa3809..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5424 zcmeHL&59F25bpfwX59sK7bGVMo^o+WVzOrU6m=DZQ9KCZDRyQW4VsxHJ1(1(PvLub z@Zh85H9QGkVtv!~#Wm~;#*eC%iXqj^)_Mi)NDU`@UT6s$ znW3r6ykoWvFqdGuhRGA32HsR1IdQPnVOKxci3h(T14O>*w^YBSV1Oro1}7nM`c*}D zSw>s^+9Jb`{FBHa@`hiAIaDB2AXFe!AXFe!AXFe!AXFe!AXFe!AXMPLsK9601@7M8 zWZ*vhQ3l9m#e8v+PqV_WZ+ceV*&$xnbyJ++r|kh=x6QuV^}21ouU0u!z=CiW2l3v% zO_6- z_NN)Xb@O$#X}=|kim8@yf#JSh09dW9`w>`zVi|i{wO{g$3U^+ZXr8CGuqH|unVn6O zQaD}AJTK+~aPMF=QIgMQvPlz(xv&%AZ%&K3mpnIu&6Dv#e=LG6re`i1TIbxr+S|$N z_ff}0vCZ-7exU6-c4!)|ZVO}a_y28Y9*o%B;dUMT1I_~p}kPaZ!g_w%n4 zYJkD-2hYQrAKv_012$0kY%iAcRhbdHraJbI*jHlz zX#M>vj^_aJ@U1icQe?znKdU1$2>#GBf9|U#I>e?w&qqTKB+rLHO4`gH`EJXgKhJMd z{h23vb0Eg2zAHLBlX(IIYO6obz1RM%AM-d817i~dK2ra4RpLD$2gc|A?~9JLS7^z; bsQ>eeN|70tYMiIv`S0ov>=l8^H~oJA4PIr@ diff --git a/tests/elfs/reloc_64_relative_data.so b/tests/elfs/reloc_64_relative_data.so deleted file mode 100755 index fe2e0db33786bd587bb9e869050f45b78320a29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5784 zcmeHL&1w@-7`;uR_1{)OqKM2wK?H}Yt%w^Vwk3twg&T2|jxjVrlhkCC1O&VA6$F>r z_yXbsWbejD&_{6L4=x(dnfXpghZYwuy&v2;-`}}+?l*S^=6k(TSkt3w_G0A6YiK}&H;wzcu7UG5d-rHmB-jYjKFw|E1!57gCZ0!2OoK54LX7C<5Of;kF?^M*qN89!xqU})_G{noqR<8g-}yN%=@ zpLWssM`=KcDWp9I=o=P4Vt%cA#%#g&opk=b6yvT7H`_15M$~J7hg76FGi#kz3l(-D z(&Okcu+fXVsg|PK_XKC3Om+Fu`rZ3$_q4TtLe`Oky(&rae5U$c@)M_@FYQ?j=3l1) z2{34@Uv?Jyv?O!GAv|e1&j+Q1!C1-G&#srX&m))jE`Hhg>brf0P0{|ux9J_9Ki^rN zON!p(qP?J;k3v50OMJcGSK;H@;%^{{c^k&pdk$A3j7`fDj34->h_Cm)Z^Vn1ob)cC zYkkde2g+d#@rSnl(D;ERX8GDb_s5v{BjbE&Gr^pLkM5>&o4PqO&6(@vHG~Ogo`x`F{XJVte)g diff --git a/tests/elfs/rodata_section.so b/tests/elfs/rodata_section.so deleted file mode 100755 index 8868f7e63d7e85b0963ee207dc796f3c0b2fdd51..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5424 zcmeHL&ubGw6rTLhrnaEAAUWwAgW!_IrVTx%wH1VI@gSmJ!e+DDpxKno3eBm1h5v^K z5B@3rH#`Ym;`?^rx5OnE@g&TH+3(Gp@4Ywkm|2*)J`JANYc)e@n2oXr>p%xCcM8P{ z3{2lN<-27z4LG+jbPu0G7!7FEMkEhoO=(vBFit+OB@IHX`rWACjc~vxzJ!wqk$!ct z-Imr-zmDkeBYqVfLM-zZX7_a!a20SBa20SBa20SBa20SBa20SBa20SB_^&JQO)kM! zR`630_u+-!kH6@u9xFan#GM^-zW~!#KYbqHb=&OfxP~*omdhDT$N|A!9Kw71R?#(W z#r#b{^p?iIqxNmZ2a10S$iJhrfNmKePO@}yIh!OIEjf$t0Kp{r7^jCe2u`fu^Sa(% zNn5KRcGLV=RtF!6p=RoNUT_%y4T$wd`5u8Td6pJhfu;yHoX1f%nI&G>?~SAP`}<_xNBw9tj>mo+`=@55p2L&3=SOERp5+Vr#}8_T#{GkE z=yT&)=qtkd(zGE8_;?S3SZU~6-KbT5wSQN*$lZ_z=}3b=-<9}&RPJApM0gIczp>Yu zpZlNhSzVAt;E%Y>&vRkLhTQb$`Dp2Z 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"))]