-
Notifications
You must be signed in to change notification settings - Fork 14k
Allow core with unwinding functions to be used in -C panic=abort crates
#148269
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //@ compile-flags: -C panic=abort -Cno-prepopulate-passes | ||
|
|
||
| // Test that Rustic `#[rustc_propagate_ffi_unwind]` functions are considered unwinding even under | ||
| // `-C panic=abort`. We disable optimizations to make sure LLVM doesn't infer attributes. | ||
|
|
||
| #![feature(rustc_attrs)] | ||
| #![crate_type = "lib"] | ||
|
|
||
| // CHECK: @caller() unnamed_addr [[ATTR0:#[0-9]+]] | ||
| #[no_mangle] | ||
| pub fn caller() { | ||
| // CHECK: call void @{{.*core9panicking19panic_cannot_unwind}} | ||
| may_unwind(); | ||
| } | ||
|
|
||
| // This function would typically be in a different crate. | ||
| // CHECK: @may_unwind() unnamed_addr [[ATTR1:#[0-9]+]] | ||
| #[no_mangle] | ||
| #[rustc_propagate_ffi_unwind] | ||
| #[inline(never)] | ||
| pub fn may_unwind() {} | ||
|
|
||
| // CHECK: attributes [[ATTR0]] = { {{.*}}nounwind{{.*}} } | ||
| // CHECK-NOT: attributes [[ATTR1]] = { {{.*}}nounwind{{.*}} } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| //@ only-wasm32 | ||
| //@ compile-flags: -C panic=abort | ||
| //@ build-pass | ||
|
|
||
| // Test that a `-C panic=abort` binary crate can link to a `-C panic=unwind` core. | ||
|
|
||
| fn main() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function must not be callable if any crate is compiled panic=abort. Otherwise you can unwind through panic=abort functions and thus skip destructors, which is unsound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the declaration of this intrinsic should be moved back to the panic_unwind crate?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's the case -- since
#[rustc_propagate_ffi_unwind]functions are always considered unwinding, theabort_unwinding_callspass will insert the correct logic whenever it's called from apanic=abortcrate; and if it's called indirectly via some other rustic function, then that nested function will be recognized as unwinding andffi_unwind_callswill force the panic strategy tounwind. I think that#[rustc_propagate_ffi_unwind]functions behave identically to FFI functions (i.e. without available source) in this regard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the propagate-ffi-unwind.rs test demonstrates this behavior; please correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When calling
extern "C"we assume that no panic can happen, when defining anextern "C"function unwinding out of it will abort unconditionally. When callingextern "C-unwind"from a panic=abort crate we insert an aborting landingpad. And if theextern "C-unwind"function is declared in a panic=unwind crate that forces the final compilation to be panic=unwind as we don't know if any panic=unwind function called it that could allow exceptions to escape into panic=abort crates. For callingextern "Rust"functions with a hidden origin no landingpads get inserted because if any crate is panic=abort, we ensure there is no way to unwind through any rust crate thanks to theextern "C-unwind"landingpad + guarantee that if any crate is panic=abort, allextern "C-unwind"functions are declared in panic=abort crates too and thus the landingpads are forced.AFAICT with this PR you could call
throwfrom a panic=unwind crate (which thus doesn't have an aborting landingpad) and then call this function from a panic=abort crate which also doesn't have an aborting landingpad due to the assumption that you can't unwind into any Rust code if any crate is panic=abort. This unwinding into a panic=abort crate then results in UB.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right -- I forgot to update
has_ffi_unwind_callsto consider calls to#[rustc_propagate_ffi_unwind]functions as tainting even if the function has rustic ABI. I think that's sufficient to fix the issue?EDIT: scratch that, that doesn't work due to function pointers. It kind of seems like this would require a new ABI, then...
EDIT 2: Maybe we can just make
throwC-unwind(and also use this attribute)? That sounds like it works.