Skip to content

Commit 7807074

Browse files
committed
Auto merge of #49672 - alexcrichton:fix-another-std-core-cycle, r=michaelwoerister
Fix another circular deps link args issue It turns out that the support in #49316 wasn't enough to handle all cases notably the example in #48661. The underlying bug was connected to panic=abort where lang items were listed in the `missing_lang_items` sets but didn't actually exist anywhere. This caused the linker backend to deduce that start-group/end-group wasn't needed because not all items were defined. Instead the missing lang items that don't actually need to have a definition are filtered out and not considered for the start-group/end-group arguments Closes #48661
2 parents 8228d8e + 48ede3f commit 7807074

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

src/librustc/middle/weak_lang_items.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> {
6464
})
6565
}
6666

67+
/// Returns whether the specified `lang_item` doesn't actually need to be
68+
/// present for this compilation.
69+
///
70+
/// Not all lang items are always required for each compilation, particularly in
71+
/// the case of panic=abort. In these situations some lang items are injected by
72+
/// crates and don't actually need to be defined in libstd.
73+
pub fn whitelisted(tcx: TyCtxt, lang_item: lang_items::LangItem) -> bool {
74+
// If we're not compiling with unwinding, we won't actually need these
75+
// symbols. Other panic runtimes ensure that the relevant symbols are
76+
// available to link things together, but they're never exercised.
77+
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
78+
return lang_item == lang_items::EhPersonalityLangItem ||
79+
lang_item == lang_items::EhUnwindResumeLangItem
80+
}
81+
82+
false
83+
}
84+
6785
fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6886
items: &lang_items::LanguageItems) {
6987
// We only need to check for the presence of weak lang items if we're
@@ -89,18 +107,9 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
89107
}
90108
}
91109

92-
// If we're not compiling with unwinding, we won't actually need these
93-
// symbols. Other panic runtimes ensure that the relevant symbols are
94-
// available to link things together, but they're never exercised.
95-
let mut whitelisted = HashSet::new();
96-
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
97-
whitelisted.insert(lang_items::EhPersonalityLangItem);
98-
whitelisted.insert(lang_items::EhUnwindResumeLangItem);
99-
}
100-
101110
$(
102111
if missing.contains(&lang_items::$item) &&
103-
!whitelisted.contains(&lang_items::$item) &&
112+
!whitelisted(tcx, lang_items::$item) &&
104113
items.$name().is_none() {
105114
tcx.sess.err(&format!("language item required, but not found: `{}`",
106115
stringify!($name)));

src/librustc_trans/base.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use llvm;
3636
use metadata;
3737
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
3838
use rustc::middle::lang_items::StartFnLangItem;
39+
use rustc::middle::weak_lang_items;
3940
use rustc::mir::mono::{Linkage, Visibility, Stats};
4041
use rustc::middle::cstore::{EncodedMetadata};
4142
use rustc::ty::{self, Ty, TyCtxt};
@@ -1141,6 +1142,13 @@ impl CrateInfo {
11411142
info.lang_item_to_crate.insert(item, id.krate);
11421143
}
11431144
}
1145+
1146+
// No need to look for lang items that are whitelisted and don't
1147+
// actually need to exist.
1148+
let missing = missing.iter()
1149+
.cloned()
1150+
.filter(|&l| !weak_lang_items::whitelisted(tcx, l))
1151+
.collect();
11441152
info.missing_lang_items.insert(cnum, missing);
11451153
}
11461154

src/librustc_trans/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ struct CrateInfo {
404404
wasm_custom_sections: BTreeMap<String, Vec<u8>>,
405405
wasm_imports: FxHashMap<String, String>,
406406
lang_item_to_crate: FxHashMap<LangItem, CrateNum>,
407-
missing_lang_items: FxHashMap<CrateNum, Lrc<Vec<LangItem>>>,
407+
missing_lang_items: FxHashMap<CrateNum, Vec<LangItem>>,
408408
}
409409

410410
__build_diagnostic_array! { librustc_trans, DIAGNOSTICS }

src/test/run-make-fulldeps/std-core-cycle/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ endif
1313
all:
1414
$(RUSTC) bar.rs
1515
$(RUSTC) foo.rs $(FLAGS)
16+
$(RUSTC) foo.rs $(FLAGS) -C panic=abort

0 commit comments

Comments
 (0)