Skip to content
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

Relax mipsel-sony-psp's linker script #97843

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
overdrivenpotato committed Jun 7, 2022
commit 94134695b5c08af393da1c321913e10dd4b7c6e0
5 changes: 4 additions & 1 deletion compiler/rustc_target/src/spec/mipsel_sony_psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
21 changes: 16 additions & 5 deletions compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) }
}