]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #86105 - bjorn3:link_info_refactor, r=petrochenkov
authorbors <bors@rust-lang.org>
Wed, 7 Jul 2021 18:28:53 +0000 (18:28 +0000)
committerbors <bors@rust-lang.org>
Wed, 7 Jul 2021 18:28:53 +0000 (18:28 +0000)
Refactor the generation of the metadata for linking

1  2 
compiler/rustc_codegen_ssa/src/base.rs
compiler/rustc_middle/src/middle/cstore.rs

index 7df17bd20b99208873e69d284c42c835e3108ab2,15c4ce8a4d0a46e90ccf9bcb884332d4cc82b61f..be2bf8b199724ab59a00a6c054d38034b783e914
@@@ -775,10 -769,25 +775,26 @@@ impl 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,
              local_crate_name,
 -            panic_runtime: None,
              compiler_builtins: None,
              profiler_runtime: None,
              is_no_builtins: Default::default(),