Skip to content

Commit 27e95f9

Browse files
committed
linker: Avoid calling linker_and_flavor twice
1 parent 43653c1 commit 27e95f9

File tree

1 file changed

+9
-6
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+9
-6
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ fn link_natively(
670670
) {
671671
info!("preparing {:?} to {:?}", crate_type, out_filename);
672672
let (linker_path, flavor) = linker_and_flavor(sess);
673-
let self_contained_components = self_contained_components(sess, crate_type);
673+
let self_contained_components = self_contained_components(sess, crate_type, &linker_path);
674674

675675
// On AIX, we ship all libraries as .a big_af archive
676676
// the expected format is lib<name>.a(libname.so) for the actual
@@ -1788,16 +1788,15 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
17881788
}
17891789

17901790
// Returns true if linker is located within sysroot
1791-
fn detect_self_contained_mingw(sess: &Session) -> bool {
1792-
let (linker, _) = linker_and_flavor(sess);
1791+
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
17931792
// Assume `-C linker=rust-lld` as self-contained mode
17941793
if linker == Path::new("rust-lld") {
17951794
return true;
17961795
}
17971796
let linker_with_extension = if cfg!(windows) && linker.extension().is_none() {
17981797
linker.with_extension("exe")
17991798
} else {
1800-
linker
1799+
linker.to_path_buf()
18011800
};
18021801
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
18031802
let full_path = dir.join(&linker_with_extension);
@@ -1812,7 +1811,11 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
18121811
/// Various toolchain components used during linking are used from rustc distribution
18131812
/// instead of being found somewhere on the host system.
18141813
/// We only provide such support for a very limited number of targets.
1815-
fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfContainedComponents {
1814+
fn self_contained_components(
1815+
sess: &Session,
1816+
crate_type: CrateType,
1817+
linker: &Path,
1818+
) -> LinkSelfContainedComponents {
18161819
// Turn the backwards compatible bool values for `self_contained` into fully inferred
18171820
// `LinkSelfContainedComponents`.
18181821
let self_contained =
@@ -1841,7 +1844,7 @@ fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfC
18411844
LinkSelfContainedDefault::InferredForMingw => {
18421845
sess.host == sess.target
18431846
&& sess.target.vendor != "uwp"
1844-
&& detect_self_contained_mingw(sess)
1847+
&& detect_self_contained_mingw(sess, linker)
18451848
}
18461849
}
18471850
};

0 commit comments

Comments
 (0)