Remove dead code for ELF.

The preload feature was buggy that we had disabled it even for ELF.

llvm-svn: 262194
This commit is contained in:
Rui Ueyama 2016-02-28 21:22:44 +00:00
parent 701c3250e5
commit 8cca07eacf
7 changed files with 3 additions and 136 deletions

View File

@ -11,7 +11,6 @@
#define LLD_CORE_ARCHIVE_LIBRARY_FILE_H
#include "lld/Core/File.h"
#include "lld/Core/Parallel.h"
#include <set>
namespace lld {
@ -38,12 +37,6 @@ public:
virtual std::error_code
parseAllMembers(std::vector<std::unique_ptr<File>> &result) = 0;
// Parses a member file containing a given symbol, so that when you
// need the file find() can return that immediately. Calling this function
// has no side effect other than pre-instantiating a file. Calling this
// function doesn't affect correctness.
virtual void preload(TaskGroup &group, StringRef symbolName) {}
protected:
/// only subclasses of ArchiveLibraryFile can be instantiated
ArchiveLibraryFile(StringRef path) : File(path, kindArchiveLibrary) {}

View File

@ -13,7 +13,6 @@
#include "lld/Core/Error.h"
#include "lld/Core/LLVM.h"
#include "lld/Core/Node.h"
#include "lld/Core/Parallel.h"
#include "lld/Core/Reference.h"
#include "lld/Core/Reader.h"
#include "llvm/Support/ErrorOr.h"
@ -309,8 +308,6 @@ public:
return std::error_code();
}
TaskGroup &getTaskGroup() { return _taskGroup; }
/// @}
protected:
LinkingContext(); // Must be subclassed
@ -354,7 +351,6 @@ protected:
private:
/// Validate the subclass bits. Only called by validate.
virtual bool validateImpl(raw_ostream &diagnostics) = 0;
TaskGroup _taskGroup;
};
} // end namespace lld

View File

@ -62,41 +62,6 @@ public:
}
};
/// \brief An implementation of future. std::future and std::promise in
/// old libstdc++ have a threading bug; there is a small chance that a
/// call of future::get throws an exception in the normal use case.
/// We want to use our own future implementation until we drop support
/// of old versions of libstdc++.
/// https://gcc.gnu.org/ml/gcc-patches/2014-05/msg01389.html
template<typename T> class Future {
public:
Future() : _hasValue(false) {}
void set(T &&val) {
assert(!_hasValue);
{
std::unique_lock<std::mutex> lock(_mutex);
_val = val;
_hasValue = true;
}
_cond.notify_all();
}
T &get() {
std::unique_lock<std::mutex> lock(_mutex);
if (_hasValue)
return _val;
_cond.wait(lock, [&] { return _hasValue; });
return _val;
}
private:
T _val;
bool _hasValue;
std::mutex _mutex;
std::condition_variable _cond;
};
// Classes in this namespace are implementation details of this header.
namespace internal {

View File

@ -64,7 +64,6 @@ private:
File *getFile(int &index);
/// \brief The main function that iterates over the files to resolve
void updatePreloadArchiveMap();
bool resolveUndefines();
void updateReferences();
void deadStripOptimize();
@ -76,7 +75,6 @@ private:
void markLive(const Atom *atom);
void addAtoms(const std::vector<const DefinedAtom *>&);
void maybePreloadArchiveMember(StringRef sym);
class MergedFile : public SimpleFile {
public:
@ -98,10 +96,6 @@ private:
std::map<File *, bool> _newUndefinesAdded;
size_t _fileIndex;
// Preloading
llvm::StringMap<ArchiveLibraryFile *> _archiveMap;
llvm::DenseSet<ArchiveLibraryFile *> _archiveSeen;
// List of undefined symbols.
std::vector<StringRef> _undefines;

View File

@ -36,10 +36,8 @@ ErrorOr<bool> Resolver::handleFile(File &file) {
for (const DefinedAtom *atom : file.defined())
doDefinedAtom(*atom);
for (const UndefinedAtom *atom : file.undefined()) {
if (doUndefinedAtom(*atom)) {
if (doUndefinedAtom(*atom))
undefAdded = true;
maybePreloadArchiveMember(atom->name());
}
}
for (const SharedLibraryAtom *atom : file.sharedLibrary())
doSharedLibraryAtom(*atom);
@ -98,7 +96,6 @@ ErrorOr<bool> Resolver::handleArchiveFile(File &file) {
bool dataSymbolOnly)->ErrorOr<bool> {
if (File *member = archiveFile->find(undefName, dataSymbolOnly)) {
member->setOrdinal(_ctx.getNextOrdinalAndIncrement());
updatePreloadArchiveMap();
return handleFile(*member);
}
return false;
@ -207,17 +204,6 @@ void Resolver::addAtoms(const std::vector<const DefinedAtom *> &newAtoms) {
doDefinedAtom(*newAtom);
}
// Instantiate an archive file member if there's a file containing a
// defined symbol for a given symbol name. Instantiation is done in a
// different worker thread and has no visible side effect.
void Resolver::maybePreloadArchiveMember(StringRef sym) {
auto it = _archiveMap.find(sym);
if (it == _archiveMap.end())
return;
ArchiveLibraryFile *archive = it->second;
archive->preload(_ctx.getTaskGroup(), sym);
}
// Returns true if at least one of N previous files has created an
// undefined symbol.
bool Resolver::undefinesAdded(int begin, int end) {
@ -248,23 +234,6 @@ File *Resolver::getFile(int &index) {
return cast<FileNode>(inputs[index++].get())->getFile();
}
// Update a map of Symbol -> ArchiveFile. The map is used for speculative
// file loading.
void Resolver::updatePreloadArchiveMap() {
std::vector<std::unique_ptr<Node>> &nodes = _ctx.getNodes();
for (int i = nodes.size() - 1; i >= 0; --i) {
auto *fnode = dyn_cast<FileNode>(nodes[i].get());
if (!fnode)
continue;
auto *archive = dyn_cast<ArchiveLibraryFile>(fnode->getFile());
if (!archive || _archiveSeen.count(archive))
continue;
_archiveSeen.insert(archive);
for (StringRef sym : archive->getDefinedSymbols())
_archiveMap[sym] = archive;
}
}
// Keep adding atoms until _ctx.getNextFile() returns an error. This
// function is where undefined atoms are resolved.
bool Resolver::resolveUndefines() {
@ -287,7 +256,6 @@ bool Resolver::resolveUndefines() {
}
DEBUG_WITH_TYPE("resolver",
llvm::dbgs() << "Loaded file: " << file->path() << "\n");
updatePreloadArchiveMap();
switch (file->kind()) {
case File::kindErrorObject:
case File::kindNormalizedObject:
@ -503,7 +471,6 @@ void Resolver::removeCoalescedAwayAtoms() {
bool Resolver::resolve() {
DEBUG_WITH_TYPE("resolver",
llvm::dbgs() << "******** Resolving atom references:\n");
updatePreloadArchiveMap();
if (!resolveUndefines())
return false;
updateReferences();

View File

@ -11,7 +11,6 @@
#include "lld/Core/File.h"
#include "lld/Core/Instrumentation.h"
#include "lld/Core/LLVM.h"
#include "lld/Core/Parallel.h"
#include "lld/Core/PassManager.h"
#include "lld/Core/Reader.h"
#include "lld/Core/Resolver.h"
@ -84,7 +83,7 @@ bool Driver::link(LinkingContext &ctx, raw_ostream &diagnostics) {
for (std::unique_ptr<Node> &ie : ctx.getNodes())
if (FileNode *node = dyn_cast<FileNode>(ie.get()))
ctx.getTaskGroup().spawn([node] { node->getFile()->parse(); });
node->getFile()->parse();
std::vector<std::unique_ptr<File>> internalFiles;
ctx.createInternalFiles(internalFiles);
@ -108,10 +107,8 @@ bool Driver::link(LinkingContext &ctx, raw_ostream &diagnostics) {
// Do core linking.
ScopedTask resolveTask(getDefaultDomain(), "Resolve");
Resolver resolver(ctx);
if (!resolver.resolve()) {
ctx.getTaskGroup().sync();
if (!resolver.resolve())
return false;
}
std::unique_ptr<SimpleFile> merged = resolver.resultFile();
resolveTask.end();

View File

@ -10,7 +10,6 @@
#include "lld/Core/ArchiveLibraryFile.h"
#include "lld/Core/LLVM.h"
#include "lld/Core/LinkingContext.h"
#include "lld/Core/Parallel.h"
#include "lld/Driver/Driver.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
@ -64,17 +63,6 @@ public:
_membersInstantiated.insert(memberStart);
// Check if a file is preloaded.
{
std::lock_guard<std::mutex> lock(_mutex);
auto it = _preloaded.find(memberStart);
if (it != _preloaded.end()) {
std::unique_ptr<Future<File *>> &p = it->second;
Future<File *> *future = p.get();
return future->get();
}
}
std::unique_ptr<File> result;
if (instantiateMember(ci, result))
return nullptr;
@ -86,38 +74,6 @@ public:
return file;
}
// Instantiate a member file containing a given symbol name.
void preload(TaskGroup &group, StringRef name) override {
auto member = _symbolMemberMap.find(name);
if (member == _symbolMemberMap.end())
return;
Archive::child_iterator ci = member->second;
if (ci->getError())
return;
// Do nothing if a member is already instantiated.
ErrorOr<StringRef> buf = (*ci)->getBuffer();
if (!buf)
return;
const char *memberStart = buf->data();
if (_membersInstantiated.count(memberStart))
return;
std::lock_guard<std::mutex> lock(_mutex);
if (_preloaded.find(memberStart) != _preloaded.end())
return;
// Instantiate the member
auto *future = new Future<File *>();
_preloaded[memberStart] = std::unique_ptr<Future<File *>>(future);
group.spawn([=] {
std::unique_ptr<File> result;
std::error_code ec = instantiateMember(ci, result);
future->set(ec ? nullptr : result.release());
});
}
/// \brief parse each member
std::error_code
parseAllMembers(std::vector<std::unique_ptr<File>> &result) override {
@ -262,7 +218,6 @@ private:
InstantiatedSet _membersInstantiated;
bool _logLoading;
std::vector<std::unique_ptr<MemoryBuffer>> _memberBuffers;
std::map<const char *, std::unique_ptr<Future<File *>>> _preloaded;
std::mutex _mutex;
FileVector _filesReturned;
};