Skip to content

Commit 62641a7

Browse files
committed
[llvm][DebugInfo] Support DW_AT_linkage_names that are different between declaration and definition
1 parent c68b4d6 commit 62641a7

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
@@ -1403,11 +1403,8 @@ bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,
14031403

14041404
// Add the linkage name if we have one and it isn't in the Decl.
14051405
StringRef LinkageName = SP->getLinkageName();
1406-
assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
1407-
LinkageName == DeclLinkageName) &&
1408-
"decl has a linkage name and it is different");
1409-
if (DeclLinkageName.empty() &&
1410-
// Always emit it for abstract subprograms.
1406+
// Always emit linkage name for abstract subprograms.
1407+
if (DeclLinkageName != LinkageName &&
14111408
(DD->useAllLinkageNames() || DU->getAbstractScopeDIEs().lookup(SP)))
14121409
addLinkageName(SPDie, LinkageName);
14131410

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)