From 763bc13ccce4b81ec623d4e8c0a34f77d0401f0f Mon Sep 17 00:00:00 2001 From: Piotr Kubaj Date: Thu, 22 Jul 2021 17:29:33 +0200 Subject: [PATCH] Add support for powerpc-unknown-freebsd --- compiler/rustc_target/src/spec/mod.rs | 1 + .../src/spec/powerpc_unknown_freebsd.rs | 27 +++++++++++++++++++ src/bootstrap/native.rs | 9 +++++++ src/doc/rustc/src/platform-support.md | 1 + 4 files changed, 38 insertions(+) create mode 100644 compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 0185132ee36..ad84e07edfb 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -802,6 +802,7 @@ fn $module() { ("armv6-unknown-freebsd", armv6_unknown_freebsd), ("armv7-unknown-freebsd", armv7_unknown_freebsd), ("i686-unknown-freebsd", i686_unknown_freebsd), + ("powerpc-unknown-freebsd", powerpc_unknown_freebsd), ("powerpc64-unknown-freebsd", powerpc64_unknown_freebsd), ("powerpc64le-unknown-freebsd", powerpc64le_unknown_freebsd), ("x86_64-unknown-freebsd", x86_64_unknown_freebsd), diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs b/compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs new file mode 100644 index 00000000000..e11318027d5 --- /dev/null +++ b/compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs @@ -0,0 +1,27 @@ +use crate::abi::Endian; +use crate::spec::{LinkerFlavor, RelocModel, Target, TargetOptions}; + +pub fn target() -> Target { + let mut base = super::freebsd_base::opts(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + // Extra hint to linker that we are generating secure-PLT code. + base.pre_link_args + .entry(LinkerFlavor::Gcc) + .or_default() + .push("--target=powerpc-unknown-freebsd13.0".to_string()); + base.max_atomic_width = Some(32); + + Target { + llvm_target: "powerpc-unknown-freebsd13.0".to_string(), + pointer_width: 32, + data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), + arch: "powerpc".to_string(), + options: TargetOptions { + endian: Endian::Big, + features: "+secure-plt".to_string(), + relocation_model: RelocModel::Pic, + mcount: "_mcount".to_string(), + ..base + }, + } +} diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 1be414b29a1..b8a1513f2a6 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -118,6 +118,10 @@ fn run(self, builder: &Builder<'_>) -> PathBuf { let idx = target.triple.find('-').unwrap(); format!("riscv{}{}", &target.triple[5..7], &target.triple[idx..]) + } else if self.target.starts_with("powerpc") && self.target.ends_with("freebsd") { + // FreeBSD 13 had incompatible ABI changes on all PowerPC platforms. + // Set the version suffix to 13.0 so the correct target details are used. + format!("{}{}", self.target, "13.0") } else { target.to_string() }; @@ -277,6 +281,11 @@ fn run(self, builder: &Builder<'_>) -> PathBuf { } } + // Workaround for ppc32 lld limitation + if target == "powerpc-unknown-freebsd" { + cfg.define("CMAKE_EXE_LINKER_FLAGS", "-fuse-ld=bfd"); + } + // https://llvm.org/docs/HowToCrossCompileLLVM.html if target != builder.config.build { builder.ensure(Llvm { target: builder.config.build }); diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 885010b039e..90ef48798dd 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -249,6 +249,7 @@ target | std | host | notes `powerpc-wrs-vxworks` | ? | | `powerpc64-unknown-freebsd` | ✓ | ✓ | PPC64 FreeBSD (ELFv1 and ELFv2) `powerpc64le-unknown-freebsd` | | | PPC64LE FreeBSD +`powerpc-unknown-freebsd` | | | PowerPC FreeBSD `powerpc64-unknown-linux-musl` | ? | | `powerpc64-wrs-vxworks` | ? | | `powerpc64le-unknown-linux-musl` | ? | |