summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_ssa/src/base.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/base.rs')
-rw-r--r--compiler/rustc_codegen_ssa/src/base.rs41
1 files changed, 27 insertions, 14 deletions
diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs
index 84b89cd71..4f396e970 100644
--- a/compiler/rustc_codegen_ssa/src/base.rs
+++ b/compiler/rustc_codegen_ssa/src/base.rs
@@ -22,7 +22,6 @@ use rustc_data_structures::sync::ParallelIterator;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::lang_items::LangItem;
-use rustc_hir::weak_lang_items::WEAK_ITEMS_SYMBOLS;
use rustc_index::vec::Idx;
use rustc_metadata::EncodedMetadata;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
@@ -639,7 +638,14 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
let llmod_id =
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
let module_llvm = tcx.sess.time("write_allocator_module", || {
- backend.codegen_allocator(tcx, &llmod_id, kind, tcx.lang_items().oom().is_some())
+ backend.codegen_allocator(
+ tcx,
+ &llmod_id,
+ kind,
+ // If allocator_kind is Some then alloc_error_handler_kind must
+ // also be Some.
+ tcx.alloc_error_handler_kind(()).unwrap(),
+ )
});
Some(ModuleCodegen { name: llmod_id, module_llvm, kind: ModuleKind::Allocator })
@@ -827,20 +833,30 @@ impl CrateInfo {
//
// In order to get this left-to-right dependency ordering, we use the reverse
// postorder of all crates putting the leaves at the right-most positions.
- let used_crates = tcx
+ let mut compiler_builtins = None;
+ let mut used_crates: Vec<_> = tcx
.postorder_cnums(())
.iter()
.rev()
.copied()
- .filter(|&cnum| !tcx.dep_kind(cnum).macros_only())
+ .filter(|&cnum| {
+ let link = !tcx.dep_kind(cnum).macros_only();
+ if link && tcx.is_compiler_builtins(cnum) {
+ compiler_builtins = Some(cnum);
+ return false;
+ }
+ link
+ })
.collect();
+ // `compiler_builtins` are always placed last to ensure that they're linked correctly.
+ used_crates.extend(compiler_builtins);
let mut info = CrateInfo {
target_cpu,
exported_symbols,
linked_symbols,
local_crate_name,
- compiler_builtins: None,
+ compiler_builtins,
profiler_runtime: None,
is_no_builtins: Default::default(),
native_libraries: Default::default(),
@@ -866,9 +882,6 @@ impl CrateInfo {
let used_crate_source = tcx.used_crate_source(cnum);
info.used_crate_source.insert(cnum, used_crate_source.clone());
- if tcx.is_compiler_builtins(cnum) {
- info.compiler_builtins = Some(cnum);
- }
if tcx.is_profiler_runtime(cnum) {
info.profiler_runtime = Some(cnum);
}
@@ -887,14 +900,14 @@ impl CrateInfo {
// by the compiler, but that's ok because all this stuff is unstable anyway.
let target = &tcx.sess.target;
if !are_upstream_rust_objects_already_included(tcx.sess) {
- let missing_weak_lang_items: FxHashSet<&Symbol> = info
+ let missing_weak_lang_items: FxHashSet<Symbol> = info
.used_crates
.iter()
- .flat_map(|cnum| {
- tcx.missing_lang_items(*cnum)
- .iter()
- .filter(|l| lang_items::required(tcx, **l))
- .filter_map(|item| WEAK_ITEMS_SYMBOLS.get(item))
+ .flat_map(|&cnum| tcx.missing_lang_items(cnum))
+ .filter(|l| l.is_weak())
+ .filter_map(|&l| {
+ let name = l.link_name()?;
+ lang_items::required(tcx, l).then_some(name)
})
.collect();
let prefix = if target.is_like_windows && target.arch == "x86" { "_" } else { "" };