Skip to content

Commit

Permalink
Ensure that crates are linked with compatible panic-in-drop settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Sep 11, 2021
1 parent 007bd17 commit a149bed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
32 changes: 23 additions & 9 deletions compiler/rustc_metadata/src/dependency_format.rs
Expand Up @@ -400,21 +400,35 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
continue;
}
let cnum = CrateNum::new(i + 1);
let found_strategy = tcx.panic_strategy(cnum);
let is_compiler_builtins = tcx.is_compiler_builtins(cnum);
if is_compiler_builtins || desired_strategy == found_strategy {
if tcx.is_compiler_builtins(cnum) {
continue;
}

sess.err(&format!(
"the crate `{}` is compiled with the \
let found_strategy = tcx.panic_strategy(cnum);
if desired_strategy != found_strategy {
sess.err(&format!(
"the crate `{}` is compiled with the \
panic strategy `{}` which is \
incompatible with this crate's \
strategy of `{}`",
tcx.crate_name(cnum),
found_strategy.desc(),
desired_strategy.desc()
));
tcx.crate_name(cnum),
found_strategy.desc(),
desired_strategy.desc()
));
}

let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
if tcx.sess.opts.debugging_opts.panic_in_drop != found_drop_strategy {
sess.err(&format!(
"the crate `{}` is compiled with the \
panic-in-drop strategy `{}` which is \
incompatible with this crate's \
strategy of `{}`",
tcx.crate_name(cnum),
found_drop_strategy.desc(),
tcx.sess.opts.debugging_opts.panic_in_drop.desc()
));
}
}
}
}
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Expand Up @@ -160,6 +160,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
has_panic_handler => { cdata.root.has_panic_handler }
is_profiler_runtime => { cdata.root.profiler_runtime }
panic_strategy => { cdata.root.panic_strategy }
panic_in_drop_strategy => { cdata.root.panic_in_drop_strategy }
extern_crate => {
let r = *cdata.extern_crate.lock();
r.map(|c| &*tcx.arena.alloc(c))
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Expand Up @@ -691,6 +691,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
hash: tcx.crate_hash(LOCAL_CRATE),
stable_crate_id: tcx.def_path_hash(LOCAL_CRATE.as_def_id()).stable_crate_id(),
panic_strategy: tcx.sess.panic_strategy(),
panic_in_drop_strategy: tcx.sess.opts.debugging_opts.panic_in_drop,
edition: tcx.sess.edition(),
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Expand Up @@ -204,6 +204,7 @@ crate struct CrateRoot<'tcx> {
hash: Svh,
stable_crate_id: StableCrateId,
panic_strategy: PanicStrategy,
panic_in_drop_strategy: PanicStrategy,
edition: Edition,
has_global_allocator: bool,
has_panic_handler: bool,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Expand Up @@ -1159,6 +1159,10 @@ rustc_queries! {
fatal_cycle
desc { "query a crate's configured panic strategy" }
}
query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
fatal_cycle
desc { "query a crate's configured panic-in-drop strategy" }
}
query is_no_builtins(_: CrateNum) -> bool {
fatal_cycle
desc { "test whether a crate has `#![no_builtins]`" }
Expand Down

0 comments on commit a149bed

Please sign in to comment.