Skip to content

Commit 2df5ced

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

18 files changed

Lines changed: 155 additions & 63 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,10 @@ jobs:
5959
- name: mingw-check-tidy
6060
os: ubuntu-latest
6161
env: {}
62-
- name: x86_64-gnu-llvm-15
63-
env:
64-
ENABLE_GCC_CODEGEN: "1"
65-
os: ubuntu-latest
66-
- name: sbf-solana-solana
62+
- name: sbpfv3-solana-solana
6763
tidy: false
6864
os: ubuntu-latest
6965
env: {}
70-
- name: x86_64-gnu-tools
71-
os: ubuntu-latest
72-
env: {}
7366
timeout-minutes: 600
7467
runs-on: "${{ matrix.os }}"
7568
steps:
@@ -161,7 +154,7 @@ jobs:
161154
run: src/ci/scripts/create-doc-artifacts.sh
162155
if: success() && !env.SKIP_JOB
163156
- name: upload artifacts to github
164-
uses: actions/upload-artifact@v3
157+
uses: actions/upload-artifact@v4
165158
with:
166159
name: "${{ env.DOC_ARTIFACT_NAME }}"
167160
path: obj/artifacts/doc
@@ -201,7 +194,7 @@ jobs:
201194
- name: x86_64-gnu-llvm-12
202195
os: ubuntu-latest
203196
env: {}
204-
- name: sbf-solana-solana
197+
- name: sbpfv3-solana-solana
205198
os: ubuntu-latest
206199
env: {}
207200
timeout-minutes: 600
@@ -295,7 +288,7 @@ jobs:
295288
run: src/ci/scripts/create-doc-artifacts.sh
296289
if: success() && !env.SKIP_JOB
297290
- name: upload artifacts to github
298-
uses: actions/upload-artifact@v3
291+
uses: actions/upload-artifact@v4
299292
with:
300293
name: "${{ env.DOC_ARTIFACT_NAME }}"
301294
path: obj/artifacts/doc
@@ -442,14 +435,6 @@ jobs:
442435
env:
443436
RUST_BACKTRACE: 1
444437
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
453438
- name: x86_64-gnu-nopt
454439
os: ubuntu-latest
455440
env: {}
@@ -691,7 +676,7 @@ jobs:
691676
run: src/ci/scripts/create-doc-artifacts.sh
692677
if: success() && !env.SKIP_JOB
693678
- name: upload artifacts to github
694-
uses: actions/upload-artifact@v3
679+
uses: actions/upload-artifact@v4
695680
with:
696681
name: "${{ env.DOC_ARTIFACT_NAME }}"
697682
path: obj/artifacts/doc
@@ -821,7 +806,7 @@ jobs:
821806
run: src/ci/scripts/create-doc-artifacts.sh
822807
if: success() && !env.SKIP_JOB
823808
- name: upload artifacts to github
824-
uses: actions/upload-artifact@v3
809+
uses: actions/upload-artifact@v4
825810
with:
826811
name: "${{ env.DOC_ARTIFACT_NAME }}"
827812
path: obj/artifacts/doc

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335"
723723
[[package]]
724724
name = "compiler_builtins"
725725
version = "0.1.103"
726-
source = "git+https://github.com/anza-xyz/compiler-builtins?tag=solana-tools-v1.40#81ef46f3fe1357095acdd089a700890fe4e13974"
726+
source = "git+https://github.com/anza-xyz/compiler-builtins?tag=solana-tools-v1.42.1#b9d3bd3463c95deac85d25c8fa19e754f6e92b9e"
727727
dependencies = [
728728
"cc",
729729
"rustc-std-workspace-core",

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ miniz_oxide.debug = 0
105105
object.debug = 0
106106

107107
[patch.crates-io]
108-
compiler_builtins = { git = "https://github.com/anza-xyz/compiler-builtins", tag = "solana-tools-v1.40" }
108+
compiler_builtins = { git = "https://github.com/anza-xyz/compiler-builtins", tag = "solana-tools-v1.42.1" }
109109
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
110110
# here
111111
rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }

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"
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ supported_targets! {
16921692
("bpfeb-unknown-none", bpfeb_unknown_none),
16931693
("bpfel-unknown-none", bpfel_unknown_none),
16941694
("bpfel-unknown-unknown", bpfel_unknown_unknown),
1695-
("sbf-solana-solana", sbf_solana_solana),
1695+
("sbpfv3-solana-solana", sbpfv3_solana_solana),
16961696

16971697
("armv6k-nintendo-3ds", armv6k_nintendo_3ds),
16981698

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
}

0 commit comments

Comments
 (0)