Skip to content

Commit a87dc12

Browse files
committed
[SBF] Backport sbpfv3
1 parent 693cf63 commit a87dc12

14 files changed

Lines changed: 147 additions & 37 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ jobs:
6767
tidy: false
6868
os: ubuntu-latest
6969
env: {}
70-
- name: x86_64-gnu-tools
70+
- name: sbpfv3-solana-solana
71+
tidy: false
7172
os: ubuntu-latest
7273
env: {}
7374
timeout-minutes: 600
@@ -161,7 +162,7 @@ jobs:
161162
run: src/ci/scripts/create-doc-artifacts.sh
162163
if: success() && !env.SKIP_JOB
163164
- name: upload artifacts to github
164-
uses: actions/upload-artifact@v3
165+
uses: actions/upload-artifact@v4
165166
with:
166167
name: "${{ env.DOC_ARTIFACT_NAME }}"
167168
path: obj/artifacts/doc
@@ -295,7 +296,7 @@ jobs:
295296
run: src/ci/scripts/create-doc-artifacts.sh
296297
if: success() && !env.SKIP_JOB
297298
- name: upload artifacts to github
298-
uses: actions/upload-artifact@v3
299+
uses: actions/upload-artifact@v4
299300
with:
300301
name: "${{ env.DOC_ARTIFACT_NAME }}"
301302
path: obj/artifacts/doc
@@ -442,14 +443,6 @@ jobs:
442443
env:
443444
RUST_BACKTRACE: 1
444445
os: ubuntu-latest
445-
- name: x86_64-gnu-llvm-16
446-
env:
447-
RUST_BACKTRACE: 1
448-
os: ubuntu-latest
449-
- name: x86_64-gnu-llvm-15
450-
env:
451-
RUST_BACKTRACE: 1
452-
os: ubuntu-latest
453446
- name: x86_64-gnu-nopt
454447
os: ubuntu-latest
455448
env: {}
@@ -691,7 +684,7 @@ jobs:
691684
run: src/ci/scripts/create-doc-artifacts.sh
692685
if: success() && !env.SKIP_JOB
693686
- name: upload artifacts to github
694-
uses: actions/upload-artifact@v3
687+
uses: actions/upload-artifact@v4
695688
with:
696689
name: "${{ env.DOC_ARTIFACT_NAME }}"
697690
path: obj/artifacts/doc
@@ -821,7 +814,7 @@ jobs:
821814
run: src/ci/scripts/create-doc-artifacts.sh
822815
if: success() && !env.SKIP_JOB
823816
- name: upload artifacts to github
824-
uses: actions/upload-artifact@v3
817+
uses: actions/upload-artifact@v4
825818
with:
826819
name: "${{ env.DOC_ARTIFACT_NAME }}"
827820
path: obj/artifacts/doc

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ esac
2020
if [ "$1" == "--llvm" ]; then
2121
rm -f build/${HOST_TRIPLE}/llvm/llvm-finished-building;
2222
fi
23-
./x.py build --stage 1 --target ${HOST_TRIPLE},bpfel-unknown-unknown,sbf-solana-solana
23+
./x.py build --stage 1 --target ${HOST_TRIPLE},bpfel-unknown-unknown,sbf-solana-solana,sbpfv3-solana-solana

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
211211
"loongarch64" => Architecture::LoongArch64,
212212
"csky" => Architecture::Csky,
213213
"bpf" => Architecture::Bpf,
214+
"sbf" if sess.target.options.cpu.as_ref() == "v3" => Architecture::Bpf,
214215
"sbf" => Architecture::Bpf,
215216
// Unsupported architecture.
216217
_ => return None,

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
303303
// tidy-alphabetical-end
304304
];
305305

306-
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
306+
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", None)];
307307

308308
const SBF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] =
309309
&[("alu32", Some(sym::sbf_target_feature)), ("static-syscalls", Some(sym::sbf_target_feature))];

compiler/rustc_target/src/spec/base/sbf_base.rs

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::abi::Endian;
2-
use crate::spec::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, TargetOptions};
2+
use crate::spec::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, Target, TargetOptions};
33

4-
pub fn opts() -> TargetOptions {
5-
let linker_script = r"
4+
const V0_LINKER_SCRIPT: &str = r"
65
PHDRS
76
{
87
text PT_LOAD ;
@@ -28,11 +27,74 @@ SECTIONS
2827
}
2928
}
3029
";
30+
31+
const V3_LINKER_SCRIPT: &str = r"
32+
SECTIONS
33+
{
34+
.rodata 0x000000000 : SUBALIGN(8) {
35+
BYTE(0);
36+
*(.rodata*)
37+
*(.data.rel.ro*)
38+
. = ALIGN(8);
39+
} :rodata
40+
.text 0x100000000 : {
41+
*(.text*)
42+
} :text
43+
/DISCARD/ : {
44+
*(.comment*)
45+
*(.eh_frame*)
46+
*(*hash*)
47+
*(.bss*)
48+
*(.data*)
49+
*(.rel.dyn*)
50+
*(.dynamic)
51+
*(.dynsym)
52+
*(.dynstr)
53+
}
54+
}
55+
56+
PHDRS
57+
{
58+
rodata PT_LOAD FLAGS(4);
59+
text PT_LOAD FLAGS(1);
60+
other PT_NULL FLAGS(0);
61+
}
62+
";
63+
64+
pub fn opts(version: &'static str) -> TargetOptions {
65+
let mut linker_args: Vec<&str> = vec![
66+
"--threads=1", "-z", "notext"
67+
];
68+
69+
if version != "v3" {
70+
linker_args.push("-z");
71+
linker_args.push("max-page-size=4096");
72+
}
73+
3174
let pre_link_args = TargetOptions::link_args(
3275
LinkerFlavor::Gnu(Cc::No, Lld::No),
33-
&["--threads=1", "-z", "notext"],
76+
linker_args.as_slice(),
3477
);
3578

79+
let linker_script = if version == "v3" {
80+
V3_LINKER_SCRIPT
81+
} else {
82+
V0_LINKER_SCRIPT
83+
};
84+
let cpu = if version == "v0" {
85+
"generic"
86+
} else {
87+
version
88+
};
89+
90+
let features = if version == "v3" {
91+
"+static-syscalls"
92+
} else if version == "v0" {
93+
"+store-imm,+jmp-ext,+solana"
94+
} else {
95+
""
96+
};
97+
3698
TargetOptions {
3799
allow_asm: true,
38100
c_int_width: "64".into(),
@@ -44,7 +106,6 @@ SECTIONS
44106
endian: Endian::Little,
45107
env: "".into(),
46108
executables: true,
47-
features: "+solana".into(),
48109
families: cvs!["solana"],
49110
link_script: Some(linker_script.into()),
50111
linker: Some("rust-lld".into()),
@@ -61,6 +122,18 @@ SECTIONS
61122
singlethread: true,
62123
vendor: "solana".into(),
63124
c_enum_min_bits: Some(32),
125+
cpu: cpu.into(),
126+
features: features.into(),
64127
.. Default::default()
65128
}
66129
}
130+
131+
pub fn sbf_target(version: &'static str) -> Target {
132+
Target {
133+
llvm_target: "sbf".into(),
134+
pointer_width: 64,
135+
arch: "sbf".into(),
136+
data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".into(),
137+
options: opts(version),
138+
}
139+
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,7 @@ supported_targets! {
16931693
("bpfel-unknown-none", bpfel_unknown_none),
16941694
("bpfel-unknown-unknown", bpfel_unknown_unknown),
16951695
("sbf-solana-solana", sbf_solana_solana),
1696+
("sbpfv3-solana-solana", sbpfv3_solana_solana),
16961697

16971698
("armv6k-nintendo-3ds", armv6k_nintendo_3ds),
16981699

compiler/rustc_target/src/spec/targets/bpfel_unknown_unknown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ pub fn target() -> Target {
77
pointer_width: 64,
88
arch: "bpf".into(),
99
data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".into(),
10-
options: sbf_base::opts(),
10+
options: sbf_base::opts("v0"),
1111
}
1212
}

compiler/rustc_target/src/spec/targets/sbf_solana_solana.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ pub fn target() -> Target {
77
pointer_width: 64,
88
arch: "sbf".into(),
99
data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".into(),
10-
options: sbf_base::opts(),
10+
options: sbf_base::opts("v0"),
1111
}
1212
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use crate::spec::Target;
2+
use crate::spec::base::sbf_base;
3+
4+
pub fn target() -> Target {
5+
sbf_base::sbf_target("v3")
6+
}

src/bootstrap/src/utils/cc_detect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn default_compiler(
220220
}
221221
}
222222

223-
"bpfel-unknown-unknown" | "sbf-solana-solana" => {
223+
"bpfel-unknown-unknown" | "sbf-solana-solana" | "sbpfv3-solana-solana" => {
224224
Some(PathBuf::from(build.llvm_bin(target).join(compiler.clang())))
225225
}
226226

0 commit comments

Comments
 (0)