Skip to content

Commit a3e5c78

Browse files
dmakarovLucasSte
authored andcommitted
[SOL] Adjust BPF customization after upgrading to rust 1.62.0
1 parent 8f68080 commit a3e5c78

File tree

20 files changed

+112
-310
lines changed

20 files changed

+112
-310
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl<'a> GccLinker<'a> {
449449
} else {
450450
self.linker_arg("--entry=entrypoint");
451451
}
452-
if self.sess.opts.cg.target_cpu.as_ref().unwrap_or(&self.sess.target.cpu) == "sbfv2"
452+
if self.sess.opts.cg.target_cpu.as_ref().unwrap_or(&self.sess.target.cpu.as_ref().to_string()) == "sbfv2"
453453
{
454454
self.linker_arg("--section-start=.text=0x100000000");
455455
self.linker_arg("--pack-dyn-relocs=relr");

compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::spec::sbf_base;
33

44
pub fn target() -> Target {
55
Target {
6-
llvm_target: "bpfel".to_string(),
6+
llvm_target: "bpfel".into(),
77
pointer_width: 64,
8-
arch: "bpf".to_string(),
9-
data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(),
8+
arch: "bpf".into(),
9+
data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".into(),
1010
options: sbf_base::opts(),
1111
}
1212
}

compiler/rustc_target/src/spec/sbf_base.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::abi::Endian;
2-
use super::{LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor};
3-
use std::{collections::BTreeMap};
2+
use super::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor};
43

54
pub fn opts() -> TargetOptions {
65
let linker_script = r"
@@ -30,38 +29,38 @@ SECTIONS
3029
}
3130
";
3231
let mut lld_args = Vec::new();
33-
lld_args.push("--threads=1".to_string());
34-
lld_args.push("-z".to_string());
35-
lld_args.push("notext".to_string());
36-
let mut pre_link_args = BTreeMap::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();
3736
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args);
3837

3938
TargetOptions {
4039
allow_asm: true,
41-
c_int_width: "64".to_string(),
42-
dll_prefix: "".to_string(),
40+
c_int_width: "64".into(),
41+
dll_prefix: "".into(),
4342
dynamic_linking: true,
4443
eh_frame_header: false,
4544
emit_debug_gdb_scripts: false,
4645
endian: Endian::Little,
47-
env: String::new(),
46+
env: "".into(),
4847
executables: true,
49-
features: "+solana".to_string(),
50-
link_script: Some(linker_script.to_string()),
51-
linker: Some("rust-lld".to_owned()),
48+
features: "+solana".into(),
49+
link_script: Some(linker_script.into()),
50+
linker: Some("rust-lld".into()),
5251
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
5352
linker_is_gnu: true,
5453
main_needs_argc_argv: false,
5554
max_atomic_width: Some(64),
5655
no_default_libraries: true,
5756
only_cdylib: true,
58-
os: "solana".to_string(),
57+
os: "solana".into(),
5958
panic_strategy: PanicStrategy::Abort,
6059
position_independent_executables: true,
6160
pre_link_args,
6261
requires_lto: false,
6362
singlethread: true,
64-
vendor: "solana".to_string(),
63+
vendor: "solana".into(),
6564
.. Default::default()
6665
}
6766
}

compiler/rustc_target/src/spec/sbf_solana_solana.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::spec::sbf_base;
33

44
pub fn target() -> Target {
55
Target {
6-
llvm_target: "sbf".to_string(),
6+
llvm_target: "sbf".into(),
77
pointer_width: 64,
8-
arch: "sbf".to_string(),
9-
data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(),
8+
arch: "sbf".into(),
9+
data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".into(),
1010
options: sbf_base::opts(),
1111
}
1212
}

library/core/benches/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// wasm32 does not support benches (no time).
2-
#![cfg(not(target_arch = "wasm32"))]
32
// Disabling in Miri as these would take too long.
43
#![cfg(not(miri))]
4+
#![cfg(not(any(target_arch = "wasm32", target_arch = "bpf", target_arch = "sbf")))]
55
#![feature(flt2dec)]
66
#![feature(test)]
77
#![feature(trusted_random_access)]

library/std/src/io/stdio.rs

Lines changed: 5 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::panic::{RefUnwindSafe, UnwindSafe};
1313
#[cfg(not(target_os = "solana"))]
1414
use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines, SpecReadByte};
1515
#[cfg(target_os = "solana")]
16-
use crate::io::{self, BufReader, IoSlice, IoSliceMut};
16+
use crate::io::{self, BufReader, IoSlice, IoSliceMut, LineWriter, Lines};
1717
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
1818
use crate::sync::atomic::{AtomicBool, Ordering};
1919
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
@@ -357,49 +357,6 @@ pub fn stdin() -> Stdin {
357357
Stdin {}
358358
}
359359

360-
/// Constructs a new locked handle to the standard input of the current
361-
/// process.
362-
///
363-
/// Each handle returned is a guard granting locked access to a shared
364-
/// global buffer whose access is synchronized via a mutex. If you need
365-
/// more explicit control over locking, for example, in a multi-threaded
366-
/// program, use the [`io::stdin`] function to obtain an unlocked handle,
367-
/// along with the [`Stdin::lock`] method.
368-
///
369-
/// The lock is released when the returned guard goes out of scope. The
370-
/// returned guard also implements the [`Read`] and [`BufRead`] traits for
371-
/// accessing the underlying data.
372-
///
373-
/// **Note**: The mutex locked by this handle is not reentrant. Even in a
374-
/// single-threaded program, calling other code that accesses [`Stdin`]
375-
/// could cause a deadlock or panic, if this locked handle is held across
376-
/// that call.
377-
///
378-
/// ### Note: Windows Portability Consideration
379-
/// When operating in a console, the Windows implementation of this stream does not support
380-
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
381-
/// an error.
382-
///
383-
/// # Examples
384-
///
385-
/// ```no_run
386-
/// #![feature(stdio_locked)]
387-
/// use std::io::{self, BufRead};
388-
///
389-
/// fn main() -> io::Result<()> {
390-
/// let mut buffer = String::new();
391-
/// let mut handle = io::stdin_locked();
392-
///
393-
/// handle.read_line(&mut buffer)?;
394-
/// Ok(())
395-
/// }
396-
/// ```
397-
#[unstable(feature = "stdio_locked", issue = "86845")]
398-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
399-
pub fn stdin_locked() -> StdinLock<'static> {
400-
stdin().into_locked()
401-
}
402-
403360
impl Stdin {
404361
/// Locks this handle to the standard input stream, returning a readable
405362
/// guard.
@@ -423,7 +380,7 @@ impl Stdin {
423380
/// }
424381
/// ```
425382
#[stable(feature = "rust1", since = "1.0.0")]
426-
#[cfg(not(target_os = "solana"))]
383+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
427384
pub fn lock(&self) -> StdinLock<'static> {
428385
// Locks this handle with 'static lifetime. This depends on the
429386
// implementation detail that the underlying `Mutex` is static.
@@ -468,45 +425,6 @@ impl Stdin {
468425
self.lock().read_line(buf)
469426
}
470427

471-
// Locks this handle with any lifetime. This depends on the
472-
// implementation detail that the underlying `Mutex` is static.
473-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
474-
fn lock_any<'a>(&self) -> StdinLock<'a> {
475-
StdinLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) }
476-
}
477-
478-
/// Consumes this handle to the standard input stream, locking the
479-
/// shared global buffer associated with the stream and returning a
480-
/// readable guard.
481-
///
482-
/// The lock is released when the returned guard goes out of scope. The
483-
/// returned guard also implements the [`Read`] and [`BufRead`] traits
484-
/// for accessing the underlying data.
485-
///
486-
/// It is often simpler to directly get a locked handle using the
487-
/// [`stdin_locked`] function instead, unless nearby code also needs to
488-
/// use an unlocked handle.
489-
///
490-
/// # Examples
491-
///
492-
/// ```no_run
493-
/// #![feature(stdio_locked)]
494-
/// use std::io::{self, BufRead};
495-
///
496-
/// fn main() -> io::Result<()> {
497-
/// let mut buffer = String::new();
498-
/// let mut handle = io::stdin().into_locked();
499-
///
500-
/// handle.read_line(&mut buffer)?;
501-
/// Ok(())
502-
/// }
503-
/// ```
504-
#[unstable(feature = "stdio_locked", issue = "86845")]
505-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
506-
pub fn into_locked(self) -> StdinLock<'static> {
507-
self.lock_any()
508-
}
509-
510428
/// Consumes this handle and returns an iterator over input lines.
511429
///
512430
/// For detailed semantics of this method, see the documentation on
@@ -524,34 +442,10 @@ impl Stdin {
524442
/// ```
525443
#[must_use = "`self` will be dropped if the result is not used"]
526444
#[stable(feature = "stdin_forwarders", since = "1.62.0")]
527-
#[cfg(not(target_os = "solana"))]
445+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
528446
pub fn lines(self) -> Lines<StdinLock<'static>> {
529447
self.lock().lines()
530448
}
531-
532-
/// Consumes this handle and returns an iterator over input bytes,
533-
/// split at the specified byte value.
534-
///
535-
/// For detailed semantics of this method, see the documentation on
536-
/// [`BufRead::split`].
537-
///
538-
/// # Examples
539-
///
540-
/// ```no_run
541-
/// #![feature(stdin_forwarders)]
542-
/// use std::io;
543-
///
544-
/// let splits = io::stdin().split(b'-');
545-
/// for split in splits {
546-
/// println!("got a chunk: {}", String::from_utf8_lossy(&split.unwrap()));
547-
/// }
548-
/// ```
549-
#[must_use = "`self` will be dropped if the result is not used"]
550-
#[unstable(feature = "stdin_forwarders", issue = "87096")]
551-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
552-
pub fn split(self, byte: u8) -> Split<StdinLock<'static>> {
553-
self.into_locked().split(byte)
554-
}
555449
}
556450

557451
#[stable(feature = "std_debug", since = "1.16.0")]
@@ -891,52 +785,13 @@ impl Stdout {
891785
/// }
892786
/// ```
893787
#[stable(feature = "rust1", since = "1.0.0")]
894-
#[cfg(not(target_os = "solana"))]
788+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
895789
pub fn lock(&self) -> StdoutLock<'static> {
896790
// Locks this handle with 'static lifetime. This depends on the
897791
// implementation detail that the underlying `ReentrantMutex` is
898792
// static.
899793
StdoutLock { inner: self.inner.lock() }
900794
}
901-
902-
// Locks this handle with any lifetime. This depends on the
903-
// implementation detail that the underlying `ReentrantMutex` is
904-
// static.
905-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
906-
fn lock_any<'a>(&self) -> StdoutLock<'a> {
907-
StdoutLock { inner: self.inner.lock() }
908-
}
909-
910-
/// Consumes this handle to the standard output stream, locking the
911-
/// shared global buffer associated with the stream and returning a
912-
/// writable guard.
913-
///
914-
/// The lock is released when the returned lock goes out of scope. The
915-
/// returned guard also implements the [`Write`] trait for writing data.
916-
///
917-
/// It is often simpler to directly get a locked handle using the
918-
/// [`io::stdout_locked`] function instead, unless nearby code also
919-
/// needs to use an unlocked handle.
920-
///
921-
/// # Examples
922-
///
923-
/// ```no_run
924-
/// #![feature(stdio_locked)]
925-
/// use std::io::{self, Write};
926-
///
927-
/// fn main() -> io::Result<()> {
928-
/// let mut handle = io::stdout().into_locked();
929-
///
930-
/// handle.write_all(b"hello world")?;
931-
///
932-
/// Ok(())
933-
/// }
934-
/// ```
935-
#[unstable(feature = "stdio_locked", issue = "86845")]
936-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
937-
pub fn into_locked(self) -> StdoutLock<'static> {
938-
self.lock_any()
939-
}
940795
}
941796

942797
#[stable(feature = "catch_unwind", since = "1.9.0")]
@@ -1198,36 +1053,6 @@ pub fn stderr() -> Stderr {
11981053
Stderr {}
11991054
}
12001055

1201-
/// Constructs a new locked handle to the standard error of the current
1202-
/// process.
1203-
///
1204-
/// This handle is not buffered.
1205-
///
1206-
/// ### Note: Windows Portability Consideration
1207-
/// When operating in a console, the Windows implementation of this stream does not support
1208-
/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
1209-
/// an error.
1210-
///
1211-
/// # Example
1212-
///
1213-
/// ```no_run
1214-
/// #![feature(stdio_locked)]
1215-
/// use std::io::{self, Write};
1216-
///
1217-
/// fn main() -> io::Result<()> {
1218-
/// let mut handle = io::stderr_locked();
1219-
///
1220-
/// handle.write_all(b"hello world")?;
1221-
///
1222-
/// Ok(())
1223-
/// }
1224-
/// ```
1225-
#[unstable(feature = "stdio_locked", issue = "86845")]
1226-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
1227-
pub fn stderr_locked() -> StderrLock<'static> {
1228-
stderr().into_locked()
1229-
}
1230-
12311056
impl Stderr {
12321057
/// Locks this handle to the standard error stream, returning a writable
12331058
/// guard.
@@ -1250,49 +1075,13 @@ impl Stderr {
12501075
/// }
12511076
/// ```
12521077
#[stable(feature = "rust1", since = "1.0.0")]
1253-
#[cfg(not(target_os = "solana"))]
1078+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
12541079
pub fn lock(&self) -> StderrLock<'static> {
12551080
// Locks this handle with 'static lifetime. This depends on the
12561081
// implementation detail that the underlying `ReentrantMutex` is
12571082
// static.
12581083
StderrLock { inner: self.inner.lock() }
12591084
}
1260-
1261-
// Locks this handle with any lifetime. This depends on the
1262-
// implementation detail that the underlying `ReentrantMutex` is
1263-
// static.
1264-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
1265-
fn lock_any<'a>(&self) -> StderrLock<'a> {
1266-
StderrLock { inner: self.inner.lock() }
1267-
}
1268-
1269-
/// Locks and consumes this handle to the standard error stream,
1270-
/// returning a writable guard.
1271-
///
1272-
/// The lock is released when the returned guard goes out of scope. The
1273-
/// returned guard also implements the [`Write`] trait for writing
1274-
/// data.
1275-
///
1276-
/// # Examples
1277-
///
1278-
/// ```
1279-
/// #![feature(stdio_locked)]
1280-
/// use std::io::{self, Write};
1281-
///
1282-
/// fn foo() -> io::Result<()> {
1283-
/// let stderr = io::stderr();
1284-
/// let mut handle = stderr.into_locked();
1285-
///
1286-
/// handle.write_all(b"hello world")?;
1287-
///
1288-
/// Ok(())
1289-
/// }
1290-
/// ```
1291-
#[unstable(feature = "stdio_locked", issue = "86845")]
1292-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
1293-
pub fn into_locked(self) -> StderrLock<'static> {
1294-
self.lock_any()
1295-
}
12961085
}
12971086

12981087
#[stable(feature = "catch_unwind", since = "1.9.0")]

0 commit comments

Comments
 (0)