Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4bc8549

Browse files
committed
Add linker script for switch
1 parent f688a56 commit 4bc8549

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

compiler/rustc_target/src/spec/aarch64_nintendo_switch.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel, Target, TargetOptions};
22

3+
const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_linker_script.ld");
4+
35
/// A base target for Nintendo Switch devices using a pure LLVM toolchain.
46
pub fn target() -> Target {
57
let mut opts = TargetOptions {
68
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
79
linker: Some("rust-lld".into()),
10+
link_script: Some(LINKER_SCRIPT.into()),
811
os: "horizon".into(),
912
max_atomic_width: Some(128),
1013
panic_strategy: PanicStrategy::Abort,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
.mod0 : {
36+
KEEP(crt0.nso.o(.data.mod0))
37+
KEEP(crt0.nro.o(.data.mod0))
38+
KEEP(crt0.lib.nro.o(.data.mod0))
39+
}
40+
.hash : { *(.hash) }
41+
.dynsym : { *(.dynsym .dynsym.*) }
42+
.dynstr : { *(.dynstr .dynstr.*) }
43+
.rela.dyn : { *(.rela.dyn) }
44+
45+
.eh_frame : {
46+
HIDDEN(__eh_frame_start = .);
47+
*(.eh_frame .eh_frame.*)
48+
HIDDEN(__eh_frame_end = .);
49+
}
50+
51+
.eh_frame_hdr : {
52+
HIDDEN(__eh_frame_hdr_start = .);
53+
*(.eh_frame_hdr .eh_frame_hdr.*)
54+
HIDDEN(__eh_frame_hdr_end = .);
55+
}
56+
57+
/* Read-write sections */
58+
59+
. = ALIGN(0x1000);
60+
61+
.data : {
62+
*(.data .data.*)
63+
*(.got .got.*)
64+
*(.got.plt .got.plt.*)
65+
} :data
66+
67+
.dynamic : {
68+
HIDDEN(__dynamic_start = .);
69+
*(.dynamic)
70+
}
71+
72+
/* BSS section */
73+
74+
. = ALIGN(0x1000);
75+
76+
.bss : {
77+
HIDDEN(__bss_start = .);
78+
*(.bss .bss.*)
79+
*(COMMON)
80+
. = ALIGN(8);
81+
HIDDEN(__bss_end = .);
82+
} :bss
83+
}

0 commit comments

Comments
 (0)