Skip to content

Commit cf1c38d

Browse files
committed
Strip debuginfo from rustc and rustdoc binaries
1 parent b998812 commit cf1c38d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1010,14 +1010,18 @@ impl Step for Rustc {
10101010
// our LLVM wrapper. Unless we're explicitly requesting `librustc_driver` to be built with
10111011
// debuginfo (via the debuginfo level of the executables using it): strip this debuginfo
10121012
// away after the fact.
1013+
let target_root_dir = stamp.parent().unwrap();
10131014
if builder.config.rust_debuginfo_level_rustc == DebuginfoLevel::None
10141015
&& builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None
10151016
{
1016-
let target_root_dir = stamp.parent().unwrap();
10171017
let rustc_driver = target_root_dir.join("librustc_driver.so");
10181018
strip_debug(builder, target, &rustc_driver);
10191019
}
10201020

1021+
// Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
1022+
// our final binaries
1023+
strip_debug(builder, target, &target_root_dir.join("rustc-main"));
1024+
10211025
builder.ensure(RustcLink::from_rustc(
10221026
self,
10231027
builder.compiler(compiler.stage, builder.config.build),
@@ -2291,7 +2295,14 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
22912295
}
22922296

22932297
let previous_mtime = t!(t!(path.metadata()).modified());
2294-
command("strip").arg("--strip-debug").arg(path).run_capture(builder);
2298+
let result = command("strip").arg("--strip-debug").arg(path).run_capture(builder);
2299+
if result.is_failure() {
2300+
eprintln!(
2301+
"warning: `strip --strip-debug {}` failed: `{}`",
2302+
path.display(),
2303+
result.stderr()
2304+
);
2305+
}
22952306

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

src/bootstrap/src/core/build_steps/tool.rs

+3
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ impl Step for Rustdoc {
671671

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

0 commit comments

Comments
 (0)