-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add Nintendo Switch as tier 3 target #88991
Merged
bors
merged 10 commits into
rust-lang:master
from
libstd-switch:aarch64-nintendo-switch
Jul 15, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e6aedf6
Add Nintendo Switch tier 3 target
jam1garner 60beb1a
Don't use host linker for switch
leo60228 f688a56
Remove unnecessary linker args
leo60228 4bc8549
Add linker script for switch
leo60228 bee373c
Don't build std for switch
leo60228 7f88049
Remove unneeded options from Nintendo Switch target
jam1garner c690db4
Remove obsolete crt0 references in linker script
leo60228 fd81b99
Add docs for Switch target
leo60228 d04753e
Add aarch64-nintendo-switch.md to SUMMARY.md
leo60228 62aafb0
Rename aarch64-nintendo-switch to aarch64-nintendo-switch-freestanding
leo60228 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Off topic - could this be turned into a
no_std
flag in the target config file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linker has the same issue with a
FIXME
for pulling the info from the target config file. I'm guessing thatbootstrap
doesn't have a way to access the actual target definition.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap
could invoke rustc using--print cfg
or something similar to print if the target is no_std if the target config file contains this. If it is a cfg, libstd could use the same cfg for restricted-std.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, though, it's just temporary until std is implemented on Switch.