Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uprustc: Switch `extern` functions to abort by default on panic #55982
Conversation
rust-highfive
assigned
zackmdavis
Nov 15, 2018
This comment has been minimized.
This comment has been minimized.
|
r? @zackmdavis (rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Nov 15, 2018
alexcrichton
referenced this pull request
Nov 15, 2018
Open
Abort instead of unwinding past FFI functions #52652
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Nov 15, 2018
Mark-Simulacrum
added
the
relnotes
label
Nov 15, 2018
This comment has been minimized.
This comment has been minimized.
|
FWIW I still personally feel like changing stable behavior without providing a stabilized way to get back the old behavior is not great, but I'm not going to block this myself, both because I think this is fairly rare and the new behavior seems overall later. |
This comment has been minimized.
This comment has been minimized.
|
Maybe we should do a Crater run for this? |
This comment has been minimized.
This comment has been minimized.
|
@bors: r- Seems fine by me to hold off on a crater run happening! |
bors
added
S-waiting-on-author
and removed
S-waiting-on-bors
labels
Nov 15, 2018
This comment has been minimized.
This comment has been minimized.
|
@bors: try |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Nov 15, 2018
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@craterbot run start=master#6b9b97bd9b704f85f0184f7a213cc4d62bd9654c end=try#2e026d6e5d7621634147ad4c8074f1d964dbb1be mode=build-and-test |
This comment has been minimized.
This comment has been minimized.
|
|
craterbot
added
S-waiting-on-crater
and removed
S-waiting-on-author
labels
Nov 16, 2018
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
craterbot
added
S-waiting-on-review
and removed
S-waiting-on-crater
labels
Nov 18, 2018
This comment has been minimized.
This comment has been minimized.
|
From that report there are four legitimate-looking regressions
In testing I've also noticed that the compiler no longer emits I've now pushed a follow-up commit to fix the regression, now applying |
alexcrichton
force-pushed the
alexcrichton:panic-extern-abort
branch
from
6ea11fd
to
95310d6
Nov 20, 2018
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
alexcrichton
force-pushed the
alexcrichton:panic-extern-abort
branch
from
95310d6
to
07aafac
Nov 20, 2018
alexcrichton
force-pushed the
alexcrichton:panic-extern-abort
branch
from
c3fc942
to
1091eee
Dec 12, 2018
This comment has been minimized.
This comment has been minimized.
|
@bors: r=zackmdavis |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-author
labels
Dec 12, 2018
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Dec 12, 2018
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Dec 13, 2018
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 1091eee
into
rust-lang:master
Dec 13, 2018
This was referenced Dec 13, 2018
This comment has been minimized.
This comment has been minimized.
This sounds like the default is unchanged, and this PR doesn’t do anything without |
alexcrichton
deleted the
alexcrichton:panic-extern-abort
branch
Dec 13, 2018
This comment has been minimized.
This comment has been minimized.
|
Sure! @SimonSapin does this clear things up? This was intended to land way back in 1.24, but it was backed out due to breakage which has long since been fixed. Prior to this PR a crate could panic and unwind past an extern fn foo() {
panic!();
}
fn main() {
foo();
}This PR changes the behavior of generated code to be sound-by-default. If an The implementation in this PR is pretty simple because an unstable |
This comment has been minimized.
This comment has been minimized.
|
Yes this is better, thanks! I don’t know if this example is actually UB though. I though what was undefined was unwinding from Rust into a call stack of another language. |
This comment has been minimized.
This comment has been minimized.
|
You can explore the UB through the IR of a program like this: #![crate_type = "lib"]
#[inline(never)]
extern fn foo() {
panic!("x");
}
struct A;
impl Drop for A {
fn drop(&mut self) {
extern { fn foo(); }
unsafe { foo(); }
}
}
pub fn bar() {
let _x = A;
foo();
} The compiler places the
Note that recent compilers have a bug where they don't place |
This comment has been minimized.
This comment has been minimized.
|
Ok I see. I didn’t know about |
alexcrichton commentedNov 15, 2018
•
edited
This was intended to land way back in 1.24, but it was backed out due to breakage which has long since been fixed. Prior to this PR a crate could panic and unwind past an
extern fnboundary, but such behavior is UB. For example, this is undefined behavior:This PR changes the behavior of generated code to be sound-by-default. If an
extern fnis unwound (panicked through) then it immediately aborts the program. Put another way, noextern fncan unwind.The implementation in this PR is pretty simple because an unstable
#[unwind]attribute could already be used to tweak the unwinding behavior. As a result this PR basically just switches the default from#[unwind]to#[unwind(abort)]for allextern fndefinitions.Closes #52652