From 9c8e8fd2326478b18f14459c7f20a20c9d4917ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 24 Oct 2024 16:37:33 +0100 Subject: [PATCH] Adds new linker script and test ELF. --- tests/elfs/elf.ld | 45 ++++++++++++++++++++---------------- tests/elfs/elf_sbpfv1.ld | 26 +++++++++++++++++++++ tests/elfs/elfs.sh | 9 +++++--- tests/elfs/strict_header.rs | 21 +++++++++++++++++ tests/elfs/strict_header.so | Bin 0 -> 13816 bytes 5 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 tests/elfs/elf_sbpfv1.ld create mode 100644 tests/elfs/strict_header.rs create mode 100644 tests/elfs/strict_header.so diff --git a/tests/elfs/elf.ld b/tests/elfs/elf.ld index e01debd2..cf6f4e3f 100644 --- a/tests/elfs/elf.ld +++ b/tests/elfs/elf.ld @@ -1,26 +1,31 @@ -PHDRS -{ - text PT_LOAD ; - rodata PT_LOAD ; - data PT_LOAD ; - dynamic PT_DYNAMIC ; -} - SECTIONS { - . = SIZEOF_HEADERS; - .text : { *(.text*) } :text - .rodata : { *(.rodata*) } :rodata - .data.rel.ro : { *(.data.rel.ro*) } :rodata - .dynamic : { *(.dynamic) } :dynamic - .dynsym : { *(.dynsym) } :data - .dynstr : { *(.dynstr) } :data - .rel.dyn : { *(.rel.dyn) } :data - .data : { *(.data*) } :data - .bss : { *(.bss*) } :data + .text 0x000000000 : { *(.text*) } :text + .rodata 0x100000000 : { *(.rodata*) } :rodata + .bss.stack 0x200000000 : { *(.bss.stack*) } :stack + .bss.heap 0x300000000 : { *(.bss.heap*) } :heap + .dynsym 0xFFFFFFFF00000000 : { *(.dynsym) } :dynsym + .dynstr : { *(.dynstr) } :other + .dynamic : { *(.dynamic) } :other + .symtab : { *(.symtab) } :other + .shstrtab : { *(.shstrtab) } :other + .strtab : { *(.strtab) } :other /DISCARD/ : { + *(.comment*) *(.eh_frame*) - *(.gnu.hash*) - *(.hash*) + *(*hash*) + *(.bss*) + *(.data*) + *(.rel.dyn*) } } + +PHDRS +{ + text PT_LOAD FLAGS(1); + rodata PT_LOAD FLAGS(4); + stack PT_GNU_STACK FLAGS(6); + heap PT_LOAD FLAGS(6); + dynsym PT_NULL FLAGS(0); + other PT_NULL FLAGS(0); +} diff --git a/tests/elfs/elf_sbpfv1.ld b/tests/elfs/elf_sbpfv1.ld new file mode 100644 index 00000000..859ab669 --- /dev/null +++ b/tests/elfs/elf_sbpfv1.ld @@ -0,0 +1,26 @@ +PHDRS +{ + text PT_LOAD ; + rodata PT_LOAD ; + data PT_LOAD ; + dynamic PT_DYNAMIC ; +} + +SECTIONS +{ + . = SIZEOF_HEADERS; + .text : { *(.text*) } :text + .rodata : { *(.rodata*) } :rodata + .data.rel.ro : { *(.data.rel.ro*) } :rodata + .dynamic : { *(.dynamic) } :dynamic + .dynsym : { *(.dynsym) } :data + .dynstr : { *(.dynstr) } :data + .rel.dyn : { *(.rel.dyn) } :data + .data : { *(.data*) } :data + .bss : { *(.bss*) } :data + /DISCARD/ : { + *(.eh_frame*) + *(.gnu.hash*) + *(.hash*) + } +} diff --git a/tests/elfs/elfs.sh b/tests/elfs/elfs.sh index 5f02e69b..f8cfc974 100755 --- a/tests/elfs/elfs.sh +++ b/tests/elfs/elfs.sh @@ -7,9 +7,12 @@ TOOLCHAIN=../../../agave/sdk/sbf/dependencies/platform-tools RC_COMMON="$TOOLCHAIN/rust/bin/rustc --target sbf-solana-solana --crate-type lib -C panic=abort -C opt-level=2" RC="$RC_COMMON -C target_cpu=sbfv2" RC_V1="$RC_COMMON -C target_cpu=generic" -LD_COMMON="$TOOLCHAIN/llvm/bin/ld.lld -z notext -shared --Bdynamic -entry entrypoint --script elf.ld" -LD="$LD_COMMON --section-start=.text=0x100000000" -LD_V1=$LD_COMMON +LD_COMMON="$TOOLCHAIN/llvm/bin/ld.lld -z notext -shared --Bdynamic -entry entrypoint" +LD="$LD_COMMON --script elf.ld" +LD_V1="$LD_COMMON --script elf_sbpfv1.ld" + +$RC -o strict_header.o strict_header.rs +$LD -o strict_header.so strict_header.o $RC_V1 -o relative_call.o relative_call.rs $LD_V1 -o relative_call_sbpfv1.so relative_call.o diff --git a/tests/elfs/strict_header.rs b/tests/elfs/strict_header.rs new file mode 100644 index 00000000..43388c6d --- /dev/null +++ b/tests/elfs/strict_header.rs @@ -0,0 +1,21 @@ +#![feature(linkage)] + +#[link_section = ".bss.stack"] +pub static _STACK: [u8; 0x1000] = [0; 0x1000]; +#[link_section = ".bss.heap"] +pub static _HEAP: [u8; 0x1000] = [0; 0x1000]; + +static _VAL_A: u64 = 41; +static VAL_B: u64 = 42; +static _VAL_C: u64 = 43; + +#[inline(never)] +#[linkage="external"] +fn foo() -> u64 { + return unsafe { core::ptr::read_volatile(&VAL_B) }; +} + +#[no_mangle] +pub fn entrypoint() -> u64 { + return foo(); +} diff --git a/tests/elfs/strict_header.so b/tests/elfs/strict_header.so new file mode 100644 index 0000000000000000000000000000000000000000..5bea25c41c9ce0f02cfb7cc1614d9812efe658d8 GIT binary patch literal 13816 zcmeHOziSjh6n?qHL`|Va5V4Rg#6oo0+r8V{D}Mb@{?q*(k<3^8|MxX#d4c{< z{J$#xz9!efQ~^~$6;K6K0aZX1Pz6*0RX`O`1yli5;6N0(a3EPUi7KE9r~;~hDxeCe z0;+&2pbDr0s(>n>3jB`>&{=>Pb0Wab&f!U3s1>oQ9aJWX4TIVFY=S9*@kSr=x=WHR@V!FvplZ33xM_s_626xa2QWAO5Pva+dT^L zF$R0apZm}``)RgMGah1;^Y};EZ!n%>{9B;>6Y$O43n+8Xqcg@g6sV8f4|qxOioJPY zt^)82y*F{IhH2&aM~p*d3bqjFy~w4qh|j2Xdd6`Fk&5UAZjn7L!0q?axQM}B8VuY) z5hstWi7U4OZo0WX*j%$%^bN*qs|mOmE#f7_6TH3gj zEI)C*5qqS5zct^zg1e;Y*J^3l%o~xPr=g#>M|A#^4Yhk4hTX+`t+|`D6LAxUxfj*^ zFbx~AKPpGP+iAD%VCOu`yu2C&&6*ebUX0ted-dT$>(-4qE9gJgv=`_xcT&n@@j`j! z7}~OLBs_%%@ymB!$Onh2-Tim+k8z*!-4_~bc&}!-VQ4g)%UZTRgFs`J`No!s@4-KZ zT>3W4^EdmN`5kPdLi*5q$^7Lzrr#mTCw%Hpe7SEU-!q0yG1`cOSi^_Lmicd?P5dp+ z{}z2JvObbuUh6WpNp91TE3aye5A4(L3ymRsnSUE&lAF64_{#hT72{}-@S$$|g? literal 0 HcmV?d00001