Skip to content

Commit b64fc0a

Browse files
committed
[ORC] Add bootstrap symbols to ExecutorProcessControl.
Bootstrap symbols are symbols whose addresses may be required to bootstrap the rest of the JIT. The bootstrap symbols map generalizes the existing JITDispatchInfo class provide an arbitrary map of symbol names to addresses. The JITDispatchInfo class will be replaced by bootstrap symbols with reserved names in upcoming commits.
1 parent e339303 commit b64fc0a

File tree

4 files changed

+77
-91
lines changed

4 files changed

+77
-91
lines changed

llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,29 @@ class ExecutorProcessControl {
158158
return *MemMgr;
159159
}
160160

161+
/// Returns the bootstrap symbol map.
162+
const StringMap<ExecutorAddress> &getBootstrapSymbolsMap() const {
163+
return BootstrapSymbols;
164+
}
165+
166+
/// For each (ExecutorAddress&, StringRef) pair, looks up the string in the
167+
/// bootstrap symbols map and writes its address to the ExecutorAddress if
168+
/// found. If any symbol is not found then the function returns an error.
169+
Error getBootstrapSymbols(
170+
ArrayRef<std::pair<ExecutorAddress &, StringRef>> Pairs) const {
171+
for (auto &KV : Pairs) {
172+
auto I = BootstrapSymbols.find(KV.second);
173+
if (I == BootstrapSymbols.end())
174+
return make_error<StringError>("Symbol \"" + KV.second +
175+
"\" not found "
176+
"in bootstrap symbols map",
177+
inconvertibleErrorCode());
178+
179+
KV.first = I->second;
180+
}
181+
return Error::success();
182+
}
183+
161184
/// Load the dynamic library at the given path and return a handle to it.
162185
/// If LibraryPath is null this function will return the global handle for
163186
/// the target process.
@@ -252,6 +275,7 @@ class ExecutorProcessControl {
252275
JITDispatchInfo JDI;
253276
MemoryAccess *MemAccess = nullptr;
254277
jitlink::JITLinkMemoryManager *MemMgr = nullptr;
278+
StringMap<ExecutorAddress> BootstrapSymbols;
255279
};
256280

257281
/// A ExecutorProcessControl instance that asserts if any of its methods are

llvm/include/llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,6 @@ struct SimpleRemoteEPCExecutorInfo {
4545
std::string TargetTriple;
4646
uint64_t PageSize;
4747
StringMap<ExecutorAddress> BootstrapSymbols;
48-
49-
Expected<ExecutorAddress> getBootstrapSymbol(StringRef Name) const {
50-
auto I = BootstrapSymbols.find(Name);
51-
if (I == BootstrapSymbols.end())
52-
return make_error<StringError>("Symbol \"" + Name +
53-
"\" not found in "
54-
"bootstrap symbols map",
55-
inconvertibleErrorCode());
56-
return I->second;
57-
}
58-
59-
Error getBootstrapSymbols(
60-
ArrayRef<std::pair<ExecutorAddress &, StringRef>> Pairs) const {
61-
for (auto &KV : Pairs) {
62-
if (auto A = getBootstrapSymbol(KV.second))
63-
KV.first = *A;
64-
else
65-
return A.takeError();
66-
}
67-
return Error::success();
68-
}
6948
};
7049

7150
using SimpleRemoteEPCArgBytesVector = SmallVector<char, 128>;

llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ class SimpleRemoteEPC : public ExecutorProcessControl,
6161
SimpleRemoteEPC &operator=(SimpleRemoteEPC &&) = delete;
6262
~SimpleRemoteEPC();
6363

64-
/// Called at the end of the construction process to set up the instance.
65-
///
66-
/// Override to set up custom memory manager and/or memory access objects.
67-
/// This method must be called at the *end* of the subclass's
68-
/// implementation.
69-
virtual Error setup(std::unique_ptr<SimpleRemoteEPCTransport> T,
70-
const SimpleRemoteEPCExecutorInfo &EI);
71-
7264
Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
7365

7466
Expected<std::vector<tpctypes::LookupResult>>
@@ -91,20 +83,20 @@ class SimpleRemoteEPC : public ExecutorProcessControl,
9183
void handleDisconnect(Error Err) override;
9284

9385
protected:
94-
void setMemoryManager(std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);
95-
void setMemoryAccess(std::unique_ptr<MemoryAccess> MemAccess);
86+
virtual Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
87+
createMemoryManager();
88+
virtual Expected<std::unique_ptr<MemoryAccess>> createMemoryAccess();
9689

9790
private:
9891
SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP)
9992
: ExecutorProcessControl(std::move(SSP)) {}
10093

101-
Error setupDefaultMemoryManager(const SimpleRemoteEPCExecutorInfo &EI);
102-
Error setupDefaultMemoryAccess(const SimpleRemoteEPCExecutorInfo &EI);
103-
10494
Error handleSetup(uint64_t SeqNo, ExecutorAddress TagAddr,
10595
SimpleRemoteEPCArgBytesVector ArgBytes);
10696
void prepareToReceiveSetupMessage(
10797
std::promise<MSVCPExpected<SimpleRemoteEPCExecutorInfo>> &ExecInfoP);
98+
Error setup(std::unique_ptr<SimpleRemoteEPCTransport> T,
99+
SimpleRemoteEPCExecutorInfo EI);
108100

109101
Error handleResult(uint64_t SeqNo, ExecutorAddress TagAddr,
110102
SimpleRemoteEPCArgBytesVector ArgBytes);

llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -64,40 +64,6 @@ SimpleRemoteEPC::~SimpleRemoteEPC() {
6464
assert(Disconnected && "Destroyed without disconnection");
6565
}
6666

67-
Error SimpleRemoteEPC::setup(std::unique_ptr<SimpleRemoteEPCTransport> T,
68-
const SimpleRemoteEPCExecutorInfo &EI) {
69-
using namespace SimpleRemoteEPCDefaultBootstrapSymbolNames;
70-
LLVM_DEBUG({
71-
dbgs() << "SimpleRemoteEPC received setup message:\n"
72-
<< " Triple: " << EI.TargetTriple << "\n"
73-
<< " Page size: " << EI.PageSize << "\n"
74-
<< " Bootstrap symbols:\n";
75-
for (const auto &KV : EI.BootstrapSymbols)
76-
dbgs() << " " << KV.first() << ": "
77-
<< formatv("{0:x16}", KV.second.getValue()) << "\n";
78-
});
79-
this->T = std::move(T);
80-
TargetTriple = Triple(EI.TargetTriple);
81-
PageSize = EI.PageSize;
82-
83-
if (auto Err = EI.getBootstrapSymbols(
84-
{{JDI.JITDispatchContextAddress, ExecutorSessionObjectName},
85-
{JDI.JITDispatchFunctionAddress, DispatchFnName},
86-
{LoadDylibAddr, "__llvm_orc_load_dylib"},
87-
{LookupSymbolsAddr, "__llvm_orc_lookup_symbols"},
88-
{RunAsMainAddr, "__llvm_orc_run_as_main"}}))
89-
return Err;
90-
91-
if (!MemMgr)
92-
if (auto Err = setupDefaultMemoryManager(EI))
93-
return Err;
94-
if (!MemAccess)
95-
if (auto Err = setupDefaultMemoryAccess(EI))
96-
return Err;
97-
98-
return Error::success();
99-
}
100-
10167
Expected<tpctypes::DylibHandle>
10268
SimpleRemoteEPC::loadDylib(const char *DylibPath) {
10369
Expected<tpctypes::DylibHandle> H((tpctypes::DylibHandle()));
@@ -201,37 +167,22 @@ void SimpleRemoteEPC::handleDisconnect(Error Err) {
201167
}
202168
}
203169

204-
void SimpleRemoteEPC::setMemoryManager(
205-
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) {
206-
OwnedMemMgr = std::move(MemMgr);
207-
this->MemMgr = OwnedMemMgr.get();
208-
}
209-
210-
void SimpleRemoteEPC::setMemoryAccess(std::unique_ptr<MemoryAccess> MemAccess) {
211-
OwnedMemAccess = std::move(MemAccess);
212-
this->MemAccess = OwnedMemAccess.get();
213-
}
214-
215-
Error SimpleRemoteEPC::setupDefaultMemoryManager(
216-
const SimpleRemoteEPCExecutorInfo &EI) {
217-
170+
Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
171+
SimpleRemoteEPC::createMemoryManager() {
218172
EPCGenericJITLinkMemoryManager::FuncAddrs FAs;
219-
220-
if (auto Err = EI.getBootstrapSymbols(
173+
if (auto Err = getBootstrapSymbols(
221174
{{FAs.Reserve, "__llvm_orc_memory_reserve"},
222175
{FAs.Finalize, "__llvm_orc_memory_finalize"},
223176
{FAs.Deallocate, "__llvm_orc_memory_deallocate"}}))
224-
return Err;
177+
return std::move(Err);
225178

226-
setMemoryManager(
227-
std::make_unique<EPCGenericJITLinkMemoryManager>(*this, FAs));
228-
return Error::success();
179+
return std::make_unique<EPCGenericJITLinkMemoryManager>(*this, FAs);
229180
}
230181

231-
Error SimpleRemoteEPC::setupDefaultMemoryAccess(
232-
const SimpleRemoteEPCExecutorInfo &EI) {
182+
Expected<std::unique_ptr<ExecutorProcessControl::MemoryAccess>>
183+
SimpleRemoteEPC::createMemoryAccess() {
233184

234-
return Error::success();
185+
return nullptr;
235186
}
236187

237188
Error SimpleRemoteEPC::handleSetup(uint64_t SeqNo, ExecutorAddress TagAddr,
@@ -279,6 +230,46 @@ void SimpleRemoteEPC::prepareToReceiveSetupMessage(
279230
};
280231
}
281232

233+
Error SimpleRemoteEPC::setup(std::unique_ptr<SimpleRemoteEPCTransport> T,
234+
SimpleRemoteEPCExecutorInfo EI) {
235+
using namespace SimpleRemoteEPCDefaultBootstrapSymbolNames;
236+
LLVM_DEBUG({
237+
dbgs() << "SimpleRemoteEPC received setup message:\n"
238+
<< " Triple: " << EI.TargetTriple << "\n"
239+
<< " Page size: " << EI.PageSize << "\n"
240+
<< " Bootstrap symbols:\n";
241+
for (const auto &KV : EI.BootstrapSymbols)
242+
dbgs() << " " << KV.first() << ": "
243+
<< formatv("{0:x16}", KV.second.getValue()) << "\n";
244+
});
245+
this->T = std::move(T);
246+
TargetTriple = Triple(EI.TargetTriple);
247+
PageSize = EI.PageSize;
248+
BootstrapSymbols = std::move(EI.BootstrapSymbols);
249+
250+
if (auto Err = getBootstrapSymbols(
251+
{{JDI.JITDispatchContextAddress, ExecutorSessionObjectName},
252+
{JDI.JITDispatchFunctionAddress, DispatchFnName},
253+
{LoadDylibAddr, "__llvm_orc_load_dylib"},
254+
{LookupSymbolsAddr, "__llvm_orc_lookup_symbols"},
255+
{RunAsMainAddr, "__llvm_orc_run_as_main"}}))
256+
return Err;
257+
258+
if (auto MemMgr = createMemoryManager()) {
259+
OwnedMemMgr = std::move(*MemMgr);
260+
this->MemMgr = OwnedMemMgr.get();
261+
} else
262+
return MemMgr.takeError();
263+
264+
if (auto MemAccess = createMemoryAccess()) {
265+
OwnedMemAccess = std::move(*MemAccess);
266+
this->MemAccess = OwnedMemAccess.get();
267+
} else
268+
return MemAccess.takeError();
269+
270+
return Error::success();
271+
}
272+
282273
Error SimpleRemoteEPC::handleResult(uint64_t SeqNo, ExecutorAddress TagAddr,
283274
SimpleRemoteEPCArgBytesVector ArgBytes) {
284275
SendResultFunction SendResult;

0 commit comments

Comments
 (0)