[PATCH] D94669: [llvm-nm] - Simplify the code in dumpSymbolNamesFromObject. NFC.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 01:30:30 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG021ea78a97ed: [llvm-nm] - Simplify the code in dumpSymbolNamesFromObject. NFC. (authored by grimar).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94669/new/

https://reviews.llvm.org/D94669

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


Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -1698,8 +1698,7 @@
     }
     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 @@
       }
       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 @@
         } 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).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94669.316871.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210115/aba73bbc/attachment.bin>


More information about the llvm-commits mailing list