Brian Stinson c96953
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
Brian Stinson c96953
index 2748903f2d47..10d02d6db829 100644
Brian Stinson c96953
--- a/src/bootstrap/builder.rs
Brian Stinson c96953
+++ b/src/bootstrap/builder.rs
Brian Stinson c96953
@@ -1231,7 +1231,8 @@ impl<'a> Builder<'a> {
Brian Stinson c96953
             cargo.arg("--frozen");
Brian Stinson c96953
         }
Brian Stinson c96953
 
Brian Stinson c96953
-        cargo.env("RUSTC_INSTALL_BINDIR", &self.config.bindir);
Brian Stinson c96953
+        // Try to use a sysroot-relative bindir, in case it was configured absolutely.
Brian Stinson c96953
+        cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());
Brian Stinson c96953
 
Brian Stinson c96953
         self.ci_env.force_coloring_in_ci(&mut cargo);
Brian Stinson c96953
 
Brian Stinson c96953
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
Brian Stinson c96953
index d1bdfa0a7676..0c03b95c7b25 100644
Brian Stinson c96953
--- a/src/bootstrap/config.rs
Brian Stinson c96953
+++ b/src/bootstrap/config.rs
Brian Stinson c96953
@@ -647,6 +647,20 @@ impl Config {
Brian Stinson c96953
         config
Brian Stinson c96953
     }
Brian Stinson c96953
 
Brian Stinson c96953
+    /// Try to find the relative path of `bindir`, otherwise return it in full.
Brian Stinson c96953
+    pub fn bindir_relative(&self) -> &Path {
Brian Stinson c96953
+        let bindir = &self.bindir;
Brian Stinson c96953
+        if bindir.is_absolute() {
Brian Stinson c96953
+            // Try to make it relative to the prefix.
Brian Stinson c96953
+            if let Some(prefix) = &self.prefix {
Brian Stinson c96953
+                if let Ok(stripped) = bindir.strip_prefix(prefix) {
Brian Stinson c96953
+                    return stripped;
Brian Stinson c96953
+                }
Brian Stinson c96953
+            }
Brian Stinson c96953
+        }
Brian Stinson c96953
+        bindir
Brian Stinson c96953
+    }
Brian Stinson c96953
+
Brian Stinson c96953
     /// Try to find the relative path of `libdir`.
Brian Stinson c96953
     pub fn libdir_relative(&self) -> Option<&Path> {
Brian Stinson c96953
         let libdir = self.libdir.as_ref()?;