about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2024-05-18 22:58:25 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2024-05-23 15:47:35 +0000
commitfab28f2a4d0bd394546cc37417c7b8aa4ecc1a21 (patch)
tree7b5bab60a5ca9ec5fb4970bcb3806ae1c780f727 /compiler/rustc_codegen_ssa
parent6867d6492b1b96173d175b4a4b5887691798daf6 (diff)
downloadrust-fab28f2a4d0bd394546cc37417c7b8aa4ecc1a21.tar.gz
rust-fab28f2a4d0bd394546cc37417c7b8aa4ecc1a21.zip
rust-lld: fallback to the default default sysroot where rustc is currently located
Diffstat (limited to 'compiler/rustc_codegen_ssa')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 6939674ce9d..874732ee9ef 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -3116,13 +3116,21 @@ fn add_lld_args(
 
     let self_contained_linker = self_contained_cli || self_contained_target;
     if self_contained_linker && !sess.opts.cg.link_self_contained.is_linker_disabled() {
+        let mut linker_path_exists = false;
         for path in sess.get_tools_search_paths(false) {
+            let linker_path = path.join("gcc-ld");
+            linker_path_exists |= linker_path.exists();
             cmd.arg({
                 let mut arg = OsString::from("-B");
-                arg.push(path.join("gcc-ld"));
+                arg.push(linker_path);
                 arg
             });
         }
+        if !linker_path_exists {
+            // As an additional sanity check, we do nothing if the sysroot doesn't contain the
+            // linker path at all.
+            return;
+        }
     }
 
     // 2. Implement the "linker flavor" part of this feature by asking `cc` to use some kind of