Index: include/lld/Core/ArchiveLibraryFile.h =================================================================== --- include/lld/Core/ArchiveLibraryFile.h +++ include/lld/Core/ArchiveLibraryFile.h @@ -32,7 +32,7 @@ /// Check if any member of the archive contains an Atom with the /// specified name and return the File object for that member, or nullptr. - virtual File *find(StringRef name, bool dataSymbolOnly) = 0; + virtual File *find(StringRef name) = 0; virtual std::error_code parseAllMembers(std::vector> &result) = 0; Index: include/lld/Core/LinkingContext.h =================================================================== --- include/lld/Core/LinkingContext.h +++ include/lld/Core/LinkingContext.h @@ -75,28 +75,6 @@ _deadStripRoots.push_back(symbolName); } - /// Archive files (aka static libraries) are normally lazily loaded. That is, - /// object files within an archive are only loaded and linked in, if the - /// object file contains a DefinedAtom which will replace an existing - /// UndefinedAtom. If this method returns true, core linking will also look - /// for archive members to replace existing tentative definitions in addition - /// to replacing undefines. Note: a "tentative definition" (also called a - /// "common" symbols) is a C (but not C++) concept. They are modeled in lld - /// as a DefinedAtom with merge() of mergeAsTentative. - bool searchArchivesToOverrideTentativeDefinitions() const { - return _searchArchivesToOverrideTentativeDefinitions; - } - - /// Normally core linking will turn a tentative definition into a real - /// definition if not replaced by a real DefinedAtom from some object file. - /// If this method returns true, core linking will search all supplied - /// dynamic shared libraries for symbol names that match remaining tentative - /// definitions. If any are found, the corresponding tentative definition - /// atom is replaced with SharedLibraryAtom. - bool searchSharedLibrariesToOverrideTentativeDefinitions() const { - return _searchSharedLibrariesToOverrideTentativeDefinitions; - } - /// Normally, every UndefinedAtom must be replaced by a DefinedAtom or a /// SharedLibraryAtom for the link to be successful. This method controls /// whether core linking prints out a list of remaining UndefinedAtoms. @@ -145,12 +123,6 @@ void setDeadStripping(bool enable) { _deadStrip = enable; } void setGlobalsAreDeadStripRoots(bool v) { _globalsAreDeadStripRoots = v; } - void setSearchArchivesToOverrideTentativeDefinitions(bool search) { - _searchArchivesToOverrideTentativeDefinitions = search; - } - void setSearchSharedLibrariesToOverrideTentativeDefinitions(bool search) { - _searchSharedLibrariesToOverrideTentativeDefinitions = search; - } void setPrintRemainingUndefines(bool print) { _printRemainingUndefines = print; } @@ -280,8 +252,6 @@ StringRef _entrySymbolName; bool _deadStrip; bool _globalsAreDeadStripRoots; - bool _searchArchivesToOverrideTentativeDefinitions; - bool _searchSharedLibrariesToOverrideTentativeDefinitions; bool _printRemainingUndefines; bool _allowRemainingUndefines; bool _logInputFiles; Index: include/lld/Core/Resolver.h =================================================================== --- include/lld/Core/Resolver.h +++ include/lld/Core/Resolver.h @@ -58,7 +58,7 @@ std::unique_ptr resultFile() { return std::move(_result); } private: - typedef std::function(StringRef, bool)> UndefCallback; + typedef std::function(StringRef)> UndefCallback; bool undefinesAdded(int begin, int end); File *getFile(int &index); @@ -70,8 +70,7 @@ bool checkUndefines(); void removeCoalescedAwayAtoms(); void checkDylibSymbolCollisions(); - ErrorOr forEachUndefines(File &file, bool searchForOverrides, - UndefCallback callback); + ErrorOr forEachUndefines(File &file, UndefCallback callback); void markLive(const Atom *atom); void addAtoms(const std::vector&); Index: include/lld/Core/SharedLibraryFile.h =================================================================== --- include/lld/Core/SharedLibraryFile.h +++ include/lld/Core/SharedLibraryFile.h @@ -27,8 +27,7 @@ /// Check if the shared library exports a symbol with the specified name. /// If so, return a SharedLibraryAtom which represents that exported /// symbol. Otherwise return nullptr. - virtual const SharedLibraryAtom *exports(StringRef name, - bool dataSymbolOnly) const = 0; + virtual const SharedLibraryAtom *exports(StringRef name) const = 0; // Returns the install name. virtual StringRef getDSOName() const = 0; Index: include/lld/Core/Simple.h =================================================================== --- include/lld/Core/Simple.h +++ include/lld/Core/Simple.h @@ -105,7 +105,7 @@ return _absoluteAtoms; } - File *find(StringRef sym, bool dataSymbolOnly) override { + File *find(StringRef sym) override { // For descendants: // do some checks here and return dynamically generated files with atoms. return nullptr; Index: lib/Core/LinkingContext.cpp =================================================================== --- lib/Core/LinkingContext.cpp +++ lib/Core/LinkingContext.cpp @@ -17,8 +17,6 @@ LinkingContext::LinkingContext() : _deadStrip(false), _globalsAreDeadStripRoots(false), - _searchArchivesToOverrideTentativeDefinitions(false), - _searchSharedLibrariesToOverrideTentativeDefinitions(false), _printRemainingUndefines(true), _allowRemainingUndefines(false), _logInputFiles(false), _allowShlibUndefines(true), _outputFileType(OutputFileType::Default), _nextOrdinal(0) {} Index: lib/Core/Resolver.cpp =================================================================== --- lib/Core/Resolver.cpp +++ lib/Core/Resolver.cpp @@ -46,8 +46,7 @@ return undefAdded; } -ErrorOr Resolver::forEachUndefines(File &file, bool searchForOverrides, - UndefCallback callback) { +ErrorOr Resolver::forEachUndefines(File &file, UndefCallback callback) { size_t i = _undefineIndex[&file]; bool undefAdded = false; do { @@ -61,27 +60,11 @@ _undefines[i] = ""; continue; } - auto undefAddedOrError = callback(undefName, false); + auto undefAddedOrError = callback(undefName); if (undefAddedOrError.getError()) return undefAddedOrError; undefAdded |= undefAddedOrError.get(); } - if (!searchForOverrides) - continue; - for (StringRef tentDefName : _symbolTable.tentativeDefinitions()) { - // Load for previous tentative may also have loaded - // something that overrode this tentative, so always check. - const Atom *curAtom = _symbolTable.findByName(tentDefName); - assert(curAtom != nullptr); - if (const DefinedAtom *curDefAtom = dyn_cast(curAtom)) { - if (curDefAtom->merge() == DefinedAtom::mergeAsTentative) { - auto undefAddedOrError = callback(tentDefName, true); - if (undefAddedOrError.getError()) - return undefAddedOrError; - undefAdded |= undefAddedOrError.get(); - } - } - } } while (i < _undefines.size()); _undefineIndex[&file] = i; return undefAdded; @@ -89,12 +72,8 @@ ErrorOr Resolver::handleArchiveFile(File &file) { ArchiveLibraryFile *archiveFile = cast(&file); - bool searchForOverrides = - _ctx.searchArchivesToOverrideTentativeDefinitions(); - return forEachUndefines(file, searchForOverrides, - [&](StringRef undefName, - bool dataSymbolOnly)->ErrorOr { - if (File *member = archiveFile->find(undefName, dataSymbolOnly)) { + return forEachUndefines(file, [&](StringRef undefName) -> ErrorOr { + if (File *member = archiveFile->find(undefName)) { member->setOrdinal(_ctx.getNextOrdinalAndIncrement()); return handleFile(*member); } @@ -108,16 +87,12 @@ auto undefAddedOrError = handleFile(*sharedLibrary); if (undefAddedOrError.getError()) return undefAddedOrError.getError(); - bool searchForOverrides = - _ctx.searchSharedLibrariesToOverrideTentativeDefinitions(); - undefAddedOrError = forEachUndefines(file, searchForOverrides, - [&](StringRef undefName, - bool dataSymbolOnly)->ErrorOr { - if (const SharedLibraryAtom *atom = - sharedLibrary->exports(undefName, dataSymbolOnly)) - doSharedLibraryAtom(*atom); - return false; - }); + undefAddedOrError = + forEachUndefines(file, [&](StringRef undefName) -> ErrorOr { + if (const SharedLibraryAtom *atom = sharedLibrary->exports(undefName)) + doSharedLibraryAtom(*atom); + return false; + }); if (undefAddedOrError.getError()) return undefAddedOrError.getError(); Index: lib/ReaderWriter/FileArchive.cpp =================================================================== --- lib/ReaderWriter/FileArchive.cpp +++ lib/ReaderWriter/FileArchive.cpp @@ -42,7 +42,7 @@ /// \brief Check if any member of the archive contains an Atom with the /// specified name and return the File object for that member, or nullptr. - File *find(StringRef name, bool dataSymbolOnly) override { + File *find(StringRef name) override { auto member = _symbolMemberMap.find(name); if (member == _symbolMemberMap.end()) return nullptr; @@ -57,9 +57,6 @@ const char *memberStart = buf->data(); if (_membersInstantiated.count(memberStart)) return nullptr; - if (dataSymbolOnly && !isDataSymbol(ci, name)) - return nullptr; - _membersInstantiated.insert(memberStart); std::unique_ptr result; @@ -150,43 +147,6 @@ return std::error_code(); } - // Parses the given memory buffer as an object file, and returns true - // code if the given symbol is a data symbol. If the symbol is not a data - // symbol or does not exist, returns false. - bool isDataSymbol(Archive::child_iterator cOrErr, StringRef symbol) const { - if (cOrErr->getError()) - return false; - Archive::child_iterator member = cOrErr->get(); - ErrorOr buf = (*member)->getMemoryBufferRef(); - if (buf.getError()) - return false; - std::unique_ptr mb(MemoryBuffer::getMemBuffer( - buf.get().getBuffer(), buf.get().getBufferIdentifier(), false)); - - auto objOrErr(ObjectFile::createObjectFile(mb->getMemBufferRef())); - if (objOrErr.getError()) - return false; - std::unique_ptr obj = std::move(objOrErr.get()); - - for (SymbolRef sym : obj->symbols()) { - // Skip until we find the symbol. - ErrorOr name = sym.getName(); - if (!name) - return false; - if (*name != symbol) - continue; - uint32_t flags = sym.getFlags(); - if (flags <= SymbolRef::SF_Undefined) - continue; - - // Returns true if it's a data symbol. - SymbolRef::Type type = sym.getType(); - if (type == SymbolRef::ST_Data) - return true; - } - return false; - } - std::error_code buildTableOfContents() { DEBUG_WITH_TYPE("FileArchive", llvm::dbgs() << "Table of contents for archive '" Index: lib/ReaderWriter/MachO/File.h =================================================================== --- lib/ReaderWriter/MachO/File.h +++ lib/ReaderWriter/MachO/File.h @@ -275,7 +275,7 @@ MachODylibFile(StringRef path) : SharedLibraryFile(path) {} - const SharedLibraryAtom *exports(StringRef name, bool isData) const override { + const SharedLibraryAtom *exports(StringRef name) const override { // Pass down _installName so that if this requested symbol // is re-exported through this dylib, the SharedLibraryAtom's loadName() // is this dylib installName and not the implementation dylib's. Index: lib/ReaderWriter/MachO/FlatNamespaceFile.h =================================================================== --- lib/ReaderWriter/MachO/FlatNamespaceFile.h +++ lib/ReaderWriter/MachO/FlatNamespaceFile.h @@ -25,8 +25,7 @@ FlatNamespaceFile(const MachOLinkingContext &context) : SharedLibraryFile("flat namespace") { } - const SharedLibraryAtom *exports(StringRef name, - bool dataSymbolOnly) const override { + const SharedLibraryAtom *exports(StringRef name) const override { _sharedLibraryAtoms.push_back( new (allocator()) MachOSharedLibraryAtom(*this, name, getDSOName(), false)); Index: lib/ReaderWriter/YAML/ReaderWriterYAML.cpp =================================================================== --- lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -575,22 +575,11 @@ return _noAbsoluteAtoms; } - File *find(StringRef name, bool dataSymbolOnly) override { - for (const ArchMember &member : _members) { - for (const lld::DefinedAtom *atom : member._content->defined()) { - if (name == atom->name()) { - if (!dataSymbolOnly) - return const_cast(member._content); - switch (atom->contentType()) { - case lld::DefinedAtom::typeData: - case lld::DefinedAtom::typeZeroFill: - return const_cast(member._content); - default: - break; - } - } - } - } + File *find(StringRef name) override { + for (const ArchMember &member : _members) + for (const lld::DefinedAtom *atom : member._content->defined()) + if (name == atom->name()) + return const_cast(member._content); return nullptr; }