X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_codegen_ssa%2Fsrc%2Fbase.rs;fp=compiler%2Frustc_codegen_ssa%2Fsrc%2Fbase.rs;h=be2bf8b199724ab59a00a6c054d38034b783e914;hb=d2b04f075c0ce010758c4c8674152ff89d1d73f3;hp=7df17bd20b99208873e69d284c42c835e3108ab2;hpb=c5e344f7747dbd7e7d4b209e3c480deb5979a56f;p=rust.git diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 7df17bd20b9..be2bf8b1997 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -19,7 +19,7 @@ use rustc_hir::lang_items::LangItem; use rustc_index::vec::Idx; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; -use rustc_middle::middle::cstore::{self, EncodedMetadata}; +use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::middle::lang_items; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; @@ -775,6 +775,22 @@ pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> CrateInfo { subsystem.to_string() }); + // This list is used when generating the command line to pass through to + // system linker. The linker expects undefined symbols on the left of the + // command line to be defined in libraries on the right, not the other way + // around. For more info, see some comments in the add_used_library function + // below. + // + // 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 + .postorder_cnums(()) + .iter() + .rev() + .copied() + .filter(|&cnum| !tcx.dep_kind(cnum).macros_only()) + .collect(); + let mut info = CrateInfo { target_cpu, exported_symbols, @@ -785,7 +801,7 @@ pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> CrateInfo { native_libraries: Default::default(), used_libraries: tcx.native_libraries(LOCAL_CRATE).iter().map(Into::into).collect(), crate_name: Default::default(), - used_crates: cstore::used_crates(tcx), + used_crates, used_crate_source: Default::default(), lang_item_to_crate: Default::default(), missing_lang_items: Default::default(),