From 98fbbc65bf1003de2856a89f8ddfec68083e3f24 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Fri, 2 Feb 2024 18:24:45 -0300 Subject: [PATCH] [SOL] Adjust compiler after upgrade to 1.75.0 --- .github/workflows/ci.yml | 10 ++++- Cargo.lock | 43 ++++++++++++------- Cargo.toml | 2 +- .../rustc_codegen_gcc/src/intrinsic/mod.rs | 3 +- compiler/rustc_codegen_ssa/src/base.rs | 3 +- compiler/rustc_target/src/spec/base/mod.rs | 1 + .../src/spec/{ => base}/sbf_base.rs | 2 +- .../{ => targets}/bpfel_unknown_unknown.rs | 2 +- .../spec/{ => targets}/sbf_solana_solana.rs | 2 +- library/alloc/src/alloc.rs | 2 +- library/std/src/backtrace.rs | 5 ++- library/std/src/panicking.rs | 7 +-- library/std/src/sys/sbf/cmath.rs | 4 ++ library/std/src/sys/sbf/mod.rs | 5 +++ library/std/src/sys/sbf/os.rs | 7 +++ src/bootstrap/Cargo.toml | 2 +- src/bootstrap/src/lib.rs | 11 ----- src/bootstrap/src/utils/cc_detect.rs | 9 ---- src/llvm-project | 2 +- src/tools/tidy/src/extdeps.rs | 2 +- 20 files changed, 71 insertions(+), 53 deletions(-) rename compiler/rustc_target/src/spec/{ => base}/sbf_base.rs (95%) rename compiler/rustc_target/src/spec/{ => targets}/bpfel_unknown_unknown.rs (88%) rename compiler/rustc_target/src/spec/{ => targets}/sbf_solana_solana.rs (88%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f24253c17dc0b..4db0b6c6da44e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -208,7 +208,7 @@ jobs: - name: disable git crlf conversion run: git config --global core.autocrlf false - name: checkout the source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: configure the PR in which the error message will be posted @@ -230,6 +230,9 @@ jobs: - name: show the current environment run: src/ci/scripts/dump-environment.sh if: success() && !env.SKIP_JOB + - name: install awscli + run: src/ci/scripts/install-awscli.sh + if: success() && !env.SKIP_JOB - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB @@ -239,6 +242,9 @@ jobs: - name: install clang run: src/ci/scripts/install-clang.sh if: success() && !env.SKIP_JOB + - name: install tidy + run: src/ci/scripts/install-tidy.sh + if: success() && !env.SKIP_JOB - name: install WIX run: src/ci/scripts/install-wix.sh if: success() && !env.SKIP_JOB @@ -431,7 +437,7 @@ jobs: - name: x86_64-gnu-llvm-17 env: RUST_BACKTRACE: 1 - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest - name: x86_64-gnu-llvm-16 env: RUST_BACKTRACE: 1 diff --git a/Cargo.lock b/Cargo.lock index 9a8935920b745..6685003391945 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -723,8 +723,7 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335" [[package]] name = "compiler_builtins" version = "0.1.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b73c3443a5fd2438d7ba4853c64e4c8efc2404a9e28a9234cc2d5eebc6c242" +source = "git+https://github.com/LucasSte/compiler-builtins?tag=solana-tools-v1.40#81ef46f3fe1357095acdd089a700890fe4e13974" dependencies = [ "cc", "rustc-std-workspace-core", @@ -781,8 +780,8 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" name = "core" version = "0.0.0" dependencies = [ - "getrandom 0.1.14", - "rand 0.7.3", + "getrandom 0.1.16", + "rand", "rand_xorshift", ] @@ -1592,6 +1591,17 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -1600,7 +1610,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -2524,7 +2534,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -2545,7 +2555,7 @@ dependencies = [ "colored", "ctrlc", "env_logger 0.10.0", - "getrandom", + "getrandom 0.2.10", "lazy_static", "libc", "libffi", @@ -3176,7 +3186,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] @@ -3241,7 +3251,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom", + "getrandom 0.2.10", "redox_syscall 0.2.16", "thiserror", ] @@ -5138,7 +5148,7 @@ dependencies = [ "rustc-demangle", "std_detect", "unwind", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -5964,7 +5974,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] @@ -6004,6 +6014,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -6439,8 +6455,3 @@ dependencies = [ "crossbeam-utils", "flate2", ] - -[[patch.unused]] -name = "compiler_builtins" -version = "0.1.76" -source = "git+https://github.com/solana-labs/compiler-builtins#2044d7e16a99d951853ce362e384027dec4c5b92" diff --git a/Cargo.toml b/Cargo.toml index c735a5b648c8f..72e4ca6d28a89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ miniz_oxide.debug = 0 object.debug = 0 [patch.crates-io] -compiler_builtins = { git = "https://github.com/solana-labs/compiler-builtins" } +compiler_builtins = { git = "https://github.com/LucasSte/compiler-builtins", tag = "solana-tools-v1.40" } # See comments in `library/rustc-std-workspace-core/README.md` for what's going on # here rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs index ba1cae03f3e41..0324e206b463e 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs @@ -14,7 +14,8 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::{ArgAbiMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods}; #[cfg(feature="master")] -use rustc_codegen_ssa::traits::{BaseTypeMethods, MiscMethods}; +use rustc_codegen_ssa::traits::MiscMethods; +use rustc_codegen_ssa::traits::BaseTypeMethods; use rustc_codegen_ssa::errors::InvalidMonomorphization; use rustc_middle::bug; use rustc_middle::ty::{self, Instance, Ty}; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 9ab953ba10b48..198e5696357af 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -422,7 +422,6 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( ) -> Bx::Function { // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, or // `usize efi_main(void *handle, void *system_table)` depending on the target. - let is_bpf = cx.sess().target.arch == "bpf" && cx.sess().opts.test; let llfty = if cx.sess().target.os.contains("uefi") { cx.type_func(&[cx.type_ptr(), cx.type_ptr()], cx.type_isize()) } else if cx.sess().target.main_needs_argc_argv { @@ -487,7 +486,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( (rust_main, start_ty, vec![arg_argc, arg_argv]) }; - let result = bx.call(start_ty, None, start_fn, &args, None); + let result = bx.call(start_ty, None, None, start_fn, &args, None); if cx.sess().target.os.contains("uefi") { bx.ret(result); } else { diff --git a/compiler/rustc_target/src/spec/base/mod.rs b/compiler/rustc_target/src/spec/base/mod.rs index d137aaa535858..77e97ea58967d 100644 --- a/compiler/rustc_target/src/spec/base/mod.rs +++ b/compiler/rustc_target/src/spec/base/mod.rs @@ -22,6 +22,7 @@ pub(crate) mod netbsd; pub(crate) mod nto_qnx; pub(crate) mod openbsd; pub(crate) mod redox; +pub(crate) mod sbf_base; pub(crate) mod solaris; pub(crate) mod solid; pub(crate) mod teeos; diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/base/sbf_base.rs similarity index 95% rename from compiler/rustc_target/src/spec/sbf_base.rs rename to compiler/rustc_target/src/spec/base/sbf_base.rs index d6248b9e30f4a..50ffc6c883fc7 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/base/sbf_base.rs @@ -1,5 +1,5 @@ use crate::abi::Endian; -use super::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, TargetOptions}; +use crate::spec::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, TargetOptions}; pub fn opts() -> TargetOptions { let linker_script = r" diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/targets/bpfel_unknown_unknown.rs similarity index 88% rename from compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs rename to compiler/rustc_target/src/spec/targets/bpfel_unknown_unknown.rs index b4df123cfc2b9..6d28df29e797b 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/targets/bpfel_unknown_unknown.rs @@ -1,5 +1,5 @@ use crate::spec::Target; -use crate::spec::sbf_base; +use crate::spec::base::sbf_base; pub fn target() -> Target { Target { diff --git a/compiler/rustc_target/src/spec/sbf_solana_solana.rs b/compiler/rustc_target/src/spec/targets/sbf_solana_solana.rs similarity index 88% rename from compiler/rustc_target/src/spec/sbf_solana_solana.rs rename to compiler/rustc_target/src/spec/targets/sbf_solana_solana.rs index a4adf32b7544e..534b4f911257d 100644 --- a/compiler/rustc_target/src/spec/sbf_solana_solana.rs +++ b/compiler/rustc_target/src/spec/targets/sbf_solana_solana.rs @@ -1,5 +1,5 @@ use crate::spec::Target; -use crate::spec::sbf_base; +use crate::spec::base::sbf_base; pub fn target() -> Target { Target { diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index e73540a51ebb9..bdb2cc4f714b7 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -430,7 +430,7 @@ pub mod __alloc_error_handler { pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! { core::panicking::panic_nounwind_fmt(format_args!( "memory allocation of {size} bytes failed" - )) + ), /* force_no_backtrace */ false) } } diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 7a2f54feab832..9f9dc58b4a886 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -96,6 +96,8 @@ use crate::env; use crate::ffi::c_void; use crate::fmt; #[cfg(not(target_family = "solana"))] +use crate::panic::UnwindSafe; +#[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicUsize, Ordering::Relaxed}; #[cfg(not(target_family = "solana"))] use crate::sync::LazyLock; @@ -485,9 +487,10 @@ impl fmt::Display for Backtrace { } } - +#[cfg(not(target_family = "solana"))] type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; +#[cfg(not(target_family = "solana"))] fn lazy_resolve(mut capture: Capture) -> LazyResolve { move || { // Use the global backtrace lock to synchronize this as it's a diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 65abea4ca4642..3e3c871ad7f58 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -11,7 +11,7 @@ #[cfg(not(target_family = "solana"))] use crate::panic::BacktraceStyle; -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] use core::panic::{PanicPayload}; use core::panic::{Location, PanicInfo}; @@ -521,14 +521,12 @@ pub use realstd::rt::panic_count; /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. #[cfg(feature = "panic_immediate_abort")] -#[cfg(not(target_arch = "bpf"))] pub unsafe fn r#try R>(f: F) -> Result> { Ok(f()) } /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. #[cfg(not(feature = "panic_immediate_abort"))] -#[cfg(not(target_arch = "bpf"))] pub unsafe fn r#try R>(f: F) -> Result> { union Data { f: ManuallyDrop, @@ -915,6 +913,7 @@ fn rust_panic(_: &mut dyn PanicPayload) -> ! { unsafe { crate::intrinsics::abort(); } +} // Note: The panicking functions have been stripped and rewritten // in order to save space in SBF programs. Panic messages @@ -956,6 +955,7 @@ pub fn begin_panic(_msg: M) -> ! { None, Location::caller(), false, + false, ); crate::sys::panic(&info); } @@ -974,6 +974,7 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { Some(msg), Location::caller(), false, + false, ); crate::sys::panic(&info); } diff --git a/library/std/src/sys/sbf/cmath.rs b/library/std/src/sys/sbf/cmath.rs index fa7783122c2e9..d8ef962c1ac20 100644 --- a/library/std/src/sys/sbf/cmath.rs +++ b/library/std/src/sys/sbf/cmath.rs @@ -26,4 +26,8 @@ extern { pub fn tanf(n: f32) -> f32; pub fn tanh(n: f64) -> f64; pub fn tanhf(n: f32) -> f32; + pub fn tgamma(n: f64) -> f64; + pub fn tgammaf(n: f32) -> f32; + pub fn lgamma_r(n: f64, s: &mut i32) -> f64; + pub fn lgammaf_r(n: f32, s: &mut i32) -> f32; } diff --git a/library/std/src/sys/sbf/mod.rs b/library/std/src/sys/sbf/mod.rs index 1baf6ff5470cb..e9279d94d2382 100644 --- a/library/std/src/sys/sbf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -120,3 +120,8 @@ pub fn abort_internal() -> ! { pub fn hashmap_random_keys() -> (u64, u64) { (1, 2) } + +#[inline] +pub fn is_interrupted(_errno: i32) -> bool { + false +} diff --git a/library/std/src/sys/sbf/os.rs b/library/std/src/sys/sbf/os.rs index 19190b24060a0..c54c53d90442d 100644 --- a/library/std/src/sys/sbf/os.rs +++ b/library/std/src/sys/sbf/os.rs @@ -61,6 +61,7 @@ pub fn current_exe() -> io::Result { unsupported() } +#[derive(Debug)] pub struct Env(Void); impl Iterator for Env { @@ -70,6 +71,12 @@ impl Iterator for Env { } } +impl Env { + pub fn str_debug(&self) -> impl fmt::Debug + '_ { + [OsString::new(), OsString::new()] + } +} + pub fn env() -> Env { panic!(); } diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index b1a21dff79525..e4d359141cec1 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -24,7 +24,7 @@ test = false [[bin]] name = "rustdoc" -path = "bin/rustdoc.rs" +path = "src/bin/rustdoc.rs" test = false [[bin]] diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 62648218d4458..1d01c205c08df 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -848,17 +848,6 @@ impl Build { } } - /// Returns the path to llvm/bin - fn llvm_bin(&self, target: TargetSelection) -> PathBuf { - let target_config = self.config.target_config.get(&target); - if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { - let llvm_bindir = output(Command::new(s).arg("--bindir")); - PathBuf::from(llvm_bindir.trim()) - } else { - self.llvm_out(self.config.build).join("bin") - } - } - /// Returns the path to `FileCheck` binary for the specified target fn llvm_filecheck(&self, target: TargetSelection) -> PathBuf { let target_config = self.config.target_config.get(&target); diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 44621d61af3c5..985aabda0afda 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -138,9 +138,6 @@ pub fn find_target(build: &Build, target: TargetSelection) { { cfg.compiler(cxx); true - } else if &*target.triple == "sbf-solana-solana" || &*target.triple == "bpfel-unknown-unknown" { - set_compiler(&mut cfg, Language::CPlusPlus, target, config, build); - true } else { // Use an auto-detected compiler (or one configured via `CXX_target_triple` env vars). cfg.try_get_compiler().is_ok() @@ -222,12 +219,6 @@ fn default_compiler( None } } - "bpfel-unknown-unknown" => { - cfg.compiler(build.llvm_bin(target).join(compiler.clang())); - } - "sbf-solana-solana" => { - cfg.compiler(build.llvm_bin(target).join(compiler.clang())); - } t if t.contains("musl") && compiler == Language::C => { if let Some(root) = build.musl_root(target) { diff --git a/src/llvm-project b/src/llvm-project index 2c4de6c2492d5..216ab27eb91c5 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 2c4de6c2492d5530de3f19f41d8f88ba984c2fe2 +Subproject commit 216ab27eb91c543d2fd9520c21207932d7a1ed90 diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 6b4792018dea8..09830a73a6dd9 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -5,7 +5,7 @@ use std::path::Path; /// List of allowed sources for packages. const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\"", -"\"git+https://github.com/solana-labs/compiler-builtins?tag=bpf-tools-v1.7#875087b410b77e0561b653882b431c84515eb044\""]; +"\"git+https://github.com/LucasSte/compiler-builtins?tag=solana-tools-v1.40#81ef46f3fe1357095acdd089a700890fe4e13974\""]; /// Checks for external package sources. `root` is the path to the directory that contains the /// workspace `Cargo.toml`.