Skip to content

Commit cfff3a3

Browse files
committed
Merge LinkerInfo::to_linker into get_linker
1 parent 0b061cb commit cfff3a3

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1713,11 +1713,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
17131713
codegen_results: &CodegenResults,
17141714
) -> Command {
17151715
let crt_objects_fallback = crt_objects_fallback(sess, crate_type);
1716-
let base_cmd = super::linker::get_linker(sess, path, flavor, crt_objects_fallback);
1717-
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
1718-
// to the linker args construction.
1719-
assert!(base_cmd.get_args().is_empty() || sess.target.vendor == "uwp");
1720-
let cmd = &mut *codegen_results.crate_info.linker_info.to_linker(base_cmd, &sess, flavor);
1716+
let cmd = &mut *super::linker::get_linker(
1717+
sess,
1718+
path,
1719+
flavor,
1720+
crt_objects_fallback,
1721+
&codegen_results.crate_info.linker_info,
1722+
);
17211723
let link_output_kind = link_output_kind(sess, crate_type);
17221724

17231725
// ------------ Early order-dependent options ------------

compiler/rustc_codegen_ssa/src/back/linker.rs

+33-39
Original file line numberDiff line numberDiff line change
@@ -56,52 +56,18 @@ impl LinkerInfo {
5656
.collect(),
5757
}
5858
}
59-
60-
pub fn to_linker<'a>(
61-
&'a self,
62-
cmd: Command,
63-
sess: &'a Session,
64-
flavor: LinkerFlavor,
65-
) -> Box<dyn Linker + 'a> {
66-
match flavor {
67-
LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => {
68-
Box::new(MsvcLinker { cmd, sess, info: self }) as Box<dyn Linker>
69-
}
70-
LinkerFlavor::Em => Box::new(EmLinker { cmd, sess, info: self }) as Box<dyn Linker>,
71-
LinkerFlavor::Gcc => {
72-
Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: false })
73-
as Box<dyn Linker>
74-
}
75-
76-
LinkerFlavor::Lld(LldFlavor::Ld)
77-
| LinkerFlavor::Lld(LldFlavor::Ld64)
78-
| LinkerFlavor::Ld => {
79-
Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: true })
80-
as Box<dyn Linker>
81-
}
82-
83-
LinkerFlavor::Lld(LldFlavor::Wasm) => {
84-
Box::new(WasmLd::new(cmd, sess, self)) as Box<dyn Linker>
85-
}
86-
87-
LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box<dyn Linker>,
88-
89-
LinkerFlavor::BpfLinker => {
90-
Box::new(BpfLinker { cmd, sess, info: self }) as Box<dyn Linker>
91-
}
92-
}
93-
}
9459
}
9560

9661
// The third parameter is for env vars, used on windows to set up the
9762
// path for MSVC to find its DLLs, and gcc to find its bundled
9863
// toolchain
99-
pub fn get_linker(
100-
sess: &Session,
64+
pub fn get_linker<'a>(
65+
sess: &'a Session,
10166
linker: &Path,
10267
flavor: LinkerFlavor,
10368
self_contained: bool,
104-
) -> Command {
69+
info: &'a LinkerInfo,
70+
) -> Box<dyn Linker + 'a> {
10571
let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe");
10672

10773
// If our linker looks like a batch script on Windows then to execute this
@@ -181,7 +147,35 @@ pub fn get_linker(
181147
}
182148
cmd.env("PATH", env::join_paths(new_path).unwrap());
183149

184-
cmd
150+
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
151+
// to the linker args construction.
152+
assert!(cmd.get_args().is_empty() || sess.target.vendor == "uwp");
153+
154+
match flavor {
155+
LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => {
156+
Box::new(MsvcLinker { cmd, sess, info }) as Box<dyn Linker>
157+
}
158+
LinkerFlavor::Em => Box::new(EmLinker { cmd, sess, info }) as Box<dyn Linker>,
159+
LinkerFlavor::Gcc => {
160+
Box::new(GccLinker { cmd, sess, info, hinted_static: false, is_ld: false })
161+
as Box<dyn Linker>
162+
}
163+
164+
LinkerFlavor::Lld(LldFlavor::Ld)
165+
| LinkerFlavor::Lld(LldFlavor::Ld64)
166+
| LinkerFlavor::Ld => {
167+
Box::new(GccLinker { cmd, sess, info, hinted_static: false, is_ld: true })
168+
as Box<dyn Linker>
169+
}
170+
171+
LinkerFlavor::Lld(LldFlavor::Wasm) => {
172+
Box::new(WasmLd::new(cmd, sess, info)) as Box<dyn Linker>
173+
}
174+
175+
LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box<dyn Linker>,
176+
177+
LinkerFlavor::BpfLinker => Box::new(BpfLinker { cmd, sess, info }) as Box<dyn Linker>,
178+
}
185179
}
186180

187181
/// Linker abstraction used by `back::link` to build up the command to invoke a

0 commit comments

Comments
 (0)