Skip to content

Commit e6381a7

Browse files
committed
Auto merge of #53822 - dvc94ch:riscv, r=japaric
[RISCV] Use lld as the default linker; Enable C extension; Add riscv32imc-unknown-none-elf target The riscv32imc-unknown-none-elf target is intended for soft cores. The riscv32imc target is supported by the following popular soft cores: picorv32: https://github.com/cliffordwolf/picorv32 vexriscv: https://github.com/SpinalHDL/VexRiscv pulp riscy: https://github.com/pulp-platform/riscv pulp zero-riscy: https://github.com/pulp-platform/zero-riscy
2 parents b7e4402 + 173c679 commit e6381a7

File tree

6 files changed

+82
-18
lines changed

6 files changed

+82
-18
lines changed

Diff for: src/ci/docker/dist-various-1/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ ENV TARGETS=$TARGETS,thumbv6m-none-eabi
102102
ENV TARGETS=$TARGETS,thumbv7m-none-eabi
103103
ENV TARGETS=$TARGETS,thumbv7em-none-eabi
104104
ENV TARGETS=$TARGETS,thumbv7em-none-eabihf
105+
ENV TARGETS=$TARGETS,riscv32imc-unknown-none-elf
105106
ENV TARGETS=$TARGETS,riscv32imac-unknown-none-elf
106107
ENV TARGETS=$TARGETS,armebv7r-none-eabi
107108
ENV TARGETS=$TARGETS,armebv7r-none-eabihf

Diff for: src/librustc_target/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ mod thumb_base;
7474
mod l4re_base;
7575
mod fuchsia_base;
7676
mod redox_base;
77+
mod riscv_base;
7778

7879
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
7980
RustcEncodable, RustcDecodable)]
@@ -406,6 +407,7 @@ supported_targets! {
406407
("aarch64-unknown-hermit", aarch64_unknown_hermit),
407408
("x86_64-unknown-hermit", x86_64_unknown_hermit),
408409

410+
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
409411
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
410412

411413
("aarch64-unknown-none", aarch64_unknown_none),

Diff for: src/librustc_target/spec/riscv32imac_unknown_none_elf.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use spec::{LinkerFlavor, PanicStrategy, Target, TargetOptions, TargetResult};
12-
use spec::abi::{Abi};
11+
use spec::{LinkerFlavor, LldFlavor, PanicStrategy,
12+
Target, TargetOptions, TargetResult};
1313

1414
pub fn target() -> TargetResult {
1515
Ok(Target {
@@ -22,31 +22,19 @@ pub fn target() -> TargetResult {
2222
target_env: String::new(),
2323
target_vendor: "unknown".to_string(),
2424
arch: "riscv32".to_string(),
25-
linker_flavor: LinkerFlavor::Ld,
25+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
2626

2727
options: TargetOptions {
28-
linker: Some("riscv32-unknown-elf-ld".to_string()),
28+
linker: Some("rust-lld".to_string()),
2929
cpu: "generic-rv32".to_string(),
3030
max_atomic_width: Some(32),
3131
atomic_cas: false, // incomplete +a extension
32-
features: "+m,+a".to_string(), // disable +c extension
32+
features: "+m,+a,+c".to_string(),
3333
executables: true,
3434
panic_strategy: PanicStrategy::Abort,
3535
relocation_model: "static".to_string(),
3636
emit_debug_gdb_scripts: false,
37-
abi_blacklist: vec![
38-
Abi::Cdecl,
39-
Abi::Stdcall,
40-
Abi::Fastcall,
41-
Abi::Vectorcall,
42-
Abi::Thiscall,
43-
Abi::Aapcs,
44-
Abi::Win64,
45-
Abi::SysV64,
46-
Abi::PtxKernel,
47-
Abi::Msp430Interrupt,
48-
Abi::X86Interrupt,
49-
],
37+
abi_blacklist: super::riscv_base::abi_blacklist(),
5038
.. Default::default()
5139
},
5240
})
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use spec::{LinkerFlavor, LldFlavor, PanicStrategy,
12+
Target, TargetOptions, TargetResult};
13+
14+
pub fn target() -> TargetResult {
15+
Ok(Target {
16+
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(),
17+
llvm_target: "riscv32".to_string(),
18+
target_endian: "little".to_string(),
19+
target_pointer_width: "32".to_string(),
20+
target_c_int_width: "32".to_string(),
21+
target_os: "none".to_string(),
22+
target_env: String::new(),
23+
target_vendor: "unknown".to_string(),
24+
arch: "riscv32".to_string(),
25+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
26+
27+
options: TargetOptions {
28+
linker: Some("rust-lld".to_string()),
29+
cpu: "generic-rv32".to_string(),
30+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86005
31+
max_atomic_width: None, //Some(32),
32+
atomic_cas: false,
33+
features: "+m,+c".to_string(),
34+
executables: true,
35+
panic_strategy: PanicStrategy::Abort,
36+
relocation_model: "static".to_string(),
37+
emit_debug_gdb_scripts: false,
38+
abi_blacklist: super::riscv_base::abi_blacklist(),
39+
.. Default::default()
40+
},
41+
})
42+
}

Diff for: src/librustc_target/spec/riscv_base.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use spec::abi::Abi;
12+
13+
// All the calling conventions trigger an assertion(Unsupported calling
14+
// convention) in llvm on RISCV
15+
pub fn abi_blacklist() -> Vec<Abi> {
16+
vec![
17+
Abi::Cdecl,
18+
Abi::Stdcall,
19+
Abi::Fastcall,
20+
Abi::Vectorcall,
21+
Abi::Thiscall,
22+
Abi::Aapcs,
23+
Abi::Win64,
24+
Abi::SysV64,
25+
Abi::PtxKernel,
26+
Abi::Msp430Interrupt,
27+
Abi::X86Interrupt,
28+
Abi::AmdGpuKernel,
29+
]
30+
}

Diff for: src/tools/build-manifest/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static TARGETS: &'static [&'static str] = &[
9292
"powerpc64-unknown-linux-gnu",
9393
"powerpc64le-unknown-linux-gnu",
9494
"powerpc64le-unknown-linux-musl",
95+
"riscv32imc-unknown-none-elf",
9596
"riscv32imac-unknown-none-elf",
9697
"s390x-unknown-linux-gnu",
9798
"sparc-unknown-linux-gnu",

0 commit comments

Comments
 (0)