ExecutorAddr was introduced in b8e5f91816 as an eventual replacement for
JITTargetAddress. ExecutorSymbolDef is introduced in this patch as a
replacement for JITEvaluatedSymbol: ExecutorSymbolDef is an (ExecutorAddr,
JITSymbolFlags) pair, where JITEvaluatedSymbol was a (JITTargetAddress,
JITSymbolFlags) pair.
A number of APIs had already migrated from JITTargetAddress to ExecutorAddr,
but many of ORC's internals were still using the older type. This patch aims
to address that.
Some public APIs are affected as well. If you need to migrate your APIs you can
use the following operations:
* ExecutorAddr::toPtr replaces jitTargetAddressToPointer and
jitTargetAddressToFunction.
* ExecutorAddr::fromPtr replace pointerToJITTargetAddress.
* ExecutorAddr(JITTargetAddress) creates an ExecutorAddr value from a
JITTargetAddress.
* ExecutorAddr::getValue() creates a JITTargetAddress value from an
ExecutorAddr.
JITTargetAddress and JITEvaluatedSymbol will remain in JITSymbol.h for now, but
the aim will be to eventually deprecate and remove these types (probably when
MCJIT and RuntimeDyld are deprecated).
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
//===---------------- EPCDynamicLibrarySearchGenerator.cpp ----------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
|
|
Expected<std::unique_ptr<EPCDynamicLibrarySearchGenerator>>
|
|
EPCDynamicLibrarySearchGenerator::Load(ExecutionSession &ES,
|
|
const char *LibraryPath,
|
|
SymbolPredicate Allow) {
|
|
auto Handle = ES.getExecutorProcessControl().loadDylib(LibraryPath);
|
|
if (!Handle)
|
|
return Handle.takeError();
|
|
|
|
return std::make_unique<EPCDynamicLibrarySearchGenerator>(ES, *Handle,
|
|
std::move(Allow));
|
|
}
|
|
|
|
Error EPCDynamicLibrarySearchGenerator::tryToGenerate(
|
|
LookupState &LS, LookupKind K, JITDylib &JD,
|
|
JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
|
|
|
|
if (Symbols.empty())
|
|
return Error::success();
|
|
|
|
SymbolLookupSet LookupSymbols;
|
|
|
|
for (auto &KV : Symbols) {
|
|
// Skip symbols that don't match the filter.
|
|
if (Allow && !Allow(KV.first))
|
|
continue;
|
|
LookupSymbols.add(KV.first, SymbolLookupFlags::WeaklyReferencedSymbol);
|
|
}
|
|
|
|
SymbolMap NewSymbols;
|
|
|
|
ExecutorProcessControl::LookupRequest Request(H, LookupSymbols);
|
|
auto Result = EPC.lookupSymbols(Request);
|
|
if (!Result)
|
|
return Result.takeError();
|
|
|
|
assert(Result->size() == 1 && "Results for more than one library returned");
|
|
assert(Result->front().size() == LookupSymbols.size() &&
|
|
"Result has incorrect number of elements");
|
|
|
|
auto ResultI = Result->front().begin();
|
|
for (auto &KV : LookupSymbols) {
|
|
if (*ResultI)
|
|
NewSymbols[KV.first] = {*ResultI, JITSymbolFlags::Exported};
|
|
++ResultI;
|
|
}
|
|
|
|
// If there were no resolved symbols bail out.
|
|
if (NewSymbols.empty())
|
|
return Error::success();
|
|
|
|
// Define resolved symbols.
|
|
return JD.define(absoluteSymbols(std::move(NewSymbols)));
|
|
}
|
|
|
|
} // end namespace orc
|
|
} // end namespace llvm
|