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

When doing linker-plugin based LTO, write LLVM bitcode obj-files instead of embedding the bitcode into the regular object file. #52109

Merged
merged 2 commits into from
Jul 7, 2018

Conversation

michaelwoerister
Copy link
Member

This PR makes the compiler emit LLVM bitcode object files instead of regular object files with the IR embed when compiling for linker-plugin-based LTO. The reasoning for switching the strategy is this:

  • Embedding bitcode in a section of the object file actually makes us save bitcode twice in rlibs and Rust dylibs, once for linker-based LTO and once for rustc-based LTO. That's a waste of space.
  • When compiling for plugin-based LTO, one usually has no use for the machine code also present in the object file. Generating it is a waste of time.
  • When compiling for plugin-based LTO, rustc will skip running ThinLTO because the linker will do that anyway. This has the side effect of then generating poorly optimized machine code, which makes it even less useful (and may lead to users not knowing why their code is slow instead of getting an error).
  • Not having machine code available makes it impossible for the linker to silently fall back to not inlining stuff across language boundaries.
  • This is what Clang does and according to the documentation is the better supported option.
  • The current behavior (minus the runtime performance problems) is still available via -Z embed-bitcode (we might want to do this for libstd at some point).

r? @alexcrichton

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2018
@alexcrichton
Copy link
Member

@bors: r+

Nice!

I like the idea of one day doing this by default for -C lto as well for Cargo builds too. Otherwise all the codegen intermediate work is getting immediately thrown away at the end as well!

@bors
Copy link
Contributor

bors commented Jul 6, 2018

📌 Commit 4a26964 has been approved by alexcrichton

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 6, 2018
@bors
Copy link
Contributor

bors commented Jul 7, 2018

⌛ Testing commit 4a26964 with merge e44906e...

bors added a commit that referenced this pull request Jul 7, 2018
When doing linker-plugin based LTO, write LLVM bitcode obj-files instead of embedding the bitcode into the regular object file.

This PR makes the compiler emit LLVM bitcode object files instead of regular object files with the IR embed when compiling for linker-plugin-based LTO. The reasoning for switching the strategy is this:
- Embedding bitcode in a section of the object file actually makes us save bitcode twice in rlibs and Rust dylibs, once for linker-based LTO and once for rustc-based LTO. That's a waste of space.
- When compiling for plugin-based LTO, one usually has no use for the machine code also present in the object file. Generating it is a waste of time.
- When compiling for plugin-based LTO, `rustc` will skip running ThinLTO because the linker will do that anyway. This has the side effect of then generating poorly optimized machine code, which makes it even less useful (and may lead to users not knowing why their code is slow instead of getting an error).
- Not having machine code available makes it impossible for the linker to silently fall back to not inlining stuff across language boundaries.
- This is what Clang does and according to [the documentation](https://llvm.org/docs/BitCodeFormat.html#native-object-file-wrapper-format) is the better supported option.
- The current behavior (minus the runtime performance problems) is still available via `-Z embed-bitcode` (we might want to do this for `libstd` at some point).

r? @alexcrichton
@bors
Copy link
Contributor

bors commented Jul 7, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing e44906e to master...

@bors bors merged commit 4a26964 into rust-lang:master Jul 7, 2018
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants