[lld] r329086 - [ELF] - Eliminate Lazy class.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 10:16:52 PDT 2018


Author: grimar
Date: Tue Apr  3 10:16:52 2018
New Revision: 329086

URL: http://llvm.org/viewvc/llvm-project?rev=329086&view=rev
Log:
[ELF] - Eliminate Lazy class.

Patch removes Lazy class which
is just an excessive layer.

Differential revision: https://reviews.llvm.org/D45083

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=329086&r1=329085&r2=329086&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Apr  3 10:16:52 2018
@@ -1081,12 +1081,16 @@ template <class ELFT> void LinkerDriver:
 
   // Handle the `--undefined <sym>` options.
   for (StringRef S : Config->Undefined)
-    Symtab->fetchIfLazy<ELFT>(S);
+    if (Symbol *Sym = Symtab->find(S))
+      if (InputFile *F = Symtab->fetchIfLazy(Sym))
+        Symtab->addFile<ELFT>(F);
 
   // If an entry symbol is in a static archive, pull out that file now
   // to complete the symbol table. After this, no new names except a
   // few linker-synthesized ones will be added to the symbol table.
-  Symtab->fetchIfLazy<ELFT>(Config->Entry);
+  if (Symbol *Sym = Symtab->find(Config->Entry))
+    if (InputFile *F = Symtab->fetchIfLazy(Sym))
+      Symtab->addFile<ELFT>(F);
 
   // Return if there were name resolution errors.
   if (errorCount())

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=329086&r1=329085&r2=329086&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Tue Apr  3 10:16:52 2018
@@ -46,7 +46,6 @@ namespace elf {
 
 using llvm::object::Archive;
 
-class Lazy;
 class Symbol;
 
 // If -reproduce option is given, all input files are written

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=329086&r1=329085&r2=329086&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Apr  3 10:16:52 2018
@@ -309,12 +309,12 @@ Symbol *SymbolTable::addUndefined(String
       if (!Config->GcSections)
         SS->getFile<ELFT>().IsNeeded = true;
   }
-  if (auto *L = dyn_cast<Lazy>(S)) {
+  if (S->isLazy()) {
     // An undefined weak will not fetch archive members. See comment on Lazy in
     // Symbols.h for the details.
     if (Binding == STB_WEAK)
-      L->Type = Type;
-    else if (InputFile *F = L->fetch())
+      S->Type = Type;
+    else if (InputFile *F = Symtab->fetchIfLazy(S))
       addFile<ELFT>(F);
   }
   return S;
@@ -574,16 +574,15 @@ void SymbolTable::addLazyObject(StringRe
     addFile<ELFT>(F);
 }
 
-// If we already saw this symbol, force loading its file.
-template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
-  if (Symbol *B = find(Name)) {
-    // Mark the symbol not to be eliminated by LTO
-    // even if it is a bitcode symbol.
-    B->IsUsedInRegularObj = true;
-    if (auto *L = dyn_cast<Lazy>(B))
-      if (InputFile *File = L->fetch())
-        addFile<ELFT>(File);
-  }
+InputFile *SymbolTable::fetchIfLazy(Symbol *Sym) {
+  // Mark the symbol not to be eliminated by LTO
+  // even if it is a bitcode symbol.
+  Sym->IsUsedInRegularObj = true;
+  if (LazyArchive *L = dyn_cast<LazyArchive>(Sym))
+    return L->fetch();
+  if (LazyObject *L = dyn_cast<LazyObject>(Sym))
+    return cast<LazyObjFile>(L->File)->fetch();
+  return nullptr;
 }
 
 // Initialize DemangledSyms with a map from demangled symbols to symbol
@@ -806,8 +805,3 @@ template void SymbolTable::addShared<ELF
 template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> &,
                                               const typename ELF64BE::Sym &,
                                               uint32_t Alignment, uint32_t);
-
-template void SymbolTable::fetchIfLazy<ELF32LE>(StringRef);
-template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);
-template void SymbolTable::fetchIfLazy<ELF64LE>(StringRef);
-template void SymbolTable::fetchIfLazy<ELF64BE>(StringRef);

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=329086&r1=329085&r2=329086&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Tue Apr  3 10:16:52 2018
@@ -77,7 +77,8 @@ public:
                                    uint8_t Visibility, bool CanOmitFromDynSym,
                                    InputFile *File);
 
-  template <class ELFT> void fetchIfLazy(StringRef Name);
+  InputFile *fetchIfLazy(Symbol *Sym);
+
   void scanVersionScript();
 
   Symbol *find(StringRef Name);

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=329086&r1=329085&r2=329086&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Apr  3 10:16:52 2018
@@ -207,12 +207,6 @@ void Symbol::parseSymbolVersion() {
           Verstr);
 }
 
-InputFile *Lazy::fetch() {
-  if (auto *Sym = dyn_cast<LazyArchive>(this))
-    return Sym->fetch();
-  return cast<LazyObjFile>(File)->fetch();
-}
-
 InputFile *LazyArchive::fetch() { return cast<ArchiveFile>(File)->fetch(Sym); }
 
 uint8_t Symbol::computeBinding() const {

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=329086&r1=329085&r2=329086&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Apr  3 10:16:52 2018
@@ -99,7 +99,7 @@ public:
   // True if this is an undefined weak symbol. This only works once
   // all input files have been added.
   bool isUndefWeak() const {
-    // See comment on Lazy for details.
+    // See comment on lazy symbols for details.
     return isWeak() && (isUndefined() || isLazy());
   }
 
@@ -248,38 +248,27 @@ public:
   uint32_t Alignment;
 };
 
-// This represents a symbol that is not yet in the link, but we know where to
-// find it if needed. If the resolver finds both Undefined and Lazy for the same
-// name, it will ask the Lazy to load a file.
+// LazyArchive and LazyObject represent a symbols that is not yet in the link,
+// but we know where to find it if needed. If the resolver finds both Undefined
+// and Lazy for the same name, it will ask the Lazy to load a file.
 //
 // A special complication is the handling of weak undefined symbols. They should
 // not load a file, but we have to remember we have seen both the weak undefined
 // and the lazy. We represent that with a lazy symbol with a weak binding. This
 // means that code looking for undefined symbols normally also has to take lazy
 // symbols into consideration.
-class Lazy : public Symbol {
-public:
-  static bool classof(const Symbol *S) { return S->isLazy(); }
-
-  // Returns an object file for this symbol, or a nullptr if the file
-  // was already returned.
-  InputFile *fetch();
-
-protected:
-  Lazy(Kind K, InputFile &File, StringRef Name, uint8_t Type)
-      : Symbol(K, &File, Name, llvm::ELF::STB_GLOBAL, llvm::ELF::STV_DEFAULT,
-               Type) {}
-};
 
 // This class represents a symbol defined in an archive file. It is
 // created from an archive file header, and it knows how to load an
 // object file from an archive to replace itself with a defined
 // symbol.
-class LazyArchive : public Lazy {
+class LazyArchive : public Symbol {
 public:
   LazyArchive(InputFile &File, const llvm::object::Archive::Symbol S,
               uint8_t Type)
-      : Lazy(LazyArchiveKind, File, S.getName(), Type), Sym(S) {}
+      : Symbol(LazyArchiveKind, &File, S.getName(), llvm::ELF::STB_GLOBAL,
+               llvm::ELF::STV_DEFAULT, Type),
+        Sym(S) {}
 
   static bool classof(const Symbol *S) { return S->kind() == LazyArchiveKind; }
 
@@ -291,10 +280,11 @@ private:
 
 // LazyObject symbols represents symbols in object files between
 // --start-lib and --end-lib options.
-class LazyObject : public Lazy {
+class LazyObject : public Symbol {
 public:
   LazyObject(InputFile &File, StringRef Name, uint8_t Type)
-      : Lazy(LazyObjectKind, File, Name, Type) {}
+      : Symbol(LazyObjectKind, &File, Name, llvm::ELF::STB_GLOBAL,
+               llvm::ELF::STV_DEFAULT, Type) {}
 
   static bool classof(const Symbol *S) { return S->kind() == LazyObjectKind; }
 };




More information about the llvm-commits mailing list