LLVM  16.0.0git
SimpleExecutorDylibManager.cpp
Go to the documentation of this file.
1 //===--- SimpleExecutorDylibManager.cpp - Executor-side dylib management --===//
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 
10 
13 
14 #define DEBUG_TYPE "orc"
15 
16 namespace llvm {
17 namespace orc {
18 namespace rt_bootstrap {
19 
21  assert(Dylibs.empty() && "shutdown not called?");
22 }
23 
25 SimpleExecutorDylibManager::open(const std::string &Path, uint64_t Mode) {
26  if (Mode != 0)
27  return make_error<StringError>("open: non-zero mode bits not yet supported",
29 
30  const char *PathCStr = Path.empty() ? nullptr : Path.c_str();
31  std::string ErrMsg;
32 
33  auto DL = sys::DynamicLibrary::getPermanentLibrary(PathCStr, &ErrMsg);
34  if (!DL.isValid())
35  return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
36 
37  std::lock_guard<std::mutex> Lock(M);
38  auto H = ExecutorAddr::fromPtr(DL.getOSSpecificHandle());
39  Dylibs.insert(DL.getOSSpecificHandle());
40  return H;
41 }
42 
45  const RemoteSymbolLookupSet &L) {
46  std::vector<ExecutorAddr> Result;
47  auto DL = sys::DynamicLibrary(H.toPtr<void *>());
48 
49  for (const auto &E : L) {
50  if (E.Name.empty()) {
51  if (E.Required)
52  return make_error<StringError>("Required address for empty symbol \"\"",
54  else
55  Result.push_back(ExecutorAddr());
56  } else {
57 
58  const char *DemangledSymName = E.Name.c_str();
59 #ifdef __APPLE__
60  if (E.Name.front() != '_')
61  return make_error<StringError>(Twine("MachO symbol \"") + E.Name +
62  "\" missing leading '_'",
64  ++DemangledSymName;
65 #endif
66 
67  void *Addr = DL.getAddressOfSymbol(DemangledSymName);
68  if (!Addr && E.Required)
69  return make_error<StringError>(Twine("Missing definition for ") +
70  DemangledSymName,
72 
73  Result.push_back(ExecutorAddr::fromPtr(Addr));
74  }
75  }
76 
77  return Result;
78 }
79 
81 
82  DylibSet DS;
83  {
84  std::lock_guard<std::mutex> Lock(M);
85  std::swap(DS, Dylibs);
86  }
87 
88  // There is no removal of dylibs at the moment, so nothing to do here.
89  return Error::success();
90 }
91 
96  ExecutorAddr::fromPtr(&openWrapper);
98  ExecutorAddr::fromPtr(&lookupWrapper);
99 }
100 
102 SimpleExecutorDylibManager::openWrapper(const char *ArgData, size_t ArgSize) {
103  return shared::
105  ArgData, ArgSize,
108  .release();
109 }
110 
112 SimpleExecutorDylibManager::lookupWrapper(const char *ArgData, size_t ArgSize) {
113  return shared::
115  ArgData, ArgSize,
118  .release();
119 }
120 
121 } // namespace rt_bootstrap
122 } // end namespace orc
123 } // end namespace llvm
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:31
llvm::orc::ExecutorAddr::fromPtr
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
Definition: ExecutorAddress.h:80
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::orc::RemoteSymbolLookupSet
std::vector< RemoteSymbolLookupSetElement > RemoteSymbolLookupSet
Definition: SimpleRemoteEPCUtils.h:146
llvm::orc::shared::CWrapperFunctionResult
Definition: WrapperFunctionUtils.h:33
SimpleExecutorDylibManager.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
handle
then ret i32 result Tail recursion elimination should handle
Definition: README.txt:355
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::sys::DynamicLibrary
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
Definition: DynamicLibrary.h:33
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::orc::rt::SimpleExecutorDylibManagerLookupWrapperName
const char * SimpleExecutorDylibManagerLookupWrapperName
Definition: OrcRTBridge.cpp:19
llvm::sys::DynamicLibrary::getPermanentLibrary
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path using the library load operatio...
Definition: DynamicLibrary.cpp:165
llvm::orc::rt::SimpleExecutorDylibManagerInstanceName
const char * SimpleExecutorDylibManagerInstanceName
Definition: OrcRTBridge.cpp:15
FormatVariadic.h
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:110
llvm::DenseSet< void * >
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::detail::DenseSetImpl::empty
bool empty() const
Definition: DenseSet.h:80
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::open
Expected< tpctypes::DylibHandle > open(const std::string &Path, uint64_t Mode)
Definition: SimpleExecutorDylibManager.cpp:25
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:853
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:264
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::shutdown
Error shutdown() override
Definition: SimpleExecutorDylibManager.cpp:80
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::lookup
Expected< std::vector< ExecutorAddr > > lookup(tpctypes::DylibHandle H, const RemoteSymbolLookupSet &L)
Definition: SimpleExecutorDylibManager.cpp:44
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
H
#define H(x, y, z)
Definition: MD5.cpp:57
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::~SimpleExecutorDylibManager
virtual ~SimpleExecutorDylibManager()
Definition: SimpleExecutorDylibManager.cpp:20
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::addBootstrapSymbols
void addBootstrapSymbols(StringMap< ExecutorAddr > &M) override
Definition: SimpleExecutorDylibManager.cpp:92
llvm::orc::shared::makeMethodWrapperHandler
MethodWrapperHandler< RetT, ClassT, ArgTs... > makeMethodWrapperHandler(RetT(ClassT::*Method)(ArgTs...))
Create a MethodWrapperHandler object from the given method pointer.
Definition: WrapperFunctionUtils.h:617
llvm::orc::rt::SimpleExecutorDylibManagerOpenWrapperName
const char * SimpleExecutorDylibManagerOpenWrapperName
Definition: OrcRTBridge.cpp:17
OrcRTBridge.h