[llvm] r267732 - [PDB] Fix function names for private symbols in PDBs
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 27 09:10:29 PDT 2016
Author: rnk
Date: Wed Apr 27 11:10:29 2016
New Revision: 267732
URL: http://llvm.org/viewvc/llvm-project?rev=267732&view=rev
Log:
[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
Modified:
llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp
llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp
llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.exe
llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.pdb
llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test
Modified: llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp?rev=267732&r1=267731&r2=267732&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp Wed Apr 27 11:10:29 2016
@@ -96,26 +96,24 @@ std::string PDBContext::getFunctionName(
if (NameKind == DINameKind::None)
return std::string();
+ std::unique_ptr<PDBSymbol> FuncSymbol =
+ Session->findSymbolByAddress(Address, PDB_SymType::Function);
+ auto *Func = dyn_cast_or_null<PDBSymbolFunc>(FuncSymbol.get());
+
if (NameKind == DINameKind::LinkageName) {
// It is not possible to get the mangled linkage name through a
// PDBSymbolFunc. For that we have to specifically request a
// PDBSymbolPublicSymbol.
auto PublicSym =
Session->findSymbolByAddress(Address, PDB_SymType::PublicSymbol);
- if (auto PS = dyn_cast_or_null<PDBSymbolPublicSymbol>(PublicSym.get()))
- return PS->getName();
+ if (auto *PS = dyn_cast_or_null<PDBSymbolPublicSymbol>(PublicSym.get())) {
+ // If we also have a function symbol, prefer the use of public symbol name
+ // only if it refers to the same address. The public symbol uses the
+ // linkage name while the function does not.
+ if (!Func || Func->getVirtualAddress() == PS->getVirtualAddress())
+ return PS->getName();
+ }
}
- auto FuncSymbol =
- Session->findSymbolByAddress(Address, PDB_SymType::Function);
-
- // This could happen either if there was no public symbol (e.g. not
- // external) or the user requested the short name. In the former case,
- // although they technically requested the linkage name, if the linkage
- // name is not available we fallback to at least returning a non-empty
- // string.
- if (auto Func = dyn_cast_or_null<PDBSymbolFunc>(FuncSymbol.get()))
- return Func->getName();
-
- return std::string();
+ return Func ? Func->getName() : std::string();
}
Modified: llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp?rev=267732&r1=267731&r2=267732&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp Wed Apr 27 11:10:29 2016
@@ -10,11 +10,15 @@ struct Foo {
void foo() {
}
+static void private_symbol() {
+}
+
int main() {
foo();
NS::Foo f;
f.bar();
+ private_symbol();
}
extern "C" {
Modified: llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.exe
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.exe?rev=267732&r1=267731&r2=267732&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.exe (original) and llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.exe Wed Apr 27 11:10:29 2016 differ
Modified: llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.pdb
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.pdb?rev=267732&r1=267731&r2=267732&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.pdb (original) and llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.pdb Wed Apr 27 11:10:29 2016 differ
Modified: llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test?rev=267732&r1=267731&r2=267732&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test Wed Apr 27 11:10:29 2016
@@ -13,33 +13,37 @@ RUN: | %python -c 'import sys;print("\n
RUN: | llvm-symbolizer -obj="%p/Inputs/test.exe" -demangle=false --relative-address \
RUN: | FileCheck %s --check-prefix=CHECK-NO-DEMANGLE
-ADDR: 0x401000
-ADDR: 0x401010
-ADDR: 0x401070
-ADDR: 0x401030
-ADDR: 0x401040
-ADDR: 0x401050
-ADDR: 0x401060
-ADDR: 0x500000
+ADDR: 0x401380
+ADDR: 0x401390
+ADDR: 0x4013A0
+ADDR: 0x4013C0
+ADDR: 0x4013D0
+ADDR: 0x4013E0
+ADDR: 0x4013F0
+ADDR: 0x401420
CHECK: foo(void)
CHECK-NEXT: test.cpp:10
-CHECK: main
+CHECK: {{^private_symbol$}}
CHECK-NEXT: test.cpp:13:0
-CHECK: NS::Foo::bar(void)
-CHECK-NEXT: test.cpp:6:0
+CHECK: {{^main}}
+CHECK-NEXT: test.cpp:16:0
CHECK: {{^foo_cdecl$}}
CHECK: {{^foo_stdcall$}}
CHECK: {{^foo_fastcall$}}
CHECK: {{^foo_vectorcall$}}
+CHECK: NS::Foo::bar(void)
+CHECK-NEXT: test.cpp:6:0
CHECK-NO-DEMANGLE: ?foo@@YAXXZ
CHECK-NO-DEMANGLE-NEXT: test.cpp:10
-CHECK-NO-DEMANGLE: _main
+CHECK-NO-DEMANGLE: private_symbol
CHECK-NO-DEMANGLE-NEXT: test.cpp:13
-CHECK-NO-DEMANGLE: ?bar at Foo@NS@@QAEXXZ
-CHECK-NO-DEMANGLE-NEXT: test.cpp:6
+CHECK-NO-DEMANGLE: _main
+CHECK-NO-DEMANGLE-NEXT: test.cpp:16
CHECK-NO-DEMANGLE: _foo_cdecl
CHECK-NO-DEMANGLE: _foo_stdcall at 0
CHECK-NO-DEMANGLE: @foo_fastcall at 0
CHECK-NO-DEMANGLE: foo_vectorcall@@0
+CHECK-NO-DEMANGLE: ?bar at Foo@NS@@QAEXXZ
+CHECK-NO-DEMANGLE-NEXT: test.cpp:6
More information about the llvm-commits
mailing list