Skip to content

Commit 1b112c8

Browse files
committed
PR37255: DebugInfo: LTO with -g inlined into -gmlt combined with Split DWARF without CU cross-references
A combination of features ^ that lead to a mismatch of expectations about how a subprogram definition DIE would be produced with/without a declaration when taking full -g debug info and inlining it into a -gmlt CU - specifically when using Split DWARF that doesn't support cross-CU references, so we have to put the -g debug info into the -gmlt CU, which gets confusing about which mode is respected. This patch comes down on respecting the CU the debug info is emitted into, rather than preserving the full debug info when it's emitted into the gmlt CU.
1 parent 4c92e31 commit 1b112c8

File tree

3 files changed

+107
-25
lines changed

3 files changed

+107
-25
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,32 +1130,34 @@ DIE *DwarfUnit::getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal) {
11301130
}
11311131

11321132
bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,
1133-
DIE &SPDie) {
1133+
DIE &SPDie, bool Minimal) {
11341134
DIE *DeclDie = nullptr;
11351135
StringRef DeclLinkageName;
11361136
if (auto *SPDecl = SP->getDeclaration()) {
1137-
DITypeRefArray DeclArgs, DefinitionArgs;
1138-
DeclArgs = SPDecl->getType()->getTypeArray();
1139-
DefinitionArgs = SP->getType()->getTypeArray();
1140-
1141-
if (DeclArgs.size() && DefinitionArgs.size())
1142-
if (DefinitionArgs[0] != NULL && DeclArgs[0] != DefinitionArgs[0])
1143-
addType(SPDie, DefinitionArgs[0]);
1144-
1145-
DeclDie = getDIE(SPDecl);
1146-
assert(DeclDie && "This DIE should've already been constructed when the "
1147-
"definition DIE was created in "
1148-
"getOrCreateSubprogramDIE");
1149-
// Look at the Decl's linkage name only if we emitted it.
1150-
if (DD->useAllLinkageNames())
1151-
DeclLinkageName = SPDecl->getLinkageName();
1152-
unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());
1153-
unsigned DefID = getOrCreateSourceID(SP->getFile());
1154-
if (DeclID != DefID)
1155-
addUInt(SPDie, dwarf::DW_AT_decl_file, None, DefID);
1156-
1157-
if (SP->getLine() != SPDecl->getLine())
1158-
addUInt(SPDie, dwarf::DW_AT_decl_line, None, SP->getLine());
1137+
if (!Minimal) {
1138+
DITypeRefArray DeclArgs, DefinitionArgs;
1139+
DeclArgs = SPDecl->getType()->getTypeArray();
1140+
DefinitionArgs = SP->getType()->getTypeArray();
1141+
1142+
if (DeclArgs.size() && DefinitionArgs.size())
1143+
if (DefinitionArgs[0] != NULL && DeclArgs[0] != DefinitionArgs[0])
1144+
addType(SPDie, DefinitionArgs[0]);
1145+
1146+
DeclDie = getDIE(SPDecl);
1147+
assert(DeclDie && "This DIE should've already been constructed when the "
1148+
"definition DIE was created in "
1149+
"getOrCreateSubprogramDIE");
1150+
// Look at the Decl's linkage name only if we emitted it.
1151+
if (DD->useAllLinkageNames())
1152+
DeclLinkageName = SPDecl->getLinkageName();
1153+
unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());
1154+
unsigned DefID = getOrCreateSourceID(SP->getFile());
1155+
if (DeclID != DefID)
1156+
addUInt(SPDie, dwarf::DW_AT_decl_file, None, DefID);
1157+
1158+
if (SP->getLine() != SPDecl->getLine())
1159+
addUInt(SPDie, dwarf::DW_AT_decl_line, None, SP->getLine());
1160+
}
11591161
}
11601162

11611163
// Add function template parameters.
@@ -1187,7 +1189,7 @@ void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
11871189
bool SkipSPSourceLocation = SkipSPAttributes &&
11881190
!CUNode->getDebugInfoForProfiling();
11891191
if (!SkipSPSourceLocation)
1190-
if (applySubprogramDefinitionAttributes(SP, SPDie))
1192+
if (applySubprogramDefinitionAttributes(SP, SPDie, SkipSPAttributes))
11911193
return;
11921194

11931195
// Constructors and operators for anonymous aggregates do not have names.

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class DwarfUnit : public DIEUnit {
7373
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW,
7474
DwarfFile *DWU);
7575

76-
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie);
76+
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie, bool Minimal);
7777

7878
bool isShareableAcrossCUs(const DINode *D) const;
7979

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
; RUN: llc -mtriple=x86_64-linux -split-dwarf-file=foo.dwo -filetype=obj -o %t < %s
2+
; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
3+
4+
; CHECK: DW_AT_name ("b.cpp")
5+
; CHECK: DW_TAG_subprogram
6+
; CHECK-NEXT: DW_AT_linkage_name ("_ZN5outer2f2Ev")
7+
; CHECK-NEXT: DW_AT_name ("f2")
8+
; CHECK-NEXT: DW_AT_decl_file (0x02)
9+
; CHECK-NEXT: DW_AT_decl_line (4)
10+
11+
; Function Attrs: noinline nounwind optnone uwtable mustprogress
12+
define dso_local void @_Z2f1v() local_unnamed_addr #0 !dbg !12 {
13+
entry:
14+
ret void, !dbg !15
15+
}
16+
17+
; Function Attrs: nounwind uwtable mustprogress
18+
define dso_local void @_ZN5outer2f2Ev() local_unnamed_addr #1 align 2 !dbg !16 {
19+
entry:
20+
tail call void @_Z2f1v(), !dbg !21
21+
ret void, !dbg !22
22+
}
23+
24+
; Function Attrs: nounwind uwtable mustprogress
25+
define dso_local void @_Z2f2v() local_unnamed_addr #1 !dbg !23 {
26+
entry:
27+
tail call void @_Z2f1v(), !dbg !24
28+
ret void, !dbg !25
29+
}
30+
31+
; Function Attrs: norecurse nounwind uwtable mustprogress
32+
define dso_local i32 @main() local_unnamed_addr #2 !dbg !26 {
33+
entry:
34+
tail call void @_Z2f1v() #3, !dbg !28
35+
tail call void @_Z2f1v() #3, !dbg !30
36+
ret i32 0, !dbg !32
37+
}
38+
39+
attributes #0 = { noinline nounwind optnone uwtable mustprogress "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
40+
attributes #1 = { nounwind uwtable mustprogress "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
41+
attributes #2 = { norecurse nounwind uwtable mustprogress "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
42+
attributes #3 = { nounwind }
43+
44+
!llvm.dbg.cu = !{!0, !3}
45+
!llvm.ident = !{!5, !5}
46+
!llvm.module.flags = !{!6, !7, !8, !9, !10, !11}
47+
48+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0 ([email protected]:llvm/llvm-project.git 9aa951e80e72decd95c7d972e1e0dde24260d336)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
49+
!1 = !DIFile(filename: "a.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
50+
!2 = !{}
51+
!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !4, producer: "clang version 13.0.0 ([email protected]:llvm/llvm-project.git 9aa951e80e72decd95c7d972e1e0dde24260d336)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
52+
!4 = !DIFile(filename: "b.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
53+
!5 = !{!"clang version 13.0.0 ([email protected]:llvm/llvm-project.git 9aa951e80e72decd95c7d972e1e0dde24260d336)"}
54+
!6 = !{i32 7, !"Dwarf Version", i32 4}
55+
!7 = !{i32 2, !"Debug Info Version", i32 3}
56+
!8 = !{i32 1, !"wchar_size", i32 4}
57+
!9 = !{i32 7, !"uwtable", i32 1}
58+
!10 = !{i32 1, !"ThinLTO", i32 0}
59+
!11 = !{i32 1, !"EnableSplitLTOUnit", i32 1}
60+
!12 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !1, file: !1, line: 2, type: !13, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
61+
!13 = !DISubroutineType(types: !14)
62+
!14 = !{null}
63+
!15 = !DILocation(line: 3, column: 1, scope: !12)
64+
!16 = distinct !DISubprogram(name: "f2", linkageName: "_ZN5outer2f2Ev", scope: !17, file: !1, line: 4, type: !13, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !20, retainedNodes: !2)
65+
!17 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "outer", file: !18, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !19, identifier: "_ZTS5outer")
66+
!18 = !DIFile(filename: "./a.h", directory: "/usr/local/google/home/blaikie/dev/scratch")
67+
!19 = !{!20}
68+
!20 = !DISubprogram(name: "f2", linkageName: "_ZN5outer2f2Ev", scope: !17, file: !18, line: 2, type: !13, scopeLine: 2, flags: DIFlagPrototyped | DIFlagStaticMember, spFlags: DISPFlagOptimized)
69+
!21 = !DILocation(line: 5, column: 3, scope: !16)
70+
!22 = !DILocation(line: 6, column: 1, scope: !16)
71+
!23 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 7, type: !13, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
72+
!24 = !DILocation(line: 8, column: 3, scope: !23)
73+
!25 = !DILocation(line: 9, column: 1, scope: !23)
74+
!26 = distinct !DISubprogram(name: "main", scope: !4, file: !4, line: 2, type: !27, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3, retainedNodes: !2)
75+
!27 = !DISubroutineType(types: !2)
76+
!28 = !DILocation(line: 5, column: 3, scope: !16, inlinedAt: !29)
77+
!29 = distinct !DILocation(line: 3, column: 3, scope: !26)
78+
!30 = !DILocation(line: 8, column: 3, scope: !23, inlinedAt: !31)
79+
!31 = distinct !DILocation(line: 4, column: 3, scope: !26)
80+
!32 = !DILocation(line: 5, column: 1, scope: !26)

0 commit comments

Comments
 (0)