Skip to content

Commit

Permalink
Rollup merge of #69080 - eddyb:one-billion-dwarves-walk-into-a-bar, r…
Browse files Browse the repository at this point in the history
…=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
  • Loading branch information
Centril authored Mar 23, 2020
2 parents 8ff7850 + b5e78a2 commit 1980242
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use super::metadata::{file_metadata, UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
use super::utils::DIB;
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
use rustc_codegen_ssa::traits::*;

use crate::common::CodegenCx;
use crate::llvm;
use crate::llvm::debuginfo::{DIScope, DISubprogram};
use rustc::mir::{Body, SourceScope};
use rustc_session::config::DebugInfo;

use rustc_index::bit_set::BitSet;
use rustc_index::vec::Idx;
Expand All @@ -19,10 +21,17 @@ pub fn compute_mir_scopes(
) {
// Find all the scopes with variables defined in them.
let mut has_variables = BitSet::new_empty(mir.source_scopes.len());
// FIXME(eddyb) take into account that arguments always have debuginfo,
// irrespective of their name (assuming full debuginfo is enabled).
for var_debug_info in &mir.var_debug_info {
has_variables.insert(var_debug_info.source_info.scope);

// Only consider variables when they're going to be emitted.
// FIXME(eddyb) don't even allocate `has_variables` otherwise.
if cx.sess().opts.debuginfo == DebugInfo::Full {
// FIXME(eddyb) take into account that arguments always have debuginfo,
// irrespective of their name (assuming full debuginfo is enabled).
// NOTE(eddyb) actually, on second thought, those are always in the
// function scope, which always exists.
for var_debug_info in &mir.var_debug_info {
has_variables.insert(var_debug_info.source_info.scope);
}
}

// Instantiate all scopes.
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,11 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
return;
}

// Only create type information if full debuginfo is enabled
if cx.sess().opts.debuginfo != DebugInfo::Full {
return;
}

let tcx = cx.tcx;
let attrs = tcx.codegen_fn_attrs(def_id);

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

// Only create type information if full debuginfo is enabled
if cx.sess().opts.debuginfo != DebugInfo::Full {
return;
}

let type_metadata = type_metadata(cx, ty, rustc_span::DUMMY_SP);

unsafe {
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,12 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
// so avoid methods on other types (e.g., `<*mut T>::null`).
match impl_self_ty.kind {
ty::Adt(def, ..) if !def.is_box() => {
Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP))
// Again, only create type information if full debuginfo is enabled
if cx.sess().opts.debuginfo == DebugInfo::Full {
Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP))
} else {
Some(namespace::item_namespace(cx, def.did))
}
}
_ => None,
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ fn main() {

if env::var_os("LLVM_NDEBUG").is_some() {
cfg.define("NDEBUG", None);
cfg.debug(false);
}

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

0 comments on commit 1980242

Please sign in to comment.