From 021ea78a97ed8f4796d92a61cdf62284def36f1e Mon Sep 17 00:00:00 2001 From: Georgii Rymar Date: Thu, 14 Jan 2021 14:45:05 +0300 Subject: [PATCH] [llvm-nm] - Simplify the code in dumpSymbolNamesFromObject. NFC. It is possible to simplify the logic that extracts symbol names. D94667 made the `NMSymbol::Name` to be `std::string`, what allowed this simplification. Differential revision: https://reviews.llvm.org/D94669 --- llvm/tools/llvm-nm/llvm-nm.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index 130201a..ccb54c3 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -1698,8 +1698,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName, } Symbols = E->getDynamicSymbolIterators(); } - std::string NameBuffer; - raw_string_ostream OS(NameBuffer); + // If a "-s segname sectname" option was specified and this is a Mach-O // file get the section number for that section in this object file. unsigned int Nsect = 0; @@ -1742,6 +1741,8 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName, } S.TypeName = getNMTypeName(Obj, Sym); S.TypeChar = getNMSectionTagAndName(Obj, Sym, S.SectionName); + + raw_string_ostream OS(S.Name); if (Error E = Sym.printName(OS)) { if (MachO) { OS << "bad string index"; @@ -1749,20 +1750,11 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName, } else error(std::move(E), Obj.getFileName()); } - OS << '\0'; S.Sym = Sym; SymbolList.push_back(S); } } - OS.flush(); - const char *P = NameBuffer.c_str(); - unsigned I; - for (I = 0; I < SymbolList.size(); ++I) { - SymbolList[I].Name = P; - P += strlen(P) + 1; - } - // If this is a Mach-O file where the nlist symbol table is out of sync // with the dyld export trie then look through exports and fake up symbols // for the ones that are missing (also done with the -add-dyldinfo flag). -- 2.7.4