LLVM  14.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 
13 namespace llvm {
14 namespace 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, 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->setValue((I != Result->end()) ? I->second.getAddress()
35  : 0);
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, 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->setValue(Result->front()[I]);
77 
78  return Error::success();
79 }
80 
81 } // End namespace orc.
82 } // End namespace llvm.
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::unique_function
unique_function is a type-erasing functor similar to std::function.
Definition: FunctionExtras.h:56
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:175
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::orc::ExecutorProcessControl
ExecutorProcessControl supports interaction with a JIT target process.
Definition: ExecutorProcessControl.h:38
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::orc::LookupKind
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:149
llvm::orc::SymbolLookupFlags
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition: Core.h:137
llvm::orc::NoDependenciesToRegister
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Definition: Core.cpp:34
llvm::orc::tpctypes::DylibHandle
JITTargetAddress DylibHandle
A handle used to represent a loaded dylib in the target process.
Definition: TargetProcessControlTypes.h:142
llvm::orc::ExecutorProcessControl::LookupRequest
A pair of a dylib and a set of symbols to be looked up.
Definition: ExecutorProcessControl.h:165
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
LookupAndRecordAddrs.h
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::orc::JITDylibSearchOrder
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:154
llvm::orc::SymbolState::Ready
@ Ready
Emitted to memory, but waiting on transitive dependencies.
for
this could be done in SelectionDAGISel along with other special for
Definition: README.txt:104
H
#define H(x, y, z)
Definition: MD5.cpp:58
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1275
llvm::orc::ExecutionSession::lookup
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:1951
llvm::orc::ExecutorProcessControl::lookupSymbols
virtual Expected< std::vector< tpctypes::LookupResult > > lookupSymbols(ArrayRef< LookupRequest > Request)=0
Search for symbols in the target process.
llvm::orc::lookupAndRecordAddrs
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.
Definition: LookupAndRecordAddrs.cpp:16