Skip to content

Commit a6d3ee3

Browse files
authored
Rollup merge of #88991 - libstd-switch:aarch64-nintendo-switch, r=wesleywiser
Add Nintendo Switch as tier 3 target [Relevant Zulip Discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Upstreaming.20Nintendo.20Switch.20Support/near/253445503) This is the first step towards working on incrementally adding support for the Nintendo Switch. After this lands `@leo60228` and I will work on ensuring further work is cleared from a legal perspective before continuing on to work on an allocator and porting libstd. The plan is to keep these changes small and incremental enough so as to not cause unneeded burden on reviewers by submitting a single large patch, as was felt to be the case last attempt at upstreaming (#74567). All this specific patch does is add the target itself without and std support, which has been tested on-device and is working as expected. Designated Target Maintainers: * `@leo60228` * `@jam1garner`
2 parents 522abf6 + 62aafb0 commit a6d3ee3

File tree

8 files changed

+160
-2
lines changed

8 files changed

+160
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel, Target, TargetOptions};
2+
3+
const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_freestanding_linker_script.ld");
4+
5+
/// A base target for Nintendo Switch devices using a pure LLVM toolchain.
6+
pub fn target() -> Target {
7+
Target {
8+
llvm_target: "aarch64-unknown-none".into(),
9+
pointer_width: 64,
10+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
11+
arch: "aarch64".into(),
12+
options: TargetOptions {
13+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
14+
linker: Some("rust-lld".into()),
15+
link_script: Some(LINKER_SCRIPT.into()),
16+
os: "horizon".into(),
17+
max_atomic_width: Some(128),
18+
panic_strategy: PanicStrategy::Abort,
19+
position_independent_executables: true,
20+
dynamic_linking: true,
21+
executables: true,
22+
relro_level: RelroLevel::Off,
23+
..Default::default()
24+
},
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
OUTPUT_FORMAT(elf64-littleaarch64)
2+
OUTPUT_ARCH(aarch64)
3+
ENTRY(_start)
4+
5+
PHDRS
6+
{
7+
text PT_LOAD FLAGS(5);
8+
rodata PT_LOAD FLAGS(4);
9+
data PT_LOAD FLAGS(6);
10+
bss PT_LOAD FLAGS(6);
11+
dynamic PT_DYNAMIC;
12+
}
13+
14+
SECTIONS
15+
{
16+
. = 0;
17+
18+
.text : ALIGN(0x1000) {
19+
HIDDEN(__text_start = .);
20+
KEEP(*(.text.jmp))
21+
22+
. = 0x80;
23+
24+
*(.text .text.*)
25+
*(.plt .plt.*)
26+
}
27+
28+
/* Read-only sections */
29+
30+
. = ALIGN(0x1000);
31+
32+
.module_name : { *(.module_name) } :rodata
33+
34+
.rodata : { *(.rodata .rodata.*) } :rodata
35+
.hash : { *(.hash) }
36+
.dynsym : { *(.dynsym .dynsym.*) }
37+
.dynstr : { *(.dynstr .dynstr.*) }
38+
.rela.dyn : { *(.rela.dyn) }
39+
40+
.eh_frame : {
41+
HIDDEN(__eh_frame_start = .);
42+
*(.eh_frame .eh_frame.*)
43+
HIDDEN(__eh_frame_end = .);
44+
}
45+
46+
.eh_frame_hdr : {
47+
HIDDEN(__eh_frame_hdr_start = .);
48+
*(.eh_frame_hdr .eh_frame_hdr.*)
49+
HIDDEN(__eh_frame_hdr_end = .);
50+
}
51+
52+
/* Read-write sections */
53+
54+
. = ALIGN(0x1000);
55+
56+
.data : {
57+
*(.data .data.*)
58+
*(.got .got.*)
59+
*(.got.plt .got.plt.*)
60+
} :data
61+
62+
.dynamic : {
63+
HIDDEN(__dynamic_start = .);
64+
*(.dynamic)
65+
}
66+
67+
/* BSS section */
68+
69+
. = ALIGN(0x1000);
70+
71+
.bss : {
72+
HIDDEN(__bss_start = .);
73+
*(.bss .bss.*)
74+
*(COMMON)
75+
. = ALIGN(8);
76+
HIDDEN(__bss_end = .);
77+
} :bss
78+
}

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,8 @@ supported_targets! {
10351035

10361036
("armv6k-nintendo-3ds", armv6k_nintendo_3ds),
10371037

1038+
("aarch64-nintendo-switch-freestanding", aarch64_nintendo_switch_freestanding),
1039+
10381040
("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi),
10391041
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),
10401042

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pub struct Target {
411411
impl Target {
412412
pub fn from_triple(triple: &str) -> Self {
413413
let mut target: Self = Default::default();
414-
if triple.contains("-none") || triple.contains("nvptx") {
414+
if triple.contains("-none") || triple.contains("nvptx") || triple.contains("switch") {
415415
target.no_std = true;
416416
}
417417
target

src/bootstrap/util.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ pub fn use_host_linker(target: TargetSelection) -> bool {
298298
|| target.contains("nvptx")
299299
|| target.contains("fortanix")
300300
|| target.contains("fuchsia")
301-
|| target.contains("bpf"))
301+
|| target.contains("bpf")
302+
|| target.contains("switch"))
302303
}
303304

304305
pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [Template for Target-specific Documentation](platform-support/TEMPLATE.md)
1818
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
1919
- [\*-apple-watchos\*](platform-support/apple-watchos.md)
20+
- [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md)
2021
- [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md)
2122
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
2223
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)

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

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ target | std | host | notes
209209
`aarch64-apple-tvos` | * | | ARM64 tvOS
210210
[`aarch64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | ARM64 Apple WatchOS Simulator
211211
[`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3
212+
[`aarch64-nintendo-switch-freestanding`](platform-support/aarch64-nintendo-switch-freestanding.md) | * | | ARM64 Nintendo Switch, Horizon
212213
[`aarch64-pc-windows-gnullvm`](platform-support/pc-windows-gnullvm.md) | ✓ | ✓ |
213214
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
214215
`aarch64-unknown-hermit` | ✓ | | ARM64 HermitCore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# aarch64-nintendo-switch-freestanding
2+
3+
**Tier: 3**
4+
5+
Nintendo Switch with pure-Rust toolchain.
6+
7+
## Designated Developers
8+
9+
* [@leo60228](https://github.com/leo60228)
10+
* [@jam1garner](https://github.com/jam1garner)
11+
12+
## Requirements
13+
14+
This target is cross-compiled.
15+
It has no special requirements for the host.
16+
17+
## Building
18+
19+
The target can be built by enabling it for a `rustc` build:
20+
21+
```toml
22+
[build]
23+
build-stage = 1
24+
target = ["aarch64-nintendo-switch-freestanding"]
25+
```
26+
27+
## Cross-compilation
28+
29+
This target can be cross-compiled from any host.
30+
31+
## Testing
32+
33+
Currently there is no support to run the rustc test suite for this target.
34+
35+
## Building Rust programs
36+
37+
If `rustc` has support for that target and the library artifacts are available,
38+
then Rust programs can be built for that target:
39+
40+
```text
41+
rustc --target aarch64-nintendo-switch-freestanding your-code.rs
42+
```
43+
44+
To generate binaries in the NRO format that can be easily run on-device, you
45+
can use [cargo-nx](https://github.com/aarch64-switch-rs/cargo-nx):
46+
47+
```text
48+
cargo nx --triple=aarch64-nintendo-switch-freestanding
49+
```

0 commit comments

Comments
 (0)