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

Add support for LTO and remove link-dead-code #118

Merged
merged 4 commits into from
Jun 11, 2022
Merged

Add support for LTO and remove link-dead-code #118

merged 4 commits into from
Jun 11, 2022

Conversation

overdrivenpotato
Copy link
Owner

Before being merged, this requires an accompanying rustc patch, TBA soon.

@sajattack
Copy link
Collaborator

Seems to work but the rustc patch needs a big rebase.

JohnTitor pushed a commit to JohnTitor/rust that referenced this pull request Jun 9, 2022
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
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 9, 2022
…woerister

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
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 9, 2022
…woerister

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
@overdrivenpotato overdrivenpotato changed the title WIP: Add support for LTO and remove link-dead-code Add support for LTO and remove link-dead-code Jun 9, 2022
@overdrivenpotato overdrivenpotato marked this pull request as ready for review June 9, 2022 23:24
@overdrivenpotato overdrivenpotato marked this pull request as draft June 9, 2022 23:25
@overdrivenpotato overdrivenpotato marked this pull request as ready for review June 11, 2022 22:15
This is achieved by utilizing the 8 bytes of a function stub as a place
to store pointers to the relevant NID and library entry struct. At
runtime these are overwritten by the OS, but this link lets LLVM know
not to remove those seemingly unused sections.

Because this means that the number of function stubs depends on the
linker output, cargo-psp has been modified to properly update the
library stub count after the normal linking stage.

This commit requires linker script changes in rustc; this will happen in
an accompanying patch.
This greatly reduces binary sizes, at the expense of compilation speed.
Normal builds still use a regular non-LTO build of libunwind.
Through testing, LLVM is not able to see past the transmute, so we
effectively already have a black box. To avoid UB, this should probably
be done via external linking through a different crate, though this is
simpler and works well enough for this particularly constrained target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants