LLVM  14.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  Dylibs[NextId] = std::move(DL);
39  return NextId++;
40 }
41 
44  const RemoteSymbolLookupSet &L) {
45  std::vector<ExecutorAddr> Result;
46 
47  std::lock_guard<std::mutex> Lock(M);
48  auto I = Dylibs.find(H);
49  if (I == Dylibs.end())
50  return make_error<StringError>("No dylib for handle " + formatv("{0:x}", H),
52  auto &DL = I->second;
53 
54  for (const auto &E : L) {
55 
56  if (E.Name.empty()) {
57  if (E.Required)
58  return make_error<StringError>("Required address for empty symbol \"\"",
60  else
61  Result.push_back(ExecutorAddr());
62  } else {
63 
64  const char *DemangledSymName = E.Name.c_str();
65 #ifdef __APPLE__
66  if (E.Name.front() != '_')
67  return make_error<StringError>(Twine("MachO symbol \"") + E.Name +
68  "\" missing leading '_'",
70  ++DemangledSymName;
71 #endif
72 
73  void *Addr = DL.getAddressOfSymbol(DemangledSymName);
74  if (!Addr && E.Required)
75  return make_error<StringError>(Twine("Missing definition for ") +
76  DemangledSymName,
78 
79  Result.push_back(ExecutorAddr::fromPtr(Addr));
80  }
81  }
82 
83  return Result;
84 }
85 
87 
88  DylibsMap DM;
89  {
90  std::lock_guard<std::mutex> Lock(M);
91  std::swap(DM, Dylibs);
92  }
93 
94  // There is no removal of dylibs at the moment, so nothing to do here.
95  return Error::success();
96 }
97 
102  ExecutorAddr::fromPtr(&openWrapper);
104  ExecutorAddr::fromPtr(&lookupWrapper);
105 }
106 
108 SimpleExecutorDylibManager::openWrapper(const char *ArgData, size_t ArgSize) {
109  return shared::
111  ArgData, ArgSize,
114  .release();
115 }
116 
118 SimpleExecutorDylibManager::lookupWrapper(const char *ArgData, size_t ArgSize) {
119  return shared::
121  ArgData, ArgSize,
124  .release();
125 }
126 
127 } // namespace rt_bootstrap
128 } // end namespace orc
129 } // end namespace llvm
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:37
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
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
DM
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
SimpleExecutorDylibManager.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
handle
then ret i32 result Tail recursion elimination should handle
Definition: README.txt:355
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:250
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.
Definition: DynamicLibrary.cpp:146
llvm::orc::rt::SimpleExecutorDylibManagerInstanceName
const char * SimpleExecutorDylibManagerInstanceName
Definition: OrcRTBridge.cpp:15
llvm::orc::ExecutorAddr::fromPtr
static ExecutorAddr fromPtr(T *Value)
Create an ExecutorAddr from the given pointer.
Definition: ExecutorAddress.h:46
FormatVariadic.h
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
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::DenseMap< uint64_t, sys::DynamicLibrary >
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::open
Expected< tpctypes::DylibHandle > open(const std::string &Path, uint64_t Mode)
Definition: SimpleExecutorDylibManager.cpp:25
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
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:840
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:262
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::shutdown
Error shutdown() override
Definition: SimpleExecutorDylibManager.cpp:86
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:43
llvm::DenseMapBase::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
H
#define H(x, y, z)
Definition: MD5.cpp:58
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:77
llvm::DenseMapBase::end
iterator end()
Definition: DenseMap.h:83
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:157
llvm::orc::rt_bootstrap::SimpleExecutorDylibManager::addBootstrapSymbols
void addBootstrapSymbols(StringMap< ExecutorAddr > &M) override
Definition: SimpleExecutorDylibManager.cpp:98
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:608
llvm::orc::rt::SimpleExecutorDylibManagerOpenWrapperName
const char * SimpleExecutorDylibManagerOpenWrapperName
Definition: OrcRTBridge.cpp:17
OrcRTBridge.h