Skip to content
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

Permit unwinding through FFI by default #62603

Merged
merged 3 commits into from
Aug 26, 2019
Merged

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Jul 11, 2019

This repeats #62505 for master (Rust 1.38+), as #58794 is not yet resolved. This is a stopgap until a stable alternative is available, like RFC 2699, as long as progress is being made to that end.

r? @joshtriplett

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 11, 2019
@RalfJung
Copy link
Member

RalfJung commented Jul 13, 2019

To be clear, this allows extern C functions to unwind and it does not set the nounwind attribute for them? So there's lots of platform-specific concerns, but at least not outright UB?

@cuviper
Copy link
Member Author

cuviper commented Jul 18, 2019

@RalfJung no, this has no effect on the nounwind attribute, maintaining the (questionable) status quo that we've been releasing with so far. The only effect here is whether we add a cleanup block to non-Rust-ABI functions, so it forces an abort on panic/unwinding.

I believe nounwind is controlled here:

if cx.tcx.is_foreign_item(id) {
// Foreign items like `extern "C" { fn foo(); }` are assumed not to
// unwind
false
} else if sig.abi != Abi::Rust && sig.abi != Abi::RustCall {
// Any items defined in Rust that *don't* have the `extern` ABI are
// defined to not unwind. We insert shims to abort if an unwind
// happens to enforce this.
false

@bors
Copy link
Contributor

bors commented Jul 27, 2019

☔ The latest upstream changes (presumably #63029) made this pull request unmergeable. Please resolve the merge conflicts.

@cuviper
Copy link
Member Author

cuviper commented Jul 31, 2019

Rebased.

@Alexendoo
Copy link
Member

Ping from triage: Any updates? @joshtriplett

@cuviper
Copy link
Member Author

cuviper commented Aug 13, 2019

A new beta 1.38 has branched -- @joshtriplett what's your preference here? Are we ready to land this on master and then nominate for beta? Or should I do another beta-targeted PR?

@bors
Copy link
Contributor

bors commented Aug 16, 2019

☔ The latest upstream changes (presumably #63627) made this pull request unmergeable. Please resolve the merge conflicts.

@wirelessringo
Copy link

Ping from triage. @cuviper please resolve the merge conflicts. Thanks.

@rustbot modify labels to +S-waiting-on-author, -S-waiting-on-review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2019
@RalfJung RalfJung added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Aug 25, 2019
@RalfJung
Copy link
Member

RalfJung commented Aug 25, 2019

I believe nounwind is controlled here:

Could you expand this PR to also remove the nounwind then? We keep applying this on beta, which is silly -- but IMO applying this patch while still emitting nounwind is also a bad idea.

With that change, I will nominate this for lang-team discussion.

@RalfJung
Copy link
Member

RalfJung commented Aug 25, 2019

Ideally, that code (deciding about the LLVM unwind attribute) would call should_abort_on_panic. Not sure if that is possible.

EDIT: Hm, this is odd -- the code tests for CodegenFnAttrFlags::UNWIND but I am not sure how that relates to Rust's UnwindAttr.

EDIT2: Looks like the code here permits a function to unwind if any unwind attribute is present, including unwind(aborts)?!?

@RalfJung
Copy link
Member

Looks like #48380 repurposed the attribute, but some old users still treat is as basically a boolean. I think CodegenFnAttrFlags::UNWIND should be removed, and from_fn_attrs should just call should_abort_on_panic to make sure that it only ever adds nounwind when we really do the abort-on-panic. I can do this in a separate cleanup PR, maybe?

@RalfJung
Copy link
Member

See #63884 for fixing how we control the nounwind attribute. If both that PR and this one land, that will correctly stop adding nounwind to extern "C" fn.

@cuviper
Copy link
Member Author

cuviper commented Aug 25, 2019

@RalfJung - Thanks for tackling the other side of this!

I've rebased this PR, and I got a verbal r+ to go ahead at RustConf. I'll also nominate for beta since we missed the branch.

@bors r=joshtriplett

@bors
Copy link
Contributor

bors commented Aug 25, 2019

📌 Commit 367b793 has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 25, 2019
@cuviper cuviper added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 25, 2019
@bors
Copy link
Contributor

bors commented Aug 26, 2019

⌛ Testing commit 367b793 with merge 4c58535...

bors added a commit that referenced this pull request Aug 26, 2019
Permit unwinding through FFI by default

This repeats #62505 for master (Rust 1.38+), as #58794 is not yet resolved. This is a stopgap until a stable alternative is available, like [RFC 2699](rust-lang/rfcs#2699), as long as progress is being made to that end.

r? @joshtriplett
@bors
Copy link
Contributor

bors commented Aug 26, 2019

☀️ Test successful - checks-azure
Approved by: joshtriplett
Pushing 4c58535 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 26, 2019
@bors bors merged commit 367b793 into rust-lang:master Aug 26, 2019
bors added a commit that referenced this pull request Aug 28, 2019
fix nounwind attribute logic

With #62603 landed, we no longer add abort-on-panic shims to `extern "C"` functions. However, that means we should also not emit `nounwind` for `extern fn` because we are not actually catching those panics. The comment justifying that `nounwind` in the source is just factually wrong.

I also noticed that we annotate `extern` *declarations* (of any ABI) with `nounwind`, which seems wrong? I removed this. Code like mozjpeg (the code that prompted the removal of the abort-on-panic shim) throws a panic from Rust code that enters C code (meaning the `extern "C"` *definition* must not have `nounwind`, or else we got UB), but then the panic bubbles through the C code and re-enters Rust code (meaning the `extern "C"` *declaration* that gets called from the Rust side must not have `nounwind` either).

This should be beta-backported if #62603 gets backported.
@pnkfelix
Copy link
Member

pnkfelix commented Sep 13, 2019

based on my interpretation of the recent Lang Team meetings (including the one last night), I am going to unilaterally accept this for a beta backport, due to time pressure with a release in two weeks. @joshtriplett shares this interpretation of the lang team meetings.

(The other motivating detail is that, the way things are now, if we do not beta-backport this, then we will have breakage that is solely on the current beta, not in stable nor master, which means we'd be scheduling one cycle of breakage.)

(I'm pretty sure there was some sort of process failure along the way here that led to a breakdown in our normal procedure, probably due to a conflation of how this PR is semi-coupled with PR #63909, the question of which teams should have been tagged to each PR, etc...)

@pnkfelix pnkfelix added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Sep 13, 2019
@cuviper
Copy link
Member Author

cuviper commented Sep 13, 2019

Thanks @pnkfelix -- the backport is underway in #64438.

bors added a commit that referenced this pull request Sep 14, 2019
[beta] Rollup backports

Cherry-picked:

- Permit unwinding through FFI by default #62603
- pprust: Do not print spaces before some tokens #63897
- Account for doc comments coming from proc macros without spans #63930
- Support "soft" feature-gating using a lint #64066
- Update xLTO compatibility table in rustc book. #64092
- Include compiler-rt in the source tarball #64240
- Update LLVM submodule #64317

r? @Mark-Simulacrum
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Sep 14, 2019
@cuviper cuviper deleted the no-unwind-abort branch April 3, 2020 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants