diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h @@ -241,10 +241,22 @@ /// Returns null if no name is found. const char *getSubroutineName(DINameKind Kind) const; - /// Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin - /// references if necessary. Returns null if no name is found. + /// Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin + /// references if necessary. For the LinkageName case it additionaly searches + /// for ShortName if LinkageName is not found. + /// Returns null if no name is found. const char *getName(DINameKind Kind) const; + /// Return the DIE short name resolving DW_AT_specification or + /// DW_AT_abstract_origin references if necessary. Returns null if no name + /// is found. + const char *getShortName() const; + + /// Return the DIE linkage name resolving DW_AT_specification or + /// DW_AT_abstract_origin references if necessary. Returns null if no name + /// is found. + const char *getLinkageName() const; + /// Returns the declaration line (start line) for a DIE, assuming it specifies /// a subprogram. This may be fetched from specification or abstract origin /// for this subprogram by resolving DW_AT_sepcification or diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp --- a/llvm/lib/DWARFLinker/DWARFLinker.cpp +++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp @@ -160,16 +160,17 @@ if (Die.getTag() == dwarf::DW_TAG_lexical_block) return false; - // FIXME: a bit wasteful as the first getName might return the - // short name. if (!Info.MangledName) - if (const char *MangledName = Die.getName(DINameKind::LinkageName)) + if (const char *MangledName = Die.getLinkageName()) Info.MangledName = StringPool.getEntry(MangledName); if (!Info.Name) - if (const char *Name = Die.getName(DINameKind::ShortName)) + if (const char *Name = Die.getShortName()) Info.Name = StringPool.getEntry(Name); + if (!Info.MangledName) + Info.MangledName = Info.Name; + if (StripTemplate && Info.Name && Info.MangledName != Info.Name) { StringRef Name = Info.Name.getString(); if (Optional StrippedName = StripTemplateParameters(Name)) diff --git a/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp b/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp --- a/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp +++ b/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp @@ -80,8 +80,12 @@ break; } - const char *Name = DIE.getName(DINameKind::LinkageName); - const char *ShortName = DIE.getName(DINameKind::ShortName); + const char *Name = DIE.getLinkageName(); + const char *ShortName = DIE.getShortName(); + + if (!Name) + Name = ShortName; + StringRef NameRef; StringRef ShortNameRef; StringRef FileRef; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -531,14 +531,26 @@ return nullptr; // Try to get mangled name only if it was asked for. if (Kind == DINameKind::LinkageName) { - if (auto Name = dwarf::toString( - findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}), - nullptr)) + if (auto Name = getLinkageName()) return Name; } - if (auto Name = dwarf::toString(findRecursively(DW_AT_name), nullptr)) - return Name; - return nullptr; + return getShortName(); +} + +const char *DWARFDie::getShortName() const { + if (!isValid()) + return nullptr; + + return dwarf::toString(findRecursively(dwarf::DW_AT_name), nullptr); +} + +const char *DWARFDie::getLinkageName() const { + if (!isValid()) + return nullptr; + + return dwarf::toString(findRecursively({dwarf::DW_AT_MIPS_linkage_name, + dwarf::DW_AT_linkage_name}), + nullptr); } uint64_t DWARFDie::getDeclLine() const {