[llvm-branch-commits] [llvm] 021ea78 - [llvm-nm] - Simplify the code in dumpSymbolNamesFromObject. NFC.

Georgii Rymar via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 15 01:34:48 PST 2021


Author: Georgii Rymar
Date: 2021-01-15T12:29:49+03:00
New Revision: 021ea78a97ed8f4796d92a61cdf62284def36f1e

URL: https://github.com/llvm/llvm-project/commit/021ea78a97ed8f4796d92a61cdf62284def36f1e
DIFF: https://github.com/llvm/llvm-project/commit/021ea78a97ed8f4796d92a61cdf62284def36f1e.diff

LOG: [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

Added: 
    

Modified: 
    llvm/tools/llvm-nm/llvm-nm.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 130201aac9dd..ccb54c3576fe 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).


        


More information about the llvm-branch-commits mailing list