llvm.org GIT mirror llvm / 8a9e8e9
[PDB] Fix function names for private symbols in PDBs Summary: llvm-symbolizer wants to get linkage names of functions for historical reasons. Linkage names are only recorded in the PDB for public symbols, and the linkage name is apparently stored separately in some "public symbol" record. We had a workaround in PDBContext which would look for such symbols when the user requested linkage names. However, when given an address that was truly in a private function and public funciton, we would accidentally find nearby public symbols and return those function names. The fix is to look for both function symbols and public symbols and only prefer the public symbol name if the addresses of the symbols agree. Fixes PR27492 Reviewers: zturner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D19571 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267732 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 3 years ago
5 changed file(s) with 34 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
9595 if (NameKind == DINameKind::None)
9696 return std::string();
9797
98 std::unique_ptr FuncSymbol =
99 Session->findSymbolByAddress(Address, PDB_SymType::Function);
100 auto *Func = dyn_cast_or_null(FuncSymbol.get());
101
98102 if (NameKind == DINameKind::LinkageName) {
99103 // It is not possible to get the mangled linkage name through a
100104 // PDBSymbolFunc. For that we have to specifically request a
101105 // PDBSymbolPublicSymbol.
102106 auto PublicSym =
103107 Session->findSymbolByAddress(Address, PDB_SymType::PublicSymbol);
104 if (auto PS = dyn_cast_or_null(PublicSym.get()))
105 return PS->getName();
108 if (auto *PS = dyn_cast_or_null(PublicSym.get())) {
109 // If we also have a function symbol, prefer the use of public symbol name
110 // only if it refers to the same address. The public symbol uses the
111 // linkage name while the function does not.
112 if (!Func || Func->getVirtualAddress() == PS->getVirtualAddress())
113 return PS->getName();
114 }
106115 }
107116
108 auto FuncSymbol =
109 Session->findSymbolByAddress(Address, PDB_SymType::Function);
110
111 // This could happen either if there was no public symbol (e.g. not
112 // external) or the user requested the short name. In the former case,
113 // although they technically requested the linkage name, if the linkage
114 // name is not available we fallback to at least returning a non-empty
115 // string.
116 if (auto Func = dyn_cast_or_null(FuncSymbol.get()))
117 return Func->getName();
118
119 return std::string();
117 return Func ? Func->getName() : std::string();
120118 }
99 void foo() {
1010 }
1111
12 static void private_symbol() {
13 }
14
1215 int main() {
1316 foo();
1417
1518 NS::Foo f;
1619 f.bar();
20 private_symbol();
1721 }
1822
1923 extern "C" {
1212 RUN: | llvm-symbolizer -obj="%p/Inputs/test.exe" -demangle=false --relative-address \
1313 RUN: | FileCheck %s --check-prefix=CHECK-NO-DEMANGLE
1414
15 ADDR: 0x401000
16 ADDR: 0x401010
17 ADDR: 0x401070
18 ADDR: 0x401030
19 ADDR: 0x401040
20 ADDR: 0x401050
21 ADDR: 0x401060
22 ADDR: 0x500000
15 ADDR: 0x401380
16 ADDR: 0x401390
17 ADDR: 0x4013A0
18 ADDR: 0x4013C0
19 ADDR: 0x4013D0
20 ADDR: 0x4013E0
21 ADDR: 0x4013F0
22 ADDR: 0x401420
2323
2424 CHECK: foo(void)
2525 CHECK-NEXT: test.cpp:10
26 CHECK: main
26 CHECK: {{^private_symbol$}}
2727 CHECK-NEXT: test.cpp:13:0
28 CHECK: NS::Foo::bar(void)
29 CHECK-NEXT: test.cpp:6:0
28 CHECK: {{^main}}
29 CHECK-NEXT: test.cpp:16:0
3030 CHECK: {{^foo_cdecl$}}
3131 CHECK: {{^foo_stdcall$}}
3232 CHECK: {{^foo_fastcall$}}
3333 CHECK: {{^foo_vectorcall$}}
34 CHECK: NS::Foo::bar(void)
35 CHECK-NEXT: test.cpp:6:0
3436
3537 CHECK-NO-DEMANGLE: ?foo@@YAXXZ
3638 CHECK-NO-DEMANGLE-NEXT: test.cpp:10
39 CHECK-NO-DEMANGLE: private_symbol
40 CHECK-NO-DEMANGLE-NEXT: test.cpp:13
3741 CHECK-NO-DEMANGLE: _main
38 CHECK-NO-DEMANGLE-NEXT: test.cpp:13
39 CHECK-NO-DEMANGLE: ?bar@Foo@NS@@QAEXXZ
40 CHECK-NO-DEMANGLE-NEXT: test.cpp:6
42 CHECK-NO-DEMANGLE-NEXT: test.cpp:16
4143 CHECK-NO-DEMANGLE: _foo_cdecl
4244 CHECK-NO-DEMANGLE: _foo_stdcall@0
4345 CHECK-NO-DEMANGLE: @foo_fastcall@0
4446 CHECK-NO-DEMANGLE: foo_vectorcall@@0
47 CHECK-NO-DEMANGLE: ?bar@Foo@NS@@QAEXXZ
48 CHECK-NO-DEMANGLE-NEXT: test.cpp:6