diff --git a/llvm/lib/Demangle/Demangle.cpp b/llvm/lib/Demangle/Demangle.cpp --- a/llvm/lib/Demangle/Demangle.cpp +++ b/llvm/lib/Demangle/Demangle.cpp @@ -27,6 +27,10 @@ nonMicrosoftDemangle(MangledName.substr(1), Result)) return Result; + if (starts_with(MangledName, '.') && + nonMicrosoftDemangle(MangledName.substr(1), Result)) + return "." + Result; + if (char *Demangled = microsoftDemangle(MangledName, nullptr, nullptr)) { Result = Demangled; std::free(Demangled); diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -629,30 +629,6 @@ outs() << format(" %02x", NType); } -static std::optional demangle(StringRef Name) { - std::string Demangled; - if (nonMicrosoftDemangle(Name, Demangled)) - return Demangled; - return std::nullopt; -} - -static std::optional demangleXCOFF(StringRef Name) { - if (Name.empty() || Name[0] != '.') - return demangle(Name); - - Name = Name.drop_front(); - std::optional DemangledName = demangle(Name); - if (DemangledName) - return "." + *DemangledName; - return std::nullopt; -} - -static std::optional demangleMachO(StringRef Name) { - if (!Name.empty() && Name[0] == '_') - Name = Name.drop_front(); - return demangle(Name); -} - static bool symbolIsDefined(const NMSymbol &Sym) { return Sym.TypeChar != 'U' && Sym.TypeChar != 'w' && Sym.TypeChar != 'v'; } @@ -822,15 +798,8 @@ std::string Name = S.Name; MachOObjectFile *MachO = dyn_cast(&Obj); - if (Demangle) { - function_ref(StringRef)> Fn = ::demangle; - if (Obj.isXCOFF()) - Fn = demangleXCOFF; - if (Obj.isMachO()) - Fn = demangleMachO; - if (std::optional Opt = Fn(S.Name)) - Name = *Opt; - } + if (Demangle) + Name = llvm::demangle(Name); if (PrintFileName) writeFileName(outs(), ArchiveName, ArchitectureName);