Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ class LibraryManager {
return FilteredView(Libraries.begin(), Libraries.end(), S, K);
}

using LibraryFilterFn = std::function<bool(const LibraryInfo &)>;
void getLibraries(LibState S, PathType K,
std::vector<std::shared_ptr<LibraryInfo>> &Outs,
LibraryFilterFn Filter = nullptr) const {
std::shared_lock<std::shared_mutex> Lock(Mtx);
for (const auto &[_, Entry] : Libraries) {
const auto &Info = *Entry;
if (Info.getKind() != K || Info.getState() != S)
continue;
if (Filter && !Filter(Info))
continue;
Outs.push_back(Entry);
}
}

void forEachLibrary(const LibraryVisitor &visitor) const {
std::unique_lock<std::shared_mutex> Lock(Mtx);
for (const auto &[_, entry] : Libraries) {
Expand All @@ -220,14 +235,14 @@ class LibraryManager {
}

bool isLoaded(StringRef Path) const {
std::unique_lock<std::shared_mutex> Lock(Mtx);
std::shared_lock<std::shared_mutex> Lock(Mtx);
if (auto It = Libraries.find(Path.str()); It != Libraries.end())
return It->second->getState() == LibState::Loaded;
return false;
}

bool isQueried(StringRef Path) const {
std::unique_lock<std::shared_mutex> Lock(Mtx);
std::shared_lock<std::shared_mutex> Lock(Mtx);
if (auto It = Libraries.find(Path.str()); It != Libraries.end())
return It->second->getState() == LibState::Queried;
return false;
Expand Down
33 changes: 15 additions & 18 deletions llvm/lib/ExecutionEngine/Orc/TargetProcess/LibraryResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ class SymbolSearchContext {
public:
SymbolSearchContext(SymbolQuery &Q) : Q(Q) {}

bool hasSearched(LibraryInfo *Lib) const { return Searched.count(Lib); }
bool hasSearched(const LibraryInfo *Lib) const { return Searched.count(Lib); }

void markSearched(LibraryInfo *Lib) { Searched.insert(Lib); }
void markSearched(const LibraryInfo *Lib) { Searched.insert(Lib); }

inline bool allResolved() const { return Q.allResolved(); }

SymbolQuery &query() { return Q; }

private:
SymbolQuery &Q;
DenseSet<LibraryInfo *> Searched;
DenseSet<const LibraryInfo *> Searched;
};

void LibraryResolver::resolveSymbolsInLibrary(
Expand Down Expand Up @@ -226,19 +226,18 @@ void LibraryResolver::resolveSymbolsInLibrary(
return EnumerateResult::Continue;
},
Opts);
};

if (!Lib.hasFilter()) {
LLVM_DEBUG(dbgs() << "Building filter for library: " << Lib.getFullPath()
<< "\n";);
enumerateSymbolsIfNeeded();
if (DiscoveredSymbols.empty()) {
LLVM_DEBUG(dbgs() << " No symbols and remove library : "
<< Lib.getFullPath() << "\n";);
LibMgr.removeLibrary(Lib.getFullPath());
return;
}
};

if (!Lib.hasFilter()) {
LLVM_DEBUG(dbgs() << "Building filter for library: " << Lib.getFullPath()
<< "\n";);
enumerateSymbolsIfNeeded();
SmallVector<StringRef> SymbolVec;
SymbolVec.reserve(DiscoveredSymbols.size());
for (const auto &KV : DiscoveredSymbols)
Expand Down Expand Up @@ -288,24 +287,22 @@ void LibraryResolver::searchSymbolsInLibraries(

SymbolSearchContext Ctx(Q);
while (!Ctx.allResolved()) {
std::vector<std::shared_ptr<LibraryInfo>> Libs;
LibMgr.getLibraries(S, K, Libs, [&](const LibraryInfo &Lib) {
return !Ctx.hasSearched(&Lib);
});

for (auto &Lib : LibMgr.getView(S, K)) {
if (Ctx.hasSearched(Lib.get()))
continue;
if (Libs.empty() && !scanLibrariesIfNeeded(K, scanBatchSize))
break; // no more new libs to scan

for (auto &Lib : Libs) {
// can use Async here?
resolveSymbolsInLibrary(*Lib, Ctx.query(), Config.Options);
Ctx.markSearched(Lib.get());

if (Ctx.allResolved())
return;
}

if (Ctx.allResolved())
return;

if (!scanLibrariesIfNeeded(K, scanBatchSize))
break; // no more new libs to scan
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void handleError(Error Err, StringRef context = "") {
}

bool ObjectFileLoader::isArchitectureCompatible(const object::ObjectFile &Obj) {
Triple HostTriple(sys::getDefaultTargetTriple());
Triple HostTriple(sys::getProcessTriple());
Triple ObjTriple = Obj.makeTriple();

LLVM_DEBUG({
Expand Down