diff --git a/src/jit.rs b/src/jit.rs index 806e6425..5eb6df0f 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -50,7 +50,7 @@ impl JitProgram { page_size, pc_section: std::slice::from_raw_parts_mut(raw as *mut usize, pc), text_section: std::slice::from_raw_parts_mut( - (raw as *mut u8).add(pc_loc_table_size), + raw.add(pc_loc_table_size), over_allocated_code_size, ), }) diff --git a/src/memory_region.rs b/src/memory_region.rs index f3292e93..9eed3cf6 100644 --- a/src/memory_region.rs +++ b/src/memory_region.rs @@ -982,7 +982,7 @@ impl MappingCache { #[cfg(test)] mod test { - use std::{cell::RefCell, sync::Arc}; + use std::{cell::RefCell, rc::Rc}; use test_utils::assert_error; use super::*; @@ -1728,9 +1728,9 @@ mod test { ..Config::default() }; let original = [11, 22]; - let copied = Arc::new(RefCell::new(Vec::new())); + let copied = Rc::new(RefCell::new(Vec::new())); - let c = Arc::clone(&copied); + let c = Rc::clone(&copied); let m = MemoryMapping::new_with_cow( vec![MemoryRegion::new_cow(&original, ebpf::MM_PROGRAM_START, 42)], Box::new(move |_| { @@ -1763,9 +1763,9 @@ mod test { ..Config::default() }; let original = [11, 22]; - let copied = Arc::new(RefCell::new(Vec::new())); + let copied = Rc::new(RefCell::new(Vec::new())); - let c = Arc::clone(&copied); + let c = Rc::clone(&copied); let m = MemoryMapping::new_with_cow( vec![MemoryRegion::new_cow(&original, ebpf::MM_PROGRAM_START, 42)], Box::new(move |_| { @@ -1803,9 +1803,9 @@ mod test { }; let original1 = [11, 22]; let original2 = [33, 44]; - let copied = Arc::new(RefCell::new(Vec::new())); + let copied = Rc::new(RefCell::new(Vec::new())); - let c = Arc::clone(&copied); + let c = Rc::clone(&copied); let m = MemoryMapping::new_with_cow( vec![ MemoryRegion::new_cow(&original1, ebpf::MM_PROGRAM_START, 42), diff --git a/tests/elfs/bss_section.so b/tests/elfs/bss_section.so index 7aa3f4bb..fb87a951 100755 Binary files a/tests/elfs/bss_section.so and b/tests/elfs/bss_section.so differ diff --git a/tests/elfs/elfs.sh b/tests/elfs/elfs.sh index 2a7727ba..30db9cea 100755 --- a/tests/elfs/elfs.sh +++ b/tests/elfs/elfs.sh @@ -4,8 +4,12 @@ #https://github.com/solana-labs/llvm-builder/releases LLVM_DIR=../../../solana/sdk/sbf/dependencies/sbf-tools/llvm/bin/ -CC_FLAGS="-Werror -target sbf -mcpu=sbfv2 -O2 -fno-builtin -fPIC" -LD_FLAGS="-z notext -shared --Bdynamic -entry entrypoint --script elf.ld" +CC_FLAGS_COMMON="-Werror -target sbf -O2 -fno-builtin -fPIC" +CC_FLAGS="$CC_FLAGS_COMMON -mcpu=sbfv2" +CC_FLAGS_V1="$CC_FLAGS_COMMON -mcpu=generic" +LD_FLAGS_COMMON="-z notext -shared --Bdynamic -entry entrypoint --script elf.ld" +LD_FLAGS="$LD_FLAGS_COMMON --section-start=.text=0x100000000" +LD_FLAGS_V1=$LD_FLAGS_COMMON "$LLVM_DIR"clang $CC_FLAGS -o noop.o -c noop.c "$LLVM_DIR"ld.lld $LD_FLAGS -o noop.so noop.o @@ -33,33 +37,33 @@ rm multiple_file.o "$LLVM_DIR"ld.lld $LD_FLAGS -o relative_call.so relative_call.o rm relative_call.o +"$LLVM_DIR"clang $CC_FLAGS_V1 -o reloc_64_64.o -c reloc_64_64.c +"$LLVM_DIR"ld.lld $LD_FLAGS_V1 -o reloc_64_64_sbpfv1.so reloc_64_64.o +rm reloc_64_64.o + "$LLVM_DIR"clang $CC_FLAGS -o reloc_64_64.o -c reloc_64_64.c "$LLVM_DIR"ld.lld $LD_FLAGS -o reloc_64_64.so reloc_64_64.o rm reloc_64_64.o -"$LLVM_DIR"clang $CC_FLAGS -o reloc_64_64_high_vaddr.o -c reloc_64_64.c -"$LLVM_DIR"ld.lld -z notext -shared --Bdynamic -entry entrypoint --nmagic --section-start=.text=0x100000000 -o reloc_64_64_high_vaddr.so reloc_64_64_high_vaddr.o -rm reloc_64_64_high_vaddr.o - "$LLVM_DIR"clang $CC_FLAGS -o reloc_64_relative.o -c reloc_64_relative.c "$LLVM_DIR"ld.lld $LD_FLAGS -o reloc_64_relative.so reloc_64_relative.o rm reloc_64_relative.o -"$LLVM_DIR"clang $CC_FLAGS -o reloc_64_relative_high_vaddr.o -c reloc_64_relative.c -"$LLVM_DIR"ld.lld $LD_FLAGS --section-start=.text=0x100000000 -o reloc_64_relative_high_vaddr.so reloc_64_relative_high_vaddr.o -rm reloc_64_relative_high_vaddr.o +"$LLVM_DIR"clang $CC_FLAGS_V1 -o reloc_64_relative.o -c reloc_64_relative.c +"$LLVM_DIR"ld.lld $LD_FLAGS_V1 -o reloc_64_relative_sbpfv1.so reloc_64_relative.o +rm reloc_64_relative.o -"$LLVM_DIR"clang $CC_FLAGS -o reloc_64_relative_data.o -c reloc_64_relative_data.c -"$LLVM_DIR"ld.lld $LD_FLAGS -o reloc_64_relative_data.so reloc_64_relative_data.o +"$LLVM_DIR"clang $CC_FLAGS_V1 -o reloc_64_relative_data.o -c reloc_64_relative_data.c +"$LLVM_DIR"ld.lld $LD_FLAGS_V1 -o reloc_64_relative_data_sbpfv1.so reloc_64_relative_data.o rm reloc_64_relative_data.o -"$LLVM_DIR"clang $CC_FLAGS -o reloc_64_relative_data_high_vaddr.o -c reloc_64_relative_data.c -"$LLVM_DIR"ld.lld $LD_FLAGS --section-start=.text=0x100000000 -o reloc_64_relative_data_high_vaddr.so reloc_64_relative_data_high_vaddr.o -rm reloc_64_relative_data_high_vaddr.o +"$LLVM_DIR"clang $CC_FLAGS -o reloc_64_relative_data.o -c reloc_64_relative_data.c +"$LLVM_DIR"ld.lld $LD_FLAGS --section-start=.text=0x100000000 -o reloc_64_relative_data.so reloc_64_relative_data.o +rm reloc_64_relative_data.o -"$LLVM_DIR"clang $CC_FLAGS -o reloc_64_relative_data_pre_sbfv2.o -c reloc_64_relative_data.c -"$LLVM_DIR"ld.lld $LD_FLAGS -o reloc_64_relative_data_pre_sbfv2.so reloc_64_relative_data_pre_sbfv2.o -rm reloc_64_relative_data_pre_sbfv2.o +"$LLVM_DIR"clang $CC_FLAGS_V1 -o reloc_64_relative_data.o -c reloc_64_relative_data.c +"$LLVM_DIR"ld.lld $LD_FLAGS_V1 -o reloc_64_relative_data_sbpfv1.so reloc_64_relative_data.o +rm reloc_64_relative_data.o "$LLVM_DIR"clang $CC_FLAGS -o scratch_registers.o -c scratch_registers.c "$LLVM_DIR"ld.lld $LD_FLAGS -o scratch_registers.so scratch_registers.o @@ -81,14 +85,10 @@ rm bss_section.o "$LLVM_DIR"ld.lld $LD_FLAGS -o rodata.so rodata.o rm rodata.o -"$LLVM_DIR"clang $CC_FLAGS -mcpu=generic -o rodata.o -c rodata.c -"$LLVM_DIR"ld.lld $LD_FLAGS -o rodata_sbpfv1.so rodata.o +"$LLVM_DIR"clang $CC_FLAGS_V1 -mcpu=generic -o rodata.o -c rodata.c +"$LLVM_DIR"ld.lld $LD_FLAGS_V1 -o rodata_sbpfv1.so rodata.o rm rodata.o -"$LLVM_DIR"clang $CC_FLAGS -o rodata_high_vaddr.o -c rodata.c -"$LLVM_DIR"ld.lld -z notext -shared --Bdynamic -entry entrypoint --nmagic --section-start=.text=0x100000000 --section-start=.rodata=0x100000020 -o rodata_high_vaddr.so rodata_high_vaddr.o -rm rodata_high_vaddr.o - "$LLVM_DIR"clang $CC_FLAGS -o syscall_static_unknown.o -c syscall_static_unknown.c "$LLVM_DIR"ld.lld $LD_FLAGS -o syscall_static_unknown.so syscall_static_unknown.o rm syscall_static_unknown.o diff --git a/tests/elfs/empty_rodata.so b/tests/elfs/empty_rodata.so index faeeb480..913460ed 100755 Binary files a/tests/elfs/empty_rodata.so and b/tests/elfs/empty_rodata.so differ diff --git a/tests/elfs/multiple_file.so b/tests/elfs/multiple_file.so index 970631c5..a9c2e763 100755 Binary files a/tests/elfs/multiple_file.so and b/tests/elfs/multiple_file.so differ diff --git a/tests/elfs/noop.so b/tests/elfs/noop.so index 7e74e2d7..f017a1a9 100755 Binary files a/tests/elfs/noop.so and b/tests/elfs/noop.so differ diff --git a/tests/elfs/noro.so b/tests/elfs/noro.so index d24ebcda..daf428d6 100755 Binary files a/tests/elfs/noro.so and b/tests/elfs/noro.so differ diff --git a/tests/elfs/pass_stack_reference.so b/tests/elfs/pass_stack_reference.so index 0b947de0..2e9d2aa6 100755 Binary files a/tests/elfs/pass_stack_reference.so and b/tests/elfs/pass_stack_reference.so differ diff --git a/tests/elfs/program_headers_overflow.so b/tests/elfs/program_headers_overflow.so index ef844f10..be60c249 100755 Binary files a/tests/elfs/program_headers_overflow.so and b/tests/elfs/program_headers_overflow.so differ diff --git a/tests/elfs/relative_call.so b/tests/elfs/relative_call.so index cb7f0464..9adff4bb 100755 Binary files a/tests/elfs/relative_call.so and b/tests/elfs/relative_call.so differ diff --git a/tests/elfs/reloc_64_64.so b/tests/elfs/reloc_64_64.so index 141445eb..c3906368 100755 Binary files a/tests/elfs/reloc_64_64.so and b/tests/elfs/reloc_64_64.so differ diff --git a/tests/elfs/reloc_64_64_high_vaddr.so b/tests/elfs/reloc_64_64_high_vaddr.so deleted file mode 100755 index 53d0ed40..00000000 Binary files a/tests/elfs/reloc_64_64_high_vaddr.so and /dev/null differ diff --git a/tests/elfs/reloc_64_64_sbpfv1.so b/tests/elfs/reloc_64_64_sbpfv1.so new file mode 100755 index 00000000..446194c9 Binary files /dev/null and b/tests/elfs/reloc_64_64_sbpfv1.so differ diff --git a/tests/elfs/reloc_64_relative.so b/tests/elfs/reloc_64_relative.so index 81e7163a..4644ad3d 100755 Binary files a/tests/elfs/reloc_64_relative.so and b/tests/elfs/reloc_64_relative.so differ diff --git a/tests/elfs/reloc_64_relative_data.so b/tests/elfs/reloc_64_relative_data.so index df390505..98b54d79 100755 Binary files a/tests/elfs/reloc_64_relative_data.so and b/tests/elfs/reloc_64_relative_data.so differ diff --git a/tests/elfs/reloc_64_relative_data_high_vaddr.so b/tests/elfs/reloc_64_relative_data_high_vaddr.so deleted file mode 100755 index 86969116..00000000 Binary files a/tests/elfs/reloc_64_relative_data_high_vaddr.so and /dev/null differ diff --git a/tests/elfs/reloc_64_relative_data_pre_sbfv2.so b/tests/elfs/reloc_64_relative_data_sbpfv1.so similarity index 90% rename from tests/elfs/reloc_64_relative_data_pre_sbfv2.so rename to tests/elfs/reloc_64_relative_data_sbpfv1.so index df390505..256662fc 100755 Binary files a/tests/elfs/reloc_64_relative_data_pre_sbfv2.so and b/tests/elfs/reloc_64_relative_data_sbpfv1.so differ diff --git a/tests/elfs/reloc_64_relative_high_vaddr.so b/tests/elfs/reloc_64_relative_high_vaddr.so deleted file mode 100755 index d4763889..00000000 Binary files a/tests/elfs/reloc_64_relative_high_vaddr.so and /dev/null differ diff --git a/tests/elfs/reloc_64_relative_sbpfv1.so b/tests/elfs/reloc_64_relative_sbpfv1.so new file mode 100755 index 00000000..658846e8 Binary files /dev/null and b/tests/elfs/reloc_64_relative_sbpfv1.so differ diff --git a/tests/elfs/rodata.so b/tests/elfs/rodata.so index 9b8a8b8e..f7a1a819 100755 Binary files a/tests/elfs/rodata.so and b/tests/elfs/rodata.so differ diff --git a/tests/elfs/rodata_high_vaddr.so b/tests/elfs/rodata_high_vaddr.so deleted file mode 100755 index cb818461..00000000 Binary files a/tests/elfs/rodata_high_vaddr.so and /dev/null differ diff --git a/tests/elfs/scratch_registers.so b/tests/elfs/scratch_registers.so index 05016a81..f1da1850 100755 Binary files a/tests/elfs/scratch_registers.so and b/tests/elfs/scratch_registers.so differ diff --git a/tests/elfs/scratch_registers_debug.so b/tests/elfs/scratch_registers_debug.so index 38ab6dc5..70581390 100755 Binary files a/tests/elfs/scratch_registers_debug.so and b/tests/elfs/scratch_registers_debug.so differ diff --git a/tests/elfs/struct_func_pointer.so b/tests/elfs/struct_func_pointer.so index 6d34f68e..04901f6b 100755 Binary files a/tests/elfs/struct_func_pointer.so and b/tests/elfs/struct_func_pointer.so differ diff --git a/tests/elfs/syscall_static.so b/tests/elfs/syscall_static.so index 9dcb9397..31582f76 100755 Binary files a/tests/elfs/syscall_static.so and b/tests/elfs/syscall_static.so differ diff --git a/tests/elfs/syscall_static_unknown.so b/tests/elfs/syscall_static_unknown.so index 93d32b83..1da65e31 100755 Binary files a/tests/elfs/syscall_static_unknown.so and b/tests/elfs/syscall_static_unknown.so differ diff --git a/tests/elfs/unresolved_syscall.so b/tests/elfs/unresolved_syscall.so index b72e3723..bb949a07 100755 Binary files a/tests/elfs/unresolved_syscall.so and b/tests/elfs/unresolved_syscall.so differ diff --git a/tests/elfs/writable_data_section.so b/tests/elfs/writable_data_section.so index e4c7546b..8b5f92f1 100755 Binary files a/tests/elfs/writable_data_section.so and b/tests/elfs/writable_data_section.so differ diff --git a/tests/execution.rs b/tests/execution.rs index 83d01dde..6ff743f5 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -3097,7 +3097,7 @@ fn test_load_elf_empty_rodata() { } #[test] -fn test_load_elf_rodata_sbpfv2() { +fn test_load_elf_rodata() { let config = Config::default(); test_interpreter_and_jit_elf!( "tests/elfs/rodata.so", @@ -3122,17 +3122,6 @@ fn test_load_elf_rodata_sbpfv1() { ); } -#[test] -fn test_load_elf_rodata_high_vaddr() { - test_interpreter_and_jit_elf!( - "tests/elfs/rodata_high_vaddr.so", - [1], - (), - TestContextObject::new(3), - ProgramResult::Ok(42), - ); -} - // Instruction Meter Limit #[test] @@ -3436,7 +3425,7 @@ fn test_err_unresolved_elf() { file.read_to_end(&mut elf).unwrap(); assert_error!( Executable::::from_elf(&elf, Arc::new(loader)), - "UnresolvedSymbol(\"log_64\", 67, 304)" + "UnresolvedSymbol(\"log_64\", 550, 4168)" ); } @@ -3471,12 +3460,12 @@ fn test_syscall_unknown_static() { } #[test] -fn test_reloc_64_64() { +fn test_reloc_64_64_sbpfv1() { // Tests the correctness of R_BPF_64_64 relocations. The program returns the // address of the entrypoint. // [ 1] .text PROGBITS 00000000000000e8 0000e8 000018 00 AX 0 0 8 test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_64.so", + "tests/elfs/reloc_64_64_sbpfv1.so", [], (), TestContextObject::new(2), @@ -3485,11 +3474,12 @@ fn test_reloc_64_64() { } #[test] -fn test_reloc_64_64_high_vaddr() { +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_high_vaddr.so", + "tests/elfs/reloc_64_64.so", [], (), TestContextObject::new(2), @@ -3498,13 +3488,13 @@ fn test_reloc_64_64_high_vaddr() { } #[test] -fn test_reloc_64_relative() { +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 00000000000000e8 0000e8 000018 00 AX 0 0 8 // [ 2] .rodata PROGBITS 0000000000000100 000100 00000b 01 AMS 0 0 1 test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_relative.so", + "tests/elfs/reloc_64_relative_sbpfv1.so", [], (), TestContextObject::new(2), @@ -3513,13 +3503,13 @@ fn test_reloc_64_relative() { } #[test] -fn test_reloc_64_relative_high_vaddr() { +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_high_vaddr.so", + "tests/elfs/reloc_64_relative.so", [], (), TestContextObject::new(2), @@ -3528,7 +3518,7 @@ fn test_reloc_64_relative_high_vaddr() { } #[test] -fn test_reloc_64_relative_data() { +fn test_reloc_64_relative_data_sbfv1() { // Tests the correctness of R_BPF_64_RELATIVE relocations in sections other // than .text. The program returns the address of the first .rodata byte. // [ 1] .text PROGBITS 00000000000000e8 0000e8 000020 00 AX 0 0 8 @@ -3537,7 +3527,7 @@ fn test_reloc_64_relative_data() { // 00000000000001f8 : // 63: 08 01 00 00 00 00 00 00 test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_relative_data.so", + "tests/elfs/reloc_64_relative_data_sbpfv1.so", [], (), TestContextObject::new(3), @@ -3546,7 +3536,7 @@ fn test_reloc_64_relative_data() { } #[test] -fn test_reloc_64_relative_data_high_vaddr() { +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 @@ -3555,7 +3545,7 @@ fn test_reloc_64_relative_data_high_vaddr() { // 0000000100000110 : // 536870946: 20 00 00 00 01 00 00 00 test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_relative_data_high_vaddr.so", + "tests/elfs/reloc_64_relative_data.so", [], (), TestContextObject::new(3), @@ -3564,7 +3554,7 @@ fn test_reloc_64_relative_data_high_vaddr() { } #[test] -fn test_reloc_64_relative_data_pre_sbfv2() { +fn test_reloc_64_relative_data_sbpfv1() { // Before https://github.com/solana-labs/llvm-project/pull/35, we used to // generate invalid R_BPF_64_RELATIVE relocations in sections other than // .text. @@ -3579,7 +3569,7 @@ fn test_reloc_64_relative_data_pre_sbfv2() { // 00000000000001f8 : // 63: 00 00 00 00 08 01 00 00 test_interpreter_and_jit_elf!( - "tests/elfs/reloc_64_relative_data_pre_sbfv2.so", + "tests/elfs/reloc_64_relative_data_sbpfv1.so", [], (), TestContextObject::new(3),