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

rustc: Add -C lto=val option #47521

Merged
merged 1 commit into from
Jan 26, 2018
Merged

Conversation

alexcrichton
Copy link
Member

This commit primarily adds the ability to control what kind of LTO happens when
rustc performs LTO, namely allowing values to be specified to the -C lto
option, such as -C lto=thin and -C lto=fat. (where "fat" is the previous
kind of LTO, throw everything in one giant module)

Along the way this also refactors a number of fields which store information
about whether LTO/ThinLTO are enabled to unify them all into one field through
which everything is dispatched, hopefully removing a number of special cases
throughout.

This is intended to help mitigate #47409 but will require a backport as well,
and this would unfortunately need to be an otherwise insta-stable option.

@rust-highfive
Copy link
Collaborator

r? @arielb1

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

@alexcrichton
Copy link
Member Author

r? @michaelwoerister

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 17, 2018

/// Do a local graph LTO with ThinLTO (only relevant for multiple codegen
/// units).
AutoThin,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe LocalThin?

Copy link
Member

Choose a reason for hiding this comment

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

ThinLocal is what I would do.


// If there's only one codegen unit and LTO isn't enabled then there's
// no need for ThinLTO so just return false.
if self.codegen_units() == 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Hm, so I sort of feel like this logic should be in trans somewhere instead of here. Though it doesn't really matter.

Copy link
Member

Choose a reason for hiding this comment

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

Actually it would make sense to move that to trans at some point because we only really know after CGU partitioning how many object files there are. At moment it's likely that there's always more than one though.

crate_types[0] == config::CrateTypeRlib;
// let crate_types = sess.crate_types.borrow();
// let only_rlib = crate_types.len() == 1 &&
// crate_types[0] == config::CrateTypeRlib;
Copy link
Member

Choose a reason for hiding this comment

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

Forgotten comments?

Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

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

Thanks, @alexcrichton! I left some comments about the implementation. We'll need buy-in from the whole @rust-lang/compiler team before merging, I think.


// If there's only one codegen unit and LTO isn't enabled then there's
// no need for ThinLTO so just return false.
if self.codegen_units() == 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Actually it would make sense to move that to trans at some point because we only really know after CGU partitioning how many object files there are. At moment it's likely that there's always more than one though.

Lto::AutoThin => SymbolExportLevel::Rust,

// We're doing LTO for the entire crate graph
_ => symbol_export::crates_export_threshold(&cgcx.crate_types),
Copy link
Member

Choose a reason for hiding this comment

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

Could you make this match exhaustive?

@alexcrichton
Copy link
Member Author

Ok I've updated! This PR also now switches the default (the meaning of -C lto) back to "fat" LTO by default as discussed during the compiler triage meeting.

r? @michaelwoerister

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Jan 18, 2018
This commit reverts a small portion of the switch to ThinLTO by default which
changed the meaning of `-C lto` from "put the whole crate graph into one codegen
unit" to "perform ThinLTO over the whole crate graph". This backport has no
corresponding commit on master as rust-lang#47521 is making the same change but in a
slightly different manner. This commit is intended to be a surgical change with
low impact on beta.

Closes rust-lang#47409
@kennytm kennytm added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 19, 2018
No,

/// Do a full crate graph LTO. The flavor is determined by the compiler
/// (currently the default is "thin").
Copy link
Member

Choose a reason for hiding this comment

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

s/thin/fat

@michaelwoerister
Copy link
Member

Thanks, Alex! r=me with the comment updated.

@alexcrichton
Copy link
Member Author

@bors: r=michaelwoerister

@bors
Copy link
Contributor

bors commented Jan 19, 2018

📌 Commit 43c5f62 has been approved by michaelwoerister

@estebank
Copy link
Contributor

@bors r-

@alexcrichton https://travis-ci.org/rust-lang/rust/builds/330845572#L1220:

[00:19:06] Assembling stage1 compiler (x86_64-unknown-linux-gnu)
stage1-std
28.95sBuilding stage1 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:19:07]    Compiling cfg-if v0.1.2
[00:19:07]    Compiling cc v1.0.4
[00:19:07]    Compiling libc v0.2.36
[00:19:07]    Compiling unwind v0.0.0 (file:///checkout/src/libunwind)
[00:19:07]    Compiling core v0.0.0 (file:///checkout/src/libcore)
[00:19:08]    Compiling filetime v0.1.15
[00:19:10]    Compiling build_helper v0.1.0 (file:///checkout/src/build_helper)
[00:19:12]    Compiling std v0.0.0 (file:///checkout/src/libstd)
[00:19:13]    Compiling compiler_builtins v0.0.0 (file:///checkout/src/rustc/compiler_builtins_shim)
[00:19:13]    Compiling cmake v0.1.29
[00:19:16]    Compiling alloc_jemalloc v0.0.0 (file:///checkout/src/liballoc_jemalloc)
[00:19:18]    Compiling rustc_lsan v0.0.0 (file:///checkout/src/librustc_lsan)
[00:19:19]    Compiling rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:19:20]    Compiling rustc_tsan v0.0.0 (file:///checkout/src/librustc_tsan)
[00:19:20]    Compiling rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:19:35] LLVM ERROR: ThinLTO not available
[00:19:35] error: Could not compile `core`.
[00:19:35] 
[00:19:35] Caused by:
[00:19:35]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name core libcore/lib.rs --color always --error-format json --crate-type lib --emit=dep-info,link -C opt-level=2 -C metadata=488df6a35606ef3a -C extra-filename=-488df6a35606ef3a --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps` (exit code: 1)
[00:19:35] thread 'main' panicked at 'command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:19:35] expected success, got: exit code: 101', bootstrap/compile.rs:881:9
[00:19:35] note: Run with `RUST_BACKTRACE=1` for a backtrace.

@alexcrichton alexcrichton force-pushed the configure-lto branch 2 times, most recently from 34c2fa8 to 7517c66 Compare January 19, 2018 19:36
@alexcrichton
Copy link
Member Author

@bors: r=michaelwoerister

@bors
Copy link
Contributor

bors commented Jan 19, 2018

📌 Commit 7517c66 has been approved by michaelwoerister

@estebank
Copy link
Contributor

@alexcrichton https://travis-ci.org/rust-lang/rust/builds/330958787#L1202:

[00:16:46] error: unnecessary `unsafe` block
[00:16:46]     --> librustc_trans/back/write.rs:1307:35
[00:16:46]      |
[00:16:46] 1274 |         unsafe {
[00:16:46]      |         ------ because it's nested under this `unsafe` block
[00:16:46] ...
[00:16:46] 1307 |                 Lto::ThinLocal => unsafe {
[00:16:46]      |                                   ^^^^^^ unnecessary `unsafe` block
[00:16:46]      |
[00:16:46] note: lint level defined here
[00:16:46]     --> librustc_trans/lib.rs:20:9
[00:16:46]      |
[00:16:46] 20   | #![deny(warnings)]
[00:16:46]      |         ^^^^^^^^
[00:16:46]      = note: #[deny(unused_unsafe)] implied by #[deny(warnings)]
[00:16:46] 
[00:16:46] error: aborting due to previous error
[00:16:46] 
[00:16:46] error: Could not compile `rustc_trans`.

@alexcrichton
Copy link
Member Author

@bors: r=michaelwoerister

wheeeeeee

@bors
Copy link
Contributor

bors commented Jan 19, 2018

📌 Commit ee63bc6 has been approved by michaelwoerister

@bors
Copy link
Contributor

bors commented Jan 21, 2018

☔ The latest upstream changes (presumably #45684) made this pull request unmergeable. Please resolve the merge conflicts.

@kennytm kennytm removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 22, 2018
@alexcrichton
Copy link
Member Author

@bors: r=michaelwoerister

@bors
Copy link
Contributor

bors commented Jan 22, 2018

📌 Commit dc902b1 has been approved by michaelwoerister

@kennytm kennytm 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 Jan 22, 2018
@bors
Copy link
Contributor

bors commented Jan 23, 2018

☔ The latest upstream changes (presumably #47678) made this pull request unmergeable. Please resolve the merge conflicts.

This commit primarily adds the ability to control what kind of LTO happens when
rustc performs LTO, namely allowing values to be specified to the `-C lto`
option, such as `-C lto=thin` and `-C lto=fat`. (where "fat" is the previous
kind of LTO, throw everything in one giant module)

Along the way this also refactors a number of fields which store information
about whether LTO/ThinLTO are enabled to unify them all into one field through
which everything is dispatched, hopefully removing a number of special cases
throughout.

This is intended to help mitigate rust-lang#47409 but will require a backport as well,
and this would unfortunately need to be an otherwise insta-stable option.
@alexcrichton
Copy link
Member Author

@bors: r=michaelwoerister

@bors
Copy link
Contributor

bors commented Jan 23, 2018

📌 Commit 8bde2ac has been approved by michaelwoerister

bors added a commit that referenced this pull request Jan 26, 2018
@bors bors merged commit 8bde2ac into rust-lang:master Jan 26, 2018
@bors
Copy link
Contributor

bors commented Jan 26, 2018

☔ The latest upstream changes (presumably #47748) made this pull request unmergeable. Please resolve the merge conflicts.

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.

8 participants