Skip to content

Commit 14dc103

Browse files
authored
Rollup merge of #72620 - tmiasko:linkage-name, r=eddyb
Omit DW_AT_linkage_name when it is the same as DW_AT_name The DWARF standard suggests that it might be useful to include `DW_AT_linkage_name` when it is *distinct* from the identifier name. Fixes #46487. Fixes #59422.
2 parents e093b65 + e4b7d2c commit 14dc103

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_hir::def::CtorKind;
2929
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
3030
use rustc_index::vec::{Idx, IndexVec};
3131
use rustc_middle::ich::NodeIdHashingMode;
32-
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
3332
use rustc_middle::mir::interpret::truncate;
3433
use rustc_middle::mir::{self, Field, GeneratorLayout};
3534
use rustc_middle::ty::layout::{self, IntegerExt, PrimitiveExt, TyAndLayout};
@@ -2382,9 +2381,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
23822381
}
23832382

23842383
let tcx = cx.tcx;
2385-
let attrs = tcx.codegen_fn_attrs(def_id);
23862384

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

24132407
let global_align = cx.align_of(variable_type);
24142408

src/librustc_codegen_llvm/debuginfo/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
267267
let substs = instance.substs.truncate_to(self.tcx(), generics);
268268
let template_parameters = get_template_parameters(self, &generics, substs, &mut name);
269269

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

274274
// FIXME(eddyb) does this need to be separate from `loc.line` for some reason?
275275
let scope_line = loc.line;
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Verifies that linkage name is omitted when it is
2+
// the same as variable / function name.
3+
//
4+
// compile-flags: -C no-prepopulate-passes
5+
// compile-flags: -C debuginfo=2
6+
#![crate_type = "lib"]
7+
8+
pub mod xyz {
9+
// CHECK: !DIGlobalVariable(name: "A",
10+
// CHECK: linkageName:
11+
// CHECK-SAME: line: 12,
12+
pub static A: u32 = 1;
13+
14+
// CHECK: !DIGlobalVariable(name: "B",
15+
// CHECK-NOT: linkageName:
16+
// CHECK-SAME: line: 18,
17+
#[no_mangle]
18+
pub static B: u32 = 2;
19+
20+
// CHECK: !DIGlobalVariable(name: "C",
21+
// CHECK-NOT: linkageName:
22+
// CHECK-SAME: line: 24,
23+
#[export_name = "C"]
24+
pub static C: u32 = 2;
25+
26+
// CHECK: !DISubprogram(name: "e",
27+
// CHECK: linkageName:
28+
// CHECK-SAME: line: 29,
29+
pub extern fn e() {}
30+
31+
// CHECK: !DISubprogram(name: "f",
32+
// CHECK-NOT: linkageName:
33+
// CHECK-SAME: line: 35,
34+
#[no_mangle]
35+
pub extern fn f() {}
36+
37+
// CHECK: !DISubprogram(name: "g",
38+
// CHECK-NOT: linkageName:
39+
// CHECK-SAME: line: 41,
40+
#[export_name = "g"]
41+
pub extern fn g() {}
42+
}

0 commit comments

Comments
 (0)