LLVM 24.0.0git
HandleLookupInJITDylib.cpp
Go to the documentation of this file.
1//===- HandleLookupInJITDylib.cpp - Lookups in JITDylibs ------------------===//
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
12
13using namespace llvm;
14using namespace llvm::orc;
15
18 GetJITDylibForKeyFn GetJD) {
19 return [&ES, GetJD = std::move(GetJD)](
22 const std::vector<std::pair<StringRef, bool>> &Symbols) mutable {
23 JITDylibSP JD = GetJD(Key);
24 if (!JD)
25 return SendResult(make_error<StringError>(
26 "No JITDylib associated with key " + formatv("{0:x}", Key),
28
29 // Intern the names now: they refer into the argument buffer, which doesn't
30 // outlive this call. Names records the request order for the result.
31 std::vector<SymbolStringPtr> Names;
32 Names.reserve(Symbols.size());
34 for (auto &[Name, Required] : Symbols) {
35 Names.push_back(ES.intern(Name));
36 LS.add(Names.back(), Required
39 }
40
41 // The executor may name a symbol more than once, but the lookup needs a
42 // proper set. The result is rebuilt from Names, so it still has one entry
43 // per element of the request.
44 LS.mergeEntries();
45
46 auto &JDRef = *JD;
47 ES.lookup(
48 LookupKind::DLSym, {{&JDRef, JDLookupFlags}}, std::move(LS),
50 [JD = std::move(JD), Names = std::move(Names),
51 SendResult = std::move(SendResult)](Expected<SymbolMap> Syms) mutable {
52 if (!Syms)
53 return SendResult(Syms.takeError());
54
55 // A missing required symbol fails the lookup, so any name without a
56 // definition here was weakly referenced: report it as nullopt.
58 Result.reserve(Names.size());
59 for (auto &Name : Names) {
60 auto I = Syms->find(Name);
61 if (I != Syms->end())
62 Result.push_back(I->second.getAddress());
63 else
64 Result.push_back(std::nullopt);
65 }
66 SendResult(std::move(Result));
67 },
69 };
70}
#define I(x, y, z)
Definition MD5.cpp:57
Tagged union holding either a T or a Error.
Definition Error.h:485
An ExecutionSession represents a running JIT program.
Definition Core.h:1096
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition Core.h:1177
LLVM_ABI 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:1783
Represents an address in the executor process.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
unique_function is a type-erasing functor similar to std::function.
unique_function< void( unique_function< void(Expected< SymbolLookupResult >)> SendResult, ExecutorAddr Key, JITDylibLookupFlags JDLookupFlags, const std::vector< std::pair< StringRef, bool > > &Symbols)> HandleLookupInJITDylibFn
Handler for executor-initiated lookups in JITDylibs.
unique_function< JITDylibSP(ExecutorAddr Key)> GetJITDylibForKeyFn
Maps an executor-supplied key to the JITDylib that it identifies, returning null if the key identifie...
IntrusiveRefCntPtr< JITDylib > JITDylibSP
Definition Core.h:60
std::vector< std::optional< ExecutorAddr > > SymbolLookupResult
The result of looking up a SymbolLookupSet in the executor: one entry per element of the set,...
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
LLVM_ABI RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Definition Core.cpp:42
@ Ready
Emitted to memory, but waiting on transitive dependencies.
Definition Core.h:545
LLVM_ABI HandleLookupInJITDylibFn createLookupInJITDylibHandler(ExecutionSession &ES, GetJITDylibForKeyFn GetJD)
Create a handler for executor-initiated lookups in JITDylibs, callable via the ORC runtime's call-con...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340