Skip to content

Commit 4d3d96a

Browse files
committed
strip debuginfo from librustc_driver.so when applicable, on x64 linux
1 parent 67263d0 commit 4d3d96a

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/bootstrap/compile.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::builder::crate_description;
2323
use crate::builder::Cargo;
2424
use crate::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
2525
use crate::cache::{Interned, INTERNER};
26-
use crate::config::{LlvmLibunwind, RustcLto, TargetSelection};
26+
use crate::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
2727
use crate::dist;
2828
use crate::llvm;
2929
use crate::tool::SourceType;
@@ -883,16 +883,39 @@ impl Step for Rustc {
883883
compiler.host,
884884
target,
885885
);
886+
let stamp = librustc_stamp(builder, compiler, target);
886887
run_cargo(
887888
builder,
888889
cargo,
889890
vec![],
890-
&librustc_stamp(builder, compiler, target),
891+
&stamp,
891892
vec![],
892893
false,
893894
true, // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files.
894895
);
895896

897+
// When building `librustc_driver.so` (like `libLLVM.so`) on linux, it can contain
898+
// unexpected debuginfo from dependencies, for example from the C++ standard library used in
899+
// our LLVM wrapper. Unless we're explicitly requesting `librustc_driver` to be built with
900+
// debuginfo (via the debuginfo level of the executables using it): strip this debuginfo
901+
// away after the fact. This is to make the distributed artifacts smaller, and therefore we
902+
// only do this at stage >= 1.
903+
// FIXME: to make things simpler for now, limit this to the host and target where we know
904+
// `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
905+
// cross-compiling. Expand this to other appropriate targets in the future.
906+
if compiler.stage != 0
907+
&& builder.config.rust_debuginfo_level_rustc == DebuginfoLevel::None
908+
&& builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None
909+
&& target == "x86_64-unknown-linux-gnu"
910+
&& target == builder.config.build
911+
{
912+
let target_root_dir = stamp.parent().unwrap();
913+
let rustc_driver = target_root_dir.join("librustc_driver.so");
914+
if rustc_driver.exists() {
915+
output(Command::new("strip").arg("--strip-debug").arg(rustc_driver));
916+
}
917+
}
918+
896919
builder.ensure(RustcLink::from_rustc(
897920
self,
898921
builder.compiler(compiler.stage, builder.config.build),

0 commit comments

Comments
 (0)