-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #88991 - libstd-switch:aarch64-nintendo-switch, r=wes…
…leywiser 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`
- Loading branch information
Showing
8 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel, Target, TargetOptions}; | ||
|
||
const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_freestanding_linker_script.ld"); | ||
|
||
/// A base target for Nintendo Switch devices using a pure LLVM toolchain. | ||
pub fn target() -> Target { | ||
Target { | ||
llvm_target: "aarch64-unknown-none".into(), | ||
pointer_width: 64, | ||
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), | ||
arch: "aarch64".into(), | ||
options: TargetOptions { | ||
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), | ||
linker: Some("rust-lld".into()), | ||
link_script: Some(LINKER_SCRIPT.into()), | ||
os: "horizon".into(), | ||
max_atomic_width: Some(128), | ||
panic_strategy: PanicStrategy::Abort, | ||
position_independent_executables: true, | ||
dynamic_linking: true, | ||
executables: true, | ||
relro_level: RelroLevel::Off, | ||
..Default::default() | ||
}, | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
compiler/rustc_target/src/spec/aarch64_nintendo_switch_freestanding_linker_script.ld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
OUTPUT_FORMAT(elf64-littleaarch64) | ||
OUTPUT_ARCH(aarch64) | ||
ENTRY(_start) | ||
|
||
PHDRS | ||
{ | ||
text PT_LOAD FLAGS(5); | ||
rodata PT_LOAD FLAGS(4); | ||
data PT_LOAD FLAGS(6); | ||
bss PT_LOAD FLAGS(6); | ||
dynamic PT_DYNAMIC; | ||
} | ||
|
||
SECTIONS | ||
{ | ||
. = 0; | ||
|
||
.text : ALIGN(0x1000) { | ||
HIDDEN(__text_start = .); | ||
KEEP(*(.text.jmp)) | ||
|
||
. = 0x80; | ||
|
||
*(.text .text.*) | ||
*(.plt .plt.*) | ||
} | ||
|
||
/* Read-only sections */ | ||
|
||
. = ALIGN(0x1000); | ||
|
||
.module_name : { *(.module_name) } :rodata | ||
|
||
.rodata : { *(.rodata .rodata.*) } :rodata | ||
.hash : { *(.hash) } | ||
.dynsym : { *(.dynsym .dynsym.*) } | ||
.dynstr : { *(.dynstr .dynstr.*) } | ||
.rela.dyn : { *(.rela.dyn) } | ||
|
||
.eh_frame : { | ||
HIDDEN(__eh_frame_start = .); | ||
*(.eh_frame .eh_frame.*) | ||
HIDDEN(__eh_frame_end = .); | ||
} | ||
|
||
.eh_frame_hdr : { | ||
HIDDEN(__eh_frame_hdr_start = .); | ||
*(.eh_frame_hdr .eh_frame_hdr.*) | ||
HIDDEN(__eh_frame_hdr_end = .); | ||
} | ||
|
||
/* Read-write sections */ | ||
|
||
. = ALIGN(0x1000); | ||
|
||
.data : { | ||
*(.data .data.*) | ||
*(.got .got.*) | ||
*(.got.plt .got.plt.*) | ||
} :data | ||
|
||
.dynamic : { | ||
HIDDEN(__dynamic_start = .); | ||
*(.dynamic) | ||
} | ||
|
||
/* BSS section */ | ||
|
||
. = ALIGN(0x1000); | ||
|
||
.bss : { | ||
HIDDEN(__bss_start = .); | ||
*(.bss .bss.*) | ||
*(COMMON) | ||
. = ALIGN(8); | ||
HIDDEN(__bss_end = .); | ||
} :bss | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/doc/rustc/src/platform-support/aarch64-nintendo-switch-freestanding.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# aarch64-nintendo-switch-freestanding | ||
|
||
**Tier: 3** | ||
|
||
Nintendo Switch with pure-Rust toolchain. | ||
|
||
## Designated Developers | ||
|
||
* [@leo60228](https://github.com/leo60228) | ||
* [@jam1garner](https://github.com/jam1garner) | ||
|
||
## Requirements | ||
|
||
This target is cross-compiled. | ||
It has no special requirements for the host. | ||
|
||
## Building | ||
|
||
The target can be built by enabling it for a `rustc` build: | ||
|
||
```toml | ||
[build] | ||
build-stage = 1 | ||
target = ["aarch64-nintendo-switch-freestanding"] | ||
``` | ||
|
||
## Cross-compilation | ||
|
||
This target can be cross-compiled from any host. | ||
|
||
## Testing | ||
|
||
Currently there is no support to run the rustc test suite for this target. | ||
|
||
## Building Rust programs | ||
|
||
If `rustc` has support for that target and the library artifacts are available, | ||
then Rust programs can be built for that target: | ||
|
||
```text | ||
rustc --target aarch64-nintendo-switch-freestanding your-code.rs | ||
``` | ||
|
||
To generate binaries in the NRO format that can be easily run on-device, you | ||
can use [cargo-nx](https://github.com/aarch64-switch-rs/cargo-nx): | ||
|
||
```text | ||
cargo nx --triple=aarch64-nintendo-switch-freestanding | ||
``` |