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

Disable building rustc with (Thin)LTO on Windows #113433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Jul 7, 2023

We know that rustc currently produces miscompilations when it is compiled with (Thin)LTO on Windows (#109067). We have therefore disabled LTO for dist windows builds. However, other people who build their own rustc might now know this, and this leads to them having miscompilations in the wild (#112946 (comment)).

I think that we should give a loud warning that this build configuration produces known miscompilations.

@rustbot
Copy link
Collaborator

rustbot commented Jul 7, 2023

r? @clubby789

(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-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 7, 2023
@@ -817,6 +817,12 @@ impl Step for Rustc {
if compiler.stage != 0 {
match builder.config.rust_lto {
RustcLto::Thin | RustcLto::Fat => {
if target.contains("windows") {
Copy link
Member

Choose a reason for hiding this comment

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

(we know windows-msvc has the miscompile but it could be fine on windows-gnu.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I suppose that we only definitely know about miscompiles in x86_64-pc-windows-msvc, right? So maybe we should just warn against this single target.

Copy link
Member

@lqd lqd Jul 7, 2023

Choose a reason for hiding this comment

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

Yeah, for sure on x86_64-pc-windows-msvc, on the others there have been no reports yet I don't think, but it may just be that they're less commonly used. But now that we know a few ways to trigger them, it may be possible to test there. (maybe even on CI depending on the Tier)

Copy link
Member

Choose a reason for hiding this comment

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

Hm, do the current reports affect out-of-the-box msvc or just when using lld?

Copy link
Member

Choose a reason for hiding this comment

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

lld is usually involved (e.g. #103353), and it should also be the case in #109114

Copy link
Member

Choose a reason for hiding this comment

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

#109114 (if we don't use lld on CI) coupled with #113425 (which involves lld) together mean that building rustc with rust.lto = "thin" will result in a miscompiled rustc.

We're not building rustc with ThinLTO on windows because of these issues, and those -msvc miscompilations look serious enough that people probably shouldn't do so either, and instead be made aware of that?

So I'm not sure what you mean by "maybe a bit heavy handed to disable thinlto for x86_64-pc-windows-msvc" ? This PR is not disabling ThinLTO, it's about bootstrap preventing building rustc with -Zdylib-lto, to avoid miscompilations.

Copy link
Member

Choose a reason for hiding this comment

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

We can (hopefully) test for issues like #109114 in CI. But the same is not true for lld, no?

Copy link
Contributor Author

@Kobzol Kobzol Jul 7, 2023

Choose a reason for hiding this comment

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

#109114 => Rustc compiled with LLD=false, ThinLTO=true => produces miscompilations
#112946 (comment) => Rustc compiled with LLD=true, ThinLTO=true => produces miscompilations

So it seems that when we compile rustc with ThinLTO, it then produces miscompilations regardless whether it was itself compiled with LLD or not. Therefore we want to ban ThinLTO when you build Rustc for Windows for the moment.

Note 1: This has nothing to do with applying LTO to Rust programs. Rustc can still perform LTO when building Rust code on Windows.
Note 2: Rustc on Windows is currently not optimized with LTO because of the miscompilations. This PR doesn't change that.

Copy link
Member

@lqd lqd Jul 7, 2023

Choose a reason for hiding this comment

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

We could instead emit a scary warning, if an error would disturb your use-cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I recall seeing many MSVC + LTO + LLD miscompilation issues over the years but strangely they didn't reproduce on windows-gnu when I tested them, so I'd agree it makes sense to apply this limit on windows-msvc only.

@Kobzol Kobzol force-pushed the bootstrap-window-thinlto-error branch from 2091be1 to 292cafe Compare July 7, 2023 10:49
@workingjubilee workingjubilee added the O-windows Operating system: Windows label Jul 30, 2023
@bors
Copy link
Contributor

bors commented Oct 17, 2023

☔ The latest upstream changes (presumably #116196) 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
O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants