Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit DW_AT_linkage_name when it is the same as DW_AT_name #72620

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use rustc_hir::def::CtorKind;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::ich::NodeIdHashingMode;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::interpret::truncate;
use rustc_middle::mir::{self, Field, GeneratorLayout};
use rustc_middle::ty::layout::{self, IntegerExt, PrimitiveExt, TyAndLayout};
Expand Down Expand Up @@ -2299,9 +2298,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
}

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

let no_mangle = attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE);
// We may want to remove the namespace scope if we're in an extern block (see
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
let var_scope = get_namespace_for_item(cx, def_id);
Expand All @@ -2318,14 +2315,11 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
let variable_type = Instance::mono(cx.tcx, def_id).monomorphic_ty(cx.tcx);
let type_metadata = type_metadata(cx, variable_type, span);
let var_name = tcx.item_name(def_id).as_str();
let linkage_name = if no_mangle {
None
} else {
Some(mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name.as_str())
};
let linkage_name: &str =
&mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name.as_str();
// When empty, linkage_name field is omitted,
// which is what we want for no_mangle statics
let linkage_name = linkage_name.as_deref().unwrap_or("");
let linkage_name = if var_name == linkage_name { "" } else { linkage_name };

let global_align = cx.align_of(variable_type);

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let substs = instance.substs.truncate_to(self.tcx(), generics);
let template_parameters = get_template_parameters(self, &generics, substs, &mut name);

// Get the linkage_name, which is just the symbol name
let linkage_name = mangled_name_of_instance(self, instance);
let linkage_name = linkage_name.name.as_str();
let linkage_name: &str = &mangled_name_of_instance(self, instance).name.as_str();
// Omit the linkage_name if it is the same as subprogram name.
let linkage_name = if &name == linkage_name { "" } else { linkage_name };

// FIXME(eddyb) does this need to be separate from `loc.line` for some reason?
let scope_line = loc.line;
Expand Down
42 changes: 42 additions & 0 deletions src/test/codegen/debug-linkage-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Verifies that linkage name is omitted when it is
// the same as variable / function name.
//
// compile-flags: -C no-prepopulate-passes
// compile-flags: -C debuginfo=2
#![crate_type = "lib"]

pub mod xyz {
// CHECK: !DIGlobalVariable(name: "A",
// CHECK: linkageName:
// CHECK-SAME: line: 12,
pub static A: u32 = 1;

// CHECK: !DIGlobalVariable(name: "B",
// CHECK-NOT: linkageName:
// CHECK-SAME: line: 18,
#[no_mangle]
pub static B: u32 = 2;

// CHECK: !DIGlobalVariable(name: "C",
// CHECK-NOT: linkageName:
// CHECK-SAME: line: 24,
#[export_name = "C"]
pub static C: u32 = 2;

// CHECK: !DISubprogram(name: "e",
// CHECK: linkageName:
// CHECK-SAME: line: 29,
pub extern fn e() {}

// CHECK: !DISubprogram(name: "f",
// CHECK-NOT: linkageName:
// CHECK-SAME: line: 35,
#[no_mangle]
pub extern fn f() {}

// CHECK: !DISubprogram(name: "g",
// CHECK-NOT: linkageName:
// CHECK-SAME: line: 41,
#[export_name = "g"]
pub extern fn g() {}
}