-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(svm): initial sbfv2 work (#496)
* svm: initial sbfv2 work * svm: format for the style guide * address some comments * svm.elf: address some review comments * svm: verify the length of the `.text` section * svm: don't check for internal functions if an external one was already found * svm: clarify and fixup some behaviour arround the frame pointer * svm: correct `safeSlice`
- Loading branch information
1 parent
3e0043e
commit 6ea81ac
Showing
32 changed files
with
970 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.bc | ||
*.o |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// NOTE: the value is 0 in order to get the symbol into .bss | ||
var x: u32 = 0; | ||
|
||
export fn entrypoint() u32 { | ||
@as(*volatile u32, &x).* = 10; | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var x: u32 = 42; | ||
|
||
export fn entrypoint() u32 { | ||
@as(*volatile u32, &x).* = 10; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
PHDRS | ||
{ | ||
text PT_LOAD ; | ||
rodata PT_LOAD ; | ||
data PT_LOAD ; | ||
dynamic PT_DYNAMIC ; | ||
} | ||
ENTRY ( entrypoint ) | ||
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*) | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export fn entrypoint() u64 { | ||
return @intFromPtr(&entrypoint); | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export fn entrypoint() u64 { | ||
return @intFromPtr("entrypoint"); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const DATA = "hello"; | ||
|
||
export fn entrypoint() u64 { | ||
return @intFromPtr(&DATA); | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const VAL_A: u64 = 41; | ||
const VAL_B: u64 = 42; | ||
const VAL_C: u64 = 43; | ||
|
||
export fn entrypoint() u64 { | ||
return @as(*const volatile u64, &VAL_B).*; | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const PubkeyLutEntry = extern struct { | ||
fp: *const fn (u8) callconv(.C) u8, | ||
key: u64, | ||
}; | ||
|
||
fn f1(a: u8) callconv(.C) u8 { | ||
return a + 1; | ||
} | ||
|
||
export const entry: PubkeyLutEntry linksection(".data.rel.ro") = .{ | ||
.fp = f1, | ||
.key = 0x0102030405060708, | ||
}; | ||
|
||
export fn entrypoint() u64 { | ||
return entry.key; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extern fn log(msg: [*]const u8, len: u64) void; | ||
|
||
export fn entrypoint() u64 { | ||
log("foo\n", 4); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
CC="../toolchain/llvm/bin/clang" | ||
LD="../toolchain/llvm/bin/ld.lld" | ||
ZIG="zig" | ||
|
||
|
||
LD_FLAGS="-z notext -shared --Bdynamic --script data/test-elfs/elf.ld" | ||
C_BASE_FLAGS="-target sbf-solana-solana \ | ||
-fno-builtin \ | ||
-fPIC -fno-unwind-tables \ | ||
-fomit-frame-pointer -fno-exceptions \ | ||
-fno-asynchronous-unwind-tables \ | ||
-std=c23 \ | ||
-O2 \ | ||
-Werror \ | ||
-Wno-override-module" | ||
C_FLAGS="${C_BASE_FLAGS} -mcpu=v1" | ||
C_FLAGS_V2="${C_BASE_FLAGS} -mcpu=sbfv2" | ||
|
||
CC_V1="${CC} ${C_FLAGS}" | ||
CC_V2="${CC} ${C_FLAGS_V2}" | ||
|
||
LD_V1="${LD} ${LD_FLAGS}" | ||
LD_V2="${LD_V1} --section-start=.text=0x100000000" | ||
|
||
V1_FILES=(reloc_64_64 reloc_64_relative reloc_64_relative_data rodata_section) | ||
|
||
for ZIG_FILE in data/test-elfs/*.zig; do | ||
BASE_NAME=$(basename "$ZIG_FILE" .zig) | ||
|
||
$ZIG build-obj "$ZIG_FILE" -OReleaseSmall -fstrip -fno-emit-bin -femit-llvm-bc="data/test-elfs/${BASE_NAME}.bc" | ||
$CC_V2 "data/test-elfs/${BASE_NAME}.bc" -c -o "data/test-elfs/${BASE_NAME}.o" | ||
$LD_V2 "data/test-elfs/${BASE_NAME}.o" -o "data/test-elfs/${BASE_NAME}.so" | ||
|
||
if [[ " ${V1_FILES[@]} " =~ " ${BASE_NAME} " ]]; then | ||
$CC_V1 "data/test-elfs/${BASE_NAME}.bc" -c -o "data/test-elfs/${BASE_NAME}_sbpfv1.o" | ||
$LD_V1 "data/test-elfs/${BASE_NAME}_sbpfv1.o" -o "data/test-elfs/${BASE_NAME}_sbpfv1.so" | ||
fi | ||
done | ||
|
||
rm data/test-elfs/*.o | ||
rm data/test-elfs/*.bc |
Oops, something went wrong.