Skip to content

Commit 0ea7d0b

Browse files
authored
Rollup merge of #148790 - kevaundray:kw/rv64im-unknown-elf, r=davidtwco,JonathanBrouwer
Add new Tier-3 target: riscv64im-unknown-none-elf This PR proposes to add riscv64im-unknown-none-elf, a subset of the already supported riscv64imac-unknown-none-elf. The motivation behind this PR is that we want to standardize (most) zkVMs on riscv64im-none and riscv64ima-none. Having different variants of riscv extensions, also seems to be within expectation, atleast with respects to riscv32. Note: This does not mean that we will be able to remove [riscv32im-risc0-zkvm-elf](https://doc.rust-lang.org/rustc/platform-support/riscv32im-risc0-zkvm-elf.html) -- I am not aware of all of the dependents for this **Tier-3 Policy** > A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.) I assigned Rust Embedded Working Group, since they are already maintaining riscv64IMAC, though I am happy to assign myself. > Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target. It follows the naming convention of the other bare metal riscv targets > Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users. This has the same requirements as riscv{32, 64}imac > Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions. > Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions. > The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary. > Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ````@)```` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages. > Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target. > Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.) Acknowledging the above.
2 parents bd1e142 + 9ba7852 commit 0ea7d0b

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,7 @@ supported_targets! {
16861686
("riscv32imac-unknown-xous-elf", riscv32imac_unknown_xous_elf),
16871687
("riscv32gc-unknown-linux-gnu", riscv32gc_unknown_linux_gnu),
16881688
("riscv32gc-unknown-linux-musl", riscv32gc_unknown_linux_musl),
1689+
("riscv64im-unknown-none-elf", riscv64im_unknown_none_elf),
16891690
("riscv64imac-unknown-none-elf", riscv64imac_unknown_none_elf),
16901691
("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
16911692
("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::spec::{
2+
Arch, Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetMetadata,
3+
TargetOptions,
4+
};
5+
6+
pub(crate) fn target() -> Target {
7+
Target {
8+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
9+
llvm_target: "riscv64".into(),
10+
metadata: TargetMetadata {
11+
description: Some("Bare RISC-V (RV64IM ISA)".into()),
12+
tier: Some(3),
13+
host_tools: Some(false),
14+
std: Some(false),
15+
},
16+
pointer_width: 64,
17+
arch: Arch::RiscV64,
18+
19+
options: TargetOptions {
20+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
21+
linker: Some("rust-lld".into()),
22+
cpu: "generic-rv64".into(),
23+
max_atomic_width: Some(64),
24+
atomic_cas: false,
25+
features: "+m,+forced-atomics".into(),
26+
llvm_abiname: "lp64".into(),
27+
panic_strategy: PanicStrategy::Abort,
28+
relocation_model: RelocModel::Static,
29+
code_model: Some(CodeModel::Medium),
30+
emit_debug_gdb_scripts: false,
31+
eh_frame_header: false,
32+
..Default::default()
33+
},
34+
}
35+
}

src/bootstrap/src/core/sanity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[
4141
"sparc64-unknown-helenos",
4242
// just a dummy comment so the list doesn't get onelined
4343
"riscv64gc-unknown-redox",
44+
"riscv64im-unknown-none-elf",
4445
"hexagon-unknown-qurt",
4546
];
4647

src/doc/rustc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
- [riscv32i\*-unknown-none-elf](platform-support/riscv32-unknown-none-elf.md)
113113
- [riscv32im-risc0-zkvm-elf](platform-support/riscv32im-risc0-zkvm-elf.md)
114114
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
115+
- [riscv64im-unknown-none-elf](platform-support/riscv64im-unknown-none-elf.md)
115116
- [riscv64gc-unknown-linux-gnu](platform-support/riscv64gc-unknown-linux-gnu.md)
116117
- [riscv64gc-unknown-linux-musl](platform-support/riscv64gc-unknown-linux-musl.md)
117118
- [riscv64a23-unknown-linux-gnu](platform-support/riscv64a23-unknown-linux-gnu.md)

src/doc/rustc/src/platform-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ target | std | notes
184184
[`riscv32imc-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | Bare RISC-V (RV32IMC ISA)
185185
[`riscv64gc-unknown-linux-musl`](platform-support/riscv64gc-unknown-linux-musl.md) | ✓ |RISC-V Linux (kernel 4.20+, musl 1.2.5)
186186
`riscv64gc-unknown-none-elf` | * | Bare RISC-V (RV64IMAFDC ISA)
187+
[`riscv64im-unknown-none-elf`](platform-support/riscv64im-unknown-none-elf.md) | * | Bare RISC-V (RV64IM ISA)
187188
`riscv64imac-unknown-none-elf` | * | Bare RISC-V (RV64IMAC ISA)
188189
`sparc64-unknown-linux-gnu` | ✓ | SPARC Linux (kernel 4.4+, glibc 2.23)
189190
[`thumbv6m-none-eabi`](platform-support/thumbv6m-none-eabi.md) | * | Bare Armv6-M
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# `riscv64im-unknown-none-elf`
2+
3+
**Tier: 3**
4+
5+
Bare-metal target for RISC-V CPUs with the RV64IM ISA.
6+
7+
## Target maintainers
8+
9+
* Rust Embedded Working Group, [RISC-V team](https://github.com/rust-embedded/wg#the-risc-v-team)
10+
11+
## Requirements
12+
13+
This target is cross-compiled and uses static linking. The target supports `core` and `alloc`, but not `std`.
14+
15+
As the RV64IM ISA lacks the "A" (Atomics) extension, atomic operations are emulated using the `+forced-atomics` feature.
16+
17+
No external toolchain is required and the default `rust-lld` linker works, but you must specify a linker script. The [`riscv-rt`] crate provides suitable linker scripts. The [`riscv-rust-quickstart`] repository gives examples of RISC-V bare-metal projects.
18+
19+
[`riscv-rt`]: https://crates.io/crates/riscv-rt
20+
[`riscv-rust-quickstart`]: https://github.com/riscv-rust/riscv-rust-quickstart
21+
22+
## Building the target
23+
24+
You can build Rust with support for the target by adding it to the `target` list in `bootstrap.toml`:
25+
26+
```toml
27+
[build]
28+
target = ["riscv64im-unknown-none-elf"]
29+
```
30+
31+
Alternatively, you can use the `-Z build-std` flag to build the standard library on-demand:
32+
33+
```bash
34+
cargo build -Z build-std=core,alloc --target riscv64im-unknown-none-elf
35+
```
36+
37+
## Building Rust programs
38+
39+
Rust does not yet ship pre-compiled artifacts for this target. To compile for this target (see "Building the target" above)
40+
41+
## Testing
42+
43+
This is a cross-compiled `no-std` target, which must be run either in a simulator or by programming onto suitable hardware. It is not possible to run the Rust test-suite on this target.
44+
45+
## Cross-compilation toolchains and C code
46+
47+
This target supports C code. If interlinking with C or C++, you may need to use `riscv64-unknown-elf-gcc` with the appropriate `-march=rv64im -mabi=lp64` flags as a linker instead of `rust-lld`.

tests/assembly-llvm/targets/targets-elf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@
520520
//@ revisions: riscv64gc_unknown_redox
521521
//@ [riscv64gc_unknown_redox] compile-flags: --target riscv64gc-unknown-redox
522522
//@ [riscv64gc_unknown_redox] needs-llvm-components: riscv
523+
//@ revisions: riscv64im_unknown_none_elf
524+
//@ [riscv64im_unknown_none_elf] compile-flags: --target riscv64im-unknown-none-elf
525+
//@ [riscv64im_unknown_none_elf] needs-llvm-components: riscv
523526
//@ revisions: riscv64imac_unknown_none_elf
524527
//@ [riscv64imac_unknown_none_elf] compile-flags: --target riscv64imac-unknown-none-elf
525528
//@ [riscv64imac_unknown_none_elf] needs-llvm-components: riscv

0 commit comments

Comments
 (0)