From 6642b4b1e2f2edec71cdf3fabef8fcdc8b8517a7 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Wed, 25 Oct 2023 15:23:34 +0000 Subject: [PATCH 1/7] 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 2/7] 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 893e7266376f8c7629a5b5130e95bc3063128f77 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Fri, 27 Oct 2023 07:24:31 +0000 Subject: [PATCH 3/7] 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 4/7] 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 5/7] 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 6/7] 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 f5fa36fbb72fe6d676adcb9bb7c1cba869c81c00 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Sat, 28 Oct 2023 16:50:14 +0000 Subject: [PATCH 7/7] 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]