From cfff3a35a2f871491b6d8f73b6025fd3cc0a3be1 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 6 Jul 2021 18:01:44 +0200 Subject: Merge LinkerInfo::to_linker into get_linker --- compiler/rustc_codegen_ssa/src/back/link.rs | 12 +++-- compiler/rustc_codegen_ssa/src/back/linker.rs | 72 ++++++++++++--------------- 2 files changed, 40 insertions(+), 44 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src/back') diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 5f133f7afe4..b04fbe8f0d2 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1713,11 +1713,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( codegen_results: &CodegenResults, ) -> Command { let crt_objects_fallback = crt_objects_fallback(sess, crate_type); - let base_cmd = super::linker::get_linker(sess, path, flavor, crt_objects_fallback); - // FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction - // to the linker args construction. - assert!(base_cmd.get_args().is_empty() || sess.target.vendor == "uwp"); - let cmd = &mut *codegen_results.crate_info.linker_info.to_linker(base_cmd, &sess, flavor); + let cmd = &mut *super::linker::get_linker( + sess, + path, + flavor, + crt_objects_fallback, + &codegen_results.crate_info.linker_info, + ); let link_output_kind = link_output_kind(sess, crate_type); // ------------ Early order-dependent options ------------ diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 8d76f9814e0..c5a595cbf08 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -56,52 +56,18 @@ impl LinkerInfo { .collect(), } } - - pub fn to_linker<'a>( - &'a self, - cmd: Command, - sess: &'a Session, - flavor: LinkerFlavor, - ) -> Box { - match flavor { - LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => { - Box::new(MsvcLinker { cmd, sess, info: self }) as Box - } - LinkerFlavor::Em => Box::new(EmLinker { cmd, sess, info: self }) as Box, - LinkerFlavor::Gcc => { - Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: false }) - as Box - } - - LinkerFlavor::Lld(LldFlavor::Ld) - | LinkerFlavor::Lld(LldFlavor::Ld64) - | LinkerFlavor::Ld => { - Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: true }) - as Box - } - - LinkerFlavor::Lld(LldFlavor::Wasm) => { - Box::new(WasmLd::new(cmd, sess, self)) as Box - } - - LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box, - - LinkerFlavor::BpfLinker => { - Box::new(BpfLinker { cmd, sess, info: self }) as Box - } - } - } } // The third parameter is for env vars, used on windows to set up the // path for MSVC to find its DLLs, and gcc to find its bundled // toolchain -pub fn get_linker( - sess: &Session, +pub fn get_linker<'a>( + sess: &'a Session, linker: &Path, flavor: LinkerFlavor, self_contained: bool, -) -> Command { + info: &'a LinkerInfo, +) -> Box { let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe"); // If our linker looks like a batch script on Windows then to execute this @@ -181,7 +147,35 @@ pub fn get_linker( } cmd.env("PATH", env::join_paths(new_path).unwrap()); - cmd + // FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction + // to the linker args construction. + assert!(cmd.get_args().is_empty() || sess.target.vendor == "uwp"); + + match flavor { + LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => { + Box::new(MsvcLinker { cmd, sess, info }) as Box + } + LinkerFlavor::Em => Box::new(EmLinker { cmd, sess, info }) as Box, + LinkerFlavor::Gcc => { + Box::new(GccLinker { cmd, sess, info, hinted_static: false, is_ld: false }) + as Box + } + + LinkerFlavor::Lld(LldFlavor::Ld) + | LinkerFlavor::Lld(LldFlavor::Ld64) + | LinkerFlavor::Ld => { + Box::new(GccLinker { cmd, sess, info, hinted_static: false, is_ld: true }) + as Box + } + + LinkerFlavor::Lld(LldFlavor::Wasm) => { + Box::new(WasmLd::new(cmd, sess, info)) as Box + } + + LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box, + + LinkerFlavor::BpfLinker => Box::new(BpfLinker { cmd, sess, info }) as Box, + } } /// Linker abstraction used by `back::link` to build up the command to invoke a -- cgit 1.4.1-3-g733a5