Skip to content

Commit

Permalink
Strip debuginfo from rustc and rustdoc binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Dec 26, 2024
1 parent b998812 commit cf1c38d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,14 +1010,18 @@ impl Step for Rustc {
// 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.
let target_root_dir = stamp.parent().unwrap();
if builder.config.rust_debuginfo_level_rustc == DebuginfoLevel::None
&& builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None
{
let target_root_dir = stamp.parent().unwrap();
let rustc_driver = target_root_dir.join("librustc_driver.so");
strip_debug(builder, target, &rustc_driver);
}

// Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
// our final binaries
strip_debug(builder, target, &target_root_dir.join("rustc-main"));

builder.ensure(RustcLink::from_rustc(
self,
builder.compiler(compiler.stage, builder.config.build),
Expand Down Expand Up @@ -2291,7 +2295,14 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
}

let previous_mtime = t!(t!(path.metadata()).modified());
command("strip").arg("--strip-debug").arg(path).run_capture(builder);
let result = command("strip").arg("--strip-debug").arg(path).run_capture(builder);
if result.is_failure() {
eprintln!(
"warning: `strip --strip-debug {}` failed: `{}`",
path.display(),
result.stderr()
);
}

let file = t!(fs::File::open(path));

Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ impl Step for Rustdoc {

// don't create a stage0-sysroot/bin directory.
if target_compiler.stage > 0 {
// Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
// our final binaries
compile::strip_debug(builder, target, &tool_rustdoc);
let bin_rustdoc = bin_rustdoc();
builder.copy_link(&tool_rustdoc, &bin_rustdoc);
bin_rustdoc
Expand Down

0 comments on commit cf1c38d

Please sign in to comment.