Skip to content

Commit 5632d3b

Browse files
dmakarovLucasSte
authored andcommitted
[SOL] Adjust SBF customization after upgrading to rust 1.72.0
1 parent 5e06016 commit 5632d3b

File tree

20 files changed

+81
-346
lines changed

20 files changed

+81
-346
lines changed

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ pub(crate) unsafe fn codegen(
8181
let llval = llvm::LLVMConstInt(i8, val as u64, False);
8282
llvm::set_initializer(ll_g, llval);
8383

84-
// __rust_no_alloc_shim_is_unstable_v2
85-
create_wrapper_function(
86-
tcx,
87-
&cx,
88-
&mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
89-
None,
90-
&[],
91-
None,
92-
false,
93-
);
84+
if tcx.sess.target.arch != "sbf" {
85+
// __rust_no_alloc_shim_is_unstable_v2
86+
create_wrapper_function(
87+
tcx,
88+
&cx,
89+
&mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
90+
None,
91+
&[],
92+
None,
93+
false,
94+
);
95+
}
9496
}
9597

9698
if tcx.sess.opts.debuginfo != DebugInfo::None {

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ fn patch_synthetic_object_file(sess: &Session, path: &PathBuf) {
20782078
sf.write(&EM_SBF).unwrap();
20792079
}
20802080
} else {
2081-
sess.fatal(&format!("failed to patch {}", path.display()));
2081+
sess.fatal(format!("failed to patch {}", path.display()));
20822082
}
20832083
}
20842084

config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ experimental-targets = "BPF;SBF"
7474
# each linker process.
7575
# If absent or 0, linker invocations are treated like any other job and
7676
# controlled by rustbuild's -j parameter.
77-
#link-jobs = 0
77+
link-jobs = 2
7878

7979
# When invoking `llvm-config` this configures whether the `--shared` argument is
8080
# passed to prefer linking to shared libraries.

library/alloc/src/alloc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ unsafe extern "Rust" {
3131
#[rustc_std_internal_symbol]
3232
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
3333

34+
<<<<<<< HEAD
3435
#[rustc_nounwind]
3536
#[rustc_std_internal_symbol]
3637
fn __rust_no_alloc_shim_is_unstable_v2();
38+
=======
39+
#[cfg(not(target_family = "solana"))]
40+
static __rust_no_alloc_shim_is_unstable: u8;
41+
>>>>>>> 29896c3591c ([SOL] Adjust SBF customization after upgrading to rust 1.72.0)
3742
}
3843

3944
/// The global memory allocator.
@@ -89,7 +94,12 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
8994
unsafe {
9095
// Make sure we don't accidentally allow omitting the allocator shim in
9196
// stable code until it is actually stabilized.
97+
<<<<<<< HEAD
9298
__rust_no_alloc_shim_is_unstable_v2();
99+
=======
100+
#[cfg(not(target_family = "solana"))]
101+
core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable);
102+
>>>>>>> 29896c3591c ([SOL] Adjust SBF customization after upgrading to rust 1.72.0)
93103

94104
__rust_alloc(layout.size(), layout.align())
95105
}

library/std/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ crate-type = ["dylib", "rlib"]
1515
[dependencies]
1616
alloc = { path = "../alloc", public = true }
1717
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
18+
panic_unwind = { path = "../panic_unwind", optional = true }
1819
panic_abort = { path = "../panic_abort" }
1920
core = { path = "../core", public = true }
2021
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }

library/std/src/io/stdio.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ impl Read for Stdin {
525525
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
526526
Ok(0)
527527
}
528+
fn read_buf(&mut self, _buf: BorrowedCursor<'_>) -> io::Result<()> {
529+
Ok(())
530+
}
528531
fn read_vectored(&mut self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
529532
Ok(0)
530533
}

library/std/src/panicking.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ pub mod panic_count {
494494
})
495495
}
496496

497+
#[cfg(not(target_family = "solana"))]
497498
pub fn finished_panic_hook() {
498499
LOCAL_PANIC_COUNT.with(|c| {
499500
let (count, _) = c.get();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use super::select::Selected;
44
use super::waker::current_thread_id;
5+
6+
#[cfg(not(target_family = "solana"))]
57
use crate::cell::Cell;
68
use crate::ptr;
79
use crate::sync::Arc;
@@ -33,6 +35,7 @@ struct Inner {
3335

3436
impl Context {
3537
/// Creates a new context for the duration of the closure.
38+
#[cfg(not(target_family = "solana"))]
3639
#[inline]
3740
pub fn with<F, R>(f: F) -> R
3841
where
@@ -62,6 +65,15 @@ impl Context {
6265
.unwrap_or_else(|_| f(&Context::new()))
6366
}
6467

68+
#[cfg(target_family = "solana")]
69+
#[inline]
70+
pub fn with<F, R>(f: F) -> R
71+
where
72+
F: FnOnce(&Context) -> R,
73+
{
74+
f(&Context::new())
75+
}
76+
6577
/// Creates a new `Context`.
6678
#[cold]
6779
fn new() -> Context {
@@ -76,6 +88,7 @@ impl Context {
7688
}
7789

7890
/// Resets `select` and `packet`.
91+
#[cfg(not(target_family = "solana"))]
7992
#[inline]
8093
fn reset(&self) {
8194
self.inner.select.store(Selected::Waiting.into(), Ordering::Release);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,18 @@ impl Drop for SyncWaker {
200200
}
201201

202202
/// Returns a unique id for the current thread.
203+
#[cfg(not(target_family = "solana"))]
203204
#[inline]
204205
pub fn current_thread_id() -> usize {
205206
// `u8` is not drop so this variable will be available during thread destruction,
206207
// whereas `thread::current()` would not be
207208
thread_local! { static DUMMY: u8 = const { 0 } }
208209
DUMMY.with(|x| (x as *const u8).addr())
209210
}
211+
212+
/// Returns a unique id for the current thread.
213+
#[cfg(target_family = "solana")]
214+
#[inline]
215+
pub fn current_thread_id() -> usize {
216+
0
217+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![unstable(feature = "thread_local_internals", issue = "none")]
2+
3+
// unused on solana and wasm32-unknown-unknown
4+
#[cfg_attr(any(target_family = "solana", target_family = "wasm"), allow(unused))]
5+
pub unsafe fn register_dtor(_t: *mut u8, _dtor: unsafe extern "C" fn(*mut u8)) {
6+
// FIXME: right now there is no concept of "thread exit", but this is likely
7+
// going to show up at some point in the form of an exported symbol that the
8+
// wasm runtime is going to be expected to call. For now we basically just
9+
// ignore the arguments, but if such a function starts to exist it will
10+
// likely look like the OSX implementation in `unix/fast_thread_local.rs`
11+
}

0 commit comments

Comments
 (0)