Skip to content

Commit 157d0f0

Browse files
authored
Rollup merge of #112310 - loongarch-rs:bare-metal, r=WaffleLapkin
Add new Tier-3 targets: `loongarch64-unknown-none*` This PR adds new Tier-3 targets `loongarch64-unknown-none*` that are introduced by MCP rust-lang/compiler-team#628
2 parents 1788d49 + bd32075 commit 157d0f0

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use super::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy};
2+
use super::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
Target {
6+
llvm_target: "loongarch64-unknown-none".into(),
7+
pointer_width: 64,
8+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),
9+
arch: "loongarch64".into(),
10+
options: TargetOptions {
11+
cpu: "generic".into(),
12+
features: "+f,+d".into(),
13+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::No),
14+
llvm_abiname: "lp64d".into(),
15+
max_atomic_width: Some(64),
16+
position_independent_executables: true,
17+
static_position_independent_executables: true,
18+
panic_strategy: PanicStrategy::Abort,
19+
code_model: Some(CodeModel::Small),
20+
..Default::default()
21+
},
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use super::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy};
2+
use super::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
Target {
6+
llvm_target: "loongarch64-unknown-none-softfloat".into(),
7+
pointer_width: 64,
8+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),
9+
arch: "loongarch64".into(),
10+
options: TargetOptions {
11+
cpu: "generic".into(),
12+
features: "-f,-d".into(),
13+
abi: "softfloat".into(),
14+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::No),
15+
llvm_abiname: "lp64s".into(),
16+
max_atomic_width: Some(64),
17+
position_independent_executables: true,
18+
static_position_independent_executables: true,
19+
panic_strategy: PanicStrategy::Abort,
20+
code_model: Some(CodeModel::Small),
21+
..Default::default()
22+
},
23+
}
24+
}

compiler/rustc_target/src/spec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,9 @@ supported_targets! {
12931293
("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
12941294
("riscv64gc-unknown-linux-musl", riscv64gc_unknown_linux_musl),
12951295

1296+
("loongarch64-unknown-none", loongarch64_unknown_none),
1297+
("loongarch64-unknown-none-softfloat", loongarch64_unknown_none_softfloat),
1298+
12961299
("aarch64-unknown-none", aarch64_unknown_none),
12971300
("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat),
12981301

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [\*-unknown-fuchsia](platform-support/fuchsia.md)
3232
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
3333
- [loongarch\*-unknown-linux-\*](platform-support/loongarch-linux.md)
34+
- [loongarch\*-unknown-none\*](platform-support/loongarch-none.md)
3435
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
3536
- [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md)
3637
- [mipsel-sony-psx](platform-support/mipsel-sony-psx.md)

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

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ target | std | host | notes
267267
`i686-uwp-windows-gnu` | ? | |
268268
`i686-uwp-windows-msvc` | ? | |
269269
`i686-wrs-vxworks` | ? | |
270+
[`loongarch64-unknown-none`](platform-support/loongarch-none.md) | * | LoongArch64 Bare-metal (LP64D ABI)
271+
[`loongarch64-unknown-none-softfloat`](platform-support/loongarch-none.md) | * | LoongArch64 Bare-metal (LP64S ABI)
270272
[`m68k-unknown-linux-gnu`](platform-support/m68k-unknown-linux-gnu.md) | ? | | Motorola 680x0 Linux
271273
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
272274
[`mips64-openwrt-linux-musl`](platform-support/mips64-openwrt-linux-musl.md) | ? | | MIPS64 for OpenWrt Linux MUSL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# `loongarch*-unknown-none*`
2+
3+
**Tier: 3**
4+
5+
Freestanding/bare-metal LoongArch64 binaries in ELF format: firmware, kernels, etc.
6+
7+
| Target | Descriptions |
8+
|------------------------------------|-------------------------------------------------------|
9+
| loongarch64-unknown-none | LoongArch 64-bit, LP64D ABI (freestanding, hardfloat) |
10+
| loongarch64-unknown-none-softfloat | LoongArch 64-bit, LP64S ABI (freestanding, softfloat) |
11+
12+
## Target maintainers
13+
14+
- [WANG Rui](https://github.com/heiher) `[email protected]`
15+
- [WANG Xuerui](https://github.com/xen0n) `[email protected]`
16+
17+
## Requirements
18+
19+
This target is cross-compiled. There is no support for `std`. There is no
20+
default allocator, but it's possible to use `alloc` by supplying an allocator.
21+
22+
This allows the generated code to run in environments, such as kernels, which
23+
may need to avoid the use of such registers or which may have special considerations
24+
about the use of such registers (e.g. saving and restoring them to avoid breaking
25+
userspace code using the same registers). You can change code generation to use
26+
additional CPU features via the `-C target-feature=` codegen options to rustc, or
27+
via the `#[target_feature]` mechanism within Rust code.
28+
29+
By default, code generated with this target should run on any `loongarch`
30+
hardware; enabling additional target features may raise this baseline.
31+
32+
Code generated with this target will use the `small` code model by default.
33+
You can change this using the `-C code-model=` option to rustc.
34+
35+
On `loongarch64-unknown-none*`, `extern "C"` uses the [standard calling
36+
convention](https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html).
37+
38+
This target generates binaries in the ELF format. Any alternate formats or
39+
special considerations for binary layout will require linker options or linker
40+
scripts.
41+
42+
## Building the target
43+
44+
You can build Rust with support for the target by adding it to the `target`
45+
list in `config.toml`:
46+
47+
```toml
48+
[build]
49+
build-stage = 1
50+
target = ["loongarch64-unknown-none"]
51+
```
52+
53+
## Building Rust programs
54+
55+
```text
56+
# target flag may be used with any cargo or rustc command
57+
cargo build --target loongarch64-unknown-none
58+
```
59+
60+
## Testing
61+
62+
As `loongarch64-unknown-none*` supports a variety of different environments and does
63+
not support `std`, this target does not support running the Rust test suite.
64+
65+
## Cross-compilation toolchains and C code
66+
67+
If you want to compile C code along with Rust (such as for Rust crates with C
68+
dependencies), you will need an appropriate `loongarch` toolchain.
69+
70+
Rust *may* be able to use an `loongarch64-unknown-linux-gnu-` toolchain with
71+
appropriate standalone flags to build for this toolchain (depending on the assumptions
72+
of that toolchain, see below), or you may wish to use a separate
73+
`loongarch64-unknown-none` toolchain.
74+
75+
On some `loongarch` hosts that use ELF binaries, you *may* be able to use the host
76+
C toolchain, if it does not introduce assumptions about the host environment
77+
that don't match the expectations of a standalone environment. Otherwise, you
78+
may need a separate toolchain for standalone/freestanding development, just as
79+
when cross-compiling from a non-`loongarch` platform.

0 commit comments

Comments
 (0)