1 //===---------------- TPCDynamicLibrarySearchGenerator.cpp ----------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h"
14 Expected<std::unique_ptr<TPCDynamicLibrarySearchGenerator>>
15 TPCDynamicLibrarySearchGenerator::Load(TargetProcessControl &TPC,
16 const char *LibraryPath,
17 SymbolPredicate Allow) {
18 auto Handle = TPC.loadDylib(LibraryPath);
20 return Handle.takeError();
22 return std::make_unique<TPCDynamicLibrarySearchGenerator>(TPC, *Handle,
26 Error TPCDynamicLibrarySearchGenerator::tryToGenerate(
27 LookupState &LS, LookupKind K, JITDylib &JD,
28 JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
31 return Error::success();
33 SymbolLookupSet LookupSymbols;
35 for (auto &KV : Symbols) {
36 // Skip symbols that don't match the filter.
37 if (Allow && !Allow(KV.first))
39 LookupSymbols.add(KV.first, SymbolLookupFlags::WeaklyReferencedSymbol);
44 TargetProcessControl::LookupRequestElement Request(H, LookupSymbols);
45 auto Result = TPC.lookupSymbols(Request);
47 return Result.takeError();
49 assert(Result->size() == 1 && "Results for more than one library returned");
50 assert(Result->front().size() == LookupSymbols.size() &&
51 "Result has incorrect number of elements");
53 SymbolNameVector MissingSymbols;
54 auto ResultI = Result->front().begin();
55 for (auto &KV : LookupSymbols)
57 NewSymbols[KV.first] =
58 JITEvaluatedSymbol(*ResultI++, JITSymbolFlags::Exported);
60 // If there were no resolved symbols bail out.
61 if (NewSymbols.empty())
62 return Error::success();
64 // Define resolved symbols.
65 return JD.define(absoluteSymbols(std::move(NewSymbols)));
68 } // end namespace orc
69 } // end namespace llvm