LLVM 22.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
20
21namespace llvm {
22namespace orc {
23
25
27public:
30
31 /// Create an EPCDynamicLibrarySearchGenerator that searches for symbols in
32 /// the library with the given handle.
33 ///
34 /// If the Allow predicate is given then only symbols matching the predicate
35 /// will be searched for. If the predicate is not given then all symbols will
36 /// be searched for.
37 ///
38 /// If \p AddAbsoluteSymbols is provided, it is used to add the symbols to the
39 /// \c JITDylib; otherwise it uses JD.define(absoluteSymbols(...)).
43 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr)
44 : EPC(ES.getExecutorProcessControl()), H(H), Allow(std::move(Allow)),
45 AddAbsoluteSymbols(std::move(AddAbsoluteSymbols)) {}
46
47 /// Create an EPCDynamicLibrarySearchGenerator that resolves all symbols
48 /// matching the Allow predicate to null. This can be used to emulate linker
49 /// options like -weak-l / -weak_library where the library is missing at
50 /// runtime. (Note: here we're explicitly returning null for these symbols,
51 /// rather than returning no value at all for them, which is the usual
52 /// "missing symbol" behavior in ORC. This distinction shouldn't matter for
53 /// most use-cases).
56 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr)
57 : EPC(ES.getExecutorProcessControl()), Allow(std::move(Allow)),
58 AddAbsoluteSymbols(std::move(AddAbsoluteSymbols)) {}
59
60 /// Permanently loads the library at the given path and, on success, returns
61 /// an EPCDynamicLibrarySearchGenerator that will search it for symbol
62 /// definitions in the library. On failure returns the reason the library
63 /// failed to load.
65 Load(ExecutionSession &ES, const char *LibraryPath,
66 SymbolPredicate Allow = SymbolPredicate(),
67 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr);
68
69 /// Creates a EPCDynamicLibrarySearchGenerator that searches for symbols in
70 /// the target process.
74 AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr) {
75 return Load(ES, nullptr, std::move(Allow), std::move(AddAbsoluteSymbols));
76 }
77
78 Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
79 JITDylibLookupFlags JDLookupFlags,
80 const SymbolLookupSet &Symbols) override;
81
82private:
83 Error addAbsolutes(JITDylib &JD, SymbolMap Symbols);
84
86 std::optional<tpctypes::DylibHandle> H;
87 SymbolPredicate Allow;
88 AddAbsoluteSymbolsFn AddAbsoluteSymbols;
89};
90
91} // end namespace orc
92} // end namespace llvm
93
94#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:57
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:859
friend class ExecutionSession
Definition Core.h:860
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > Load(ExecutionSession &ES, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Permanently loads the library at the given path and, on success, returns an EPCDynamicLibrarySearchGe...
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > GetForTargetProcess(ExecutionSession &ES, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Creates a EPCDynamicLibrarySearchGenerator that searches for symbols in the target process.
unique_function< bool(const SymbolStringPtr &)> SymbolPredicate
EPCDynamicLibrarySearchGenerator(ExecutionSession &ES, SymbolPredicate Allow, AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Create an EPCDynamicLibrarySearchGenerator that resolves all symbols matching the Allow predicate to ...
unique_function< Error(JITDylib &, SymbolMap)> AddAbsoluteSymbolsFn
EPCDynamicLibrarySearchGenerator(ExecutionSession &ES, tpctypes::DylibHandle H, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Create an EPCDynamicLibrarySearchGenerator that searches for symbols in the library with the given ha...
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:902
Wraps state for a lookup-in-progress.
Definition Core.h:834
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition Core.h:195
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:147
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:169
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:1869
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851