Skip to content

Commit 62d0845

Browse files
committed
strip debuginfo from LLVM's .so when applicable, on x64 linux
1 parent ae8b721 commit 62d0845

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/bootstrap/llvm.rs

+26
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,32 @@ impl Step for Llvm {
515515
}
516516
}
517517

518+
// When building LLVM as a shared library on linux, it can contain unexpected debuginfo:
519+
// some can come from the C++ standard library. Unless we're explicitly requesting LLVM to
520+
// be built with debuginfo, strip it away after the fact, to make dist artifacts smaller.
521+
// FIXME: to make things simpler for now, limit this to the host and target where we know
522+
// `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
523+
// cross-compiling. Expand this to other appropriate targets in the future.
524+
if builder.llvm_link_shared()
525+
&& builder.config.llvm_optimize
526+
&& !builder.config.llvm_release_debuginfo
527+
&& target == "x86_64-unknown-linux-gnu"
528+
&& target == builder.config.build
529+
{
530+
// Find the name of the LLVM shared library that we just built.
531+
let lib_name = find_llvm_lib_name("so");
532+
533+
// If the shared library exists in LLVM's `/build/lib/` or `/lib/` folders, strip its
534+
// debuginfo. Note: `output` will propagate any errors here.
535+
let strip_if_possible = |path: PathBuf| {
536+
if path.exists() {
537+
output(Command::new("strip").arg("--strip-debug").arg(path));
538+
}
539+
};
540+
strip_if_possible(out_dir.join("lib").join(&lib_name));
541+
strip_if_possible(out_dir.join("build").join("lib").join(&lib_name));
542+
}
543+
518544
t!(stamp.write());
519545

520546
res

0 commit comments

Comments
 (0)