2016-01-12 00:35:55 +08:00
|
|
|
//===-- RemoteJITUtils.h - Utilities for remote-JITing with LLI -*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-01-12 00:35:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Utilities for remote-JITing with LLI.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
|
|
|
#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
|
|
|
|
2020-12-29 17:27:41 +08:00
|
|
|
#include "llvm/ExecutionEngine/Orc/Shared/FDRawByteChannel.h"
|
2016-01-12 00:35:55 +08:00
|
|
|
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
|
2016-04-19 03:55:43 +08:00
|
|
|
#include <mutex>
|
2016-01-12 00:35:55 +08:00
|
|
|
|
|
|
|
#if !defined(_MSC_VER) && !defined(__MINGW32__)
|
|
|
|
#include <unistd.h>
|
|
|
|
#else
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// launch the remote process (see lli.cpp) and return a channel to it.
|
2020-12-29 17:27:41 +08:00
|
|
|
std::unique_ptr<llvm::orc::shared::FDRawByteChannel> launchRemote();
|
2016-01-12 00:35:55 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2019-07-03 02:39:32 +08:00
|
|
|
// ForwardingMM - Adapter to connect MCJIT to Orc's Remote
|
2016-11-12 05:42:09 +08:00
|
|
|
// memory manager.
|
2016-01-12 00:35:55 +08:00
|
|
|
class ForwardingMemoryManager : public llvm::RTDyldMemoryManager {
|
|
|
|
public:
|
|
|
|
void setMemMgr(std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr) {
|
|
|
|
this->MemMgr = std::move(MemMgr);
|
|
|
|
}
|
|
|
|
|
2018-01-20 06:24:13 +08:00
|
|
|
void setResolver(std::shared_ptr<LegacyJITSymbolResolver> Resolver) {
|
2016-01-12 00:35:55 +08:00
|
|
|
this->Resolver = std::move(Resolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
|
|
|
|
unsigned SectionID,
|
|
|
|
StringRef SectionName) override {
|
|
|
|
return MemMgr->allocateCodeSection(Size, Alignment, SectionID, SectionName);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
|
|
|
|
unsigned SectionID, StringRef SectionName,
|
|
|
|
bool IsReadOnly) override {
|
|
|
|
return MemMgr->allocateDataSection(Size, Alignment, SectionID, SectionName,
|
|
|
|
IsReadOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
|
|
|
|
uintptr_t RODataSize, uint32_t RODataAlign,
|
|
|
|
uintptr_t RWDataSize,
|
|
|
|
uint32_t RWDataAlign) override {
|
|
|
|
MemMgr->reserveAllocationSpace(CodeSize, CodeAlign, RODataSize, RODataAlign,
|
|
|
|
RWDataSize, RWDataAlign);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsToReserveAllocationSpace() override {
|
|
|
|
return MemMgr->needsToReserveAllocationSpace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
|
|
|
|
size_t Size) override {
|
|
|
|
MemMgr->registerEHFrames(Addr, LoadAddr, Size);
|
|
|
|
}
|
|
|
|
|
2017-05-10 05:32:18 +08:00
|
|
|
void deregisterEHFrames() override {
|
|
|
|
MemMgr->deregisterEHFrames();
|
2016-01-12 00:35:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool finalizeMemory(std::string *ErrMsg = nullptr) override {
|
|
|
|
return MemMgr->finalizeMemory(ErrMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void notifyObjectLoaded(RuntimeDyld &RTDyld,
|
|
|
|
const object::ObjectFile &Obj) override {
|
|
|
|
MemMgr->notifyObjectLoaded(RTDyld, Obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't hide the sibling notifyObjectLoaded from RTDyldMemoryManager.
|
|
|
|
using RTDyldMemoryManager::notifyObjectLoaded;
|
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol findSymbol(const std::string &Name) override {
|
2016-01-12 00:35:55 +08:00
|
|
|
return Resolver->findSymbol(Name);
|
|
|
|
}
|
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol
|
2016-01-12 00:35:55 +08:00
|
|
|
findSymbolInLogicalDylib(const std::string &Name) override {
|
|
|
|
return Resolver->findSymbolInLogicalDylib(Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr;
|
2018-01-20 06:24:13 +08:00
|
|
|
std::shared_ptr<LegacyJITSymbolResolver> Resolver;
|
2016-01-12 00:35:55 +08:00
|
|
|
};
|
2020-09-08 12:21:28 +08:00
|
|
|
|
|
|
|
template <typename RemoteT>
|
|
|
|
class RemoteResolver : public LegacyJITSymbolResolver {
|
|
|
|
public:
|
|
|
|
|
|
|
|
RemoteResolver(RemoteT &R) : R(R) {}
|
|
|
|
|
|
|
|
JITSymbol findSymbol(const std::string &Name) override {
|
|
|
|
if (auto Addr = R.getSymbolAddress(Name))
|
|
|
|
return JITSymbol(*Addr, JITSymbolFlags::Exported);
|
|
|
|
else
|
|
|
|
return Addr.takeError();
|
|
|
|
}
|
|
|
|
|
|
|
|
JITSymbol findSymbolInLogicalDylib(const std::string &Name) override {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
RemoteT &R;
|
|
|
|
};
|
2016-01-12 00:35:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|