-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Seems to work but the rustc patch needs a big rebase. |
sajattack
approved these changes
Jun 8, 2022
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before being merged, this requires an accompanying
rustc
patch, TBA soon.