1 //===------- LookupAndRecordAddrs.h - Symbol lookup support utility -------===//
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/LookupAndRecordAddrs.h"
16 void lookupAndRecordAddrs(
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
) {
22 SymbolLookupSet Symbols
;
23 for (auto &KV
: Pairs
)
24 Symbols
.add(KV
.first
, LookupFlags
);
27 K
, SearchOrder
, std::move(Symbols
), SymbolState::Ready
,
28 [Pairs
= std::move(Pairs
),
29 OnRec
= std::move(OnRecorded
)](Expected
<SymbolMap
> Result
) mutable {
31 return OnRec(Result
.takeError());
32 for (auto &KV
: Pairs
) {
33 auto I
= Result
->find(KV
.first
);
35 I
!= Result
->end() ? I
->second
.getAddress() : orc::ExecutorAddr();
37 OnRec(Error::success());
39 NoDependenciesToRegister
);
42 Error
lookupAndRecordAddrs(
43 ExecutionSession
&ES
, LookupKind K
, const JITDylibSearchOrder
&SearchOrder
,
44 std::vector
<std::pair
<SymbolStringPtr
, ExecutorAddr
*>> Pairs
,
45 SymbolLookupFlags LookupFlags
) {
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
);
54 Error
lookupAndRecordAddrs(
55 ExecutorProcessControl
&EPC
, tpctypes::DylibHandle H
,
56 std::vector
<std::pair
<SymbolStringPtr
, ExecutorAddr
*>> Pairs
,
57 SymbolLookupFlags LookupFlags
) {
59 SymbolLookupSet Symbols
;
60 for (auto &KV
: Pairs
)
61 Symbols
.add(KV
.first
, LookupFlags
);
63 DylibManager::LookupRequest
LR(H
, Symbols
);
64 auto Result
= EPC
.getDylibMgr().lookupSymbols(LR
);
66 return Result
.takeError();
68 if (Result
->size() != 1)
69 return make_error
<StringError
>("Error in lookup result",
70 inconvertibleErrorCode());
71 if (Result
->front().size() != Pairs
.size())
72 return make_error
<StringError
>("Error in lookup result elements",
73 inconvertibleErrorCode());
75 for (unsigned I
= 0; I
!= Pairs
.size(); ++I
)
76 *Pairs
[I
].second
= Result
->front()[I
].getAddress();
78 return Error::success();
81 } // End namespace orc.
82 } // End namespace llvm.