Skip to content

Commit eb3215d

Browse files
dmakarovc410-f3r
authored andcommitted
[SOL] Adjust SBF customization after upgrading to rust 1.68.0
1 parent 1a3b86b commit eb3215d

File tree

22 files changed

+103
-49
lines changed

22 files changed

+103
-49
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
os: ubuntu-20.04-16core-64gb
9393
env: {}
9494
- name: sbf-solana-solana
95+
tidy: false
9596
os: ubuntu-latest
9697
env: {}
9798
- name: x86_64-gnu-tools
@@ -288,6 +289,9 @@ jobs:
288289
- name: install sccache
289290
run: src/ci/scripts/install-sccache.sh
290291
if: success() && !env.SKIP_JOB
292+
- name: select Xcode
293+
run: src/ci/scripts/select-xcode.sh
294+
if: success() && !env.SKIP_JOB
291295
- name: install clang
292296
run: src/ci/scripts/install-clang.sh
293297
if: success() && !env.SKIP_JOB

compiler/rustc_target/src/spec/sbf_base.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::abi::Endian;
2-
use super::{cvs, LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor};
2+
use super::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, TargetOptions};
33

44
pub fn opts() -> TargetOptions {
55
let linker_script = r"
@@ -28,13 +28,10 @@ SECTIONS
2828
}
2929
}
3030
";
31-
let mut lld_args = Vec::new();
32-
lld_args.push("--threads=1".into());
33-
lld_args.push("-z".into());
34-
lld_args.push("notext".into());
35-
let mut pre_link_args = LinkArgs::new();
36-
pre_link_args.insert(LinkerFlavor::Ld, lld_args.clone());
37-
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args);
31+
let pre_link_args = TargetOptions::link_args(
32+
LinkerFlavor::Gnu(Cc::No, Lld::No),
33+
&["--threads=1", "-z", "notext"],
34+
);
3835

3936
TargetOptions {
4037
allow_asm: true,
@@ -50,8 +47,7 @@ SECTIONS
5047
families: cvs!["solana"],
5148
link_script: Some(linker_script.into()),
5249
linker: Some("rust-lld".into()),
53-
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
54-
linker_is_gnu: true,
50+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
5551
main_needs_argc_argv: false,
5652
max_atomic_width: Some(64),
5753
no_default_libraries: true,

config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ link-shared = false
108108
# Which LLVM projects to build along with the LLVM base libraries/tools
109109
enable-projects = "clang;lld"
110110

111+
download-ci-llvm = false
112+
111113
# =============================================================================
112114
# General build configuration options
113115
# =============================================================================

library/core/tests/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,9 +1809,9 @@ fn select_nth_unstable() {
18091809
use rand::Rng;
18101810
use rand::seq::SliceRandom;
18111811

1812-
let mut rng = StdRng::seed_from_u64(0);
1812+
let mut rng = crate::test_rng();
18131813

1814-
for len in (2..21).chain(200..201) {
1814+
for len in (2..21).chain(500..501) {
18151815
let mut orig = vec![0; len];
18161816

18171817
for &modulus in &[5, 10, 1000] {

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std_detect = { path = "../stdarch/crates/std_detect", default-features = false,
3232
] }
3333

3434
# Dependencies of the `backtrace` crate
35-
[target.'cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))'.dependencies]
35+
[target.'cfg(not(target_family = "solana"))'.dependencies]
3636
addr2line = { version = "0.22.0", optional = true, default-features = false }
3737
rustc-demangle = { version = "0.1.24", features = ['rustc-dep-of-std'] }
3838

library/std/src/error.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
#[cfg(test)]
55
mod tests;
66

7+
#[cfg(not(target_family = "solana"))]
8+
use crate::backtrace::Backtrace;
9+
use crate::fmt::{self, Write};
10+
711
#[stable(feature = "rust1", since = "1.0.0")]
812
pub use core::error::Error;
913
#[unstable(feature = "error_generic_member_access", issue = "99301")]
1014
pub use core::error::{Request, request_ref, request_value};
1115

12-
use crate::backtrace::Backtrace;
13-
use crate::fmt::{self, Write};
14-
1516
/// An error reporter that prints an error and its sources.
1617
///
1718
/// Report also exposes configuration options for formatting the error sources, either entirely on a
@@ -449,6 +450,7 @@ impl<E> Report<E>
449450
where
450451
E: Error,
451452
{
453+
#[cfg(not(target_family = "solana"))]
452454
fn backtrace(&self) -> Option<&Backtrace> {
453455
// have to grab the backtrace on the first error directly since that error may not be
454456
// 'static
@@ -499,6 +501,7 @@ where
499501
}
500502
}
501503

504+
#[cfg(not(target_family = "solana"))]
502505
if self.show_backtrace {
503506
if let Some(backtrace) = self.backtrace() {
504507
write!(f, "\n\nStack backtrace:\n{}", backtrace.to_string().trim_end())?;

library/std/src/io/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,10 @@ pub(crate) use error::const_io_error;
307307
pub use self::buffered::WriterPanicked;
308308
#[unstable(feature = "raw_os_error_ty", issue = "107792")]
309309
pub use self::error::RawOsError;
310+
#[cfg(not(target_family = "solana"))]
311+
pub(crate) use self::stdio::attempt_print_to_stderr;
310312
#[stable(feature = "is_terminal", since = "1.70.0")]
311313
pub use self::stdio::IsTerminal;
312-
pub(crate) use self::stdio::attempt_print_to_stderr;
313314
#[unstable(feature = "print_internals", issue = "none")]
314315
#[doc(hidden)]
315316
pub use self::stdio::{_eprint, _print};

library/std/src/io/stdio.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
#[cfg(test)]
44
mod tests;
55

6-
use crate::fmt;
7-
use crate::fs::File;
86
use crate::io::prelude::*;
97

108
#[cfg(not(target_family = "solana"))]
119
use crate::sync::{ReentrantLock, ReentrantLockGuard};
1210
#[cfg(not(target_family = "solana"))]
1311
use crate::cell::{Cell, RefCell};
12+
use crate::fmt;
13+
#[cfg(not(target_family = "solana"))]
14+
use crate::fs::File;
1415
#[cfg(not(target_os = "solana"))]
1516
use crate::io::{
1617
self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines,
@@ -1346,6 +1347,7 @@ where
13461347
}
13471348
}
13481349

1350+
#[cfg(not(target_family = "solana"))]
13491351
fn print_to_buffer_if_capture_used(args: fmt::Arguments<'_>) -> bool {
13501352
OUTPUT_CAPTURE_USED.load(Ordering::Relaxed)
13511353
&& OUTPUT_CAPTURE.try_with(|s| {
@@ -1362,6 +1364,7 @@ fn print_to_buffer_if_capture_used(args: fmt::Arguments<'_>) -> bool {
13621364
/// Used by impl Termination for Result to print error after `main` or a test
13631365
/// has returned. Should avoid panicking, although we can't help it if one of
13641366
/// the Display impls inside args decides to.
1367+
#[cfg(not(target_family = "solana"))]
13651368
pub(crate) fn attempt_print_to_stderr(args: fmt::Arguments<'_>) {
13661369
if print_to_buffer_if_capture_used(args) {
13671370
return;
@@ -1426,6 +1429,7 @@ pub trait IsTerminal: crate::sealed::Sealed {
14261429
fn is_terminal(&self) -> bool;
14271430
}
14281431

1432+
#[cfg(not(target_family = "solana"))]
14291433
macro_rules! impl_is_terminal {
14301434
($($t:ty),*$(,)?) => {$(
14311435
#[unstable(feature = "sealed", issue = "none")]
@@ -1441,6 +1445,7 @@ macro_rules! impl_is_terminal {
14411445
)*}
14421446
}
14431447

1448+
#[cfg(not(target_family = "solana"))]
14441449
impl_is_terminal!(File, Stdin, StdinLock<'_>, Stdout, StdoutLock<'_>, Stderr, StderrLock<'_>);
14451450

14461451
#[unstable(

library/std/src/panicking.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ use crate::mem;
3030
use crate::process;
3131
#[cfg(not(target_family = "solana"))]
3232
use crate::sync::atomic::{AtomicBool, Ordering};
33+
#[cfg(not(target_family = "solana"))]
3334
use crate::sync::{PoisonError, RwLock};
34-
#[cfg(not(target_os = "solana"))]
35+
#[cfg(not(target_family = "solana"))]
3536
use crate::sys::stdio::panic_output;
3637
#[cfg(not(target_family = "solana"))]
3738
use crate::sys::backtrace;
@@ -77,7 +78,7 @@ extern "C" fn __rust_foreign_exception() -> ! {
7778
rtabort!("Rust cannot catch foreign exceptions");
7879
}
7980

80-
#[cfg(not(target_os = "solana"))]
81+
#[cfg(not(target_family = "solana"))]
8182
enum Hook {
8283
Default,
8384
Custom(Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>),
@@ -94,15 +95,15 @@ impl Hook {
9495
}
9596
}
9697

97-
#[cfg(not(target_os = "solana"))]
98+
#[cfg(not(target_family = "solana"))]
9899
impl Default for Hook {
99100
#[inline]
100101
fn default() -> Hook {
101102
Hook::Default
102103
}
103104
}
104105

105-
#[cfg(not(target_os = "solana"))]
106+
#[cfg(not(target_family = "solana"))]
106107
static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);
107108

108109
/// Registers a custom panic hook, replacing the previously registered hook.
@@ -442,7 +443,7 @@ pub mod panic_count {
442443
//
443444
// This also updates thread-local state to keep track of whether a panic
444445
// hook is currently executing.
445-
#[cfg(not(target_os = "solana"))]
446+
#[cfg(not(target_family = "solana"))]
446447
pub fn increase(run_panic_hook: bool) -> Option<MustAbort> {
447448
let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed);
448449
if global_count & ALWAYS_ABORT_FLAG != 0 {
@@ -510,7 +511,7 @@ pub mod panic_count {
510511

511512
// Slow path is in a separate function to reduce the amount of code
512513
// inlined from `count_is_zero`.
513-
#[cfg(not(target_os = "solana"))]
514+
#[cfg(not(target_family = "solana"))]
514515
#[inline(never)]
515516
#[cold]
516517
fn is_zero_slow_path() -> bool {

library/std/src/process.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,10 +2452,15 @@ impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> {
24522452
fn report(self) -> ExitCode {
24532453
match self {
24542454
Ok(val) => val.report(),
2455+
#[cfg(not(target_family = "solana"))]
24552456
Err(err) => {
24562457
io::attempt_print_to_stderr(format_args_nl!("Error: {err:?}"));
24572458
ExitCode::FAILURE
24582459
}
2460+
#[cfg(target_family = "solana")]
2461+
Err(_err) => {
2462+
ExitCode::FAILURE
2463+
}
24592464
}
24602465
}
24612466
}

library/std/src/rt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ fn lang_start<T: crate::process::Termination + 'static>(
215215
main: fn() -> T,
216216
_argc: isize,
217217
_argv: *const *const u8,
218+
_sigpipe: u8,
218219
) -> isize {
219220
main().report().to_i32() as isize
220221
}

library/std/src/sync/mpmc/utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::ops::{Deref, DerefMut};
33

44
/// Pads and aligns a value to the length of a cache line.
55
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq)]
6+
#[cfg_attr(target_family = "solana", repr(align(8)))]
67
// Starting from Intel's Sandy Bridge, spatial prefetcher is now pulling pairs of 64-byte cache
78
// lines at a time, so we have to align to 128 bytes rather than 64.
89
//
@@ -66,6 +67,7 @@ use crate::ops::{Deref, DerefMut};
6667
target_arch = "mips64r6",
6768
target_arch = "riscv64",
6869
target_arch = "s390x",
70+
target_family = "solana",
6971
)),
7072
repr(align(64))
7173
)]

library/std/src/sys/sbf/futex.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use crate::sync::atomic::AtomicU32;
2+
use crate::time::Duration;
3+
4+
pub fn futex_wait(_futex: &AtomicU32, _expected: u32, _timeout: Option<Duration>) -> bool {
5+
false
6+
}
7+
8+
#[inline]
9+
pub fn futex_wake(_futex: &AtomicU32) -> bool {
10+
false
11+
}
12+
13+
#[inline]
14+
pub fn futex_wake_all(_futex: &AtomicU32) {}

library/std/src/sys/sbf/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod args;
2020
pub mod cmath;
2121
pub mod env;
2222
pub mod fs;
23+
pub mod futex;
2324
pub mod io;
2425
pub mod memchr;
2526
pub mod net;
@@ -34,16 +35,17 @@ pub mod time;
3435
#[path = "../unix/os_str.rs"]
3536
pub mod os_str;
3637

37-
pub mod condvar;
38-
pub mod mutex;
39-
pub mod rwlock;
4038
pub mod thread_local_dtor;
4139
pub mod thread_local_key;
4240

41+
#[path = "../unix/locks"]
4342
pub mod locks {
44-
pub use super::condvar::*;
45-
pub use super::mutex::*;
46-
pub use super::rwlock::*;
43+
mod futex_condvar;
44+
mod futex_mutex;
45+
mod futex_rwlock;
46+
pub(crate) use futex_condvar::Condvar;
47+
pub(crate) use futex_mutex::Mutex;
48+
pub(crate) use futex_rwlock::RwLock;
4749
}
4850

4951
#[cfg(not(target_feature = "static-syscalls"))]

library/std/src/sys/sbf/pipe.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ impl AnonPipe {
1818
false
1919
}
2020

21+
pub fn read_to_end(&self, _buf: &mut Vec<u8>) -> io::Result<usize> {
22+
match self.0 {}
23+
}
24+
2125
pub fn write(&self, _buf: &[u8]) -> io::Result<usize> {
2226
match self.0 {}
2327
}

library/std/src/sys/sbf/process.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ impl Command {
6565
unsupported()
6666
}
6767

68+
pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
69+
unsupported()
70+
}
71+
6872
pub fn get_args(&self) -> CommandArgs<'_> {
6973
let mut iter = self.args.iter();
7074
iter.next();

library/std/src/sys/sbf/thread_local_key.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(fuzzy_provenance_casts)]
12
use crate::boxed::Box;
23
use crate::ptr;
34

@@ -33,8 +34,3 @@ pub unsafe fn destroy(key: Key) {
3334
f(key.value);
3435
}
3536
}
36-
37-
#[inline]
38-
pub fn requires_synchronized_create() -> bool {
39-
false
40-
}

library/std/src/sys/sync/once/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cfg_if::cfg_if! {
1818
target_os = "dragonfly",
1919
target_os = "fuchsia",
2020
target_os = "hermit",
21+
target_os = "solana",
2122
))] {
2223
mod futex;
2324
pub use futex::{Once, OnceState};

library/std/src/thread/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ impl ThreadId {
12591259
Err(id) => last = id,
12601260
}
12611261
}
1262-
} else if #[cfg(not(target_os = "solana"))] {
1262+
} else if #[cfg(not(target_family = "solana"))] {
12631263
use crate::sync::{Mutex, PoisonError};
12641264

12651265
static COUNTER: Mutex<u64> = Mutex::new(0);

0 commit comments

Comments
 (0)