Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:52

0001 //===------------ EPCDynamicLibrarySearchGenerator.h ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Support loading and searching of dynamic libraries in an executor process
0010 // via the ExecutorProcessControl class.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
0015 #define LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H
0016 
0017 #include "llvm/ADT/FunctionExtras.h"
0018 #include "llvm/ExecutionEngine/Orc/Core.h"
0019 
0020 namespace llvm {
0021 namespace orc {
0022 
0023 class ExecutorProcessControl;
0024 
0025 class EPCDynamicLibrarySearchGenerator : public DefinitionGenerator {
0026 public:
0027   using SymbolPredicate = unique_function<bool(const SymbolStringPtr &)>;
0028   using AddAbsoluteSymbolsFn = unique_function<Error(JITDylib &, SymbolMap)>;
0029 
0030   /// Create a DynamicLibrarySearchGenerator that searches for symbols in the
0031   /// library with the given handle.
0032   ///
0033   /// If the Allow predicate is given then only symbols matching the predicate
0034   /// will be searched for. If the predicate is not given then all symbols will
0035   /// be searched for.
0036   ///
0037   /// If \p AddAbsoluteSymbols is provided, it is used to add the symbols to the
0038   /// \c JITDylib; otherwise it uses JD.define(absoluteSymbols(...)).
0039   EPCDynamicLibrarySearchGenerator(
0040       ExecutionSession &ES, tpctypes::DylibHandle H,
0041       SymbolPredicate Allow = SymbolPredicate(),
0042       AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr)
0043       : EPC(ES.getExecutorProcessControl()), H(H), Allow(std::move(Allow)),
0044         AddAbsoluteSymbols(std::move(AddAbsoluteSymbols)) {}
0045 
0046   /// Permanently loads the library at the given path and, on success, returns
0047   /// a DynamicLibrarySearchGenerator that will search it for symbol definitions
0048   /// in the library. On failure returns the reason the library failed to load.
0049   static Expected<std::unique_ptr<EPCDynamicLibrarySearchGenerator>>
0050   Load(ExecutionSession &ES, const char *LibraryPath,
0051        SymbolPredicate Allow = SymbolPredicate(),
0052        AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr);
0053 
0054   /// Creates a EPCDynamicLibrarySearchGenerator that searches for symbols in
0055   /// the target process.
0056   static Expected<std::unique_ptr<EPCDynamicLibrarySearchGenerator>>
0057   GetForTargetProcess(ExecutionSession &ES,
0058                       SymbolPredicate Allow = SymbolPredicate(),
0059                       AddAbsoluteSymbolsFn AddAbsoluteSymbols = nullptr) {
0060     return Load(ES, nullptr, std::move(Allow), std::move(AddAbsoluteSymbols));
0061   }
0062 
0063   Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
0064                       JITDylibLookupFlags JDLookupFlags,
0065                       const SymbolLookupSet &Symbols) override;
0066 
0067 private:
0068   ExecutorProcessControl &EPC;
0069   tpctypes::DylibHandle H;
0070   SymbolPredicate Allow;
0071   AddAbsoluteSymbolsFn AddAbsoluteSymbols;
0072 };
0073 
0074 } // end namespace orc
0075 } // end namespace llvm
0076 
0077 #endif // LLVM_EXECUTIONENGINE_ORC_EPCDYNAMICLIBRARYSEARCHGENERATOR_H