about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2023-07-30 16:11:10 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2023-07-31 11:32:02 +0000
commit62d084517ffd815fe0e37149967d15ee57f4c8fc (patch)
treed7093d20c402d4ad7f312c940c4995fc970b8395 /src/bootstrap
parentae8b7214a36c93b510514609f04bd576fcab9425 (diff)
downloadrust-62d084517ffd815fe0e37149967d15ee57f4c8fc.tar.gz
rust-62d084517ffd815fe0e37149967d15ee57f4c8fc.zip
strip debuginfo from LLVM's .so when applicable, on x64 linux
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/llvm.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs
index aadfd34f506..1cab3cbf092 100644
--- a/src/bootstrap/llvm.rs
+++ b/src/bootstrap/llvm.rs
@@ -515,6 +515,32 @@ impl Step for Llvm {
             }
         }
 
+        // When building LLVM as a shared library on linux, it can contain unexpected debuginfo:
+        // some can come from the C++ standard library. Unless we're explicitly requesting LLVM to
+        // be built with debuginfo, strip it away after the fact, to make dist artifacts smaller.
+        // FIXME: to make things simpler for now, limit this to the host and target where we know
+        // `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
+        // cross-compiling. Expand this to other appropriate targets in the future.
+        if builder.llvm_link_shared()
+            && builder.config.llvm_optimize
+            && !builder.config.llvm_release_debuginfo
+            && target == "x86_64-unknown-linux-gnu"
+            && target == builder.config.build
+        {
+            // Find the name of the LLVM shared library that we just built.
+            let lib_name = find_llvm_lib_name("so");
+
+            // If the shared library exists in LLVM's `/build/lib/` or `/lib/` folders, strip its
+            // debuginfo. Note: `output` will propagate any errors here.
+            let strip_if_possible = |path: PathBuf| {
+                if path.exists() {
+                    output(Command::new("strip").arg("--strip-debug").arg(path));
+                }
+            };
+            strip_if_possible(out_dir.join("lib").join(&lib_name));
+            strip_if_possible(out_dir.join("build").join("lib").join(&lib_name));
+        }
+
         t!(stamp.write());
 
         res