From 6642b4b1e2f2edec71cdf3fabef8fcdc8b8517a7 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Wed, 25 Oct 2023 15:23:34 +0000 Subject: [PATCH 01/13] Add support for i586-unknown-netbsd as target. This restricts instructions to those offered by Pentium, to support e.g. AMD Geode. There is already an entry for this target in the NetBSD platform support page at src/doc/rustc/src/platform-support/netbsd.md ...so this should forestall its removal. Additional fixes are needed for some vendored modules, this is the changes in the rust compiler core itself. --- compiler/rustc_llvm/build.rs | 6 +++++ .../src/spec/i586_unknown_netbsd.rs | 22 +++++++++++++++++++ compiler/rustc_target/src/spec/mod.rs | 1 + 3 files changed, 29 insertions(+) create mode 100644 compiler/rustc_target/src/spec/i586_unknown_netbsd.rs diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index f606fa483caf0..acb1d9607a4f5 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -258,6 +258,12 @@ fn main() { { println!("cargo:rustc-link-lib=z"); } else if target.contains("netbsd") { + // Building for i586 or i686, we need -latomic for 64-bit atomics + if target.starts_with("i586") + || target.starts_with("i686") + { + println!("cargo:rustc-link-lib=atomic"); + } println!("cargo:rustc-link-lib=z"); println!("cargo:rustc-link-lib=execinfo"); } diff --git a/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs b/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs new file mode 100644 index 0000000000000..9b36a3c28d35c --- /dev/null +++ b/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs @@ -0,0 +1,22 @@ +use crate::spec::{Cc, Lld, LinkerFlavor, StackProbeType, Target, TargetOptions}; + +pub fn target() -> Target { + let mut base = super::netbsd_base::opts(); + base.cpu = "pentium".into(); + base.max_atomic_width = Some(64); + base.pre_link_args + .entry(LinkerFlavor::Gnu(Cc::Yes, Lld::No)) + .or_default() + .push("-m32".into()); + base.stack_probes = StackProbeType::Call; + + Target { + llvm_target: "i586-unknown-netbsdelf".into(), + pointer_width: 32, + data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ + f64:32:64-f80:32-n8:16:32-S128" + .into(), + arch: "x86".into(), + options: TargetOptions { mcount: "__mcount".into(), ..base }, + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index f1c7513d88560..73e5c6c858b9e 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1426,6 +1426,7 @@ supported_targets! { ("aarch64_be-unknown-netbsd", aarch64_be_unknown_netbsd), ("armv6-unknown-netbsd-eabihf", armv6_unknown_netbsd_eabihf), ("armv7-unknown-netbsd-eabihf", armv7_unknown_netbsd_eabihf), + ("i586-unknown-netbsd", i586_unknown_netbsd), ("i686-unknown-netbsd", i686_unknown_netbsd), ("powerpc-unknown-netbsd", powerpc_unknown_netbsd), ("riscv64gc-unknown-netbsd", riscv64gc_unknown_netbsd), From 391b472a370a5d35c43bd0a26182076cf0c17ca9 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Thu, 26 Oct 2023 17:10:16 +0000 Subject: [PATCH 02/13] rustc_llvm/build.rs: improve comment for NetBSD/i386 targets ...explaining why we need -latomic (gcc & g++ built for i486, and LLVM insisting on use of 64-bit atomics). --- compiler/rustc_llvm/build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index acb1d9607a4f5..e4412132136bf 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -258,7 +258,9 @@ fn main() { { println!("cargo:rustc-link-lib=z"); } else if target.contains("netbsd") { - // Building for i586 or i686, we need -latomic for 64-bit atomics + // On NetBSD/i386, gcc and g++ is built for i486 (to maximize backward compat) + // However, LLVM insists on using 64-bit atomics. + // This gives rise to a need to link rust itself with -latomic for these targets if target.starts_with("i586") || target.starts_with("i686") { From 0a82920b568d05f230ccdd0b84dc73229bfe650e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 26 Oct 2023 19:06:16 -0700 Subject: [PATCH 03/13] Declare rustc_target dependency on object/macho --- compiler/rustc_target/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/Cargo.toml b/compiler/rustc_target/Cargo.toml index a91eb41b18aeb..779d03cd094d6 100644 --- a/compiler/rustc_target/Cargo.toml +++ b/compiler/rustc_target/Cargo.toml @@ -19,4 +19,4 @@ rustc_index = { path = "../rustc_index" } [dependencies.object] version = "0.32.0" default-features = false -features = ["elf"] +features = ["elf", "macho"] From 893e7266376f8c7629a5b5130e95bc3063128f77 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Fri, 27 Oct 2023 07:24:31 +0000 Subject: [PATCH 04/13] i586_unknown_netbsd.rs: fix formatting. This hopefully fixes the CI run after integration of this target. --- compiler/rustc_target/src/spec/i586_unknown_netbsd.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs b/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs index 9b36a3c28d35c..957cb38b79331 100644 --- a/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs @@ -1,13 +1,10 @@ -use crate::spec::{Cc, Lld, LinkerFlavor, StackProbeType, Target, TargetOptions}; +use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::netbsd_base::opts(); base.cpu = "pentium".into(); base.max_atomic_width = Some(64); - base.pre_link_args - .entry(LinkerFlavor::Gnu(Cc::Yes, Lld::No)) - .or_default() - .push("-m32".into()); + base.pre_link_args.entry(LinkerFlavor::Gnu(Cc::Yes, Lld::No)).or_default().push("-m32".into()); base.stack_probes = StackProbeType::Call; Target { From 0f04e2dd8f08951b3b9d0641febdcf3003f876aa Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Fri, 27 Oct 2023 09:37:25 +0000 Subject: [PATCH 05/13] For i586/NetBSD: fix another formatting insistence. --- compiler/rustc_llvm/build.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index e4412132136bf..fe13162cd4a3c 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -261,9 +261,7 @@ fn main() { // On NetBSD/i386, gcc and g++ is built for i486 (to maximize backward compat) // However, LLVM insists on using 64-bit atomics. // This gives rise to a need to link rust itself with -latomic for these targets - if target.starts_with("i586") - || target.starts_with("i686") - { + if target.starts_with("i586") || target.starts_with("i686") { println!("cargo:rustc-link-lib=atomic"); } println!("cargo:rustc-link-lib=z"); From a510288f0a89406ca0487cc0b1f41eb5d432208c Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Sat, 28 Oct 2023 12:14:30 +0000 Subject: [PATCH 06/13] i586_unknown_netbsd.rs: drop "-m32" flag insertion to gcc. This triggers a consistency check in rust (that all linker flavours must have identical arguments), and on NetBSD/i386, the 32-bitness is implicitly chosen through the chosen toolchain, and appears to not be required. So drop it, and also drop the imports of the now-no-longer-used identifiers. --- compiler/rustc_target/src/spec/i586_unknown_netbsd.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs b/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs index 957cb38b79331..0d8bdc3f89f72 100644 --- a/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/i586_unknown_netbsd.rs @@ -1,10 +1,9 @@ -use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions}; +use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::netbsd_base::opts(); base.cpu = "pentium".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gnu(Cc::Yes, Lld::No)).or_default().push("-m32".into()); base.stack_probes = StackProbeType::Call; Target { From d9ddad3921e24ff819a35ad030a0b7a9f7b098c6 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Sat, 28 Oct 2023 13:29:00 +0000 Subject: [PATCH 07/13] i586-unknown-netbsd: add entry in platform-support.md. --- src/doc/rustc/src/platform-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 4e55d36043027..f0be501fbbec3 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -152,6 +152,7 @@ target | std | notes `i586-pc-windows-msvc` | * | 32-bit Windows w/o SSE [^x86_32-floats-x87] `i586-unknown-linux-gnu` | ✓ | 32-bit Linux w/o SSE (kernel 3.2, glibc 2.17) [^x86_32-floats-x87] `i586-unknown-linux-musl` | ✓ | 32-bit Linux w/o SSE, MUSL [^x86_32-floats-x87] +[`i586-unknown-netbsd`](platform-support/netbsd.md) | ✓ | 32-bir x86, restricted to Pentium [`i686-linux-android`](platform-support/android.md) | ✓ | 32-bit x86 Android [^x86_32-floats-return-ABI] `i686-unknown-freebsd` | ✓ | 32-bit FreeBSD [^x86_32-floats-return-ABI] `i686-unknown-linux-musl` | ✓ | 32-bit Linux with MUSL [^x86_32-floats-return-ABI] From 3bb0c94eb6d62e6773da3bcd2043ce85937d6cfc Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 28 Oct 2023 19:36:09 +0300 Subject: [PATCH 08/13] change default output mode of `BootstrapCommand` Signed-off-by: onur-ozkan --- src/bootstrap/src/utils/exec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 9c1c21cd95894..0aede2022badd 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -54,7 +54,7 @@ impl<'a> From<&'a mut Command> for BootstrapCommand<'a> { Self { command, failure_behavior: BehaviorOnFailure::Exit, - output_mode: OutputMode::SuppressOnSuccess, + output_mode: OutputMode::PrintAll, } } } From f5fa36fbb72fe6d676adcb9bb7c1cba869c81c00 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Sat, 28 Oct 2023 16:50:14 +0000 Subject: [PATCH 09/13] i586-unknown-netbsd platform-support.md: fix typo. --- src/doc/rustc/src/platform-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index f0be501fbbec3..ef373298efa11 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -152,7 +152,7 @@ target | std | notes `i586-pc-windows-msvc` | * | 32-bit Windows w/o SSE [^x86_32-floats-x87] `i586-unknown-linux-gnu` | ✓ | 32-bit Linux w/o SSE (kernel 3.2, glibc 2.17) [^x86_32-floats-x87] `i586-unknown-linux-musl` | ✓ | 32-bit Linux w/o SSE, MUSL [^x86_32-floats-x87] -[`i586-unknown-netbsd`](platform-support/netbsd.md) | ✓ | 32-bir x86, restricted to Pentium +[`i586-unknown-netbsd`](platform-support/netbsd.md) | ✓ | 32-bit x86, restricted to Pentium [`i686-linux-android`](platform-support/android.md) | ✓ | 32-bit x86 Android [^x86_32-floats-return-ABI] `i686-unknown-freebsd` | ✓ | 32-bit FreeBSD [^x86_32-floats-return-ABI] `i686-unknown-linux-musl` | ✓ | 32-bit Linux with MUSL [^x86_32-floats-return-ABI] From 236f6ba261593e9704af8fe188ace73b3e395594 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 28 Oct 2023 20:02:41 +0300 Subject: [PATCH 10/13] set `BootstrapCommand` output mode for submodules Signed-off-by: onur-ozkan --- src/bootstrap/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 8dd1a698dfa8e..d7f49a6d11b9c 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -586,7 +586,11 @@ impl Build { .args(&["diff-index", "--quiet", "HEAD"]) .current_dir(&absolute_path), ) - .allow_failure(), + .allow_failure() + .output_mode(match self.is_verbose() { + true => OutputMode::PrintAll, + false => OutputMode::PrintOutput, + }), ); if has_local_modifications { self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path)); From 56643ec19e79ae1efba18ec9698dd297b1efaa57 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:21:31 +0200 Subject: [PATCH 11/13] Remove needless print ctx defs --- compiler/rustc_middle/src/ty/print/pretty.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 433ac33f1b820..8c76db60e3a70 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -53,7 +53,6 @@ macro_rules! p { } macro_rules! define_scoped_cx { ($cx:ident) => { - #[allow(unused_macros)] macro_rules! scoped_cx { () => { $cx @@ -408,8 +407,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { def_id: DefId, callers: &mut Vec, ) -> Result { - define_scoped_cx!(self); - debug!("try_print_visible_def_path: def_id={:?}", def_id); // If `def_id` is a direct or injected extern crate, return the @@ -1868,8 +1865,6 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> { def_id: DefId, args: &'tcx [GenericArg<'tcx>], ) -> Result<(), PrintError> { - define_scoped_cx!(self); - if args.is_empty() { match self.try_print_trimmed_def_path(def_id)? { true => return Ok(()), @@ -2401,8 +2396,6 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { let _ = write!(cx, "{cont}"); }; - define_scoped_cx!(self); - let possible_names = ('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}"))); let mut available_names = possible_names From 4dada601c17301ce897af77dbdf0375d657234a0 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:22:47 +0200 Subject: [PATCH 12/13] Move macros to usage --- compiler/rustc_middle/src/ty/print/pretty.rs | 80 ++++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 8c76db60e3a70..0bdebc41842ca 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2623,46 +2623,6 @@ where } } -macro_rules! forward_display_to_print { - ($($ty:ty),+) => { - // Some of the $ty arguments may not actually use 'tcx - $(#[allow(unused_lifetimes)] impl<'tcx> fmt::Display for $ty { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - ty::tls::with(|tcx| { - let mut cx = FmtPrinter::new(tcx, Namespace::TypeNS); - tcx.lift(*self) - .expect("could not lift for printing") - .print(&mut cx)?; - f.write_str(&cx.into_buffer())?; - Ok(()) - }) - } - })+ - }; -} - -macro_rules! define_print_and_forward_display { - (($self:ident, $cx:ident): $($ty:ty $print:block)+) => { - define_print!(($self, $cx): $($ty $print)*); - forward_display_to_print!($($ty),+); - }; -} - -macro_rules! define_print { - (($self:ident, $cx:ident): $($ty:ty $print:block)+) => { - $(impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for $ty { - fn print(&$self, $cx: &mut P) -> Result<(), PrintError> { - #[allow(unused_mut)] - let mut $cx = $cx; - define_scoped_cx!($cx); - let _: () = $print; - #[allow(unreachable_code)] - Ok(()) - } - })+ - }; -} - /// Wrapper type for `ty::TraitRef` which opts-in to pretty printing only /// the trait path. That is, it will print `Trait` instead of /// `>`. @@ -2737,6 +2697,46 @@ pub struct PrintClosureAsImpl<'tcx> { pub closure: ty::ClosureArgs<'tcx>, } +macro_rules! forward_display_to_print { + ($($ty:ty),+) => { + // Some of the $ty arguments may not actually use 'tcx + $(#[allow(unused_lifetimes)] impl<'tcx> fmt::Display for $ty { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + ty::tls::with(|tcx| { + let mut cx = FmtPrinter::new(tcx, Namespace::TypeNS); + tcx.lift(*self) + .expect("could not lift for printing") + .print(&mut cx)?; + f.write_str(&cx.into_buffer())?; + Ok(()) + }) + } + })+ + }; +} + +macro_rules! define_print { + (($self:ident, $cx:ident): $($ty:ty $print:block)+) => { + $(impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for $ty { + fn print(&$self, $cx: &mut P) -> Result<(), PrintError> { + #[allow(unused_mut)] + let mut $cx = $cx; + define_scoped_cx!($cx); + let _: () = $print; + #[allow(unreachable_code)] + Ok(()) + } + })+ + }; +} + +macro_rules! define_print_and_forward_display { + (($self:ident, $cx:ident): $($ty:ty $print:block)+) => { + define_print!(($self, $cx): $($ty $print)*); + forward_display_to_print!($($ty),+); + }; +} + forward_display_to_print! { ty::Region<'tcx>, Ty<'tcx>, From 4e2bbfef3eaddf399e33caeaa3976005855dc322 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:25:43 +0200 Subject: [PATCH 13/13] Remove needless `allow`s --- compiler/rustc_middle/src/ty/print/mod.rs | 2 -- compiler/rustc_middle/src/ty/print/pretty.rs | 3 --- 2 files changed, 5 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 80af8a9255398..6bbc8f70f5155 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -12,8 +12,6 @@ pub use self::pretty::*; pub type PrintError = std::fmt::Error; -// FIXME(eddyb) false positive, the lifetime parameters are used with `P: Printer<...>`. -#[allow(unused_lifetimes)] pub trait Print<'tcx, P> { fn print(&self, cx: &mut P) -> Result<(), PrintError>; } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 0bdebc41842ca..799ba2c35ec8b 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2719,11 +2719,8 @@ macro_rules! define_print { (($self:ident, $cx:ident): $($ty:ty $print:block)+) => { $(impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for $ty { fn print(&$self, $cx: &mut P) -> Result<(), PrintError> { - #[allow(unused_mut)] - let mut $cx = $cx; define_scoped_cx!($cx); let _: () = $print; - #[allow(unreachable_code)] Ok(()) } })+