[lld] r318683 - COFF: Remove the SymbolBodies vector, and rename SparseSymbolBodies to Symbols.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 10:52:53 PST 2017


Author: pcc
Date: Mon Nov 20 10:52:53 2017
New Revision: 318683

URL: http://llvm.org/viewvc/llvm-project?rev=318683&view=rev
Log:
COFF: Remove the SymbolBodies vector, and rename SparseSymbolBodies to Symbols.

Differential Revision: https://reviews.llvm.org/D40237

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/COFF/InputFiles.h
    lld/trunk/COFF/MapFile.cpp
    lld/trunk/COFF/SymbolTable.cpp

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=318683&r1=318682&r2=318683&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Mon Nov 20 10:52:53 2017
@@ -172,8 +172,7 @@ void ObjFile::initializeChunks() {
 
 void ObjFile::initializeSymbols() {
   uint32_t NumSymbols = COFFObj->getNumberOfSymbols();
-  SymbolBodies.reserve(NumSymbols);
-  SparseSymbolBodies.resize(NumSymbols);
+  Symbols.resize(NumSymbols);
 
   SmallVector<std::pair<Symbol *, uint32_t>, 8> WeakAliases;
   int32_t LastSectionNumber = 0;
@@ -197,10 +196,7 @@ void ObjFile::initializeSymbols() {
     } else {
       Sym = createDefined(COFFSym, AuxP, IsFirst);
     }
-    if (Sym) {
-      SymbolBodies.push_back(Sym);
-      SparseSymbolBodies[I] = Sym;
-    }
+    Symbols[I] = Sym;
     I += COFFSym.getNumberOfAuxSymbols();
     LastSectionNumber = COFFSym.getSectionNumber();
   }
@@ -208,7 +204,7 @@ void ObjFile::initializeSymbols() {
   for (auto &KV : WeakAliases) {
     Symbol *Sym = KV.first;
     uint32_t Idx = KV.second;
-    checkAndSetWeakAlias(Symtab, this, Sym, SparseSymbolBodies[Idx]);
+    checkAndSetWeakAlias(Symtab, this, Sym, Symbols[Idx]);
   }
 }
 
@@ -301,7 +297,7 @@ void ObjFile::initializeSEH() {
   auto *I = reinterpret_cast<const ulittle32_t *>(A.data());
   auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size());
   for (; I != E; ++I)
-    SEHandlers.insert(SparseSymbolBodies[*I]);
+    SEHandlers.insert(Symbols[*I]);
 }
 
 MachineTypes ObjFile::getMachineType() {

Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=318683&r1=318682&r2=318683&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Mon Nov 20 10:52:53 2017
@@ -110,12 +110,12 @@ public:
   MachineTypes getMachineType() override;
   std::vector<Chunk *> &getChunks() { return Chunks; }
   std::vector<SectionChunk *> &getDebugChunks() { return DebugChunks; }
-  std::vector<Symbol *> &getSymbols() { return SymbolBodies; }
+  std::vector<Symbol *> &getSymbols() { return Symbols; }
 
   // Returns a Symbol object for the SymbolIndex'th symbol in the
   // underlying object file.
   Symbol *getSymbol(uint32_t SymbolIndex) {
-    return SparseSymbolBodies[SymbolIndex];
+    return Symbols[SymbolIndex];
   }
 
   // Returns the underying COFF file.
@@ -162,14 +162,11 @@ private:
   // null pointer.)
   std::vector<SectionChunk *> SparseChunks;
 
-  // List of all symbols referenced or defined by this file.
-  std::vector<Symbol *> SymbolBodies;
-
-  // This vector contains the same symbols as SymbolBodies, but they
-  // are indexed such that you can get a Symbol by symbol
+  // This vector contains a list of all symbols defined or referenced by this
+  // file. They are indexed such that you can get a Symbol by symbol
   // index. Nonexistent indices (which are occupied by auxiliary
   // symbols in the real symbol table) are filled with null pointers.
-  std::vector<Symbol *> SparseSymbolBodies;
+  std::vector<Symbol *> Symbols;
 };
 
 // This type represents import library members that contain DLL names

Modified: lld/trunk/COFF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MapFile.cpp?rev=318683&r1=318682&r2=318683&view=diff
==============================================================================
--- lld/trunk/COFF/MapFile.cpp (original)
+++ lld/trunk/COFF/MapFile.cpp Mon Nov 20 10:52:53 2017
@@ -50,7 +50,7 @@ static std::vector<DefinedRegular *> get
   std::vector<DefinedRegular *> V;
   for (ObjFile *File : ObjFile::Instances)
     for (Symbol *B : File->getSymbols())
-      if (auto *Sym = dyn_cast<DefinedRegular>(B))
+      if (auto *Sym = dyn_cast_or_null<DefinedRegular>(B))
         if (Sym && !Sym->getCOFFSymbol().isSectionDefinition())
           V.push_back(Sym);
   return V;

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=318683&r1=318682&r2=318683&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Mon Nov 20 10:52:53 2017
@@ -148,7 +148,7 @@ void SymbolTable::reportRemainingUndefin
 
   for (ObjFile *File : ObjFile::Instances)
     for (Symbol *Sym : File->getSymbols())
-      if (Undefs.count(Sym))
+      if (Sym && Undefs.count(Sym))
         errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName());
 }
 




More information about the llvm-commits mailing list