Skip to content

Commit 388d0eb

Browse files
committed
strip debuginfo from LLVM's .so when asked to do so
1 parent a4bded4 commit 388d0eb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/bootstrap/llvm.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,29 @@ impl Step for Llvm {
515515
}
516516
}
517517

518+
// When building LLVM as a shared library on linux, it can contain debuginfo even when
519+
// `llvm.release-debuginfo` is false: some debuginfo can come from the C++ standard library.
520+
// If we're asked to do so, strip this debuginfo away.
521+
if builder.llvm_link_shared()
522+
&& target.contains("linux")
523+
&& builder.config.llvm_strip_debuginfo
524+
{
525+
// Find the name of the LLVM shared library that we just built.
526+
let lib_name = find_llvm_lib_name("so");
527+
528+
// If the shared library exists in LLVM's `/build/lib/` or `/lib/` folders, strip its
529+
// debuginfo. Note: `output` will propagate any errors here.
530+
let strip_if_possible = |path: PathBuf| {
531+
if path.exists() {
532+
let mut cmd = Command::new("strip");
533+
cmd.arg("--strip-debug").arg(path);
534+
output(&mut cmd);
535+
}
536+
};
537+
strip_if_possible(out_dir.join("lib").join(&lib_name));
538+
strip_if_possible(out_dir.join("build").join("lib").join(&lib_name));
539+
}
540+
518541
t!(stamp.write());
519542

520543
res

0 commit comments

Comments
 (0)