Simplify as-needed handling.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 22 Nov 2017 17:50:42 +0000 (17:50 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 22 Nov 2017 17:50:42 +0000 (17:50 +0000)
This is a reduction of a patch by Rui Ueyama.

llvm-svn: 318852

lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
lld/ELF/SymbolTable.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp

index e2b4635..64b38f3 100644 (file)
@@ -655,7 +655,7 @@ ArchiveFile::getMember(const Archive::Symbol *Sym) {
 template <class ELFT>
 SharedFile<ELFT>::SharedFile(MemoryBufferRef M, StringRef DefaultSoName)
     : ELFFileBase<ELFT>(Base::SharedKind, M), SoName(DefaultSoName),
-      AsNeeded(Config->AsNeeded) {}
+      IsNeeded(!Config->AsNeeded) {}
 
 // Partially parse the shared object file so that we can call
 // getSoName on this object.
index 5b217d5..834aa73 100644 (file)
@@ -320,9 +320,7 @@ public:
   std::map<const Elf_Verdef *, NeededVer> VerdefMap;
 
   // Used for --as-needed
-  bool AsNeeded = false;
-  bool IsUsed = false;
-  bool isNeeded() const { return !AsNeeded || IsUsed; }
+  bool IsNeeded;
 };
 
 class BinaryFile : public InputFile {
index c1bd2d1..e45ce22 100644 (file)
@@ -304,7 +304,7 @@ Symbol *SymbolTable::addUndefined(StringRef Name, uint8_t Binding,
     if (!S->isDefined())
       S->Binding = Binding;
     if (auto *SS = dyn_cast<SharedSymbol>(S))
-      SS->getFile<ELFT>()->IsUsed = true;
+      SS->getFile<ELFT>()->IsNeeded = true;
   }
   if (auto *L = dyn_cast<Lazy>(S)) {
     // An undefined weak will not fetch archive members. See comment on Lazy in
@@ -501,7 +501,7 @@ void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
     if (!WasInserted) {
       S->Binding = Binding;
       if (!S->isWeak())
-        File->IsUsed = true;
+        File->IsNeeded = true;
     }
   }
 }
index a0b20c7..4967333 100644 (file)
@@ -997,7 +997,7 @@ template <class ELFT> void DynamicSection<ELFT>::addEntries() {
          InX::DynStrTab->addString(Config->Rpath)});
   for (InputFile *File : SharedFiles) {
     SharedFile<ELFT> *F = cast<SharedFile<ELFT>>(File);
-    if (F->isNeeded())
+    if (F->IsNeeded)
       add({DT_NEEDED, InX::DynStrTab->addString(F->SoName)});
   }
   if (!Config->SoName.empty())
index 6a3655a..03b531b 100644 (file)
@@ -1275,7 +1275,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
     if (InX::DynSymTab && Sym->includeInDynsym()) {
       InX::DynSymTab->addSymbol(Sym);
       if (auto *SS = dyn_cast<SharedSymbol>(Sym))
-        if (cast<SharedFile<ELFT>>(Sym->File)->isNeeded())
+        if (cast<SharedFile<ELFT>>(Sym->File)->IsNeeded)
           In<ELFT>::VerNeed->addSymbol(SS);
     }
   }