1
Fork 0
rust/compiler/rustc_mir_transform/src
bors 6a10920564 Auto merge of #97235 - nbdd0121:unwind, r=Amanieu
Fix FFI-unwind unsoundness with mixed panic mode

UB maybe introduced when an FFI exception happens in a `C-unwind` foreign function and it propagates through a crate compiled with `-C panic=unwind` into a crate compiled with `-C panic=abort` (#96926).

To prevent this unsoundness from happening, we will disallow a crate compiled with `-C panic=unwind` to be linked into `panic-abort` *if* it contains a call to `C-unwind` foreign function or function pointer. If no such call exists, then we continue to allow such mixed panic mode linking because it's sound (and stable). In fact we still need the ability to do mixed panic mode linking for std, because we only compile std once with `-C panic=unwind` and link it regardless panic strategy.

For libraries that wish to remain compile-once-and-linkable-to-both-panic-runtimes, a `ffi_unwind_calls` lint is added (gated under `c_unwind` feature gate) to flag any FFI unwind calls that will cause the linkable panic runtime be restricted.

In summary:
```rust
#![warn(ffi_unwind_calls)]

mod foo {
    #[no_mangle]
    pub extern "C-unwind" fn foo() {}
}

extern "C-unwind" {
    fn foo();
}

fn main() {
    // Call to Rust function is fine regardless ABI.
    foo::foo();
    // Call to foreign function, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`.
    unsafe { foo(); }
    //~^ WARNING call to foreign function with FFI-unwind ABI
    let ptr: extern "C-unwind" fn() = foo::foo;
    // Call to function pointer, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`.
    ptr();
    //~^ WARNING call to function pointer with FFI-unwind ABI
}
```

Fix #96926

`@rustbot` label: T-compiler F-c_unwind
2022-07-02 14:06:27 +00:00
..
coverage Use Span::eq_ctxt method instead of .ctxt() == .ctxt() 2022-06-19 16:46:59 -07:00
inline Do not ICE when failing to resolve. 2022-06-30 21:45:29 +02:00
abort_unwinding_calls.rs Use is_fn_like instead of matching on DefKind 2022-06-08 21:32:41 +01:00
add_call_guards.rs Refactor call terminator to always hold a destination place 2022-05-23 17:49:04 -04:00
add_moves_for_packed_drops.rs Adopt let else in more places 2022-02-19 17:27:43 +01:00
add_retag.rs emit Retag for compound types with reference fields 2022-06-28 11:03:50 -04:00
check_const_item_mutation.rs rustc_error: make ErrorReported impossible to construct 2022-03-16 10:35:24 -05:00
check_packed_ref.rs Mention implementers of unsatisfied trait 2022-04-04 21:01:42 +00:00
check_unsafety.rs review 2022-05-09 18:40:18 +02:00
cleanup_post_borrowck.rs
const_debuginfo.rs cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
const_goto.rs enhance ConstGoto mir-opt by moving up StorageDead statements 2022-04-06 15:17:41 +08:00
const_prop.rs cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
const_prop_lint.rs cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
dead_store_elimination.rs Remove duplicated implementations of borrowed locals analysis 2022-06-12 07:27:57 +02:00
deaggregator.rs Clarify which kinds of MIR are allowed during which phases. 2022-03-23 18:34:08 -04:00
deduplicate_blocks.rs Remove in_band_lifetimes from rustc_mir_transform 2021-12-07 21:04:40 -08:00
deref_separator.rs validate derefer, run derefer inside generator 2022-05-30 18:36:14 +03:00
dest_prop.rs Remove duplicated implementations of borrowed locals analysis 2022-06-12 07:27:57 +02:00
dump_mir.rs Inline on_mir_pass and add inline to dump_mir 2021-10-14 15:26:59 -05:00
early_otherwise_branch.rs tut tut tut 2022-04-27 08:51:33 +01:00
elaborate_box_derefs.rs fix box derefs in var debug info 2022-06-15 18:39:23 -07:00
elaborate_drops.rs implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
ffi_unwind_calls.rs Add a explanation about required panic strategy computation 2022-06-09 16:51:08 +01:00
function_item_references.rs Refactor call terminator to always hold a destination place 2022-05-23 17:49:04 -04:00
generator.rs Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk 2022-06-21 11:00:39 +00:00
inline.rs Allow inlining #[inline] functions. 2022-06-30 21:45:29 +02:00
instcombine.rs implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
lib.rs Auto merge of #97235 - nbdd0121:unwind, r=Amanieu 2022-07-02 14:06:27 +00:00
lower_intrinsics.rs implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
lower_slice_len.rs Refactor call terminator to always hold a destination place 2022-05-23 17:49:04 -04:00
marker.rs Add pass for simple phase change 2021-12-02 17:31:38 -08:00
match_branches.rs fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
multiple_return_terminators.rs Update passes with new interface 2021-12-02 17:31:38 -08:00
normalize_array_len.rs Remove box syntax from rustc_mir_dataflow and rustc_mir_transform 2022-05-22 17:19:44 +02:00
nrvo.rs cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
pass_manager.rs Address nits 2022-04-16 18:44:27 -04:00
remove_false_edges.rs Separate RemoveFalseEdges from SimplifyBranches 2021-11-30 17:14:48 -08:00
remove_noop_landing_pads.rs implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
remove_storage_markers.rs Update passes with new interface 2021-12-02 17:31:38 -08:00
remove_uninit_drops.rs Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
remove_unneeded_drops.rs Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
remove_zsts.rs Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
required_consts.rs Rename the ConstS::val field as kind. 2022-06-14 13:06:44 +10:00
reveal_all.rs Overhaul TyS and Ty. 2022-02-15 16:03:24 +11:00
separate_const_switch.rs Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
shim.rs implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
simplify.rs cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
simplify_branches.rs Auto merge of #91279 - scottmcm:small-refactor, r=nagisa 2021-12-06 13:04:18 +00:00
simplify_comparison_integral.rs fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
simplify_try.rs cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
uninhabited_enum_branching.rs Clarify Layout interning. 2022-03-07 13:41:47 +11:00
unreachable_prop.rs Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00