diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index f606fa483ca..acb1d9607a4 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 00000000000..9b36a3c28d3 --- /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 f1c7513d885..73e5c6c858b 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1426,6 +1426,7 @@ fn $module() { ("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),