Skip to content

Commit

Permalink
Don't merge vtables when full debuginfo is enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Jan 27, 2023
1 parent 6874f4e commit e5995e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,11 @@ pub fn create_vtable_di_node<'ll, 'tcx>(
return;
}

// When full debuginfo is enabled, we want to try and prevent vtables from being
// merged. Otherwise debuggers will have a hard time mapping from dyn pointer
// to concrete type.
llvm::SetUnnamedAddress(vtable, llvm::UnnamedAddr::No);

let vtable_name =
compute_debuginfo_vtable_name(cx.tcx, ty, poly_trait_ref, VTableNameKind::GlobalVariable);
let vtable_type_di_node = build_vtable_type_di_node(cx, ty, poly_trait_ref);
Expand Down
8 changes: 8 additions & 0 deletions tests/codegen/debug-vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
// compile-flags: -Cdebuginfo=2 -Copt-level=0 -Csymbol-mangling-version=v0
// ignore-tidy-linelength

// Make sure that vtables don't have the unnamed_addr attribute when debuginfo is enabled.
// This helps debuggers more reliably map from dyn pointer to concrete type.
// CHECK: @vtable.0 = private constant <{
// CHECK: @vtable.1 = private constant <{
// CHECK: @vtable.2 = private constant <{
// CHECK: @vtable.3 = private constant <{
// CHECK: @vtable.4 = private constant <{

// NONMSVC: ![[USIZE:[0-9]+]] = !DIBasicType(name: "usize"
// MSVC: ![[USIZE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_typedef, name: "usize"
// NONMSVC: ![[PTR:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const ()"
Expand Down

0 comments on commit e5995e6

Please sign in to comment.