-
Notifications
You must be signed in to change notification settings - Fork 14k
Add new Tier-3 target: riscv64im-unknown-none-elf #148790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| use crate::spec::{ | ||
| Arch, Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetMetadata, | ||
| TargetOptions, | ||
| }; | ||
|
|
||
| pub(crate) fn target() -> Target { | ||
| Target { | ||
| data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(), | ||
| llvm_target: "riscv64".into(), | ||
| metadata: TargetMetadata { | ||
| description: Some("Bare RISC-V (RV64IM ISA)".into()), | ||
| tier: Some(3), | ||
| host_tools: Some(false), | ||
| std: Some(false), | ||
| }, | ||
| pointer_width: 64, | ||
| arch: Arch::RiscV64, | ||
|
|
||
| options: TargetOptions { | ||
| linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
| linker: Some("rust-lld".into()), | ||
| cpu: "generic-rv64".into(), | ||
| max_atomic_width: Some(64), | ||
| atomic_cas: false, | ||
| features: "+m,+forced-atomics".into(), | ||
| llvm_abiname: "lp64".into(), | ||
| panic_strategy: PanicStrategy::Abort, | ||
| relocation_model: RelocModel::Static, | ||
| code_model: Some(CodeModel::Medium), | ||
| emit_debug_gdb_scripts: false, | ||
| eh_frame_header: false, | ||
| ..Default::default() | ||
| }, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # `riscv64im-unknown-none-elf` | ||
|
|
||
| **Tier: 3** | ||
|
|
||
| Bare-metal target for RISC-V CPUs with the RV64IM ISA. | ||
|
|
||
| ## Target maintainers | ||
|
|
||
| * Rust Embedded Working Group, [RISC-V team](https://github.com/rust-embedded/wg#the-risc-v-team) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@almindor @dkhayes117 @romancardenas @MabezDev @jessebraham @rmsyn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok from my side! |
||
|
|
||
| ## Requirements | ||
|
|
||
| This target is cross-compiled and uses static linking. The target supports `core` and `alloc`, but not `std`. | ||
|
|
||
| As the RV64IM ISA lacks the "A" (Atomics) extension, atomic operations are emulated using the `+forced-atomics` feature. | ||
|
|
||
| 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. | ||
|
|
||
| [`riscv-rt`]: https://crates.io/crates/riscv-rt | ||
| [`riscv-rust-quickstart`]: https://github.com/riscv-rust/riscv-rust-quickstart | ||
|
|
||
| ## Building the target | ||
|
|
||
| You can build Rust with support for the target by adding it to the `target` list in `bootstrap.toml`: | ||
|
|
||
| ```toml | ||
| [build] | ||
| target = ["riscv64im-unknown-none-elf"] | ||
| ``` | ||
|
|
||
| Alternatively, you can use the `-Z build-std` flag to build the standard library on-demand: | ||
|
|
||
| ```bash | ||
| cargo build -Z build-std=core,alloc --target riscv64im-unknown-none-elf | ||
| ``` | ||
|
|
||
| ## Building Rust programs | ||
|
|
||
| Rust does not yet ship pre-compiled artifacts for this target. To compile for this target (see "Building the target" above) | ||
|
|
||
| ## Testing | ||
|
|
||
| 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. | ||
|
|
||
| ## Cross-compilation toolchains and C code | ||
|
|
||
| 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`. | ||
Uh oh!
There was an error while loading. Please reload this page.