Skip to content

Commit 891061a

Browse files
Michael137github-actions[bot]
authored andcommitted
Automerge: [llvm][DebugInfo] Support DW_AT_linkage_names that are different between declaration and definition (#154137)
This patch is motivated by llvm/llvm-project#149827, where we plan on using mangled names on structor declarations to find the exact structor definition that LLDB's expression evaluator should call. So far LLVM expects the declaration and definition linkage names to be identical (or the declaration to just not have a linkage name). But we plan on attaching the GCC-style "unified" mangled name to declarations, which will be different to linkage name on the definition. This patch relaxes this restriction.
2 parents 915c828 + c6286b3 commit 891061a

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,11 +1410,8 @@ bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,
14101410

14111411
// Add the linkage name if we have one and it isn't in the Decl.
14121412
StringRef LinkageName = SP->getLinkageName();
1413-
assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
1414-
LinkageName == DeclLinkageName) &&
1415-
"decl has a linkage name and it is different");
1416-
if (DeclLinkageName.empty() &&
1417-
// Always emit it for abstract subprograms.
1413+
// Always emit linkage name for abstract subprograms.
1414+
if (DeclLinkageName != LinkageName &&
14181415
(DD->useAllLinkageNames() || DU->getAbstractScopeDIEs().lookup(SP)))
14191416
addLinkageName(SPDie, LinkageName);
14201417

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump -debug-info - | FileCheck %s
2+
3+
; Make sure we attach DW_AT_linkage_name on function declarations but only
4+
; attach it on definitions if the value is different than on the declaration.
5+
6+
target triple = "arm64-apple-macosx"
7+
8+
define void @_Z11SameLinkagev() !dbg !4 {
9+
entry:
10+
ret void
11+
}
12+
13+
; CHECK: DW_AT_linkage_name ("_Z11SameLinkagev")
14+
; CHECK: DW_AT_declaration (true)
15+
; CHECK-NOT: DW_AT_linkage_name ("_Z11SameLinkagev")
16+
17+
define void @_Z11DiffLinkagev() !dbg !8 {
18+
entry:
19+
ret void
20+
}
21+
22+
; CHECK: DW_AT_linkage_name ("SomeName")
23+
; CHECK: DW_AT_declaration (true)
24+
; CHECK: DW_AT_linkage_name ("_Z11DiffLinkagev")
25+
26+
define void @_Z15EmptyDefLinkagev() !dbg !10 {
27+
entry:
28+
ret void
29+
}
30+
31+
; CHECK: DW_AT_linkage_name ("_Z15EmptyDefLinkagev")
32+
; CHECK: DW_AT_declaration (true)
33+
; CHECK-NOT: DW_AT_linkage_name
34+
35+
define void @_Z16EmptyDeclLinkagev() !dbg !12 {
36+
entry:
37+
ret void
38+
}
39+
40+
; CHECK: DW_AT_declaration (true)
41+
; CHECK: DW_AT_linkage_name ("_Z16EmptyDeclLinkagev")
42+
43+
define void @_Z13EmptyLinkagesv() !dbg !14 {
44+
entry:
45+
ret void
46+
}
47+
48+
; CHECK-NOT: DW_AT_linkage_name
49+
50+
!llvm.dbg.cu = !{!0}
51+
!llvm.module.flags = !{!2, !3}
52+
53+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
54+
!1 = !DIFile(filename: "foo.cpp", directory: "/tmp")
55+
!2 = !{i32 7, !"Dwarf Version", i32 5}
56+
!3 = !{i32 2, !"Debug Info Version", i32 3}
57+
!4 = distinct !DISubprogram(name: "SameLinkage", linkageName: "_Z11SameLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !7)
58+
!5 = !DISubroutineType(types: !6)
59+
!6 = !{null}
60+
!7 = !DISubprogram(name: "SameLinkage", linkageName: "_Z11SameLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0)
61+
!8 = distinct !DISubprogram(name: "DiffLinkage", linkageName: "_Z11DiffLinkagev", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !9)
62+
!9 = !DISubprogram(name: "DiffLinkage", linkageName: "SomeName", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0)
63+
!10 = distinct !DISubprogram(name: "EmptyDefLinkage", linkageName: "", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !11)
64+
!11 = !DISubprogram(name: "EmptyDefLinkage", linkageName: "_Z15EmptyDefLinkagev", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0)
65+
!12 = distinct !DISubprogram(name: "EmptyDeclLinkage", linkageName: "_Z16EmptyDeclLinkagev", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !13)
66+
!13 = !DISubprogram(name: "EmptyDeclLinkage", linkageName: "", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0)
67+
!14 = distinct !DISubprogram(name: "EmptyLinkages", linkageName: "", scope: !1, file: !1, line: 5, type: !5, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !15)
68+
!15 = !DISubprogram(name: "EmptyLinkages", linkageName: "", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0)

0 commit comments

Comments
 (0)