From 47474f10558a473258510b0e5dea13d607a5d34c Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Sat, 27 Nov 2021 07:23:55 +0100 Subject: [PATCH] Add riscv64gc-unknown-freebsd --- compiler/rustc_llvm/build.rs | 2 +- compiler/rustc_target/src/spec/mod.rs | 1 + .../src/spec/riscv64gc_unknown_freebsd.rs | 18 ++++++++++++++++++ library/std/src/os/raw/mod.rs | 6 ++++-- src/bootstrap/bootstrap.py | 2 +- src/bootstrap/native.rs | 2 +- src/doc/rustc/src/platform-support.md | 1 + 7 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 943ce589c4f..7f3345d2a70 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -277,7 +277,7 @@ fn main() { }; // RISC-V requires libatomic for sub-word atomic operations - if target.starts_with("riscv") { + if !target.contains("freebsd") && target.starts_with("riscv") { println!("cargo:rustc-link-lib=atomic"); } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 69b90bf10fe..35a7ec5f946 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -813,6 +813,7 @@ supported_targets! { ("powerpc-unknown-freebsd", powerpc_unknown_freebsd), ("powerpc64-unknown-freebsd", powerpc64_unknown_freebsd), ("powerpc64le-unknown-freebsd", powerpc64le_unknown_freebsd), + ("riscv64gc-unknown-freebsd", riscv64gc_unknown_freebsd), ("x86_64-unknown-freebsd", x86_64_unknown_freebsd), ("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly), diff --git a/compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs b/compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs new file mode 100644 index 00000000000..1ea1b9bea2e --- /dev/null +++ b/compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs @@ -0,0 +1,18 @@ +use crate::spec::{CodeModel, Target, TargetOptions}; + +pub fn target() -> Target { + Target { + llvm_target: "riscv64-unknown-freebsd".to_string(), + pointer_width: 64, + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(), + arch: "riscv64".to_string(), + options: TargetOptions { + code_model: Some(CodeModel::Medium), + cpu: "generic-rv64".to_string(), + features: "+m,+a,+f,+d,+c".to_string(), + llvm_abiname: "lp64d".to_string(), + max_atomic_width: Some(64), + ..super::freebsd_base::opts() + }, + } +} diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 01392ffab79..f0b38d29845 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -69,7 +69,8 @@ type_alias! { "char.md", c_char = u8, NonZero_c_char = NonZeroU8; target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc", - target_arch = "powerpc64" + target_arch = "powerpc64", + target_arch = "riscv64" ) ), all( @@ -112,7 +113,8 @@ type_alias! { "char.md", c_char = i8, NonZero_c_char = NonZeroI8; target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc", - target_arch = "powerpc64" + target_arch = "powerpc64", + target_arch = "riscv64" ) ), all( diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 38d3c7aec49..6b6cefe487a 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -265,7 +265,7 @@ def default_build_triple(verbose): err = "unknown OS type: {}".format(ostype) sys.exit(err) - if cputype == 'powerpc' and ostype == 'unknown-freebsd': + if cputype in ['powerpc', 'riscv'] and ostype == 'unknown-freebsd': cputype = subprocess.check_output( ['uname', '-p']).strip().decode(default_encoding) cputype_mapper = { diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 37578e30f6d..f50797285d2 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -249,7 +249,7 @@ impl Step for Llvm { } } - if target.starts_with("riscv") { + if !target.contains("freebsd") && target.starts_with("riscv") { // In RISC-V, using C++ atomics require linking to `libatomic` but the LLVM build // system check cannot detect this. Therefore it is set manually here. if !builder.config.llvm_tools_enabled { diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 6b0c336b3c7..eb54edc16f5 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -267,6 +267,7 @@ target | std | host | notes `riscv32gc-unknown-linux-gnu` | | | RISC-V Linux (kernel 5.4, glibc 2.33) `riscv32gc-unknown-linux-musl` | | | RISC-V Linux (kernel 5.4, musl + RISCV32 support patches) `riscv32imc-esp-espidf` | ✓ | | RISC-V ESP-IDF +`riscv64gc-unknown-freebsd` | | | RISC-V FreeBSD `riscv64gc-unknown-linux-musl` | | | RISC-V Linux (kernel 4.20, musl 1.2.0) `s390x-unknown-linux-musl` | | | S390x Linux (kernel 2.6.32, MUSL) `sparc-unknown-linux-gnu` | ✓ | | 32-bit SPARC Linux