From 94134695b5c08af393da1c321913e10dd4b7c6e0 Mon Sep 17 00:00:00 2001 From: Marko Mijalkovic Date: Sun, 16 Jan 2022 16:55:07 -0500 Subject: [PATCH 1/2] 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: https://github.com/overdrivenpotato/rust-psp/pull/118 --- .../rustc_target/src/spec/mipsel_sony_psp.rs | 5 ++++- .../src/spec/mipsel_sony_psp_linker_script.ld | 21 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs index 45966b97d6abc..c7ee52c2454be 100644 --- a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs +++ b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs @@ -6,7 +6,10 @@ const LINKER_SCRIPT: &str = include_str!("./mipsel_sony_psp_linker_script.ld"); pub fn target() -> Target { let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".into()]); + pre_link_args.insert( + LinkerFlavor::Lld(LldFlavor::Ld), + vec!["--emit-relocs".into(), "--nmagic".into()], + ); Target { llvm_target: "mipsel-sony-psp".into(), diff --git a/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld b/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld index 1bd436d6f94cc..9eb35ad9f5d2e 100644 --- a/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld +++ b/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld @@ -7,14 +7,18 @@ SECTIONS /* Sort stubs for convenient ordering */ .sceStub.text : { *(.sceStub.text) *(SORT(.sceStub.text.*)) } + /* PSP import library stub sections. Bundles together `.lib.stub.entry.*` + * sections for better `--gc-sections` support. */ + .lib.stub.top : { *(.lib.stub.top) } + .lib.stub : { *(.lib.stub) *(.lib.stub.entry.*) } + .lib.stub.btm : { *(.lib.stub.btm) } + /* Keep these sections around, even though they may appear unused to the linker */ .lib.ent.top : { KEEP(*(.lib.ent.top)) } .lib.ent : { KEEP(*(.lib.ent)) } .lib.ent.btm : { KEEP(*(.lib.ent.btm)) } - .lib.stub.top : { KEEP(*(.lib.stub.top)) } - .lib.stub : { KEEP(*(.lib.stub)) } - .lib.stub.btm : { KEEP(*(.lib.stub.btm)) } - .eh_frame_hdr : { KEEP(*(.eh_frame_hdr)) } + + .eh_frame_hdr : { *(.eh_frame_hdr) } /* Add symbols for LLVM's libunwind */ __eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0; @@ -27,8 +31,15 @@ SECTIONS } /* These are explicitly listed to avoid being merged into .rodata */ - .rodata.sceResident : { *(.rodata.sceResident) } + .rodata.sceResident : { *(.rodata.sceResident) *(.rodata.sceResident.*) } .rodata.sceModuleInfo : { *(.rodata.sceModuleInfo) } /* Sort NIDs for convenient ordering */ .rodata.sceNid : { *(.rodata.sceNid) *(SORT(.rodata.sceNid.*)) } + + .rodata : { *(.rodata .rodata.*) } + .data : { *(.data .data.*) } + .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } + .bss : { *(.bss .bss.*) } + + /DISCARD/ : { *(.rel.sceStub.text .MIPS.abiflags .reginfo) } } From 611107af5f870f8f5f1d77b19e8f735be2a1da36 Mon Sep 17 00:00:00 2001 From: Marko Mijalkovic Date: Tue, 7 Jun 2022 16:02:11 -0400 Subject: [PATCH 2/2] Formatting fix --- compiler/rustc_target/src/spec/mipsel_sony_psp.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs index c7ee52c2454be..03e0934ea5ecc 100644 --- a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs +++ b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs @@ -6,10 +6,8 @@ const LINKER_SCRIPT: &str = include_str!("./mipsel_sony_psp_linker_script.ld"); pub fn target() -> Target { let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert( - LinkerFlavor::Lld(LldFlavor::Ld), - vec!["--emit-relocs".into(), "--nmagic".into()], - ); + pre_link_args + .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".into(), "--nmagic".into()]); Target { llvm_target: "mipsel-sony-psp".into(),