about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/weak_lang_items.rs29
-rw-r--r--src/librustc_trans/base.rs8
-rw-r--r--src/librustc_trans/lib.rs2
-rw-r--r--src/test/run-make-fulldeps/std-core-cycle/Makefile1
4 files changed, 29 insertions, 11 deletions
diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs
index 95e75b4f064..e19f4483f65 100644
--- a/src/librustc/middle/weak_lang_items.rs
+++ b/src/librustc/middle/weak_lang_items.rs
@@ -64,6 +64,24 @@ pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> {
     })
 }
 
+/// Returns whether the specified `lang_item` doesn't actually need to be
+/// present for this compilation.
+///
+/// Not all lang items are always required for each compilation, particularly in
+/// the case of panic=abort. In these situations some lang items are injected by
+/// crates and don't actually need to be defined in libstd.
+pub fn whitelisted(tcx: TyCtxt, lang_item: lang_items::LangItem) -> bool {
+    // If we're not compiling with unwinding, we won't actually need these
+    // symbols. Other panic runtimes ensure that the relevant symbols are
+    // available to link things together, but they're never exercised.
+    if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
+        return lang_item == lang_items::EhPersonalityLangItem ||
+            lang_item == lang_items::EhUnwindResumeLangItem
+    }
+
+    false
+}
+
 fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                     items: &lang_items::LanguageItems) {
     // 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>,
         }
     }
 
-    // If we're not compiling with unwinding, we won't actually need these
-    // symbols. Other panic runtimes ensure that the relevant symbols are
-    // available to link things together, but they're never exercised.
-    let mut whitelisted = HashSet::new();
-    if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
-        whitelisted.insert(lang_items::EhPersonalityLangItem);
-        whitelisted.insert(lang_items::EhUnwindResumeLangItem);
-    }
-
     $(
         if missing.contains(&lang_items::$item) &&
-           !whitelisted.contains(&lang_items::$item) &&
+           !whitelisted(tcx, lang_items::$item) &&
            items.$name().is_none() {
             tcx.sess.err(&format!("language item required, but not found: `{}`",
                                   stringify!($name)));
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index a513ebbf6c7..0329264a312 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -36,6 +36,7 @@ use llvm;
 use metadata;
 use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
 use rustc::middle::lang_items::StartFnLangItem;
+use rustc::middle::weak_lang_items;
 use rustc::mir::mono::{Linkage, Visibility, Stats};
 use rustc::middle::cstore::{EncodedMetadata};
 use rustc::ty::{self, Ty, TyCtxt};
@@ -1141,6 +1142,13 @@ impl CrateInfo {
                     info.lang_item_to_crate.insert(item, id.krate);
                 }
             }
+
+            // No need to look for lang items that are whitelisted and don't
+            // actually need to exist.
+            let missing = missing.iter()
+                .cloned()
+                .filter(|&l| !weak_lang_items::whitelisted(tcx, l))
+                .collect();
             info.missing_lang_items.insert(cnum, missing);
         }
 
diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs
index 738b72dbcbb..344f959c141 100644
--- a/src/librustc_trans/lib.rs
+++ b/src/librustc_trans/lib.rs
@@ -404,7 +404,7 @@ struct CrateInfo {
     wasm_custom_sections: BTreeMap<String, Vec<u8>>,
     wasm_imports: FxHashMap<String, String>,
     lang_item_to_crate: FxHashMap<LangItem, CrateNum>,
-    missing_lang_items: FxHashMap<CrateNum, Lrc<Vec<LangItem>>>,
+    missing_lang_items: FxHashMap<CrateNum, Vec<LangItem>>,
 }
 
 __build_diagnostic_array! { librustc_trans, DIAGNOSTICS }
diff --git a/src/test/run-make-fulldeps/std-core-cycle/Makefile b/src/test/run-make-fulldeps/std-core-cycle/Makefile
index adc5be8016c..ce3b2d46bbc 100644
--- a/src/test/run-make-fulldeps/std-core-cycle/Makefile
+++ b/src/test/run-make-fulldeps/std-core-cycle/Makefile
@@ -13,3 +13,4 @@ endif
 all:
 	$(RUSTC) bar.rs
 	$(RUSTC) foo.rs $(FLAGS)
+	$(RUSTC) foo.rs $(FLAGS) -C panic=abort