-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Apply dllimport in ThinLTO #122790
Apply dllimport in ThinLTO #122790
Conversation
We can make try builds also run some tests now, so we could test this PR with it:
|
@bors try |
Apply dllimport in ThinLTO for -Z dylib-lto This partially reverts rust-lang#103353 by properly applying `dllimport` if `-Z dylib-lto` is passed. That PR should probably fully be reverted as it looks quite sketchy. We don't know locally if the entire crate graph would be statically linked. This should hopefully be sufficient to make ThinLTO work for rustc on Windows. r? `@wesleywiser`
☀️ Try build successful - checks-actions |
I'm a bit confused what you meant about underlying issues in #128947? |
In recent t-compiler meetings, Wesley said he'd be looking at this PR soon and testing with the original internal repro. I think #81408, #109114, #103353, and this PR are all pointing at unknown issues, with dllimports on our side that I guess are more or less "tracked" via #27438, and/or lld bugs on msvc (or the converse with link.exe, #109114 (comment) seems to show a damned if we do damned if we don't kind of deal). On top of this, the fact that we're using It doesn't look like we have tests for #81408's behavior, only for what the workaround is expected to produce. So we don't know if the lld issue would reproduce or has been fixed, if we land this PR. |
To be clear, I want us to land the PR. I'm just not sure we understand the issues, workarounds, and what other miscompilations we could uncover, don't have sufficient test coverage, and can't even crater any of this on windows, and last time this happened no one noticed before hitting stable. tl;dr: we’re in a tough spot to make changes confidently imho So with all of the above and previous comment, are you 100% confident this is fine as-is? |
@lqd Just to clarify, you're just talking about this PR and not applying ThinLTO to the compiler on msvc right? |
This comment has been minimized.
This comment has been minimized.
What is this referring to? I assume not #127979 (comment) since many of these were changed in #127995. |
That was the one yes, the change is recent and didn't show in the github UI in this older PR until it was rebased yesterday. The assertion is still not checking -Clto on master. But that may be moot if we land this full revert.
The latter is scarier, but #109114 (comment) seems to be saying that the same situation can happen on both lld and msvc's link, and that fixing one breaks the other (and that may be what happened with #127979). So I wished that we had a more in-depth look at the entire situation rather than a back and forth of regressions. I wish to know whether this comment is still accurate. And if we're indeed "disallowing dynamic linking" with // ThinLTO can't handle this workaround in all cases, so we don't
// emit the attrs. Instead we make them unnecessary by disallowing
// dynamic linking when linker plugin based LTO is enabled. I also wish for some involvement from people more familiar with the situation like @wesleywiser and @michaelwoerister or other windows experts.
Right, they probably don't (but do recommend What happens with this PR on the repros in #81408? A revert is just preferring to accept #81408 instead of #127979, and both were encountered in the wild. Bevy seems to use lld on windows anyways, so their users turning on ThinLTO can easily encounter either issue. Not great. The good thing out of #127979 is that we have a minimal repro to make a test. |
I tested a reproducer in #81408 with this PR applied. It crashed with lld, but not Microsoft's linker, so that's likely just a lld bug.
One is a lld bug, the other is a rustc bug introduced in #103353 and thus affects all linkers. It's pretty clear what should be fixed there. |
Ok then until wesley/michael can take a look, it'll be worthwhile to have tests in this PR that reproduce the issue on CI for sure. FWIW I tested bash's repro of #127979, and it reproduced. I then updated VS build tools to test with this PR (because of linker errors on rustc-driver with download-ci-llvm, and it didn't even help; but stage1 built when compiling llvm). With these build tools v16.11.38, bash's repro doesn't trigger the bug anymore, with link.exe or rust-lld, in release or debug, with this PR or master. I also tested the original bevy quickstart repo where the issue appeared, with this PR. It crashed when using rust-lld, but doesn't work with link.exe either (doesn't crash, just that "nothing happens", unlike in debug mode). And things were the same on nightly with link.exe. 🔥🔥🔥🔥🔥🔥🔥🔥 |
Apparently after #128469 (which is in this branch now) it no longer reproduces, assume that's why you couldn't reproduce it? That doesn't seem to contain a fix though. |
Ah yes:
As for
|
Just that |
☔ The latest upstream changes (presumably #130506) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #132581) made this pull request unmergeable. Please resolve the merge conflicts. |
It would be nice to get this merged so Bevy doesn't keep running into this issue. r? @ChrisDenton |
We've landed a non-regression test for #81408, does it pass with this PR, I guess so, right? If this lands, please reopen 81408. Did you see the question about |
#129079 fixes #81408, so I don't see why we'd want to reopen it? For |
Ah right.
Ah, unfortunate. Do you know if this is the main source for people encountering this issue or are you mentioning other bevy use cases? I assume we will hit asserts preventing ThinLTO + dylib-lto on windows if people tried to enable it again on the dist workflows. Otherwise this also looks good to me, but let’s see what chris thinks. |
I opened #137998 which would help with rust-lang/cargo#14575.
Not quite sure what you're asking here.
No. That should just work without issue if this PR lands, unless something changed since last year. I did test that it worked locally. |
Thanks for tackling this! I agree with your reasoning and I've tested locally. There's still plenty of time before this reaches stable if wesley or someone else does find this breaks in some cases but I fairly strongly suspect this won't cause regressions. @bors r+ |
Apply dllimport in ThinLTO This partially reverts rust-lang#103353 by properly applying `dllimport` if `-Z dylib-lto` is passed. That PR should probably fully be reverted as it looks quite sketchy. We don't know locally if the entire crate graph would be statically linked. This should hopefully be sufficient to make ThinLTO work for rustc on Windows. r? `@wesleywiser` --- Edit: This PR is changed to just generally revert rust-lang#103353.
Rollup of 16 pull requests Successful merges: - rust-lang#122790 (Apply dllimport in ThinLTO) - rust-lang#136127 (Allow `*const W<dyn A> -> *const dyn A` ptr cast) - rust-lang#136968 (Turn order dependent trait objects future incompat warning into a hard error) - rust-lang#137147 (Add exclude to config.toml) - rust-lang#137319 (Stabilize `const_vec_string_slice`) - rust-lang#137885 (tidy: add triagebot checks) - rust-lang#138040 (compiler: Use `size_of` from the prelude instead of imported) - rust-lang#138052 (strip `-Wlinker-messages` wrappers from `rust-lld` rmake test) - rust-lang#138084 (Use workspace lints for crates in `compiler/`) - rust-lang#138158 (Move more layouting logic to `rustc_abi`) - rust-lang#138160 (depend more on attr_data_structures and move find_attr! there) - rust-lang#138192 (crashes: couple more tests) - rust-lang#138216 (bootstrap: Fix stack printing when a step cycle is detected) - rust-lang#138232 (Reduce verbosity of GCC build log) - rust-lang#138233 (Windows: Don't link std (and run-make) against advapi32, except on win7) - rust-lang#138242 (Revert "Don't test new error messages with the stage 0 compiler") r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#122790 (Apply dllimport in ThinLTO) - rust-lang#137650 (Move `fs` into `sys`) - rust-lang#138228 (Use `disjoint_bitor` inside `borrowing_sub`) - rust-lang#138233 (Windows: Don't link std (and run-make) against advapi32, except on win7) - rust-lang#138253 (Continue to check attr if meet empty repr for adt) - rust-lang#138263 (Fix `repr128-dwarf` test) - rust-lang#138276 (Lazy load NtOpenFile for UWP) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#122790 - Zoxc:dllimp-rev, r=ChrisDenton Apply dllimport in ThinLTO This partially reverts rust-lang#103353 by properly applying `dllimport` if `-Z dylib-lto` is passed. That PR should probably fully be reverted as it looks quite sketchy. We don't know locally if the entire crate graph would be statically linked. This should hopefully be sufficient to make ThinLTO work for rustc on Windows. r? ``@wesleywiser`` --- Edit: This PR is changed to just generally revert rust-lang#103353.
This partially reverts #103353 by properly applying
dllimport
if-Z dylib-lto
is passed. That PR should probably fully be reverted as it looks quite sketchy. We don't know locally if the entire crate graph would be statically linked.This should hopefully be sufficient to make ThinLTO work for rustc on Windows.
r? @wesleywiser
Edit: This PR is changed to just generally revert #103353.