[lld] r275747 - Remove SymbolBody::PlaceholderKind.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 17 18:35:00 PDT 2016


Author: ruiu
Date: Sun Jul 17 20:35:00 2016
New Revision: 275747

URL: http://llvm.org/viewvc/llvm-project?rev=275747&view=rev
Log:
Remove SymbolBody::PlaceholderKind.

In the last patch for --trace-symbol, I introduced a new symbol type
PlaceholderKind and store it to SymVector storage. It made all code
that iterates over SymVector to recognize and skip PlaceholderKind
symbols. I found that that's annoying.

In this patch, I removed PlaceholderKind and stop storing them to SymVector.
Now the information whether a symbol is being watched by --trace-symbol
is stored to the Symtab hash table.

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=275747&r1=275746&r2=275747&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Sun Jul 17 20:35:00 2016
@@ -1465,7 +1465,6 @@ SymbolTableSection<ELFT>::getOutputSecti
   case SymbolBody::LazyArchiveKind:
   case SymbolBody::LazyObjectKind:
     break;
-  case SymbolBody::PlaceholderKind:
   case SymbolBody::DefinedBitcodeKind:
     llvm_unreachable("should have been replaced");
   }

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=275747&r1=275746&r2=275747&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Sun Jul 17 20:35:00 2016
@@ -143,17 +143,7 @@ DefinedRegular<ELFT> *SymbolTable<ELFT>:
 // Set a flag for --trace-symbol so that we can print out a log message
 // if a new symbol with the same name is inserted into the symbol table.
 template <class ELFT> void SymbolTable<ELFT>::trace(StringRef Name) {
-  Symbol *S;
-  bool WasInserted;
-  std::tie(S, WasInserted) = insert(Name);
-  assert(WasInserted);
-
-  S->Traced = true;
-
-  // We created a new symbol just to turn on Trace flag.
-  // Write a dummy SymbolBody so that trace() does not affect
-  // normal symbol operations.
-  new (S->body()) SymbolBody(SymbolBody::PlaceholderKind);
+  Symtab.insert({Name, {-1, true}});
 }
 
 // Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM.
@@ -184,10 +174,15 @@ static uint8_t getMinVisibility(uint8_t
 // Find an existing symbol or create and insert a new one.
 template <class ELFT>
 std::pair<Symbol *, bool> SymbolTable<ELFT>::insert(StringRef Name) {
-  unsigned NumSyms = SymVector.size();
-  auto P = Symtab.insert(std::make_pair(Name, NumSyms));
+  auto P = Symtab.insert({Name, {(int)SymVector.size(), false}});
+  SymIndex &V = P.first->second;
   bool IsNew = P.second;
 
+  if (V.Idx == -1) {
+    IsNew = true;
+    V = {(int)SymVector.size(), true};
+  }
+
   Symbol *Sym;
   if (IsNew) {
     Sym = new (Alloc) Symbol;
@@ -196,12 +191,10 @@ std::pair<Symbol *, bool> SymbolTable<EL
     Sym->IsUsedInRegularObj = false;
     Sym->ExportDynamic = false;
     Sym->VersionId = Config->DefaultSymbolVersion;
-    Sym->Traced = false;
+    Sym->Traced = V.Traced;
     SymVector.push_back(Sym);
   } else {
-    Sym = SymVector[P.first->second];
-    if (Sym->body()->kind() == SymbolBody::PlaceholderKind)
-      IsNew = true;
+    Sym = SymVector[V.Idx];
   }
   return {Sym, IsNew};
 }
@@ -449,7 +442,10 @@ template <class ELFT> SymbolBody *Symbol
   auto It = Symtab.find(Name);
   if (It == Symtab.end())
     return nullptr;
-  return SymVector[It->second]->body();
+  SymIndex V = It->second;
+  if (V.Idx == -1)
+    return nullptr;
+  return SymVector[V.Idx]->body();
 }
 
 // Returns a list of defined symbols that match with a given glob pattern.

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=275747&r1=275746&r2=275747&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Sun Jul 17 20:35:00 2016
@@ -101,6 +101,11 @@ private:
 
   std::map<std::string, SymbolBody *> getDemangledSyms();
 
+  struct SymIndex {
+    int Idx : 31;
+    unsigned Traced : 1;
+  };
+
   // The order the global symbols are in is not defined. We can use an arbitrary
   // order, but it has to be reproducible. That is true even when cross linking.
   // The default hashing of StringRef produces different results on 32 and 64
@@ -108,7 +113,7 @@ private:
   // but a bit inefficient.
   // FIXME: Experiment with passing in a custom hashing or sorting the symbols
   // once symbol resolution is finished.
-  llvm::DenseMap<SymName, unsigned> Symtab;
+  llvm::DenseMap<SymName, SymIndex> Symtab;
   std::vector<Symbol *> SymVector;
   llvm::BumpPtrAllocator Alloc;
 

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=275747&r1=275746&r2=275747&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Sun Jul 17 20:35:00 2016
@@ -79,7 +79,6 @@ static typename ELFT::uint getSymVA(cons
   case SymbolBody::LazyObjectKind:
     assert(Body.symbol()->IsUsedInRegularObj && "lazy symbol reached writer");
     return 0;
-  case SymbolBody::PlaceholderKind:
   case SymbolBody::DefinedBitcodeKind:
     llvm_unreachable("should have been replaced");
   }

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=275747&r1=275746&r2=275747&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Sun Jul 17 20:35:00 2016
@@ -51,7 +51,6 @@ public:
     UndefinedKind,
     LazyArchiveKind,
     LazyObjectKind,
-    PlaceholderKind,
   };
 
   SymbolBody(Kind K) : SymbolKind(K) {}

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=275747&r1=275746&r2=275747&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sun Jul 17 20:35:00 2016
@@ -698,8 +698,6 @@ template <class ELFT> void Writer<ELFT>:
   std::vector<DefinedCommon *> CommonSymbols;
   for (Symbol *S : Symtab.getSymbols()) {
     SymbolBody *Body = S->body();
-    if (Body->kind() == SymbolBody::PlaceholderKind)
-      continue;
 
     // We only report undefined symbols in regular objects. This means that we
     // will accept an undefined reference in bitcode if it can be optimized out.




More information about the llvm-commits mailing list