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
, ExecutorAddress
*>> Pairs
,
20 SymbolLookupFlags LookupFlags
) {
22 SymbolLookupSet Symbols
;
23 for (auto &KV
: Pairs
)
24 Symbols
.add(KV
.first
, LookupFlags
);
27 K
, SearchOrder
, 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
);
34 KV
.second
->setValue((I
!= Result
->end()) ? I
->second
.getAddress()
37 OnRec(Error::success());
39 NoDependenciesToRegister
);
42 Error
lookupAndRecordAddrs(
43 ExecutionSession
&ES
, LookupKind K
, const JITDylibSearchOrder
&SearchOrder
,
44 std::vector
<std::pair
<SymbolStringPtr
, ExecutorAddress
*>> 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
, Pairs
, LookupFlags
);
54 Error
lookupAndRecordAddrs(
55 ExecutorProcessControl
&EPC
, tpctypes::DylibHandle H
,
56 std::vector
<std::pair
<SymbolStringPtr
, ExecutorAddress
*>> Pairs
,
57 SymbolLookupFlags LookupFlags
) {
59 SymbolLookupSet Symbols
;
60 for (auto &KV
: Pairs
)
61 Symbols
.add(KV
.first
, LookupFlags
);
63 ExecutorProcessControl::LookupRequest
LR(H
, Symbols
);
64 auto Result
= EPC
.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
->setValue(Result
->front()[I
]);
78 return Error::success();
81 } // End namespace orc.
82 } // End namespace llvm.