-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Change how compiler-builtins gets many CGUs #73136
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Will build-std need something similar? |
@ehuss the original implementation used attribute specifically for build-std case. It would be nice if this logic was applied there at some point. There is also a similar case of debug assertions which should be disabled for compiler builtins. |
For build-std I think it sort of depends. The compiler-builtins works regardless of the number of CGUs it is compiled with, it's just that it can work best with system libraries that have conflicting symbols if it has one object per symbol. In that sense for many pure-Rust targets using build-std (e.g. anything embedded) the number of CGUs for compiler-builtins doesn't matter. In the limit though, yeah, we may have to embed this logic (like debug assertions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me
// Verifies that during compiler_builtins compilation the codegen units are kept | ||
// unmerged. Even when only a single codegen unit is requested with -Ccodegen-units=1. | ||
// | ||
// compile-flags: -Zprint-mono-items=eager -Ccodegen-units=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth keeping this test with the codegen-units=1000 logic and making sure we're not merging in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect not in the sense that there's already likely tests for that, and this is just falling back on existing functionality.
@bors: r=Mark-Simulacrum |
📌 Commit 926c7b6bb53b8a30b712759eaa9641040d15caef has been approved by |
There is a regression in 1.44 when building Firefox with cross-language LTO for OSX (and only in that combination), where libxul fails to link with error messages like:
This can be reproduced with nightly-2020-04-08 (42abbd8) and not with nightly-2020-04-07 (6dee5f1). Further narrowing down with rustup-install-toolchain-master came out with a range between 39b6253 and 42abbd8, which would seem to point at #70846. I'm hoping this change will fix it, but for some reason, I can't reproduce the problem in the first place with a local build of a revision known to be faulty in nightly, so I can't check whether this fixes it. At this point, I'll wait for the next nightly following the merge of this PR to test whether it fixes it, otherwise, I'll open a new issue. |
Corollary: if this fixes it, it would be nice to have in a 1.44.1 (or at least in 1.45). |
Both fixes you link have landed a number of days ago, but I can still reproduce with the latest nightly. |
If this (or some other PR) needs stable backports, then the window for 1.44.1 is rapidly closing, would be good to get them stable-nominated today (for either emergency approval tomorrow's compiler meeting or unilateral approval). |
@Mark-Simulacrum this only affects the performance of compiler-builtins which doesn't affect many high-profile platforms (wasm is the main motivation for this), so I would personally think it's ok to not include this in a point release. |
I wish I could test this fix... |
@bors try This'll at least get us a try build which might help with testing? |
🙅 Please do not |
src/bootstrap/bin/rustc.rs
Outdated
// Ideally this would be specified through an env var to Cargo so Cargo | ||
// knows how many CGUs are for this specific crate, but for now | ||
// per-crate configuration isn't specifiable in the environment. | ||
if crate_name == Some("compiler_builtins") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[profile.release.package.compiler_builtins]
codegen-units = 10000
in the workspace Cargo.toml
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice forgot about that, that does indeed work!
This commit intends to fix an accidental regression from rust-lang#70846. The goal of rust-lang#70846 was to build compiler-builtins with a maximal number of CGUs to ensure that each module in the source corresponds to an object file. This high degree of control for compiler-builtins is desirable to ensure that there's at most one exported symbol per CGU, ideally enabling compiler-builtins to not conflict with the system libgcc as often. In rust-lang#70846, however, only part of the compiler understands that compiler-builtins is built with many CGUs. The rest of the compiler thinks it's building with `sess.codegen_units()`. Notably the calculation of `sess.lto()` consults `sess.codegen_units()`, which when there's only one CGU it disables ThinLTO. This means that compiler-builtins is built without ThinLTO, which is quite harmful to performance! This is the root of the cause from rust-lang#73135 where intrinsics were found to not be inlining trivial functions. The fix applied in this commit is to remove the special-casing of compiler-builtins in the compiler. Instead the build system is now responsible for special-casing compiler-builtins. It doesn't know exactly how many CGUs will be needed but it passes a large number that is assumed to be much greater than the number of source-level modules needed. After reading the various locations in the compiler source, this seemed like the best solution rather than adding more and more special casing in the compiler for compiler-builtins. Closes rust-lang#73135
926c7b6
to
d6156e8
Compare
This comment has been minimized.
This comment has been minimized.
@bors: r=Mark-Simulacrum |
📌 Commit d6156e8 has been approved by |
…ins, r=Mark-Simulacrum Change how compiler-builtins gets many CGUs This commit intends to fix an accidental regression from rust-lang#70846. The goal of rust-lang#70846 was to build compiler-builtins with a maximal number of CGUs to ensure that each module in the source corresponds to an object file. This high degree of control for compiler-builtins is desirable to ensure that there's at most one exported symbol per CGU, ideally enabling compiler-builtins to not conflict with the system libgcc as often. In rust-lang#70846, however, only part of the compiler understands that compiler-builtins is built with many CGUs. The rest of the compiler thinks it's building with `sess.codegen_units()`. Notably the calculation of `sess.lto()` consults `sess.codegen_units()`, which when there's only one CGU it disables ThinLTO. This means that compiler-builtins is built without ThinLTO, which is quite harmful to performance! This is the root of the cause from rust-lang#73135 where intrinsics were found to not be inlining trivial functions. The fix applied in this commit is to remove the special-casing of compiler-builtins in the compiler. Instead the build system is now responsible for special-casing compiler-builtins. It doesn't know exactly how many CGUs will be needed but it passes a large number that is assumed to be much greater than the number of source-level modules needed. After reading the various locations in the compiler source, this seemed like the best solution rather than adding more and more special casing in the compiler for compiler-builtins. Closes rust-lang#73135
…ins, r=Mark-Simulacrum Change how compiler-builtins gets many CGUs This commit intends to fix an accidental regression from rust-lang#70846. The goal of rust-lang#70846 was to build compiler-builtins with a maximal number of CGUs to ensure that each module in the source corresponds to an object file. This high degree of control for compiler-builtins is desirable to ensure that there's at most one exported symbol per CGU, ideally enabling compiler-builtins to not conflict with the system libgcc as often. In rust-lang#70846, however, only part of the compiler understands that compiler-builtins is built with many CGUs. The rest of the compiler thinks it's building with `sess.codegen_units()`. Notably the calculation of `sess.lto()` consults `sess.codegen_units()`, which when there's only one CGU it disables ThinLTO. This means that compiler-builtins is built without ThinLTO, which is quite harmful to performance! This is the root of the cause from rust-lang#73135 where intrinsics were found to not be inlining trivial functions. The fix applied in this commit is to remove the special-casing of compiler-builtins in the compiler. Instead the build system is now responsible for special-casing compiler-builtins. It doesn't know exactly how many CGUs will be needed but it passes a large number that is assumed to be much greater than the number of source-level modules needed. After reading the various locations in the compiler source, this seemed like the best solution rather than adding more and more special casing in the compiler for compiler-builtins. Closes rust-lang#73135
I can confirm the Firefox linking error mentioned in #73136 (comment) does not happen anymore with nightly-2020-06-20, which is the first nightly with this fix. I cannot, however, say anything about nightly-2020-06-19, because rustc crashed during compilation (and so did nightly-2020-06-18). So it would have been nice in 1.44.1, but the second best thing would be to have it in 1.45. |
Beta-nominating as this (apparently) fixes a regression -- @glandium would be good to file an issue in the future for easier tracking on our end (in addition to comments like #73136 (comment)). |
FWIW this patch as-is uses a relatively new Cargo feature of profile overrides, and if it's backported I'd recommend double-checking that it works before landing. |
Adding |
Discussed in last week's T-compiler meeting We are inclined to backport the earlier version of this PR that doesn't rely on new cargo stuff. See link above for details. |
…ulacrum [beta] next Backports of: * rustdoc: Fix doc aliases with crate filtering rust-lang#73644 * rustdoc: Rename invalid_codeblock_attribute lint to be plural rust-lang#74131 * rustc_lexer: Simplify shebang parsing once more rust-lang#73596 * Perform obligation deduplication to avoid buggy `ExistentialMismatch` rust-lang#73485 * Reorder order in which MinGW libs are linked to fix recent breakage rust-lang#73184 * Change how compiler-builtins gets many CGUs rust-lang#73136 * Fix wasm32 being broken due to a NodeJS version bump rust-lang#73885
This commit intends to fix an accidental regression from #70846. The
goal of #70846 was to build compiler-builtins with a maximal number of
CGUs to ensure that each module in the source corresponds to an object
file. This high degree of control for compiler-builtins is desirable to
ensure that there's at most one exported symbol per CGU, ideally
enabling compiler-builtins to not conflict with the system libgcc as
often.
In #70846, however, only part of the compiler understands that
compiler-builtins is built with many CGUs. The rest of the compiler
thinks it's building with
sess.codegen_units()
. Notably thecalculation of
sess.lto()
consultssess.codegen_units()
, which whenthere's only one CGU it disables ThinLTO. This means that
compiler-builtins is built without ThinLTO, which is quite harmful to
performance! This is the root of the cause from #73135 where intrinsics
were found to not be inlining trivial functions.
The fix applied in this commit is to remove the special-casing of
compiler-builtins in the compiler. Instead the build system is now
responsible for special-casing compiler-builtins. It doesn't know
exactly how many CGUs will be needed but it passes a large number that
is assumed to be much greater than the number of source-level modules
needed. After reading the various locations in the compiler source, this
seemed like the best solution rather than adding more and more special
casing in the compiler for compiler-builtins.
Closes #73135