Skip to content

Commit c89bb15

Browse files
authored
Rollup merge of #107373 - michaelwoerister:dont-merge-vtables-when-debuginfo, r=WaffleLapkin
Don't merge vtables when full debuginfo is enabled. This PR makes the compiler not emit the `unnamed_addr` attribute for vtables when full debuginfo is enabled, so that they don't get merged even if they have the same contents. This allows debuggers to more reliably map from a dyn pointer to the self-type of a trait object by looking at the vtable's debuginfo. The PR only changes the behavior of the LLVM backend as other backends don't emit vtable debuginfo (as far as I can tell). The performance impact of this change should be small as [measured](#103514 (comment)) in a previous PR.
2 parents ab769a0 + e5995e6 commit c89bb15

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,11 @@ pub fn create_vtable_di_node<'ll, 'tcx>(
14991499
return;
15001500
}
15011501

1502+
// When full debuginfo is enabled, we want to try and prevent vtables from being
1503+
// merged. Otherwise debuggers will have a hard time mapping from dyn pointer
1504+
// to concrete type.
1505+
llvm::SetUnnamedAddress(vtable, llvm::UnnamedAddr::No);
1506+
15021507
let vtable_name =
15031508
compute_debuginfo_vtable_name(cx.tcx, ty, poly_trait_ref, VTableNameKind::GlobalVariable);
15041509
let vtable_type_di_node = build_vtable_type_di_node(cx, ty, poly_trait_ref);

tests/codegen/debug-vtable.rs

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
// compile-flags: -Cdebuginfo=2 -Copt-level=0 -Csymbol-mangling-version=v0
1010
// ignore-tidy-linelength
1111

12+
// Make sure that vtables don't have the unnamed_addr attribute when debuginfo is enabled.
13+
// This helps debuggers more reliably map from dyn pointer to concrete type.
14+
// CHECK: @vtable.0 = private constant <{
15+
// CHECK: @vtable.1 = private constant <{
16+
// CHECK: @vtable.2 = private constant <{
17+
// CHECK: @vtable.3 = private constant <{
18+
// CHECK: @vtable.4 = private constant <{
19+
1220
// NONMSVC: ![[USIZE:[0-9]+]] = !DIBasicType(name: "usize"
1321
// MSVC: ![[USIZE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_typedef, name: "usize"
1422
// NONMSVC: ![[PTR:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const ()"

0 commit comments

Comments
 (0)