Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,11 @@ fn main() {
"stdc++"
};

// RISC-V requires libatomic for sub-word atomic operations
if target.starts_with("riscv") {
// RISC-V GCC erroneously requires libatomic for sub-word
// atomic operations. FreeBSD uses Clang as its system
// compiler and provides no libatomic in its base system so
// does not want this.
if !target.contains("freebsd") && target.starts_with("riscv") {
println!("cargo:rustc-link-lib=atomic");
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs
Original file line number Diff line number Diff line change
@@ -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()
},
}
}
6 changes: 4 additions & 2 deletions library/std/src/os/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
11 changes: 8 additions & 3 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,14 @@ impl Step for Llvm {
}
}

if 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 !target.contains("freebsd") && target.starts_with("riscv") {
// RISC-V GCC erroneously requires linking against
// `libatomic` when using 1-byte and 2-byte C++
// atomics but the LLVM build system check cannot
// detect this. Therefore it is set manually here.
// FreeBSD uses Clang as its system compiler and
// provides no libatomic in its base system so does
// not want this.
if !builder.config.llvm_tools_enabled {
cfg.define("CMAKE_EXE_LINKER_FLAGS", "-latomic");
} else {
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down