-
Notifications
You must be signed in to change notification settings - Fork 13.3k
-Zdylib-lto
with ThinLTO is broken on windows-msvc
#109114
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
WG-prioritization assigning priority (Zulip discussion). Possibly an overly "pessimistic" prioritization label, so feel free to reassess the impact. @rustbot label -I-prioritize +P-high |
The following is enough to trigger the issue (on the latest nightly). fn main() {
let mut chars = "£".chars();
let c = chars.next().unwrap();
if c.is_whitespace() {
panic!("{:?} is whitespace", c);
}
}
It's still sensitive to changes at this point, e.g. adding a I'll start working on removing |
At fn main() {
if '£'.is_whitespace() {
panic!("'£' is whitespace");
}
}
|
I'm more familiar with Windows than LLVM/rustc's internals, but there's a few issues I see in a compiled binary based off the reproducers. |
Yep, it's due to imported data being used. It can be reproduced without involving stdlib; you need to produce a dylib dependency that exports data, e.g.
src/main.rs:
Then use it in another crate
src/main.rs:
If this is built with optimisation it inlines the data and does not exhibit the bug. |
Dumping the LLVM IR gives
|
rust/compiler/rustc_codegen_llvm/src/consts.rs Lines 292 to 296 in e21f4cd
load though.
@dwattttt can you dump the llvm-ir before any optimizations (you need |
Adding
while building with release propogated the data, so no load occurs:
FTR I changed the source being compiled from an assert to an |
I ran a build through a debug logging rustc, I've attached the log. I didn't see anything particularly helpful, but I'm not sure what to look for. |
This looks relevant: 296489c It looks like we're losing a dllimport statement because we're assuming it's static linking somewhere around here? EDIT: I see it's just what you'd already found. Their issue looks like it matches what we're observing though. |
Reading through a bunch of the previous issues around, it looks like this issue is coming down to a difference in how dllimport is handled between lld-link.exe & link.exe (at least, as far as I can tell without trying to dig into each tool). The fix in #103353 was applied to stop emitting dllimport during ThinLTO; lld-link.exe was emitting basically the same problematic code structure we see here (#81408 (comment) shows the compiled binary attempting to call what is a data address to load through). Unfortunately, link.exe is emitting that problematic code structure when we don't emit dllimport in this situation. So the fix for lld-link.exe is causing the same issue in link.exe. I tried removing I don't know whether lld-link has changed to cause this issue to disappear, or if it's just been a matter of different optimisations being triggered, so as far as I see our options are:
Option 1 needs further testing to ensure we're not breaking linking with lld + ThinLTO. There's been a few reports of this issue, so there's a few things we can build & check to get some confidence that it works. |
Handling |
Found by a miscompilation inside the shipped rustc binaries on stable windows-msvc #109067
Here's a partially minimized sample. It can maybe get smaller than this, but after a point it seems to be fairly sensitive to the code shifting around.
Build with
rustc -Zdylib-lto -Clto=thin -Cprefer-dynamic=yes -Copt-level=2 main.rs
You should see:
Originally posted by @ehuss in #109067 (comment)
The text was updated successfully, but these errors were encountered: