Skip to content

Commit 1980242

Browse files
authored
Rollup merge of #69080 - eddyb:one-billion-dwarves-walk-into-a-bar, r=michaelwoerister
rustc_codegen_llvm: don't generate any type debuginfo for -Cdebuginfo=1. Works towards #69074 by adding more checks for `DebugInfo::Full` in a few places in `rustc_codegen_llvm`, bringing us in line with what `clang -g1` generates (no debuginfo types, nor debuginfo for `static`s). <hr/> My local build's (`debuginfo-level=1`, `debug-assertions=1`) `librustc_driver-*.so` went from just over 1GiB (1019MiB) down to 402MiB. It's still bad, but the `.debug_*` sections themselves (as reported by `objdump`) went from something like 853MiB down to 236MiB, i.e. roughly a 3.6x reduction. <hr/> Sadly, I don't think this is enough to justify *shipping* all of this debuginfo, but now it's more plausible that we could at least *build* with `debuginfo-level=1` *then* strip it. That would give us real backtraces for e.g. ICEs during builds, but I don't know how often that's relevant. We could also look into split DWARF, and maybe have a `rustc-debuginfo` component in `rustup`. There's also the possibility of making it slimmer by omitting parameters to functions, or perhaps some deduplication (I think right now there is no DWARF reuse across CGUs? maybe ThinLTO helps?). r? @michaelwoerister cc @rust-lang/wg-codegen @alexcrichton @Mark-Simulacrum
2 parents 8ff7850 + b5e78a2 commit 1980242

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use super::metadata::{file_metadata, UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
22
use super::utils::DIB;
33
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
4+
use rustc_codegen_ssa::traits::*;
45

56
use crate::common::CodegenCx;
67
use crate::llvm;
78
use crate::llvm::debuginfo::{DIScope, DISubprogram};
89
use rustc::mir::{Body, SourceScope};
10+
use rustc_session::config::DebugInfo;
911

1012
use rustc_index::bit_set::BitSet;
1113
use rustc_index::vec::Idx;
@@ -19,10 +21,17 @@ pub fn compute_mir_scopes(
1921
) {
2022
// Find all the scopes with variables defined in them.
2123
let mut has_variables = BitSet::new_empty(mir.source_scopes.len());
22-
// FIXME(eddyb) take into account that arguments always have debuginfo,
23-
// irrespective of their name (assuming full debuginfo is enabled).
24-
for var_debug_info in &mir.var_debug_info {
25-
has_variables.insert(var_debug_info.source_info.scope);
24+
25+
// Only consider variables when they're going to be emitted.
26+
// FIXME(eddyb) don't even allocate `has_variables` otherwise.
27+
if cx.sess().opts.debuginfo == DebugInfo::Full {
28+
// FIXME(eddyb) take into account that arguments always have debuginfo,
29+
// irrespective of their name (assuming full debuginfo is enabled).
30+
// NOTE(eddyb) actually, on second thought, those are always in the
31+
// function scope, which always exists.
32+
for var_debug_info in &mir.var_debug_info {
33+
has_variables.insert(var_debug_info.source_info.scope);
34+
}
2635
}
2736

2837
// Instantiate all scopes.

src/librustc_codegen_llvm/debuginfo/metadata.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,11 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
22992299
return;
23002300
}
23012301

2302+
// Only create type information if full debuginfo is enabled
2303+
if cx.sess().opts.debuginfo != DebugInfo::Full {
2304+
return;
2305+
}
2306+
23022307
let tcx = cx.tcx;
23032308
let attrs = tcx.codegen_fn_attrs(def_id);
23042309

@@ -2358,6 +2363,11 @@ pub fn create_vtable_metadata(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, vtable: &
23582363
return;
23592364
}
23602365

2366+
// Only create type information if full debuginfo is enabled
2367+
if cx.sess().opts.debuginfo != DebugInfo::Full {
2368+
return;
2369+
}
2370+
23612371
let type_metadata = type_metadata(cx, ty, rustc_span::DUMMY_SP);
23622372

23632373
unsafe {

src/librustc_codegen_llvm/debuginfo/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,12 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
475475
// so avoid methods on other types (e.g., `<*mut T>::null`).
476476
match impl_self_ty.kind {
477477
ty::Adt(def, ..) if !def.is_box() => {
478-
Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP))
478+
// Again, only create type information if full debuginfo is enabled
479+
if cx.sess().opts.debuginfo == DebugInfo::Full {
480+
Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP))
481+
} else {
482+
Some(namespace::item_namespace(cx, def.did))
483+
}
479484
}
480485
_ => None,
481486
}

src/librustc_llvm/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ fn main() {
151151

152152
if env::var_os("LLVM_NDEBUG").is_some() {
153153
cfg.define("NDEBUG", None);
154+
cfg.debug(false);
154155
}
155156

156157
build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm"));

0 commit comments

Comments
 (0)