-
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
rustbuild: Build libstd with ThinLTO #45529
Conversation
This commit moves the standard library to get compiled with multiple codegen units and ThinLTO like the compiler itself. This I would hope is the last major step towards closing out rust-lang#45320
cc #45400, which enabled this for rustc |
@bors r+ |
📌 Commit 578feb5 has been approved by |
⌛ Testing commit 578feb5 with merge e462ee9c3d8c56966579d0c9c861617e9f162f86... |
💔 Test failed - status-travis |
Cannot link Errors from mipsel-unknown-linux-gnu
Errors from mips64el-unknown-linux-gnuabi64
|
I've been trying to debug this locally and figure out what's going on. I wasn't able to reproduce until I was able to reproduce. Then I found out it's nondeterministic. That's... oh boy. |
Ok so... Investigation so far: First I wanted to rule out a "trivial bug" in ThinLTO or LLVM. Let's start with this source code: #![feature(thread_local)]
#[thread_local]
static mut FOO: u32 = 3;
fn foo() -> &'static u32 {
unsafe { &*(&A as *const _) }
}
pub mod a {
pub fn bar() -> u32 {
*super::foo()
}
} Compile that with:
Next up we search through the output files for our thread local
Ok so far so good. One IR file imports one IR file exports. ThinLTO inlined the constant/function call across module boundaries. Despite all that we retain Next up let's take a look at the object files:
Ok still looking good. One object defines a So that rules out to me at least any casual oversight. Let's take a look at the test case in question. As I mentioned above it's nondeterministic, but I managed to catch a failure. A failure right now leaves a bunch of I rigged up a script to decode
Intersting! LLVM IR checks out as one module is importing a
Aha! Sure enough one object file has Next up is to figure out why if the LLVM module looks correct the object file looks incorrect. That... smells like an LLVM bug? A data race? Who knows! |
Dohoho the plot thickens! Turns out in a successful build there's not two object files. The one that has the "bad reference" didn't have the object file in the successful build, presumably optimized out? Desires for deterministic builds aside, that raised an interesting question. I compiled the program above for
And so aha! Looks like the mipsel backend is deterministically not handling |
And it keeps going...
Note that if we don't pass It looks like this is also related to Smells a lot like an LLVM bug... |
I've opened an upstream LLVM bug, and I don't think there's much we can do about this in the meantime, so here's to praying that gets a response in the next few days. |
@alexcrichton Would changing MIPS to use 1 CGU without ThinLTO workaround the bug? The TLS problem not only affects this PR but also #45187 and #45472. |
Interesting. As far as I know our builds are pretty deterministic. At least the number of object files should always be the same. |
That's some awesome debugging there, @alexcrichton, like reading a detective story I also think we should just default to one CGU on the affected platforms. |
@kennytm oh I had no idea that this was affecting other PRs! I'll implement a fix pronto. @michaelwoerister yeah I'm not entirely certain where the nondeterminism is coming from. It's probably coming from something in ThinLTO, I may do a pass to make sure we're at least feeding things to LLVM in a deterministic order. |
Discovered in rust-lang#45529 it looks like cross-module TLS imports aren't quite working today, especially with `hidden` visibility which mostly comes up with multiple codegen units. As a result this completely disables compiling with ThinLTO and multiple codegen units on MIPS when bootstrapping. cc rust-lang#45654, the tracking issue for this
rustbuild: Don't build with ThinLTO on MIPS Discovered in #45529 it looks like cross-module TLS imports aren't quite working today, especially with `hidden` visibility which mostly comes up with multiple codegen units. As a result this completely disables compiling with ThinLTO and multiple codegen units on MIPS when bootstrapping. cc #45654, the tracking issue for this
This commit moves the standard library to get compiled with multiple codegen
units and ThinLTO like the compiler itself. This I would hope is the last major
step towards closing out #45320