Skip to content

Commit

Permalink
strip debuginfo from librustc_driver.so when applicable, on x64 linux
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Jul 31, 2023
1 parent 67263d0 commit 4d3d96a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::builder::crate_description;
use crate::builder::Cargo;
use crate::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
use crate::cache::{Interned, INTERNER};
use crate::config::{LlvmLibunwind, RustcLto, TargetSelection};
use crate::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
use crate::dist;
use crate::llvm;
use crate::tool::SourceType;
Expand Down Expand Up @@ -883,16 +883,39 @@ impl Step for Rustc {
compiler.host,
target,
);
let stamp = librustc_stamp(builder, compiler, target);
run_cargo(
builder,
cargo,
vec![],
&librustc_stamp(builder, compiler, target),
&stamp,
vec![],
false,
true, // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files.
);

// When building `librustc_driver.so` (like `libLLVM.so`) on linux, it can contain
// unexpected debuginfo from dependencies, for example from the C++ standard library used in
// our LLVM wrapper. Unless we're explicitly requesting `librustc_driver` to be built with
// debuginfo (via the debuginfo level of the executables using it): strip this debuginfo
// away after the fact. This is to make the distributed artifacts smaller, and therefore we
// only do this at stage >= 1.
// 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 compiler.stage != 0
&& builder.config.rust_debuginfo_level_rustc == DebuginfoLevel::None
&& builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None
&& target == "x86_64-unknown-linux-gnu"
&& target == builder.config.build
{
let target_root_dir = stamp.parent().unwrap();
let rustc_driver = target_root_dir.join("librustc_driver.so");
if rustc_driver.exists() {
output(Command::new("strip").arg("--strip-debug").arg(rustc_driver));
}
}

builder.ensure(RustcLink::from_rustc(
self,
builder.compiler(compiler.stage, builder.config.build),
Expand Down

0 comments on commit 4d3d96a

Please sign in to comment.