LLVM 20.0.0git
LookupAndRecordAddrs.cpp
Go to the documentation of this file.
1//===------- LookupAndRecordAddrs.h - Symbol lookup support utility -------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10
11#include <future>
12
13namespace llvm {
14namespace orc {
15
17 unique_function<void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K,
18 const JITDylibSearchOrder &SearchOrder,
19 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
20 SymbolLookupFlags LookupFlags) {
21
22 SymbolLookupSet Symbols;
23 for (auto &KV : Pairs)
24 Symbols.add(KV.first, LookupFlags);
25
26 ES.lookup(
27 K, SearchOrder, std::move(Symbols), SymbolState::Ready,
28 [Pairs = std::move(Pairs),
29 OnRec = std::move(OnRecorded)](Expected<SymbolMap> Result) mutable {
30 if (!Result)
31 return OnRec(Result.takeError());
32 for (auto &KV : Pairs) {
33 auto I = Result->find(KV.first);
34 *KV.second =
35 I != Result->end() ? I->second.getAddress() : orc::ExecutorAddr();
36 }
37 OnRec(Error::success());
38 },
40}
41
43 ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder,
44 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
45 SymbolLookupFlags LookupFlags) {
46
47 std::promise<MSVCPError> ResultP;
48 auto ResultF = ResultP.get_future();
49 lookupAndRecordAddrs([&](Error Err) { ResultP.set_value(std::move(Err)); },
50 ES, K, SearchOrder, std::move(Pairs), LookupFlags);
51 return ResultF.get();
52}
53
56 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
57 SymbolLookupFlags LookupFlags) {
58
59 SymbolLookupSet Symbols;
60 for (auto &KV : Pairs)
61 Symbols.add(KV.first, LookupFlags);
62
64 auto Result = EPC.lookupSymbols(LR);
65 if (!Result)
66 return Result.takeError();
67
68 if (Result->size() != 1)
69 return make_error<StringError>("Error in lookup result",
71 if (Result->front().size() != Pairs.size())
72 return make_error<StringError>("Error in lookup result elements",
74
75 for (unsigned I = 0; I != Pairs.size(); ++I)
76 *Pairs[I].second = Result->front()[I].getAddress();
77
78 return Error::success();
79}
80
81} // End namespace orc.
82} // End namespace llvm.
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
#define I(x, y, z)
Definition: MD5.cpp:58
#define H(x, y, z)
Definition: MD5.cpp:57
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
An ExecutionSession represents a running JIT program.
Definition: Core.h:1431
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Definition: Core.cpp:1810
Represents an address in the executor process.
ExecutorProcessControl supports interaction with a JIT target process.
Expected< std::vector< tpctypes::LookupResult > > lookupSymbols(ArrayRef< LookupRequest > Request)
Search for symbols in the target process.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:183
unique_function is a type-erasing functor similar to std::function.
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition: Core.h:162
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition: Core.h:145
void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddr * > > Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddrs.
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:157
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Definition: Core.cpp:37
@ Ready
Emitted to memory, but waiting on transitive dependencies.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
A pair of a dylib and a set of symbols to be looked up.