LLVM 20.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
12
13#define DEBUG_TYPE "orc"
14
15namespace llvm {
16namespace orc {
17namespace rt_bootstrap {
18
20 assert(Dylibs.empty() && "shutdown not called?");
21}
22
25 if (Mode != 0)
26 return make_error<StringError>("open: non-zero mode bits not yet supported",
28
29 const char *PathCStr = Path.empty() ? nullptr : Path.c_str();
30 std::string ErrMsg;
31
32 auto DL = sys::DynamicLibrary::getPermanentLibrary(PathCStr, &ErrMsg);
33 if (!DL.isValid())
34 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
35
36 std::lock_guard<std::mutex> Lock(M);
37 auto H = ExecutorAddr::fromPtr(DL.getOSSpecificHandle());
38 Dylibs.insert(DL.getOSSpecificHandle());
39 return H;
40}
41
44 const RemoteSymbolLookupSet &L) {
45 std::vector<ExecutorSymbolDef> Result;
46 auto DL = sys::DynamicLibrary(H.toPtr<void *>());
47
48 for (const auto &E : L) {
49 if (E.Name.empty()) {
50 if (E.Required)
51 return make_error<StringError>("Required address for empty symbol \"\"",
53 else
54 Result.push_back(ExecutorSymbolDef());
55 } else {
56
57 const char *DemangledSymName = E.Name.c_str();
58#ifdef __APPLE__
59 if (E.Name.front() != '_')
60 return make_error<StringError>(Twine("MachO symbol \"") + E.Name +
61 "\" missing leading '_'",
63 ++DemangledSymName;
64#endif
65
66 void *Addr = DL.getAddressOfSymbol(DemangledSymName);
67 if (!Addr && E.Required)
68 return make_error<StringError>(Twine("Missing definition for ") +
69 DemangledSymName,
71
72 // FIXME: determine accurate JITSymbolFlags.
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
102SimpleExecutorDylibManager::openWrapper(const char *ArgData, size_t ArgSize) {
103 return shared::
104 WrapperFunction<rt::SPSSimpleExecutorDylibManagerOpenSignature>::handle(
105 ArgData, ArgSize,
108 .release();
109}
110
112SimpleExecutorDylibManager::lookupWrapper(const char *ArgData, size_t ArgSize) {
113 return shared::
114 WrapperFunction<rt::SPSSimpleExecutorDylibManagerLookupSignature>::handle(
115 ArgData, ArgSize,
118 .release();
119}
120
121} // namespace rt_bootstrap
122} // end namespace orc
123} // end namespace llvm
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint64_t Addr
#define H(x, y, z)
Definition: MD5.cpp:57
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:213
Represents an address in the executor process.
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
Represents a defining location for a JIT symbol.
Expected< std::vector< ExecutorSymbolDef > > lookup(tpctypes::DylibHandle H, const RemoteSymbolLookupSet &L)
Expected< tpctypes::DylibHandle > open(const std::string &Path, uint64_t Mode)
void addBootstrapSymbols(StringMap< ExecutorAddr > &M) override
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
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...
const char * SimpleExecutorDylibManagerOpenWrapperName
Definition: OrcRTBridge.cpp:17
const char * SimpleExecutorDylibManagerLookupWrapperName
Definition: OrcRTBridge.cpp:19
const char * SimpleExecutorDylibManagerInstanceName
Definition: OrcRTBridge.cpp:15
MethodWrapperHandler< RetT, ClassT, ArgTs... > makeMethodWrapperHandler(RetT(ClassT::*Method)(ArgTs...))
Create a MethodWrapperHandler object from the given method pointer.
std::vector< RemoteSymbolLookupSetElement > RemoteSymbolLookupSet
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860