Index: llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp +++ llvm/trunk/lib/DebugInfo/PDB/PDBContext.cpp @@ -96,26 +96,24 @@ if (NameKind == DINameKind::None) return std::string(); + std::unique_ptr FuncSymbol = + Session->findSymbolByAddress(Address, PDB_SymType::Function); + auto *Func = dyn_cast_or_null(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(PublicSym.get())) - return PS->getName(); + if (auto *PS = dyn_cast_or_null(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(FuncSymbol.get())) - return Func->getName(); - - return std::string(); + return Func ? Func->getName() : std::string(); } Index: llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp =================================================================== --- llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp +++ llvm/trunk/test/tools/llvm-symbolizer/pdb/Inputs/test.cpp @@ -10,11 +10,15 @@ void foo() { } +static void private_symbol() { +} + int main() { foo(); NS::Foo f; f.bar(); + private_symbol(); } extern "C" { Index: llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test =================================================================== --- llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test +++ llvm/trunk/test/tools/llvm-symbolizer/pdb/pdb.test @@ -13,33 +13,37 @@ 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@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@0 CHECK-NO-DEMANGLE: @foo_fastcall@0 CHECK-NO-DEMANGLE: foo_vectorcall@@0 +CHECK-NO-DEMANGLE: ?bar@Foo@NS@@QAEXXZ +CHECK-NO-DEMANGLE-NEXT: test.cpp:6