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

Perform LTO optimisations with wasm-ld + -Clinker-plugin-lto #118378

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

cormacrelf
Copy link
Contributor

Fixes (partially) #60059. Technically, --target wasm32-unknown-unknown -Clinker-plugin-lto would complete without errors before, but it was not producing optimized code. At least, it may have been but it was probably not the opt-level people intended.

Similarly to #118377, this could benefit from a warning about using an explicit libLTO path with LLD, which will ignore it and use its internal LLVM. Especially given we always use lld on wasm targets. I left the code open to that possibility rather than making it perfectly neat.

@rustbot
Copy link
Collaborator

rustbot commented Nov 27, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 27, 2023
LinkerPluginLto::Disabled => {
// Nothing to do
}
LinkerPluginLto::LinkerPluginAuto => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LinkerPluginLto::LinkerPluginAuto => {
LinkerPluginLto::LinkerPluginAuto | LinkerPluginLto::LinkerPlugin(_) => {

push_linker_plugin_lto_args could then be inlined and removed.

Upd: the match on self.sess.opts.optimize could be kept separate function, though, it is shared between fn optimize and fn linker_plugin_lto.

Copy link
Contributor Author

@cormacrelf cormacrelf Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally left them separate.

  • That the match turns out the same is more of a coincidence than anything else. I anticipate the --lto-O* args may change to support Os and Oz in future. (Especially with those being the most popular opt levels for webassembly.) If that happens, adding Os/Oz to a shared match statement would break the normal fn optimize that controls merging sections only, unrelated to LLVM.
  • push_linker_plugin_lto_args could be inlined, but I was going to do another PR that puts warnings in one of the match arms but not the other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 27, 2023
@petrochenkov
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 28, 2023

📌 Commit 179e193 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 28, 2023
config::OptLevel::Less => "O1",
config::OptLevel::Default => "O2",
config::OptLevel::Aggressive => "O3",
// wasm-ld only handles integer LTO opt levels. Use O2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// wasm-ld only handles integer LTO opt levels. Use O2
// `wasm-ld` only handles integer LTO opt levels. Use O2.

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 28, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#118193 (Add missing period in `std::process::Command` docs)
 - rust-lang#118222 (unify read_to_end and io::copy impls for reading into a Vec)
 - rust-lang#118323 (give dev-friendly error message for incorrect config profiles)
 - rust-lang#118378 (Perform LTO optimisations with wasm-ld + -Clinker-plugin-lto)
 - rust-lang#118399 (Clean dead codes in miri)
 - rust-lang#118410 (update test for new LLVM 18 codegen)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 28, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#118193 (Add missing period in `std::process::Command` docs)
 - rust-lang#118222 (unify read_to_end and io::copy impls for reading into a Vec)
 - rust-lang#118323 (give dev-friendly error message for incorrect config profiles)
 - rust-lang#118378 (Perform LTO optimisations with wasm-ld + -Clinker-plugin-lto)
 - rust-lang#118399 (Clean dead codes in miri)
 - rust-lang#118410 (update test for new LLVM 18 codegen)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3e202ea into rust-lang:master Nov 29, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 29, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 29, 2023
Rollup merge of rust-lang#118378 - cormacrelf:bugfix/linker-plugin-lto-wasm, r=petrochenkov

Perform LTO optimisations with wasm-ld + -Clinker-plugin-lto

Fixes (partially) rust-lang#60059. Technically, `--target wasm32-unknown-unknown -Clinker-plugin-lto` would complete without errors before, but it was not producing optimized code. At least, it may have been but it was probably not the opt-level people intended.

Similarly to rust-lang#118377, this could benefit from a warning about using an explicit libLTO path with LLD, which will ignore it and use its internal LLVM. Especially given we always use lld on wasm targets. I left the code open to that possibility rather than making it perfectly neat.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants