-
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
Drop implementations not being called on panic with Fat LTO. #64655
Comments
triage: P-high. Assigning to self. Removing nomination label. |
Doing some bisection. This was introduced between Rust 1.32 and 1.33 |
More specifically, this was introduced between nightly-2018-12-08 and nightly-2018-12-14:
(unfortunately no nightlies are available between those two points in the rustup archive.) |
These are the PR's that bors merged between those two points:
|
According to my bisection via local builds, this was injected by #55982 (!) |
(Have I mentioned before that we probably need to be doing more testing of the various LTO configurations? Would it be feasible to run our test suite in all of the lto modes from { |
Thanks for tracking this down @pnkfelix! |
Okay I added some instrumentation to the compiler and I think I know where the problem here is coming from. Here's the executive summary:
I myself was confused by this comment, because it looked to me like the PR as written was taking pains to return So why is the test crate in this issue illustrating the problem outlined by @RalfJung above? First of all, here is a standalone main.rs that reproduces the problem for me. (You still have to turn on #![feature(core_panic)]
#![no_std]
extern crate std;
struct Droppable;
impl Drop for Droppable {
fn drop(&mut self) {
let msg = "Dropping a Droppable\n";
extern "C" { fn putchar(b: u8); }
for c in msg.chars() {
unsafe { putchar(c as u8); }
}
}
}
fn main() {
let _guard = Droppable;
core::panicking::panic(&("???", "downstream.rs", 17, 4))
} Running the compiler with Second, I instrumented a local rust/src/librustc_codegen_llvm/attributes.rs Lines 278 to 287 in f2023ac
Just imagine the above, with two inserted
and
And then I reviewed the output this spits out during both the stage1 bootstrapping and the actual compilation of the test case above. Here's the smoking gun from that output, I think:
namely, we are going through that first branch, already mentioned by @RalfJung , when we compile this declaration: Lines 73 to 77 in f2023ac
This causes the generated declaration for (But you need to have a somewhat nasty combination of factors to actually observe the optimization performed by LLVM in this case, which is how I guess this has gone relatively unobserved for so long, apart from what @RalfJung noticed in their own work.) |
The short version of my previous comment is that I bet I could make a small change to mark extern fn's with Rust or RustCall ABIs as unwinding, which would have less impact than @RalfJung's proposal and thus be a better candidate for backport.
|
…arking-rust-abi-unwind-issue-64655, r=alexcrichton Always mark rust and rust-call abi's as unwind PR rust-lang#63909 identified a bug that had been injected by PR rust-lang#55982. As discussed on rust-lang#64655 (comment) , we started marking extern items as nounwind, *even* extern items that said they were using "Rust" or "rust-call" ABI. This is a more targeted variant of PR rust-lang#63909 that fixes the above bug. Fix rust-lang#64655 ---- I personally suspect we will want PR rust-lang#63909 to land in the long-term But: * it is not certain that PR rust-lang#63909 *will* land, * more importantly, PR rust-lang#63909 almost certainly will not be backported to beta/stable. The identified bug was more severe than I think anyone realized (apart from perhaps @gnzlbg, as noted [here](rust-lang#63909 (comment))). Thus, I was motivated to write this PR, which fixes *just* the issue with extern rust/rust-call functions, and deliberately avoids injecting further deviation from current behavior (you can see further notes on this in the comments of the code added here).
…arking-rust-abi-unwind-issue-64655, r=alexcrichton Always mark rust and rust-call abi's as unwind PR rust-lang#63909 identified a bug that had been injected by PR rust-lang#55982. As discussed on rust-lang#64655 (comment) , we started marking extern items as nounwind, *even* extern items that said they were using "Rust" or "rust-call" ABI. This is a more targeted variant of PR rust-lang#63909 that fixes the above bug. Fix rust-lang#64655 ---- I personally suspect we will want PR rust-lang#63909 to land in the long-term But: * it is not certain that PR rust-lang#63909 *will* land, * more importantly, PR rust-lang#63909 almost certainly will not be backported to beta/stable. The identified bug was more severe than I think anyone realized (apart from perhaps @gnzlbg, as noted [here](rust-lang#63909 (comment))). Thus, I was motivated to write this PR, which fixes *just* the issue with extern rust/rust-call functions, and deliberately avoids injecting further deviation from current behavior (you can see further notes on this in the comments of the code added here).
…arking-rust-abi-unwind-issue-64655, r=alexcrichton Always mark rust and rust-call abi's as unwind PR rust-lang#63909 identified a bug that had been injected by PR rust-lang#55982. As discussed on rust-lang#64655 (comment) , we started marking extern items as nounwind, *even* extern items that said they were using "Rust" or "rust-call" ABI. This is a more targeted variant of PR rust-lang#63909 that fixes the above bug. Fix rust-lang#64655 ---- I personally suspect we will want PR rust-lang#63909 to land in the long-term But: * it is not certain that PR rust-lang#63909 *will* land, * more importantly, PR rust-lang#63909 almost certainly will not be backported to beta/stable. The identified bug was more severe than I think anyone realized (apart from perhaps @gnzlbg, as noted [here](rust-lang#63909 (comment))). Thus, I was motivated to write this PR, which fixes *just* the issue with extern rust/rust-call functions, and deliberately avoids injecting further deviation from current behavior (you can see further notes on this in the comments of the code added here).
…king-rust-abi-unwind-issue-64655, r=alexcrichton Always mark rust and rust-call abi's as unwind PR rust-lang#63909 identified a bug that had been injected by PR rust-lang#55982. As discussed on rust-lang#64655 (comment) , we started marking extern items as nounwind, *even* extern items that said they were using "Rust" or "rust-call" ABI. This is a more targeted variant of PR rust-lang#63909 that fixes the above bug. Fix rust-lang#64655 ---- I personally suspect we will want PR rust-lang#63909 to land in the long-term But: * it is not certain that PR rust-lang#63909 *will* land, * more importantly, PR rust-lang#63909 almost certainly will not be backported to beta/stable. The identified bug was more severe than I think anyone realized (apart from perhaps @gnzlbg, as noted [here](rust-lang#63909 (comment))). Thus, I was motivated to write this PR, which fixes *just* the issue with extern rust/rust-call functions, and deliberately avoids injecting further deviation from current behavior (you can see further notes on this in the comments of the code added here).
Hi,
It looks like calls to
Drop::drop()
are getting removed when usinglto = "fat"
for a release build. It doesn't seem to occur withlto = "thin"
orlto = "no"
.I've got a test case here: https://github.com/cstorey/fat-lto-drop-repro, which can be reproduced like this:
(more details in the transcript)
For context, I first noticed this in a project where I am using an
mpsc::channel
to communciate between threads, where a producer thread reads messages from the network, and the main thread saves those to a database.I was relying on the fact that the
Drop
implementation for a channel will in effect close the channel, so the main thread can find out that the producer has failed, and so we should kill the process. What I saw instead was the producer thread panicing, but the main thread would never get woken up.I've seen this on macOS
Darwin 17.7.0 x86_64
and Linux5.0.0-25-generic #26-Ubuntu SMP Thu Aug 1 12:04:58 UTC 2019 x86_64
.The text was updated successfully, but these errors were encountered: