llvm.org GIT mirror llvm / 2bb2fc9
[DWARF] Force a linkage_name on an inlined subprogram's abstract origin. When we suppress linkage names, for a non-inlined subprogram the name can still be found in the object-file symbol table, because we have the code address of the subprogram. This is not necessarily the case for an inlined subprogram, so we still want to emit the linkage name in the DWARF. Put this on the abstract-origin DIE because it's common to all inlined instances. Differential Revision: http://reviews.llvm.org/D18706 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266692 91177308-0d34-0410-b5e6-96231b3b80d8 Paul Robinson 4 years ago
12 changed file(s) with 112 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
184184 }
185185
186186 addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
187 addLinkageName(*VariableDIE, GV->getLinkageName());
187 if (DD->useAllLinkageNames())
188 addLinkageName(*VariableDIE, GV->getLinkageName());
188189 } else if (const ConstantInt *CI =
189190 dyn_cast_or_null(GV->getVariable())) {
190191 addConstantValue(*VariableDIE, CI, GTy);
104104 clEnumVal(Disable, "Disabled"), clEnumValEnd),
105105 cl::init(Default));
106106
107 static cl::opt
108 DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
109 cl::desc("Emit DWARF linkage-name attributes."),
110 cl::values(clEnumVal(Default, "Default for platform"),
111 clEnumVal(Enable, "Enabled"),
112 clEnumVal(Disable, "Disabled"), clEnumValEnd),
113 cl::init(Default));
107 enum LinkageNameOption {
108 DefaultLinkageNames,
109 AllLinkageNames,
110 AbstractLinkageNames
111 };
112 static cl::opt
113 DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
114 cl::desc("Which DWARF linkage-name attributes to emit."),
115 cl::values(clEnumValN(DefaultLinkageNames, "Default",
116 "Default for platform"),
117 clEnumValN(AllLinkageNames, "All", "All"),
118 clEnumValN(AbstractLinkageNames, "Abstract",
119 "Abstract subprograms"),
120 clEnumValEnd),
121 cl::init(DefaultLinkageNames));
114122
115123 static const char *const DWARFGroupName = "DWARF Emission";
116124 static const char *const DbgTimerName = "DWARF Debug Writer";
244252 else
245253 HasDwarfPubSections = DwarfPubSections == Enable;
246254
247 // SCE does not use linkage names.
248 if (DwarfLinkageNames == Default)
249 UseLinkageNames = !tuneForSCE();
255 // SCE defaults to linkage names only for abstract subprograms.
256 if (DwarfLinkageNames == DefaultLinkageNames)
257 UseAllLinkageNames = !tuneForSCE();
250258 else
251 UseLinkageNames = DwarfLinkageNames == Enable;
259 UseAllLinkageNames = DwarfLinkageNames == AllLinkageNames;
252260
253261 unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
254262 DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
248248 /// Whether to use the GNU TLS opcode (instead of the standard opcode).
249249 bool UseGNUTLSOpcode;
250250
251 /// Whether to emit DW_AT_[MIPS_]linkage_name.
252 bool UseLinkageNames;
251 /// Whether to emit all linkage names, or just abstract subprograms.
252 bool UseAllLinkageNames;
253253
254254 /// Version of dwarf we're emitting.
255255 unsigned DwarfVersion;
477477 SymSize[Sym] = Size;
478478 }
479479
480 /// Returns whether to emit DW_AT_[MIPS_]linkage_name.
481 bool useLinkageNames() const { return UseLinkageNames; }
480 /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
481 /// If not, we still might emit certain cases.
482 bool useAllLinkageNames() const { return UseAllLinkageNames; }
482483
483484 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
484485 /// standard DW_OP_form_tls_address opcode
664664 }
665665
666666 void DwarfUnit::addLinkageName(DIE &Die, StringRef LinkageName) {
667 if (!LinkageName.empty() && DD->useLinkageNames())
667 if (!LinkageName.empty())
668668 addString(Die,
669669 DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name
670670 : dwarf::DW_AT_MIPS_linkage_name,
11681168 assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
11691169 LinkageName == DeclLinkageName) &&
11701170 "decl has a linkage name and it is different");
1171 if (DeclLinkageName.empty())
1171 if (DeclLinkageName.empty() &&
1172 // Always emit it for abstract subprograms.
1173 (DD->useAllLinkageNames() || DU->getAbstractSPDies().lookup(SP)))
11721174 addLinkageName(SPDie, LinkageName);
11731175
11741176 if (!DeclDie)
22 ; For some reason, the output when targetting sparc is not quite as expected.
33 ; XFAIL: sparc
44
5 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
5 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
66
77 ; IR generated from clang -O0 with:
88 ; struct C {
0 ; REQUIRES: object-emission
11
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck -implicit-check-not=DW_TAG %s
3 ; RUN: %llc_dwarf -dwarf-accel-tables=Enable -dwarf-linkage-names=Enable -O0 -filetype=obj < %s | llvm-dwarfdump - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck -implicit-check-not=DW_TAG %s
3 ; RUN: %llc_dwarf -dwarf-accel-tables=Enable -dwarf-linkage-names=All -O0 -filetype=obj < %s | llvm-dwarfdump - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
44
55 ; Build from source:
66 ; $ clang++ a.cpp b.cpp -g -c -emit-llvm
0 ; REQUIRES: object-emission
11 ;
2 ; RUN: %llc_dwarf -filetype=obj -O0 -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
2 ; RUN: %llc_dwarf -filetype=obj -O0 -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
33
44 ; Make sure we can handle enums with the same identifier but in enum types of
55 ; different compile units.
0 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Abstract < %s | llvm-dwarfdump -debug-dump=info - > %t
1 ; RUN: FileCheck %s -check-prefix=ONENAME < %t
2 ; RUN: FileCheck %s -check-prefix=REF < %t
3 ; Verify tuning for SCE gets us Abstract only.
4 ; RUN: %llc_dwarf -O0 -filetype=obj -debugger-tune=sce < %s | llvm-dwarfdump -debug-dump=info - > %t
5 ; RUN: FileCheck %s -check-prefix=ONENAME < %t
6 ; RUN: FileCheck %s -check-prefix=REF < %t
7 ; REQUIRES: object-emission
8
9 ; Verify that the only linkage-name present is the abstract origin of the
10 ; inlined subprogram.
11
12 ; IR generated from clang -O0 with:
13 ; void f1();
14 ; __attribute__((always_inline)) void f2() {
15 ; f1();
16 ; }
17 ; void f3() {
18 ; f2();
19 ; }
20
21 ; Show that there's only one linkage_name.
22 ; ONENAME: {{DW_AT(_MIPS)?_linkage_name}}
23 ; ONENAME-NOT: {{DW_AT(_MIPS)?_linkage_name}}
24
25 ; Locate the subprogram DIE with the linkage name.
26 ; Show that the inlined_subroutine refers to it.
27 ; REF: DW_TAG_subprogram
28 ; REF: [[FOO:0x.*]]: DW_TAG_subprogram
29 ; REF-NOT: {{DW_TAG|NULL}}
30 ; REF: {{DW_AT(_MIPS)?_linkage_name}}
31 ; REF: DW_TAG_inlined_subroutine
32 ; REF-NOT: {{DW_TAG|NULL}}
33 ; REF: DW_AT_abstract_origin {{.*}} {[[FOO]]}
34
35 ; Function Attrs: alwaysinline uwtable
36 define void @_Z2f2v() #0 !dbg !4 {
37 entry:
38 call void @_Z2f1v(), !dbg !11
39 ret void, !dbg !12
40 }
41
42 declare void @_Z2f1v()
43
44 ; Function Attrs: uwtable
45 define void @_Z2f3v() #2 !dbg !7 {
46 entry:
47 call void @_Z2f1v(), !dbg !13
48 ret void, !dbg !15
49 }
50
51 attributes #0 = { alwaysinline uwtable }
52 attributes #2 = { uwtable }
53
54 !llvm.dbg.cu = !{!0}
55 !llvm.module.flags = !{!8, !9}
56 !llvm.ident = !{!10}
57
58 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 265282)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
59 !1 = !DIFile(filename: "linkage-name-abstract.cpp", directory: "/home/probinson/projects/scratch")
60 !2 = !{}
61 !4 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
62 !5 = !DISubroutineType(types: !6)
63 !6 = !{null}
64 !7 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !1, file: !1, line: 5, type: !5, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
65 !8 = !{i32 2, !"Dwarf Version", i32 4}
66 !9 = !{i32 2, !"Debug Info Version", i32 3}
67 !10 = !{!"clang version 3.9.0 (trunk 265282)"}
68 !11 = !DILocation(line: 3, column: 3, scope: !4)
69 !12 = !DILocation(line: 4, column: 1, scope: !4)
70 !13 = !DILocation(line: 3, column: 3, scope: !4, inlinedAt: !14)
71 !14 = distinct !DILocation(line: 6, column: 3, scope: !7)
72 !15 = !DILocation(line: 7, column: 1, scope: !7)
0 ; REQUIRES: object-emission
11
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump - | FileCheck %s
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump - | FileCheck %s
33 ; CHECK: debug_info contents
44 ; CHECK: [[NS1:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace
55 ; CHECK-NEXT: DW_AT_name{{.*}} = "A"
0 ; REQUIRES: object-emission
11
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
33
44 ; Generated from clang with the following source:
55 ; namespace ns {
0 ; REQUIRES: object-emission
11
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Enable < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
2 ; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=All < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
33
44 ; Generate from clang with the following source. Note that the definition of
55 ; the inline function follows its use to workaround another bug that should be
0 ; REQUIRES: default_triple, object-emission
11 ;
22 ; RUN: llvm-link %s %p/type-unique-odr-b.ll -S -o - \
3 ; RUN: | %llc_dwarf -dwarf-linkage-names=Enable -filetype=obj -O0 \
3 ; RUN: | %llc_dwarf -dwarf-linkage-names=All -filetype=obj -O0 \
44 ; RUN: | llvm-dwarfdump -debug-dump=info - \
55 ; RUN: | FileCheck %s
66 ; RUN: llvm-link %p/type-unique-odr-b.ll %s -S -o - \
7 ; RUN: | %llc_dwarf -dwarf-linkage-names=Enable -filetype=obj -O0 \
7 ; RUN: | %llc_dwarf -dwarf-linkage-names=All -filetype=obj -O0 \
88 ; RUN: | llvm-dwarfdump -debug-dump=info - \
99 ; RUN: | FileCheck %s
1010 ;