Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 692f63c

Browse files
committed
Adds new linker script and test ELF.
1 parent 03e267b commit 692f63c

File tree

5 files changed

+73
-18
lines changed

5 files changed

+73
-18
lines changed

tests/elfs/elf.ld

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
PHDRS
22
{
3-
text PT_LOAD ;
3+
text PT_LOAD ;
44
rodata PT_LOAD ;
5-
data PT_LOAD ;
6-
dynamic PT_DYNAMIC ;
5+
stack PT_GNU_STACK ;
6+
heap PT_LOAD ;
7+
dynsym PT_LOAD ;
8+
other PT_NULL ;
79
}
810

911
SECTIONS
1012
{
11-
. = SIZEOF_HEADERS;
12-
.text : { *(.text*) } :text
13-
.rodata : { *(.rodata*) } :rodata
14-
.data.rel.ro : { *(.data.rel.ro*) } :rodata
15-
.dynamic : { *(.dynamic) } :dynamic
16-
.dynsym : { *(.dynsym) } :data
17-
.dynstr : { *(.dynstr) } :data
18-
.rel.dyn : { *(.rel.dyn) } :data
19-
.data : { *(.data*) } :data
20-
.bss : { *(.bss*) } :data
13+
.text 0x000000000 : { *(.text*) } :text
14+
.rodata 0x100000000 : { *(.rodata*) } :rodata
15+
.bss.stack 0x200000000 : { *(.bss.stack*) } :stack
16+
.bss.heap 0x300000000 : { *(.bss.heap*) } :heap
17+
.dynsym 0xFFFFFFFF00000000 : { *(.dynsym) } :dynsym
18+
.dynstr : { *(.dynstr) } :other
19+
.dynamic : { *(.dynamic) } :other
20+
.symtab : { *(.symtab) } :other
21+
.shstrtab : { *(.shstrtab) } :other
22+
.strtab : { *(.strtab) } :other
2123
/DISCARD/ : {
24+
*(.comment*)
2225
*(.eh_frame*)
23-
*(.gnu.hash*)
24-
*(.hash*)
26+
*(*hash*)
27+
*(.bss*)
28+
*(.data*)
29+
*(.rel.dyn*)
2530
}
2631
}

tests/elfs/elf_sbpfv1.ld

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
PHDRS
2+
{
3+
text PT_LOAD ;
4+
rodata PT_LOAD ;
5+
data PT_LOAD ;
6+
dynamic PT_DYNAMIC ;
7+
}
8+
9+
SECTIONS
10+
{
11+
. = SIZEOF_HEADERS;
12+
.text : { *(.text*) } :text
13+
.rodata : { *(.rodata*) } :rodata
14+
.data.rel.ro : { *(.data.rel.ro*) } :rodata
15+
.dynamic : { *(.dynamic) } :dynamic
16+
.dynsym : { *(.dynsym) } :data
17+
.dynstr : { *(.dynstr) } :data
18+
.rel.dyn : { *(.rel.dyn) } :data
19+
.data : { *(.data*) } :data
20+
.bss : { *(.bss*) } :data
21+
/DISCARD/ : {
22+
*(.eh_frame*)
23+
*(.gnu.hash*)
24+
*(.hash*)
25+
}
26+
}

tests/elfs/elfs.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ TOOLCHAIN=../../../agave/sdk/sbf/dependencies/platform-tools
77
RC_COMMON="$TOOLCHAIN/rust/bin/rustc --target sbf-solana-solana --crate-type lib -C panic=abort -C opt-level=2"
88
RC="$RC_COMMON -C target_cpu=sbfv2"
99
RC_V1="$RC_COMMON -C target_cpu=generic"
10-
LD_COMMON="$TOOLCHAIN/llvm/bin/ld.lld -z notext -shared --Bdynamic -entry entrypoint --script elf.ld"
11-
LD="$LD_COMMON --section-start=.text=0x100000000"
12-
LD_V1=$LD_COMMON
10+
LD_COMMON="$TOOLCHAIN/llvm/bin/ld.lld -z notext -shared --Bdynamic -entry entrypoint"
11+
LD="$LD_COMMON --script elf.ld"
12+
LD_V1="$LD_COMMON --script elf_sbpfv1.ld"
13+
14+
$RC -o strict_header.o strict_header.rs
15+
$LD -o strict_header.so strict_header.o
1316

1417
$RC_V1 -o relative_call.o relative_call.rs
1518
$LD_V1 -o relative_call_sbpfv1.so relative_call.o

tests/elfs/strict_header.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(linkage)]
2+
3+
#[link_section = ".bss.stack"]
4+
pub static _STACK: [u8; 0x1000] = [0; 0x1000];
5+
#[link_section = ".bss.heap"]
6+
pub static _HEAP: [u8; 0x1000] = [0; 0x1000];
7+
8+
static _VAL_A: u64 = 41;
9+
static VAL_B: u64 = 42;
10+
static _VAL_C: u64 = 43;
11+
12+
#[inline(never)]
13+
#[linkage="external"]
14+
fn foo() -> u64 {
15+
return unsafe { core::ptr::read_volatile(&VAL_B) };
16+
}
17+
18+
#[no_mangle]
19+
pub fn entrypoint() -> u64 {
20+
return foo();
21+
}

tests/elfs/strict_header.so

13.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)