Skip to content

Commit 5d81f91

Browse files
authored
Rollup merge of #97843 - overdrivenpotato:psp-lto, r=michaelwoerister
Relax mipsel-sony-psp's linker script Previously, the linker script forcefully kept all `.lib.stub` sections, unnecessarily bloating the binary. Now, the script is LTO and `--gc-sections` friendly. `--nmagic` was also added to the linker, because page alignment is not required on the PSP. This further reduces binary size. Accompanying changes for the `psp` crate are found in: overdrivenpotato/rust-psp#118
2 parents fa4f8f1 + 611107a commit 5d81f91

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

compiler/rustc_target/src/spec/mipsel_sony_psp.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const LINKER_SCRIPT: &str = include_str!("./mipsel_sony_psp_linker_script.ld");
66

77
pub fn target() -> Target {
88
let mut pre_link_args = LinkArgs::new();
9-
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".into()]);
9+
pre_link_args
10+
.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".into(), "--nmagic".into()]);
1011

1112
Target {
1213
llvm_target: "mipsel-sony-psp".into(),

compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld

+16-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ SECTIONS
77
/* Sort stubs for convenient ordering */
88
.sceStub.text : { *(.sceStub.text) *(SORT(.sceStub.text.*)) }
99

10+
/* PSP import library stub sections. Bundles together `.lib.stub.entry.*`
11+
* sections for better `--gc-sections` support. */
12+
.lib.stub.top : { *(.lib.stub.top) }
13+
.lib.stub : { *(.lib.stub) *(.lib.stub.entry.*) }
14+
.lib.stub.btm : { *(.lib.stub.btm) }
15+
1016
/* Keep these sections around, even though they may appear unused to the linker */
1117
.lib.ent.top : { KEEP(*(.lib.ent.top)) }
1218
.lib.ent : { KEEP(*(.lib.ent)) }
1319
.lib.ent.btm : { KEEP(*(.lib.ent.btm)) }
14-
.lib.stub.top : { KEEP(*(.lib.stub.top)) }
15-
.lib.stub : { KEEP(*(.lib.stub)) }
16-
.lib.stub.btm : { KEEP(*(.lib.stub.btm)) }
17-
.eh_frame_hdr : { KEEP(*(.eh_frame_hdr)) }
20+
21+
.eh_frame_hdr : { *(.eh_frame_hdr) }
1822

1923
/* Add symbols for LLVM's libunwind */
2024
__eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0;
@@ -27,8 +31,15 @@ SECTIONS
2731
}
2832

2933
/* These are explicitly listed to avoid being merged into .rodata */
30-
.rodata.sceResident : { *(.rodata.sceResident) }
34+
.rodata.sceResident : { *(.rodata.sceResident) *(.rodata.sceResident.*) }
3135
.rodata.sceModuleInfo : { *(.rodata.sceModuleInfo) }
3236
/* Sort NIDs for convenient ordering */
3337
.rodata.sceNid : { *(.rodata.sceNid) *(SORT(.rodata.sceNid.*)) }
38+
39+
.rodata : { *(.rodata .rodata.*) }
40+
.data : { *(.data .data.*) }
41+
.gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) }
42+
.bss : { *(.bss .bss.*) }
43+
44+
/DISCARD/ : { *(.rel.sceStub.text .MIPS.abiflags .reginfo) }
3445
}

0 commit comments

Comments
 (0)