From 621be609b5b54b818e8b496023a10784ea9cbb8a Mon Sep 17 00:00:00 2001 From: Seth Pellegrino Date: Tue, 23 May 2023 15:08:23 -0700 Subject: [PATCH 01/17] feat: `riscv-interrupt-{m,s}` calling conventions Similar to prior support added for the mips430, avr, and x86 targets this change implements the rough equivalent of clang's [`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling e.g. ```rust static mut CNT: usize = 0; pub extern "riscv-interrupt-m" fn isr_m() { unsafe { CNT += 1; } } ``` to produce highly effective assembly like: ```asm pub extern "riscv-interrupt-m" fn isr_m() { 420003a0: 1141 addi sp,sp,-16 unsafe { CNT += 1; 420003a2: c62a sw a0,12(sp) 420003a4: c42e sw a1,8(sp) 420003a6: 3fc80537 lui a0,0x3fc80 420003aa: 63c52583 lw a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0> 420003ae: 0585 addi a1,a1,1 420003b0: 62b52e23 sw a1,1596(a0) } } 420003b4: 4532 lw a0,12(sp) 420003b6: 45a2 lw a1,8(sp) 420003b8: 0141 addi sp,sp,16 420003ba: 30200073 mret ``` (disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`) This outcome is superior to hand-coded interrupt routines which, lacking visibility into any non-assembly body of the interrupt handler, have to be very conservative and save the [entire CPU state to the stack frame][full-frame-save]. By instead asking LLVM to only save the registers that it uses, we defer the decision to the tool with the best context: it can more accurately account for the cost of spills if it knows that every additional register used is already at the cost of an implicit spill. At the LLVM level, this is apparently [implemented by] marking every register as "[callee-save]," matching the semantics of an interrupt handler nicely (it has to leave the CPU state just as it found it after its `{m|s}ret`). This approach is not suitable for every interrupt handler, as it makes no attempt to e.g. save the state in a user-accessible stack frame. For a full discussion of those challenges and tradeoffs, please refer to [the interrupt calling conventions RFC][rfc]. Inside rustc, this implementation differs from prior art because LLVM does not expose the "all-saved" function flavor as a calling convention directly, instead preferring to use an attribute that allows for differentiating between "machine-mode" and "superivsor-mode" interrupts. Finally, some effort has been made to guide those who may not yet be aware of the differences between machine-mode and supervisor-mode interrupts as to why no `riscv-interrupt` calling convention is exposed through rustc, and similarly for why `riscv-interrupt-u` makes no appearance (as it would complicate future LLVM upgrades). [clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v [full-frame-save]: https://github.com/esp-rs/esp-riscv-rt/blob/9281af2ecffe13e40992917316f36920c26acaf3/src/lib.rs#L440-L469 [implemented by]: https://github.com/llvm/llvm-project/blob/b7fb2a3fec7c187d58a6d338ab512d9173bca987/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L61-L67 [callee-save]: https://github.com/llvm/llvm-project/blob/973f1fe7a8591c7af148e573491ab68cc15b6ecf/llvm/lib/Target/RISCV/RISCVCallingConv.td#L30-L37 [rfc]: https://github.com/rust-lang/rfcs/pull/3246 --- src/abi/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 2c038f22ca9..b7f56a2986c 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -48,7 +48,9 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call default_call_conv } - Conv::X86Intr => sess.fatal("x86-interrupt call conv not yet implemented"), + Conv::X86Intr | Conv::RiscvInterrupt { .. } => { + sess.fatal(format!("interrupt call conv {c:?} not yet implemented")) + } Conv::ArmAapcs => sess.fatal("aapcs call conv not yet implemented"), Conv::CCmseNonSecureCall => { From b1072412189eb27934ada08a13805fc5d3ce8f25 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 8 Aug 2023 18:28:20 +0800 Subject: [PATCH 02/17] rustc: Move `crate_types` from `Session` to `GlobalCtxt` Removes a piece of mutable state. Follow up to #114578. --- src/driver/jit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 3ea38842148..1c606494f38 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -98,7 +98,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { tcx.sess.fatal("JIT mode doesn't work with `cargo check`"); } - if !tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable) { + if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) { tcx.sess.fatal("can't jit non-executable crate"); } From 59cabd70321e9dd7a9b8d670d28cc3c4a70d4337 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:20:12 +0000 Subject: [PATCH 03/17] Merge commit '8f9ac9c22d6594cf059d8e6c71d414cc5ccd7975' into sync_cg_clif-2023-08-09 --- .github/workflows/audit.yml | 19 ++++++ build_system/abi_cafe.rs | 10 +-- build_system/bench.rs | 8 +-- build_system/build_backend.rs | 16 ++--- build_system/build_sysroot.rs | 35 ++++++----- build_system/main.rs | 5 +- build_system/path.rs | 2 +- build_system/prepare.rs | 14 ++--- build_system/shared_utils.rs | 26 ++++++++ build_system/tests.rs | 36 +++++------ build_system/usage.txt | 2 +- build_system/utils.rs | 19 +++--- example/mini_core.rs | 2 +- example/mini_core_hello_world.rs | 2 +- ...ortable-simd-Allow-internal-features.patch | 24 +++++++ patches/stdlib-lock.toml | 4 +- rust-toolchain | 2 +- scripts/cargo-clif.rs | 63 ++++++++++--------- scripts/test_rustc_tests.sh | 8 ++- src/lib.rs | 7 +++ 20 files changed, 194 insertions(+), 110 deletions(-) create mode 100644 .github/workflows/audit.yml create mode 100644 build_system/shared_utils.rs create mode 100644 patches/0001-portable-simd-Allow-internal-features.patch diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 00000000000..3efdec41559 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,19 @@ +name: Security audit +on: + workflow_dispatch: + schedule: + - cron: '0 10 * * 1' # every monday at 10:00 UTC +permissions: + issues: write + checks: write +jobs: + audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: | + sed -i 's/components.*/components = []/' rust-toolchain + echo 'profile = "minimal"' >> rust-toolchain + - uses: rustsec/audit-check@v1.4.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 29c127bf50e..2e7ba1b2060 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -1,8 +1,8 @@ -use super::build_sysroot; -use super::path::Dirs; -use super::prepare::GitRepo; -use super::utils::{spawn_and_wait, CargoProject, Compiler}; -use super::{CodegenBackend, SysrootKind}; +use crate::build_sysroot; +use crate::path::Dirs; +use crate::prepare::GitRepo; +use crate::utils::{spawn_and_wait, CargoProject, Compiler}; +use crate::{CodegenBackend, SysrootKind}; static ABI_CAFE_REPO: GitRepo = GitRepo::github( "Gankra", diff --git a/build_system/bench.rs b/build_system/bench.rs index cec608ea042..6c64faaa256 100644 --- a/build_system/bench.rs +++ b/build_system/bench.rs @@ -2,10 +2,10 @@ use std::env; use std::io::Write; use std::path::Path; -use super::path::{Dirs, RelPath}; -use super::prepare::GitRepo; -use super::rustc_info::get_file_name; -use super::utils::{hyperfine_command, spawn_and_wait, Compiler}; +use crate::path::{Dirs, RelPath}; +use crate::prepare::GitRepo; +use crate::rustc_info::get_file_name; +use crate::utils::{hyperfine_command, spawn_and_wait, Compiler}; static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "ebobby", diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 1c5db23299d..e434c36f992 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,9 +1,9 @@ -use std::env; use std::path::PathBuf; -use super::path::{Dirs, RelPath}; -use super::rustc_info::get_file_name; -use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup}; +use crate::path::{Dirs, RelPath}; +use crate::rustc_info::get_file_name; +use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env}; +use crate::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup}; pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif"); @@ -18,11 +18,11 @@ pub(crate) fn build_backend( let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs); maybe_incremental(&mut cmd); - let mut rustflags = env::var("RUSTFLAGS").unwrap_or_default(); + let mut rustflags = rustflags_from_env("RUSTFLAGS"); if is_ci() { // Deny warnings on CI - rustflags += " -Dwarnings"; + rustflags.push("-Dwarnings".to_owned()); if !is_ci_opt() { cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true"); @@ -42,10 +42,10 @@ pub(crate) fn build_backend( _ => unreachable!(), } - cmd.env("RUSTFLAGS", rustflags); + rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &rustflags); eprintln!("[BUILD] rustc_codegen_cranelift"); - super::utils::spawn_and_wait(cmd); + crate::utils::spawn_and_wait(cmd); CG_CLIF .target_dir(dirs) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 04097936d03..31a4b209826 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -2,13 +2,13 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use super::path::{Dirs, RelPath}; -use super::rustc_info::get_file_name; -use super::utils::{ +use crate::path::{Dirs, RelPath}; +use crate::rustc_info::get_file_name; +use crate::utils::{ maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, LogGroup, }; -use super::{CodegenBackend, SysrootKind}; +use crate::{config, CodegenBackend, SysrootKind}; static DIST_DIR: RelPath = RelPath::DIST; static BIN_DIR: RelPath = RelPath::DIST.join("bin"); @@ -128,8 +128,8 @@ pub(crate) fn build_sysroot( cargo: bootstrap_host_compiler.cargo.clone(), rustc: rustc_clif.clone(), rustdoc: rustdoc_clif.clone(), - rustflags: String::new(), - rustdocflags: String::new(), + rustflags: vec![], + rustdocflags: vec![], triple: target_triple, runner: vec![], } @@ -185,7 +185,7 @@ fn build_sysroot_for_triple( #[must_use] fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget { - let default_sysroot = super::rustc_info::get_default_sysroot(&compiler.rustc); + let default_sysroot = crate::rustc_info::get_default_sysroot(&compiler.rustc); let mut target_libs = SysrootTarget { triple: compiler.triple, libs: vec![] }; @@ -234,32 +234,32 @@ fn build_clif_sysroot_for_triple( let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join(channel); - if !super::config::get_bool("keep_sysroot") { + if !config::get_bool("keep_sysroot") { // Cleanup the deps dir, but keep build scripts and the incremental cache for faster // recompilation as they are not affected by changes in cg_clif. remove_dir_if_exists(&build_dir.join("deps")); } // Build sysroot - let mut rustflags = " -Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); + let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned(), "-Cpanic=abort".to_owned()]; match cg_clif_dylib_path { CodegenBackend::Local(path) => { - rustflags.push_str(&format!(" -Zcodegen-backend={}", path.to_str().unwrap())); + rustflags.push(format!("-Zcodegen-backend={}", path.to_str().unwrap())); } CodegenBackend::Builtin(name) => { - rustflags.push_str(&format!(" -Zcodegen-backend={name}")); + rustflags.push(format!("-Zcodegen-backend={name}")); } }; // Necessary for MinGW to find rsbegin.o and rsend.o - rustflags - .push_str(&format!(" --sysroot {}", RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap())); + rustflags.push("--sysroot".to_owned()); + rustflags.push(RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap().to_owned()); if channel == "release" { // Incremental compilation by default disables mir inlining. This leads to both a decent // compile perf and a significant runtime perf regression. As such forcefully enable mir // inlining. - rustflags.push_str(" -Zinline-mir"); + rustflags.push("-Zinline-mir".to_owned()); } - compiler.rustflags += &rustflags; + compiler.rustflags.extend(rustflags); let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs); maybe_incremental(&mut build_cmd); if channel == "release" { @@ -289,8 +289,8 @@ fn build_clif_sysroot_for_triple( } fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option { - if !super::config::get_bool("keep_sysroot") { - super::prepare::prepare_stdlib(dirs, &compiler.rustc); + if !config::get_bool("keep_sysroot") { + crate::prepare::prepare_stdlib(dirs, &compiler.rustc); } if !compiler.triple.ends_with("windows-gnu") { @@ -306,6 +306,7 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option { let obj = RTSTARTUP_SYSROOT.to_path(dirs).join(format!("{file}.o")); let mut build_rtstartup_cmd = Command::new(&compiler.rustc); build_rtstartup_cmd + .arg("-Ainternal_features") // Missing #[allow(internal_features)] .arg("--target") .arg(&compiler.triple) .arg("--emit=obj") diff --git a/build_system/main.rs b/build_system/main.rs index 3bc78d5db94..798ae9dbd50 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -16,6 +16,7 @@ mod config; mod path; mod prepare; mod rustc_info; +mod shared_utils; mod tests; mod utils; @@ -169,8 +170,8 @@ fn main() { cargo, rustc, rustdoc, - rustflags: String::new(), - rustdocflags: String::new(), + rustflags: vec![], + rustdocflags: vec![], triple, runner: vec![], } diff --git a/build_system/path.rs b/build_system/path.rs index 4f86c0fd29d..8572815fc55 100644 --- a/build_system/path.rs +++ b/build_system/path.rs @@ -1,7 +1,7 @@ use std::fs; use std::path::PathBuf; -use super::utils::remove_dir_if_exists; +use crate::utils::remove_dir_if_exists; #[derive(Debug, Clone)] pub(crate) struct Dirs { diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 3ee2e8f4a4e..165296cb4a9 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -3,18 +3,18 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use super::build_sysroot::STDLIB_SRC; -use super::path::{Dirs, RelPath}; -use super::rustc_info::get_default_sysroot; -use super::utils::{ +use crate::build_sysroot::STDLIB_SRC; +use crate::path::{Dirs, RelPath}; +use crate::rustc_info::get_default_sysroot; +use crate::utils::{ copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait, }; pub(crate) fn prepare(dirs: &Dirs) { RelPath::DOWNLOAD.ensure_exists(dirs); - super::tests::RAND_REPO.fetch(dirs); - super::tests::REGEX_REPO.fetch(dirs); - super::tests::PORTABLE_SIMD_REPO.fetch(dirs); + crate::tests::RAND_REPO.fetch(dirs); + crate::tests::REGEX_REPO.fetch(dirs); + crate::tests::PORTABLE_SIMD_REPO.fetch(dirs); } pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { diff --git a/build_system/shared_utils.rs b/build_system/shared_utils.rs new file mode 100644 index 00000000000..0aea545ff7d --- /dev/null +++ b/build_system/shared_utils.rs @@ -0,0 +1,26 @@ +// This file is used by both the build system as well as cargo-clif.rs + +// Adapted from https://github.com/rust-lang/cargo/blob/6dc1deaddf62c7748c9097c7ea88e9ec77ff1a1a/src/cargo/core/compiler/build_context/target_info.rs#L750-L77 +pub(crate) fn rustflags_from_env(kind: &str) -> Vec { + // First try CARGO_ENCODED_RUSTFLAGS from the environment. + // Prefer this over RUSTFLAGS since it's less prone to encoding errors. + if let Ok(a) = std::env::var(format!("CARGO_ENCODED_{}", kind)) { + if a.is_empty() { + return Vec::new(); + } + return a.split('\x1f').map(str::to_string).collect(); + } + + // Then try RUSTFLAGS from the environment + if let Ok(a) = std::env::var(kind) { + let args = a.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string); + return args.collect(); + } + + // No rustflags to be collected from the environment + Vec::new() +} + +pub(crate) fn rustflags_to_cmd_env(cmd: &mut std::process::Command, kind: &str, flags: &[String]) { + cmd.env(format!("CARGO_ENCODED_{}", kind), flags.join("\x1f")); +} diff --git a/build_system/tests.rs b/build_system/tests.rs index 0254d18cf7c..e7bd8b1278c 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -1,16 +1,17 @@ -use super::build_sysroot; -use super::config; -use super::path::{Dirs, RelPath}; -use super::prepare::{apply_patches, GitRepo}; -use super::rustc_info::get_default_sysroot; -use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, LogGroup}; -use super::{CodegenBackend, SysrootKind}; -use std::env; use std::ffi::OsStr; use std::fs; use std::path::PathBuf; use std::process::Command; +use crate::build_sysroot; +use crate::config; +use crate::path::{Dirs, RelPath}; +use crate::prepare::{apply_patches, GitRepo}; +use crate::rustc_info::get_default_sysroot; +use crate::shared_utils::rustflags_from_env; +use crate::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, LogGroup}; +use crate::{CodegenBackend, SysrootKind}; + static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example"); struct TestCase { @@ -306,7 +307,7 @@ pub(crate) fn run_tests( ); // Rust's build system denies a couple of lints that trigger on several of the test // projects. Changing the code to fix them is not worth it, so just silence all lints. - target_compiler.rustflags += " --cap-lints=allow"; + target_compiler.rustflags.push("--cap-lints=allow".to_owned()); let runner = TestRunner::new( dirs.clone(), @@ -350,18 +351,15 @@ impl<'a> TestRunner<'a> { is_native: bool, stdlib_source: PathBuf, ) -> Self { - if let Ok(rustflags) = env::var("RUSTFLAGS") { - target_compiler.rustflags.push(' '); - target_compiler.rustflags.push_str(&rustflags); - } - if let Ok(rustdocflags) = env::var("RUSTDOCFLAGS") { - target_compiler.rustdocflags.push(' '); - target_compiler.rustdocflags.push_str(&rustdocflags); - } + target_compiler.rustflags.extend(rustflags_from_env("RUSTFLAGS")); + target_compiler.rustdocflags.extend(rustflags_from_env("RUSTDOCFLAGS")); // FIXME fix `#[linkage = "extern_weak"]` without this if target_compiler.triple.contains("darwin") { - target_compiler.rustflags.push_str(" -Clink-arg=-undefined -Clink-arg=dynamic_lookup"); + target_compiler.rustflags.extend([ + "-Clink-arg=-undefined".to_owned(), + "-Clink-arg=dynamic_lookup".to_owned(), + ]); } let jit_supported = use_unstable_features @@ -470,7 +468,7 @@ impl<'a> TestRunner<'a> { S: AsRef, { let mut cmd = Command::new(&self.target_compiler.rustc); - cmd.args(self.target_compiler.rustflags.split_whitespace()); + cmd.args(&self.target_compiler.rustflags); cmd.arg("-L"); cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display())); cmd.arg("--out-dir"); diff --git a/build_system/usage.txt b/build_system/usage.txt index 6d3b3a13d6e..f652599447b 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -43,7 +43,7 @@ REQUIREMENTS: * Rustup: By default rustup is used to install the right nightly version. If you don't want to use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and point the CARGO, RUSTC and RUSTDOC env vars to the right executables. - * Git: `./y.sh prepare` uses git for applying patches and on Windows for downloading test repos. + * Git: Git is used for applying patches and on Windows for downloading test repos. * Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for repos. Git will be used to clone the whole repo when using Windows. * [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`. diff --git a/build_system/utils.rs b/build_system/utils.rs index 97c82d501c5..24624cdeab1 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -5,15 +5,16 @@ use std::path::{Path, PathBuf}; use std::process::{self, Command, Stdio}; use std::sync::atomic::{AtomicBool, Ordering}; -use super::path::{Dirs, RelPath}; +use crate::path::{Dirs, RelPath}; +use crate::shared_utils::rustflags_to_cmd_env; #[derive(Clone, Debug)] pub(crate) struct Compiler { pub(crate) cargo: PathBuf, pub(crate) rustc: PathBuf, pub(crate) rustdoc: PathBuf, - pub(crate) rustflags: String, - pub(crate) rustdocflags: String, + pub(crate) rustflags: Vec, + pub(crate) rustdocflags: Vec, pub(crate) triple: String, pub(crate) runner: Vec, } @@ -23,8 +24,8 @@ impl Compiler { match self.triple.as_str() { "aarch64-unknown-linux-gnu" => { // We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. - self.rustflags += " -Clinker=aarch64-linux-gnu-gcc"; - self.rustdocflags += " -Clinker=aarch64-linux-gnu-gcc"; + self.rustflags.push("-Clinker=aarch64-linux-gnu-gcc".to_owned()); + self.rustdocflags.push("-Clinker=aarch64-linux-gnu-gcc".to_owned()); self.runner = vec![ "qemu-aarch64".to_owned(), "-L".to_owned(), @@ -33,8 +34,8 @@ impl Compiler { } "s390x-unknown-linux-gnu" => { // We are cross-compiling for s390x. Use the correct linker and run tests in qemu. - self.rustflags += " -Clinker=s390x-linux-gnu-gcc"; - self.rustdocflags += " -Clinker=s390x-linux-gnu-gcc"; + self.rustflags.push("-Clinker=s390x-linux-gnu-gcc".to_owned()); + self.rustdocflags.push("-Clinker=s390x-linux-gnu-gcc".to_owned()); self.runner = vec![ "qemu-s390x".to_owned(), "-L".to_owned(), @@ -100,8 +101,8 @@ impl CargoProject { cmd.env("RUSTC", &compiler.rustc); cmd.env("RUSTDOC", &compiler.rustdoc); - cmd.env("RUSTFLAGS", &compiler.rustflags); - cmd.env("RUSTDOCFLAGS", &compiler.rustdocflags); + rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &compiler.rustflags); + rustflags_to_cmd_env(&mut cmd, "RUSTDOCFLAGS", &compiler.rustdocflags); if !compiler.runner.is_empty() { cmd.env( format!("CARGO_TARGET_{}_RUNNER", compiler.triple.to_uppercase().replace('-', "_")), diff --git a/example/mini_core.rs b/example/mini_core.rs index 9ecc4c5dd5b..34c7e44b288 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -11,7 +11,7 @@ thread_local )] #![no_core] -#![allow(dead_code)] +#![allow(dead_code, internal_features)] #[lang = "sized"] pub trait Sized {} diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index d97fab9eb42..91de04d9770 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -1,6 +1,6 @@ #![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)] #![no_core] -#![allow(dead_code, non_camel_case_types)] +#![allow(dead_code, non_camel_case_types, internal_features)] extern crate mini_core; diff --git a/patches/0001-portable-simd-Allow-internal-features.patch b/patches/0001-portable-simd-Allow-internal-features.patch new file mode 100644 index 00000000000..87252df1eab --- /dev/null +++ b/patches/0001-portable-simd-Allow-internal-features.patch @@ -0,0 +1,24 @@ +From fcf75306d88e533b83eaff3f8d0ab9f307e8a84d Mon Sep 17 00:00:00 2001 +From: bjorn3 <17426603+bjorn3@users.noreply.github.com> +Date: Wed, 9 Aug 2023 10:01:17 +0000 +Subject: [PATCH] Allow internal features + +--- + crates/core_simd/src/lib.rs | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs +index fde406b..b386116 100644 +--- a/crates/core_simd/src/lib.rs ++++ b/crates/core_simd/src/lib.rs +@@ -19,6 +19,7 @@ + #![warn(missing_docs, clippy::missing_inline_in_public_items)] // basically all items, really + #![deny(unsafe_op_in_unsafe_fn, clippy::undocumented_unsafe_blocks)] + #![unstable(feature = "portable_simd", issue = "86656")] ++#![allow(internal_features)] + //! Portable SIMD module. + + #[path = "mod.rs"] +-- +2.34.1 + diff --git a/patches/stdlib-lock.toml b/patches/stdlib-lock.toml index aea47bdfba2..fa175edcae6 100644 --- a/patches/stdlib-lock.toml +++ b/patches/stdlib-lock.toml @@ -74,9 +74,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.95" +version = "0.1.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6866e0f3638013234db3c89ead7a14d278354338e7237257407500009012b23f" +checksum = "d6c0f24437059853f0fa64afc51f338f93647a3de4cf3358ba1bb4171a199775" dependencies = [ "cc", "rustc-std-workspace-core", diff --git a/rust-toolchain b/rust-toolchain index 34514658359..5689bdee64d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-07-22" +channel = "nightly-2023-08-08" components = ["rust-src", "rustc-dev", "llvm-tools"] diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs index f73b2012684..1e14f41d4a2 100644 --- a/scripts/cargo-clif.rs +++ b/scripts/cargo-clif.rs @@ -3,6 +3,8 @@ use std::env; use std::os::unix::process::CommandExt; use std::process::Command; +include!("../build_system/shared_utils.rs"); + fn main() { let current_exe = env::current_exe().unwrap(); let mut sysroot = current_exe.parent().unwrap(); @@ -10,27 +12,19 @@ fn main() { sysroot = sysroot.parent().unwrap(); } - let mut rustflags = String::new(); - rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend="); + let mut rustflags = vec!["-Cpanic=abort".to_owned(), "-Zpanic-abort-tests".to_owned()]; if let Some(name) = option_env!("BUILTIN_BACKEND") { - rustflags.push_str(name); + rustflags.push(format!("-Zcodegen-backend={name}")); } else { - rustflags.push_str( - sysroot - .join(if cfg!(windows) { "bin" } else { "lib" }) - .join( - env::consts::DLL_PREFIX.to_string() - + "rustc_codegen_cranelift" - + env::consts::DLL_SUFFIX, - ) - .to_str() - .unwrap(), + let dylib = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join( + env::consts::DLL_PREFIX.to_string() + + "rustc_codegen_cranelift" + + env::consts::DLL_SUFFIX, ); + rustflags.push(format!("-Zcodegen-backend={}", dylib.to_str().unwrap())); } - rustflags.push_str(" --sysroot "); - rustflags.push_str(sysroot.to_str().unwrap()); - env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags); - env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags); + rustflags.push("--sysroot".to_owned()); + rustflags.push(sysroot.to_str().unwrap().to_owned()); let cargo = if let Some(cargo) = option_env!("CARGO") { cargo @@ -49,10 +43,7 @@ fn main() { let args: Vec<_> = match args.get(0).map(|arg| &**arg) { Some("jit") => { - env::set_var( - "RUSTFLAGS", - env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", - ); + rustflags.push("-Cprefer-dynamic".to_owned()); args.remove(0); IntoIterator::into_iter(["rustc".to_string()]) .chain(args) @@ -64,10 +55,7 @@ fn main() { .collect() } Some("lazy-jit") => { - env::set_var( - "RUSTFLAGS", - env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", - ); + rustflags.push("-Cprefer-dynamic".to_owned()); args.remove(0); IntoIterator::into_iter(["rustc".to_string()]) .chain(args) @@ -81,11 +69,28 @@ fn main() { _ => args, }; + let mut cmd = Command::new(cargo); + cmd.args(args); + rustflags_to_cmd_env( + &mut cmd, + "RUSTFLAGS", + &rustflags_from_env("RUSTFLAGS") + .into_iter() + .chain(rustflags.iter().map(|flag| flag.clone())) + .collect::>(), + ); + rustflags_to_cmd_env( + &mut cmd, + "RUSTDOCFLAGS", + &rustflags_from_env("RUSTDOCFLAGS") + .into_iter() + .chain(rustflags.iter().map(|flag| flag.clone())) + .collect::>(), + ); + #[cfg(unix)] - panic!("Failed to spawn cargo: {}", Command::new(cargo).args(args).exec()); + panic!("Failed to spawn cargo: {}", cmd.exec()); #[cfg(not(unix))] - std::process::exit( - Command::new(cargo).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), - ); + std::process::exit(cmd.spawn().unwrap().wait().unwrap().code().unwrap_or(1)); } diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 83cbe0db633..c163b854384 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -49,6 +49,8 @@ rm tests/ui/proc-macro/allowed-signatures.rs # vendor intrinsics rm tests/ui/sse2.rs # cpuid not supported, so sse2 not detected rm tests/ui/simd/array-type.rs # "Index argument for `simd_insert` is not a constant" +rm tests/ui/simd/intrinsic/generic-bswap-byte.rs # simd_bswap not yet implemented +rm tests/ui/simd/intrinsic/generic-arithmetic-pass.rs # many missing simd intrinsics # exotic linkages rm tests/ui/issues/issue-33992.rs # unsupported linkages @@ -124,6 +126,8 @@ rm tests/ui/typeck/issue-46112.rs # same rm tests/ui/consts/const_cmp_type_id.rs # same rm tests/ui/consts/issue-73976-monomorphic.rs # same rm tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs # same +rm tests/ui/consts/const-eval/nonnull_as_ref_ub.rs # same +rm tests/ui/consts/issue-94675.rs # same # rustdoc-clif passes extra args, suppressing the help message when no args are passed rm -r tests/run-make/issue-88756-default-output @@ -158,8 +162,6 @@ rm tests/ui/process/nofile-limit.rs # TODO some AArch64 linking issue rm tests/ui/stdio-is-blocking.rs # really slow with unoptimized libstd -rm tests/ui/panic-handler/weak-lang-item-2.rs # Will be fixed by #113568 - cp ../dist/bin/rustdoc-clif ../dist/bin/rustdoc # some tests expect bin/rustdoc to exist # prevent $(RUSTDOC) from picking up the sysroot built by x.py. It conflicts with the one used by @@ -172,7 +174,7 @@ index ea06b620c4c..b969d0009c6 100644 @@ -9,7 +9,7 @@ RUSTC_ORIGINAL := \$(RUSTC) BARE_RUSTC := \$(HOST_RPATH_ENV) '\$(RUSTC)' BARE_RUSTDOC := \$(HOST_RPATH_ENV) '\$(RUSTDOC)' - RUSTC := \$(BARE_RUSTC) --out-dir \$(TMPDIR) -L \$(TMPDIR) \$(RUSTFLAGS) + RUSTC := \$(BARE_RUSTC) --out-dir \$(TMPDIR) -L \$(TMPDIR) \$(RUSTFLAGS) -Ainternal_features -RUSTDOC := \$(BARE_RUSTDOC) -L \$(TARGET_RPATH_DIR) +RUSTDOC := \$(BARE_RUSTDOC) ifdef RUSTC_LINKER diff --git a/src/lib.rs b/src/lib.rs index ebd153cb71d..d01ded8abaa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -260,6 +260,13 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc "elf_gd", BinaryFormat::Macho => "macho", From c4948dc37f9863aa45fda35f705a83c3744b073b Mon Sep 17 00:00:00 2001 From: dirreke Date: Mon, 14 Aug 2023 22:57:38 +0800 Subject: [PATCH 04/17] Upgrade Object and related deps --- Cargo.lock | 38 +++++++++++++++++++++++++++++++------- Cargo.toml | 4 ++-- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af8e43da4ea..7d18679c681 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,7 +71,7 @@ dependencies = [ "cranelift-control", "cranelift-entity", "cranelift-isle", - "gimli", + "gimli 0.27.2", "hashbrown 0.13.2", "log", "regalloc2", @@ -180,7 +180,7 @@ dependencies = [ "cranelift-control", "cranelift-module", "log", - "object", + "object 0.30.4", "target-lexicon", ] @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "equivalent" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "fallible-iterator" @@ -216,6 +216,15 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +dependencies = [ + "indexmap 2.0.0", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -236,6 +245,9 @@ name = "hashbrown" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +dependencies = [ + "ahash", +] [[package]] name = "indexmap" @@ -309,6 +321,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "object" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe" +dependencies = [ + "crc32fast", + "hashbrown 0.14.0", + "indexmap 2.0.0", + "memchr", +] + [[package]] name = "once_cell" version = "1.16.0" @@ -356,10 +380,10 @@ dependencies = [ "cranelift-module", "cranelift-native", "cranelift-object", - "gimli", - "indexmap 2.0.0", + "gimli 0.28.0", + "indexmap 1.9.3", "libloading", - "object", + "object 0.32.0", "smallvec", "target-lexicon", ] diff --git a/Cargo.toml b/Cargo.toml index 8ded81d7399..2c87d260006 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ cranelift-native = { version = "0.98" } cranelift-jit = { version = "0.98", optional = true } cranelift-object = { version = "0.98" } target-lexicon = "0.12.0" -gimli = { version = "0.27.2", default-features = false, features = ["write"]} -object = { version = "0.30.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } +gimli = { version = "0.28.0", default-features = false, features = ["write"]} +object = { version = "0.32.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } indexmap = "2.0.0" libloading = { version = "0.7.3", optional = true } From 9ef3a4ff0e94e4e877a87b3497e582c89941deb1 Mon Sep 17 00:00:00 2001 From: dirreke Date: Mon, 14 Aug 2023 23:22:19 +0800 Subject: [PATCH 05/17] Update Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7d18679c681..64ee5207b01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -381,7 +381,7 @@ dependencies = [ "cranelift-native", "cranelift-object", "gimli 0.28.0", - "indexmap 1.9.3", + "indexmap 2.0.0", "libloading", "object 0.32.0", "smallvec", From 0b283557e73f89c52b4a6965506f23379fd6e834 Mon Sep 17 00:00:00 2001 From: dirreke Date: Tue, 15 Aug 2023 00:03:27 +0800 Subject: [PATCH 06/17] reverse change in rustc_codegen_cranelift --- Cargo.lock | 36 ++++++------------------------------ Cargo.toml | 4 ++-- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 64ee5207b01..af8e43da4ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,7 +71,7 @@ dependencies = [ "cranelift-control", "cranelift-entity", "cranelift-isle", - "gimli 0.27.2", + "gimli", "hashbrown 0.13.2", "log", "regalloc2", @@ -180,7 +180,7 @@ dependencies = [ "cranelift-control", "cranelift-module", "log", - "object 0.30.4", + "object", "target-lexicon", ] @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" [[package]] name = "fallible-iterator" @@ -216,15 +216,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "gimli" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" -dependencies = [ - "indexmap 2.0.0", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -245,9 +236,6 @@ name = "hashbrown" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" -dependencies = [ - "ahash", -] [[package]] name = "indexmap" @@ -321,18 +309,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "object" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe" -dependencies = [ - "crc32fast", - "hashbrown 0.14.0", - "indexmap 2.0.0", - "memchr", -] - [[package]] name = "once_cell" version = "1.16.0" @@ -380,10 +356,10 @@ dependencies = [ "cranelift-module", "cranelift-native", "cranelift-object", - "gimli 0.28.0", + "gimli", "indexmap 2.0.0", "libloading", - "object 0.32.0", + "object", "smallvec", "target-lexicon", ] diff --git a/Cargo.toml b/Cargo.toml index 2c87d260006..768d9df1652 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ cranelift-native = { version = "0.98" } cranelift-jit = { version = "0.98", optional = true } cranelift-object = { version = "0.98" } target-lexicon = "0.12.0" -gimli = { version = "0.28.0", default-features = false, features = ["write"]} -object = { version = "0.32.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } +gimli = { version = "0.27.2", default-features = false, features = ["write"]} +object = { version = "0.30.4", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } indexmap = "2.0.0" libloading = { version = "0.7.3", optional = true } From 8c6590a99b7def859208644da23238fdc7a8d9f3 Mon Sep 17 00:00:00 2001 From: dirreke Date: Tue, 15 Aug 2023 00:09:20 +0800 Subject: [PATCH 07/17] reverse change in rustc_codegen_cranelift --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 768d9df1652..8ded81d7399 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ cranelift-jit = { version = "0.98", optional = true } cranelift-object = { version = "0.98" } target-lexicon = "0.12.0" gimli = { version = "0.27.2", default-features = false, features = ["write"]} -object = { version = "0.30.4", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } +object = { version = "0.30.3", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } indexmap = "2.0.0" libloading = { version = "0.7.3", optional = true } From 9aa5fbf79c39867f144e5a38c53a8edd2e2069ba Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 18 Aug 2023 13:15:36 +0200 Subject: [PATCH 08/17] Fix shell helpers in usage docs --- docs/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage.md b/docs/usage.md index c6210f958d6..135a51ce392 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -54,7 +54,7 @@ These are a few functions that allow you to easily run rust code from the shell ```bash function jit_naked() { - echo "$@" | $cg_clif_dir/dist/rustc-clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic + echo "$@" | $cg_clif_dir/dist/rustc-clif - -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic } function jit() { From 18658cb0c9320d5a028246562ed40663ea72371b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Aug 2023 13:10:25 +0200 Subject: [PATCH 09/17] give some unwind-related terminators a more clear name --- src/base.rs | 4 ++-- src/constant.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base.rs b/src/base.rs index 522dd7189fe..ed371a04c53 100644 --- a/src/base.rs +++ b/src/base.rs @@ -474,10 +474,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { *destination, ); } - TerminatorKind::Terminate => { + TerminatorKind::UnwindTerminate => { codegen_panic_cannot_unwind(fx, source_info); } - TerminatorKind::Resume => { + TerminatorKind::UnwindResume => { // FIXME implement unwinding fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } diff --git a/src/constant.rs b/src/constant.rs index c3153574295..7db5f79eead 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -550,8 +550,8 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( match &bb_data.terminator().kind { TerminatorKind::Goto { .. } | TerminatorKind::SwitchInt { .. } - | TerminatorKind::Resume - | TerminatorKind::Terminate + | TerminatorKind::UnwindResume + | TerminatorKind::UnwindTerminate | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } From 3f4145e169f73392c3f5d0d8acf8840b2e8fc189 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Aug 2023 09:57:10 +0200 Subject: [PATCH 10/17] when terminating during unwinding, show the reason why --- src/base.rs | 9 +++++---- src/constant.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index ed371a04c53..9159bc36987 100644 --- a/src/base.rs +++ b/src/base.rs @@ -474,8 +474,8 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { *destination, ); } - TerminatorKind::UnwindTerminate => { - codegen_panic_cannot_unwind(fx, source_info); + TerminatorKind::UnwindTerminate(reason) => { + codegen_unwind_terminate(fx, source_info, *reason); } TerminatorKind::UnwindResume => { // FIXME implement unwinding @@ -971,13 +971,14 @@ pub(crate) fn codegen_panic_nounwind<'tcx>( codegen_panic_inner(fx, rustc_hir::LangItem::PanicNounwind, &args, source_info.span); } -pub(crate) fn codegen_panic_cannot_unwind<'tcx>( +pub(crate) fn codegen_unwind_terminate<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, source_info: mir::SourceInfo, + reason: UnwindTerminateReason, ) { let args = []; - codegen_panic_inner(fx, rustc_hir::LangItem::PanicCannotUnwind, &args, source_info.span); + codegen_panic_inner(fx, reason.lang_item(), &args, source_info.span); } fn codegen_panic_inner<'tcx>( diff --git a/src/constant.rs b/src/constant.rs index 7db5f79eead..a934b0767f1 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -551,7 +551,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( TerminatorKind::Goto { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } From 25a2ba2ee4febf9c22f7add7e14a0a50b3fd984d Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 26 Aug 2023 17:42:59 -0700 Subject: [PATCH 11/17] Use `preserve_mostcc` for `extern "rust-cold"` As experimentation in 115242 has shown looks better than `coldcc`. And *don't* use a different convention for cold on Windows, because that actually ends up making things worse. cc tracking issue 97544 --- src/abi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index b7f56a2986c..5d775b9b532 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -39,7 +39,7 @@ fn clif_sig_from_fn_abi<'tcx>( pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: CallConv) -> CallConv { match c { Conv::Rust | Conv::C => default_call_conv, - Conv::RustCold => CallConv::Cold, + Conv::Cold | Conv::PreserveMost | Conv::PreserveAll => CallConv::Cold, Conv::X86_64SysV => CallConv::SystemV, Conv::X86_64Win64 => CallConv::WindowsFastcall, From b88dfcfcd50d6260130c1c719cda9bef990715eb Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Mon, 28 Aug 2023 12:40:39 -0700 Subject: [PATCH 12/17] Don't ICE on layout computation failure --- src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index 3081dcfa2b7..ec2da39398b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -480,7 +480,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err { self.0.sess.span_fatal(span, err.to_string()) } else { - span_bug!(span, "failed to get layout for `{}`: {}", ty, err) + self.0.sess.span_fatal(span, format!("failed to get layout for `{}`: {}", ty, err)) } } } From 833592766f9e317e7166ffff1444ff70c6fdeda4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 27 Aug 2023 18:12:34 +0200 Subject: [PATCH 13/17] const_eval and codegen: audit uses of is_zst --- src/unsize.rs | 4 +++- src/vtable.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/unsize.rs b/src/unsize.rs index 6aeba13f639..c6133f2b35c 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -88,7 +88,8 @@ fn unsize_ptr<'tcx>( let src_f = src_layout.field(fx, i); assert_eq!(src_layout.fields.offset(i).bytes(), 0); assert_eq!(dst_layout.fields.offset(i).bytes(), 0); - if src_f.is_zst() { + if src_f.is_1zst() { + // We are looking for the one non-1-ZST field; this is not it. continue; } assert_eq!(src_layout.size, src_f.size); @@ -151,6 +152,7 @@ pub(crate) fn coerce_unsized_into<'tcx>( let dst_f = dst.place_field(fx, FieldIdx::new(i)); if dst_f.layout().is_zst() { + // No data here, nothing to copy/coerce. continue; } diff --git a/src/vtable.rs b/src/vtable.rs index b309695c190..7598c6eee03 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -51,8 +51,8 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( 'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() { for i in 0..arg.layout().fields.count() { let field = arg.value_field(fx, FieldIdx::new(i)); - if !field.layout().is_zst() { - // we found the one non-zero-sized field that is allowed + if !field.layout().is_1zst() { + // we found the one non-1-ZST field that is allowed // now find *its* non-zero-sized field, or stop if it's a // pointer arg = field; From a756bae8cae1a5eb3da9d956f162f7b040260203 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:55:18 +0000 Subject: [PATCH 14/17] Rustup to rustc 1.74.0-nightly (2f5df8a94 2023-08-31) --- patches/stdlib-lock.toml | 12 ++++++------ rust-toolchain | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/patches/stdlib-lock.toml b/patches/stdlib-lock.toml index fa175edcae6..5b79d6569bb 100644 --- a/patches/stdlib-lock.toml +++ b/patches/stdlib-lock.toml @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "compiler_builtins", "gimli", @@ -140,9 +140,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "object" -version = "0.31.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe" dependencies = [ "compiler_builtins", "memchr", diff --git a/rust-toolchain b/rust-toolchain index 5689bdee64d..39e348f37f3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-08-08" +channel = "nightly-2023-09-01" components = ["rust-src", "rustc-dev", "llvm-tools"] From 0559de65672243a97d6cd6e6ee6a8e8c291ef4ce Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:08:16 +0000 Subject: [PATCH 15/17] Fix rustc test suite --- scripts/test_rustc_tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index c163b854384..3fc462a39cc 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -45,6 +45,7 @@ rm tests/ui/proc-macro/quote-debug.rs rm tests/ui/proc-macro/no-missing-docs.rs rm tests/ui/rust-2018/proc-macro-crate-in-paths.rs rm tests/ui/proc-macro/allowed-signatures.rs +rm tests/ui/proc-macro/no-mangle-in-proc-macro-issue-111888.rs # vendor intrinsics rm tests/ui/sse2.rs # cpuid not supported, so sse2 not detected @@ -114,6 +115,7 @@ rm tests/ui/mir/mir_misc_casts.rs # depends on deduplication of constants rm tests/ui/mir/mir_raw_fat_ptr.rs # same rm tests/ui/consts/issue-33537.rs # same rm tests/ui/layout/valid_range_oob.rs # different ICE message +rm tests/ui/const-generics/generic_const_exprs/issue-80742.rs # gives error instead of ICE with cg_clif rm tests/ui/consts/issue-miri-1910.rs # different error message rm tests/ui/consts/offset_ub.rs # same From 61a0b77e17531e6d65d8fad80588237ee5e14529 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 3 Sep 2023 10:15:35 +0000 Subject: [PATCH 16/17] Use relative positions inside a SourceFile. --- src/debuginfo/line_info.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index 50bc7a127af..998263de584 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -82,12 +82,9 @@ impl DebugContext { match tcx.sess.source_map().lookup_line(span.lo()) { Ok(SourceFileAndLine { sf: file, line }) => { let line_pos = file.lines(|lines| lines[line]); + let col = file.relative_position(span.lo()) - line_pos; - ( - file, - u64::try_from(line).unwrap() + 1, - u64::from((span.lo() - line_pos).to_u32()) + 1, - ) + (file, u64::try_from(line).unwrap() + 1, u64::from(col.to_u32()) + 1) } Err(file) => (file, 0, 0), } From dda103b1e33c4902deca8bccf614991ada781fa6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 6 Sep 2023 18:33:08 +0000 Subject: [PATCH 17/17] Rustup to rustc 1.74.0-nightly (a991861ec 2023-09-05) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 39e348f37f3..2cc5d7777a6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-09-01" +channel = "nightly-2023-09-06" components = ["rust-src", "rustc-dev", "llvm-tools"]