[llvm] 6fd30f0 - [llvm-jitlink] Update llvm-jitlink to use TargetProcessControl.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 17:20:03 PDT 2020
Author: Lang Hames
Date: 2020-08-10T17:19:48-07:00
New Revision: 6fd30f0669a2dd9af7b87325e30ec1af79b86f28
URL: https://github.com/llvm/llvm-project/commit/6fd30f0669a2dd9af7b87325e30ec1af79b86f28
DIFF: https://github.com/llvm/llvm-project/commit/6fd30f0669a2dd9af7b87325e30ec1af79b86f28.diff
LOG: [llvm-jitlink] Update llvm-jitlink to use TargetProcessControl.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h
llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
llvm/tools/llvm-jitlink/llvm-jitlink.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h
index e260c64bee51..159b6e8d56df 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h
@@ -161,13 +161,19 @@ class TargetProcessControl {
MemoryAccess *MemAccess = nullptr;
};
-/// A TargetProcessControl
+/// A TargetProcessControl implementation targeting the current process.
class SelfTargetProcessControl : public TargetProcessControl,
private TargetProcessControl::MemoryAccess {
public:
- SelfTargetProcessControl(Triple TT, unsigned PageSize);
+ SelfTargetProcessControl(
+ Triple TT, unsigned PageSize,
+ std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);
- static Expected<std::unique_ptr<SelfTargetProcessControl>> Create();
+ /// Create a SelfTargetProcessControl with the given memory manager.
+ /// If no memory manager is given a jitlink::InProcessMemoryManager will
+ /// be used by default.
+ static Expected<std::unique_ptr<SelfTargetProcessControl>>
+ Create(std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr = nullptr);
Expected<DylibHandle> loadDylib(const char *DylibPath) override;
@@ -189,9 +195,7 @@ class SelfTargetProcessControl : public TargetProcessControl,
void writeBuffers(ArrayRef<BufferWrite> Ws,
WriteResultFn OnWriteComplete) override;
- std::unique_ptr<jitlink::InProcessMemoryManager> IPMM =
- std::make_unique<jitlink::InProcessMemoryManager>();
-
+ std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
char GlobalManglingPrefix = 0;
std::vector<std::unique_ptr<sys::DynamicLibrary>> DynamicLibraries;
};
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp
index f17f5bf32856..59c9ce2393c9 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp
@@ -21,25 +21,33 @@ TargetProcessControl::MemoryAccess::~MemoryAccess() {}
TargetProcessControl::~TargetProcessControl() {}
-SelfTargetProcessControl::SelfTargetProcessControl(Triple TT,
- unsigned PageSize) {
+SelfTargetProcessControl::SelfTargetProcessControl(
+ Triple TT, unsigned PageSize,
+ std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) {
+
+ OwnedMemMgr = std::move(MemMgr);
+ if (!OwnedMemMgr)
+ OwnedMemMgr = std::make_unique<jitlink::InProcessMemoryManager>();
+
this->TT = std::move(TT);
this->PageSize = PageSize;
- this->MemMgr = IPMM.get();
+ this->MemMgr = OwnedMemMgr.get();
this->MemAccess = this;
if (this->TT.isOSBinFormatMachO())
GlobalManglingPrefix = '_';
}
Expected<std::unique_ptr<SelfTargetProcessControl>>
-SelfTargetProcessControl::Create() {
+SelfTargetProcessControl::Create(
+ std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) {
auto PageSize = sys::Process::getPageSize();
if (!PageSize)
return PageSize.takeError();
Triple TT(sys::getProcessTriple());
- return std::make_unique<SelfTargetProcessControl>(std::move(TT), *PageSize);
+ return std::make_unique<SelfTargetProcessControl>(std::move(TT), *PageSize,
+ std::move(MemMgr));
}
Expected<TargetProcessControl::DylibHandle>
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index d5dc661cc69f..8e651d903a3b 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -483,8 +483,8 @@ static std::unique_ptr<JITLinkMemoryManager> createMemoryManager() {
}
LLVMJITLinkObjectLinkingLayer::LLVMJITLinkObjectLinkingLayer(
- Session &S, std::unique_ptr<JITLinkMemoryManager> MemMgr)
- : ObjectLinkingLayer(S.ES, std::move(MemMgr)), S(S) {}
+ Session &S, JITLinkMemoryManager &MemMgr)
+ : ObjectLinkingLayer(S.ES, MemMgr), S(S) {}
Error LLVMJITLinkObjectLinkingLayer::add(JITDylib &JD,
std::unique_ptr<MemoryBuffer> O,
@@ -580,7 +580,12 @@ class PhonyExternalsGenerator : public JITDylib::DefinitionGenerator {
Expected<std::unique_ptr<Session>> Session::Create(Triple TT) {
Error Err = Error::success();
- std::unique_ptr<Session> S(new Session(std::move(TT), Err));
+
+ auto PageSize = sys::Process::getPageSize();
+ if (!PageSize)
+ return PageSize.takeError();
+
+ std::unique_ptr<Session> S(new Session(std::move(TT), *PageSize, Err));
if (Err)
return std::move(Err);
return std::move(S);
@@ -588,8 +593,10 @@ Expected<std::unique_ptr<Session>> Session::Create(Triple TT) {
// FIXME: Move to createJITDylib if/when we start using Platform support in
// llvm-jitlink.
-Session::Session(Triple TT, Error &Err)
- : ObjLayer(*this, createMemoryManager()), TT(std::move(TT)) {
+Session::Session(Triple TT, uint64_t PageSize, Error &Err)
+ : TPC(std::make_unique<SelfTargetProcessControl>(std::move(TT), PageSize,
+ createMemoryManager())),
+ ObjLayer(*this, TPC->getMemMgr()) {
/// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the
/// Session.
@@ -658,15 +665,14 @@ void Session::dumpSessionInfo(raw_ostream &OS) {
OS << "Registered addresses:\n" << SymbolInfos << FileInfos;
}
-void Session::modifyPassConfig(const Triple &FTT,
+void Session::modifyPassConfig(const Triple &TT,
PassConfiguration &PassConfig) {
if (!CheckFiles.empty())
PassConfig.PostFixupPasses.push_back([this](LinkGraph &G) {
-
- if (TT.getObjectFormat() == Triple::ELF)
+ if (TPC->getTargetTriple().getObjectFormat() == Triple::ELF)
return registerELFGraphInfo(*this, G);
- if (TT.getObjectFormat() == Triple::MachO)
+ if (TPC->getTargetTriple().getObjectFormat() == Triple::MachO)
return registerMachOGraphInfo(*this, G);
return make_error<StringError>("Unsupported object format for GOT/stub "
@@ -780,7 +786,7 @@ Triple getFirstFileTriple() {
Error sanitizeArguments(const Session &S) {
if (EntryPointName.empty()) {
- if (S.TT.getObjectFormat() == Triple::MachO)
+ if (S.TPC->getTargetTriple().getObjectFormat() == Triple::MachO)
EntryPointName = "_main";
else
EntryPointName = "main";
@@ -805,7 +811,8 @@ Error loadProcessSymbols(Session &S) {
if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, &ErrMsg))
return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
- char GlobalPrefix = S.TT.getObjectFormat() == Triple::MachO ? '_' : '\0';
+ char GlobalPrefix =
+ S.TPC->getTargetTriple().getObjectFormat() == Triple::MachO ? '_' : '\0';
auto InternedEntryPointName = S.ES.intern(EntryPointName);
auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) {
return Name != InternedEntryPointName;
@@ -899,7 +906,7 @@ Error loadObjects(Session &S) {
if (Magic == file_magic::archive ||
Magic == file_magic::macho_universal_binary)
JD.addGenerator(ExitOnErr(StaticLibraryDefinitionGenerator::Load(
- S.ObjLayer, InputFile.c_str(), S.TT)));
+ S.ObjLayer, InputFile.c_str(), S.TPC->getTargetTriple())));
else
ExitOnErr(S.ObjLayer.add(JD, std::move(ObjBuffer)));
}
@@ -947,9 +954,9 @@ Error loadObjects(Session &S) {
Error runChecks(Session &S) {
- auto TripleName = S.TT.str();
+ auto TripleName = S.TPC->getTargetTriple().str();
std::string ErrorStr;
- const Target *TheTarget = TargetRegistry::lookupTarget("", S.TT, ErrorStr);
+ const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, ErrorStr);
if (!TheTarget)
ExitOnErr(make_error<StringError>("Error accessing target '" + TripleName +
"': " + ErrorStr,
@@ -1013,7 +1020,8 @@ Error runChecks(Session &S) {
RuntimeDyldChecker Checker(
IsSymbolValid, GetSymbolInfo, GetSectionInfo, GetStubInfo, GetGOTInfo,
- S.TT.isLittleEndian() ? support::little : support::big,
+ S.TPC->getTargetTriple().isLittleEndian() ? support::little
+ : support::big,
Disassembler.get(), InstPrinter.get(), dbgs());
std::string CheckLineStart = "# " + CheckName + ":";
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.h b/llvm/tools/llvm-jitlink/llvm-jitlink.h
index 227d3a9225c8..4a12bbcb7550 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.h
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.h
@@ -18,6 +18,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
#include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Regex.h"
@@ -32,8 +33,8 @@ struct Session;
/// ObjectLinkingLayer with additional support for symbol promotion.
class LLVMJITLinkObjectLinkingLayer : public orc::ObjectLinkingLayer {
public:
- LLVMJITLinkObjectLinkingLayer(
- Session &S, std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);
+ LLVMJITLinkObjectLinkingLayer(Session &S,
+ jitlink::JITLinkMemoryManager &MemMgr);
Error add(orc::JITDylib &JD, std::unique_ptr<MemoryBuffer> O,
orc::VModuleKey K = orc::VModuleKey()) override;
@@ -44,12 +45,11 @@ class LLVMJITLinkObjectLinkingLayer : public orc::ObjectLinkingLayer {
struct Session {
orc::ExecutionSession ES;
+ std::unique_ptr<orc::TargetProcessControl> TPC;
orc::JITDylib *MainJD;
LLVMJITLinkObjectLinkingLayer ObjLayer;
std::vector<orc::JITDylib *> JDSearchOrder;
- Triple TT;
- Session(Triple TT);
static Expected<std::unique_ptr<Session>> Create(Triple TT);
void dumpSessionInfo(raw_ostream &OS);
void modifyPassConfig(const Triple &FTT,
@@ -89,7 +89,7 @@ struct Session {
DenseMap<StringRef, StringRef> CanonicalWeakDefs;
private:
- Session(Triple TT, Error &Err);
+ Session(Triple TT, uint64_t PageSize, Error &Err);
};
/// Record symbols, GOT entries, stubs, and sections for ELF file.
More information about the llvm-commits
mailing list