LLVM 23.0.0git
EPCDynamicLibrarySearchGenerator.h
Go to the documentation of this file.
1//===------------ EPCDynamicLibrarySearchGenerator.h ------------*- C++ -*-===//
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//
9// Support loading and searching of dynamic libraries in an executor process
10// via the ExecutorProcessControl class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
15#define LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
16
21
22namespace llvm {
23namespace orc {
24
26
28public:
31
32 /// Create an EPCDynamicLibrarySearchGenerator that searches for symbols in
33 /// the library with the given handle.
34 ///
35 /// If the Allow predicate is given then only symbols matching the predicate
36 /// will be searched for. If the predicate is not given then all symbols will
37 /// be searched for.
38 ///
39 /// If \p AddAbsoluteSymbols is provided, it is used to add the symbols to the
40 /// \c JITDylib; otherwise it uses JD.define(absoluteSymbols(...)).
44 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr)
45 : ES(ES), DylibMgr(DylibMgr), H(H), Allow(std::move(Allow)),
46 AddAbsoluteSymbols(std::move(AddAbsoluteSymbols)) {}
47
48 /// Create an EPCDynamicLibrarySearchGenerator that resolves all symbols
49 /// matching the Allow predicate to null. This can be used to emulate linker
50 /// options like -weak-l / -weak_library where the library is missing at
51 /// runtime. (Note: here we're explicitly returning null for these symbols,
52 /// rather than returning no value at all for them, which is the usual
53 /// "missing symbol" behavior in ORC. This distinction shouldn't matter for
54 /// most use-cases).
56 ExecutionSession &ES, DylibManager &DylibMgr, SymbolPredicate Allow,
57 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr)
58 : ES(ES), DylibMgr(DylibMgr), Allow(std::move(Allow)),
59 AddAbsoluteSymbols(std::move(AddAbsoluteSymbols)) {}
60
61 /// Permanently loads the library at the given path and, on success, returns
62 /// an EPCDynamicLibrarySearchGenerator that will search it for symbol
63 /// definitions in the library. On failure returns the reason the library
64 /// failed to load.
66 Load(ExecutionSession &ES, DylibManager &DylibMgr, const char *LibraryPath,
67 SymbolPredicate Allow = SymbolPredicate(),
68 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr);
69
70 /// Creates a EPCDynamicLibrarySearchGenerator that searches for symbols in
71 /// the target process.
75 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr) {
76 return Load(ES, DylibMgr, nullptr, std::move(Allow),
77 std::move(AddAbsoluteSymbols));
78 }
79
80 Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
81 JITDylibLookupFlags JDLookupFlags,
82 const SymbolLookupSet &Symbols) override;
83
84private:
85 Error addAbsolutes(JITDylib &JD, SymbolMap Symbols);
86
88 DylibManager &DylibMgr;
89 std::optional<tpctypes::DylibHandle> H;
90 SymbolPredicate Allow;
91 AddAbsoluteSymbolsFn AddAbsoluteSymbols;
92};
93
94} // end namespace orc
95} // end namespace llvm
96
97#endif // LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
#define LLVM_ABI
Definition Compiler.h:213
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
#define H(x, y, z)
Definition MD5.cpp:56
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
Definition Core.h:876
friend class ExecutionSession
Definition Core.h:877
EPCDynamicLibrarySearchGenerator(ExecutionSession &ES, DylibManager &DylibMgr, SymbolPredicate Allow, AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Create an EPCDynamicLibrarySearchGenerator that resolves all symbols matching the Allow predicate to ...
unique_function< bool(const SymbolStringPtr &)> SymbolPredicate
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > Load(ExecutionSession &ES, DylibManager &DylibMgr, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Permanently loads the library at the given path and, on success, returns an EPCDynamicLibrarySearchGe...
unique_function< Error(JITDylib &, SymbolMap)> AddAbsoluteSymbolsFn
EPCDynamicLibrarySearchGenerator(ExecutionSession &ES, DylibManager &DylibMgr, tpctypes::DylibHandle H, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Create an EPCDynamicLibrarySearchGenerator that searches for symbols in the library with the given ha...
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > GetForTargetProcess(ExecutionSession &ES, DylibManager &DylibMgr, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Creates a EPCDynamicLibrarySearchGenerator that searches for symbols in the target process.
An ExecutionSession represents a running JIT program.
Definition Core.h:1355
ExecutorProcessControl supports interaction with a JIT target process.
Represents a JIT'd dynamic library.
Definition Core.h:919
Wraps state for a lookup-in-progress.
Definition Core.h:851
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition Core.h:199
Pointer to a pooled string representing a symbol name.
unique_function is a type-erasing functor similar to std::function.
ExecutorAddr DylibHandle
A handle used to represent a loaded dylib in the target process.
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition Core.h:151
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
LookupKind
Describes the kind of lookup being performed.
Definition Core.h:173
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870