diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 43c859b00631e..9423f309cb1cc 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -1673,7 +1673,15 @@ impl<'a> Builder<'a> {
                 self.config.rust_debuginfo_level_tools
             }
         };
-        cargo.env(profile_var("DEBUG"), debuginfo_level.to_string());
+        if debuginfo_level == 1 {
+            // Use less debuginfo than the default to save on disk space.
+            cargo.env(profile_var("DEBUG"), "line-tables-only");
+        } else {
+            cargo.env(profile_var("DEBUG"), debuginfo_level.to_string());
+        };
+        if self.cc[&target].args().iter().any(|arg| arg == "-gz") {
+            rustflags.arg("-Clink-arg=-gz");
+        }
         cargo.env(
             profile_var("DEBUG_ASSERTIONS"),
             if mode == Mode::Std {
diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs
index 65c882fb801e5..db3b69d18c8fc 100644
--- a/src/bootstrap/cc_detect.rs
+++ b/src/bootstrap/cc_detect.rs
@@ -69,6 +69,8 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
         .opt_level(2)
         .warnings(false)
         .debug(false)
+        // Compress debuginfo
+        .flag_if_supported("-gz")
         .target(&target.triple)
         .host(&build.build.triple);
     match build.crt_static(target) {