Skip to content

Commit f2611aa

Browse files
committed
rust-lld: fallback to the default linker if there's no path to the linker
1 parent eb1a5c9 commit f2611aa

File tree

1 file changed

+15
-5
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+15
-5
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -3116,12 +3116,22 @@ fn add_lld_args(
31163116

31173117
let self_contained_linker = self_contained_cli || self_contained_target;
31183118
if self_contained_linker && !sess.opts.cg.link_self_contained.is_linker_disabled() {
3119+
let mut linker_path_exists = false;
31193120
for path in sess.get_tools_search_paths(false) {
3120-
cmd.arg({
3121-
let mut arg = OsString::from("-B");
3122-
arg.push(path.join("gcc-ld"));
3123-
arg
3124-
});
3121+
let linker_path = path.join("gcc-ld");
3122+
if linker_path.exists() {
3123+
linker_path_exists = true;
3124+
cmd.arg({
3125+
let mut arg = OsString::from("-B");
3126+
arg.push(linker_path);
3127+
arg
3128+
});
3129+
}
3130+
}
3131+
if !linker_path_exists {
3132+
// As an additional sanity check, we do nothing if the sysroot doesn't contain the
3133+
// linker path at all.
3134+
return;
31253135
}
31263136
}
31273137

0 commit comments

Comments
 (0)