Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -320,9 +320,7 @@ std::map VerdefMap; // Used for --as-needed - bool AsNeeded = false; - bool IsUsed = false; - bool isNeeded() const { return !AsNeeded || IsUsed; } + bool IsNeeded; }; class BinaryFile : public InputFile { Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -655,7 +655,7 @@ template SharedFile::SharedFile(MemoryBufferRef M, StringRef DefaultSoName) : ELFFileBase(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: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -304,7 +304,7 @@ if (!S->isDefined()) S->Binding = Binding; if (auto *SS = dyn_cast(S)) - SS->getFile()->IsUsed = true; + SS->getFile()->IsNeeded = true; } if (auto *L = dyn_cast(S)) { // An undefined weak will not fetch archive members. See comment on Lazy in @@ -501,7 +501,7 @@ if (!WasInserted) { S->Binding = Binding; if (!S->isWeak()) - File->IsUsed = true; + File->IsNeeded = true; } } } Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -997,7 +997,7 @@ InX::DynStrTab->addString(Config->Rpath)}); for (InputFile *File : SharedFiles) { SharedFile *F = cast>(File); - if (F->isNeeded()) + if (F->IsNeeded) add({DT_NEEDED, InX::DynStrTab->addString(F->SoName)}); } if (!Config->SoName.empty()) Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1275,7 +1275,7 @@ if (InX::DynSymTab && Sym->includeInDynsym()) { InX::DynSymTab->addSymbol(Sym); if (auto *SS = dyn_cast(Sym)) - if (cast>(Sym->File)->isNeeded()) + if (cast>(Sym->File)->IsNeeded) In::VerNeed->addSymbol(SS); } }