<div dir="ltr"><div dir="ltr">Thanks for the heads up Arthur. This should be fixed in f2980e8849a.</div><div dir="ltr"><br></div><div>-- Lang.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Nov 14, 2020 at 6:35 AM Arthur Eubanks <<a href="mailto:aeubanks@google.com">aeubanks@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>This causes a warning on Windows:</div>[326/1881] CXX obj/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.llvm-jitlink-executor.obj<br>../../llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp(77,1): warning: non-void function does not return a value [-Wreturn-type]<br>}<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 12, 2020 at 10:06 PM Lang Hames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Author: Lang Hames<br>
Date: 2020-11-13T17:05:13+11:00<br>
New Revision: 1d0676b54c4e3a517719220def96dfdbc26d8048<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/1d0676b54c4e3a517719220def96dfdbc26d8048" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/1d0676b54c4e3a517719220def96dfdbc26d8048</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/1d0676b54c4e3a517719220def96dfdbc26d8048.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/1d0676b54c4e3a517719220def96dfdbc26d8048.diff</a><br>
<br>
LOG: [ORC] Break up OrcJIT library, add Orc-RPC based remote TargetProcessControl<br>
implementation.<br>
<br>
This patch aims to improve support for out-of-process JITing using OrcV2. It<br>
introduces two new class templates, OrcRPCTargetProcessControlBase and<br>
OrcRPCTPCServer, which together implement the TargetProcessControl API by<br>
forwarding operations to an execution process via an Orc-RPC Endpoint. These<br>
utilities are used to implement out-of-process JITing from llvm-jitlink to<br>
a new llvm-jitlink-executor tool.<br>
<br>
This patch also breaks the OrcJIT library into three parts:<br>
-- OrcTargetProcess: Contains code needed by the JIT execution process.<br>
-- OrcShared: Contains code needed by the JIT execution and compiler<br>
processes<br>
-- OrcJIT: Everything else.<br>
<br>
This break-up allows JIT executor processes to link against OrcTargetProcess<br>
and OrcShared only, without having to link in all of OrcJIT. Clients executing<br>
JIT'd code in-process should start linking against OrcTargetProcess as well as<br>
OrcJIT.<br>
<br>
In the near future these changes will enable:<br>
-- Removal of the OrcRemoteTargetClient/OrcRemoteTargetServer class templates<br>
which provided similar functionality in OrcV1.<br>
-- Restoration of Chapter 5 of the Building-A-JIT tutorial series, which will<br>
serve as a simple usage example for these APIs.<br>
-- Implementation of lazy, cross-target compilation in lli's -jit-kind=orc-lazy<br>
mode.<br>
<br>
Added: <br>
llvm/include/llvm/ExecutionEngine/Orc/OrcRPCTargetProcessControl.h<br>
llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h<br>
llvm/include/llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h<br>
llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h<br>
llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h<br>
llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h<br>
llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt<br>
llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt<br>
llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt.rej<br>
llvm/lib/ExecutionEngine/Orc/Shared/OrcError.cpp<br>
llvm/lib/ExecutionEngine/Orc/Shared/RPCError.cpp<br>
llvm/lib/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.cpp<br>
llvm/lib/ExecutionEngine/Orc/TPCEHFrameRegistrar.cpp<br>
llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt<br>
llvm/lib/ExecutionEngine/Orc/TargetProcess/LLVMBuild.txt<br>
llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp<br>
llvm/lib/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.cpp<br>
llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt<br>
llvm/tools/llvm-jitlink/llvm-jitlink-executor/LLVMBuild.txt<br>
llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp<br>
<br>
Modified: <br>
llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp<br>
llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h<br>
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h<br>
llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h<br>
llvm/include/llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h<br>
llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h<br>
llvm/include/llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h<br>
llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h<br>
llvm/lib/ExecutionEngine/CMakeLists.txt<br>
llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt<br>
llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp<br>
llvm/lib/ExecutionEngine/JITLink/LLVMBuild.txt<br>
llvm/lib/ExecutionEngine/LLVMBuild.txt<br>
llvm/lib/ExecutionEngine/Orc/CMakeLists.txt<br>
llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp<br>
llvm/lib/ExecutionEngine/Orc/LLVMBuild.txt<br>
llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp<br>
llvm/lib/ExecutionEngine/Orc/TPCIndirectionUtils.cpp<br>
llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp<br>
llvm/tools/lli/CMakeLists.txt<br>
llvm/tools/lli/ChildTarget/CMakeLists.txt<br>
llvm/tools/lli/LLVMBuild.txt<br>
llvm/tools/lli/lli.cpp<br>
llvm/tools/llvm-jitlink/CMakeLists.txt<br>
llvm/tools/llvm-jitlink/LLVMBuild.txt<br>
llvm/tools/llvm-jitlink/llvm-jitlink.cpp<br>
llvm/tools/llvm-jitlink/llvm-jitlink.h<br>
llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt<br>
llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt<br>
<br>
Removed: <br>
llvm/lib/ExecutionEngine/OrcError/CMakeLists.txt<br>
llvm/lib/ExecutionEngine/OrcError/LLVMBuild.txt<br>
llvm/lib/ExecutionEngine/OrcError/OrcError.cpp<br>
llvm/lib/ExecutionEngine/OrcError/RPCError.cpp<br>
<br>
<br>
################################################################################<br>
diff --git a/llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp b/llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp<br>
index d2ce26bddd72..4e36631ef97d 100644<br>
--- a/llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp<br>
+++ b/llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp<br>
@@ -134,7 +134,8 @@ int main(int argc, char *argv[]) {<br>
ExitOnErr.setBanner(std::string(argv[0]) + ": ");<br>
<br>
// (1) Create LLJIT instance.<br>
- auto TPC = ExitOnErr(SelfTargetProcessControl::Create());<br>
+ auto SSP = std::make_shared<SymbolStringPool>();<br>
+ auto TPC = ExitOnErr(SelfTargetProcessControl::Create(std::move(SSP)));<br>
auto J = ExitOnErr(LLJITBuilder().setTargetProcessControl(*TPC).create());<br>
<br>
// (2) Install transform to print modules as they are compiled:<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h<br>
index 72394d7c9985..ec78d9db40b6 100644<br>
--- a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h<br>
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h<br>
@@ -21,14 +21,6 @@<br>
namespace llvm {<br>
namespace jitlink {<br>
<br>
-/// Registers all FDEs in the given eh-frame section with the current process.<br>
-Error registerEHFrameSection(const void *EHFrameSectionAddr,<br>
- size_t EHFrameSectionSize);<br>
-<br>
-/// Deregisters all FDEs in the given eh-frame section with the current process.<br>
-Error deregisterEHFrameSection(const void *EHFrameSectionAddr,<br>
- size_t EHFrameSectionSize);<br>
-<br>
/// Supports registration/deregistration of EH-frames in a target process.<br>
class EHFrameRegistrar {<br>
public:<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h<br>
index 5e22837fa930..f0b4d9bcd49c 100644<br>
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h<br>
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h<br>
@@ -801,6 +801,17 @@ class LinkGraph {<br>
/// Returns the endianness of content in this graph.<br>
support::endianness getEndianness() const { return Endianness; }<br>
<br>
+ /// Allocate a copy of the given String using the LinkGraph's allocator.<br>
+ /// This can be useful when renaming symbols or adding new content to the<br>
+ /// graph.<br>
+ StringRef allocateString(Twine Source) {<br>
+ SmallString<256> TmpBuffer;<br>
+ auto SourceStr = Source.toStringRef(TmpBuffer);<br>
+ auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size());<br>
+ llvm::copy(SourceStr, AllocatedBuffer);<br>
+ return StringRef(AllocatedBuffer, SourceStr.size());<br>
+ }<br>
+<br>
/// Create a section with the given name, protection flags, and alignment.<br>
Section &createSection(StringRef Name, sys::Memory::ProtectionFlags Prot) {<br>
std::unique_ptr<Section> Sec(new Section(Name, Prot, Sections.size()));<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h<br>
index 0270f8f7d68d..1dc2af49b78e 100644<br>
--- a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h<br>
@@ -41,17 +41,6 @@ namespace orc {<br>
<br>
class ObjectLayer;<br>
<br>
-/// Run a main function, returning the result.<br>
-///<br>
-/// If the optional ProgramName argument is given then it will be inserted<br>
-/// before the strings in Args as the first argument to the called function.<br>
-///<br>
-/// It is legal to have an empty argument list and no program name, however<br>
-/// many main functions will expect a name argument at least, and will fail<br>
-/// if none is provided.<br>
-int runAsMain(int (*Main)(int, char *[]), ArrayRef<std::string> Args,<br>
- Optional<StringRef> ProgramName = None);<br>
-<br>
/// This iterator provides a convenient way to iterate over the elements<br>
/// of an llvm.global_ctors/llvm.global_dtors instance.<br>
///<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCTargetProcessControl.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCTargetProcessControl.h<br>
new file mode 100644<br>
index 000000000000..f63dcd0f3471<br>
--- /dev/null<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCTargetProcessControl.h<br>
@@ -0,0 +1,411 @@<br>
+//===--- OrcRPCTargetProcessControl.h - Remote target control ---*- C++ -*-===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// Utilities for interacting with target processes.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_EXECUTIONENGINE_ORC_ORCRPCTARGETPROCESSCONTROL_H<br>
+#define LLVM_EXECUTIONENGINE_ORC_ORCRPCTARGETPROCESSCONTROL_H<br>
+<br>
+#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"<br>
+#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"<br>
+#include "llvm/Support/MSVCErrorWorkarounds.h"<br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+/// JITLinkMemoryManager implementation for a process connected via an ORC RPC<br>
+/// endpoint.<br>
+template <typename OrcRPCTPCImplT><br>
+class OrcRPCTPCJITLinkMemoryManager : public jitlink::JITLinkMemoryManager {<br>
+private:<br>
+ struct HostAlloc {<br>
+ std::unique_ptr<char[]> Mem;<br>
+ uint64_t Size;<br>
+ };<br>
+<br>
+ struct TargetAlloc {<br>
+ JITTargetAddress Address = 0;<br>
+ uint64_t AllocatedSize = 0;<br>
+ };<br>
+<br>
+ using HostAllocMap = DenseMap<int, HostAlloc>;<br>
+ using TargetAllocMap = DenseMap<int, TargetAlloc>;<br>
+<br>
+public:<br>
+ class OrcRPCAllocation : public Allocation {<br>
+ public:<br>
+ OrcRPCAllocation(OrcRPCTPCJITLinkMemoryManager<OrcRPCTPCImplT> &Parent,<br>
+ HostAllocMap HostAllocs, TargetAllocMap TargetAllocs)<br>
+ : Parent(Parent), HostAllocs(std::move(HostAllocs)),<br>
+ TargetAllocs(std::move(TargetAllocs)) {<br>
+ assert(HostAllocs.size() == TargetAllocs.size() &&<br>
+ "HostAllocs size should match TargetAllocs");<br>
+ }<br>
+<br>
+ ~OrcRPCAllocation() override {<br>
+ assert(TargetAllocs.empty() && "failed to deallocate");<br>
+ }<br>
+<br>
+ MutableArrayRef<char> getWorkingMemory(ProtectionFlags Seg) override {<br>
+ auto I = HostAllocs.find(Seg);<br>
+ assert(I != HostAllocs.end() && "No host allocation for segment");<br>
+ auto &HA = I->second;<br>
+ return {HA.Mem.get(), HA.Size};<br>
+ }<br>
+<br>
+ JITTargetAddress getTargetMemory(ProtectionFlags Seg) override {<br>
+ auto I = TargetAllocs.find(Seg);<br>
+ assert(I != TargetAllocs.end() && "No target allocation for segment");<br>
+ return I->second.Address;<br>
+ }<br>
+<br>
+ void finalizeAsync(FinalizeContinuation OnFinalize) override {<br>
+<br>
+ std::vector<tpctypes::BufferWrite> BufferWrites;<br>
+ orcrpctpc::ReleaseOrFinalizeMemRequest FMR;<br>
+<br>
+ for (auto &KV : HostAllocs) {<br>
+ assert(TargetAllocs.count(KV.first) &&<br>
+ "No target allocation for buffer");<br>
+ auto &HA = KV.second;<br>
+ auto &TA = TargetAllocs[KV.first];<br>
+ BufferWrites.push_back({TA.Address, StringRef(HA.Mem.get(), HA.Size)});<br>
+ FMR.push_back({orcrpctpc::toWireProtectionFlags(<br>
+ static_cast<sys::Memory::ProtectionFlags>(KV.first)),<br>
+ TA.Address, TA.AllocatedSize});<br>
+ }<br>
+<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << "finalizeAsync " << (void *)this << ":\n";<br>
+ auto FMRI = FMR.begin();<br>
+ for (auto &B : BufferWrites) {<br>
+ auto Prot = FMRI->Prot;<br>
+ ++FMRI;<br>
+ dbgs() << " Writing " << formatv("{0:x16}", B.Buffer.size())<br>
+ << " bytes to " << ((Prot & orcrpctpc::WPF_Read) ? 'R' : '-')<br>
+ << ((Prot & orcrpctpc::WPF_Write) ? 'W' : '-')<br>
+ << ((Prot & orcrpctpc::WPF_Exec) ? 'X' : '-')<br>
+ << " segment: local " << (void *)B.Buffer.data()<br>
+ << " -> target " << formatv("{0:x16}", B.Address) << "\n";<br>
+ }<br>
+ });<br>
+ if (auto Err =<br>
+ Parent.Parent.getMemoryAccess().writeBuffers(BufferWrites)) {<br>
+ OnFinalize(std::move(Err));<br>
+ return;<br>
+ }<br>
+<br>
+ DEBUG_WITH_TYPE("orc", dbgs() << " Applying permissions...\n");<br>
+ if (auto Err =<br>
+ Parent.getEndpoint().template callAsync<orcrpctpc::FinalizeMem>(<br>
+ [OF = std::move(OnFinalize)](Error Err2) {<br>
+ // FIXME: Dispatch to work queue.<br>
+ std::thread([OF = std::move(OF),<br>
+ Err3 = std::move(Err2)]() mutable {<br>
+ DEBUG_WITH_TYPE(<br>
+ "orc", { dbgs() << " finalizeAsync complete\n"; });<br>
+ OF(std::move(Err3));<br>
+ }).detach();<br>
+ return Error::success();<br>
+ },<br>
+ FMR)) {<br>
+ DEBUG_WITH_TYPE("orc", dbgs() << " failed.\n");<br>
+ Parent.getEndpoint().abandonPendingResponses();<br>
+ Parent.reportError(std::move(Err));<br>
+ }<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << "Leaving finalizeAsync (finalization may continue in "<br>
+ "background)\n";<br>
+ });<br>
+ }<br>
+<br>
+ Error deallocate() override {<br>
+ orcrpctpc::ReleaseOrFinalizeMemRequest RMR;<br>
+ for (auto &KV : TargetAllocs)<br>
+ RMR.push_back({orcrpctpc::toWireProtectionFlags(<br>
+ static_cast<sys::Memory::ProtectionFlags>(KV.first)),<br>
+ KV.second.Address, KV.second.AllocatedSize});<br>
+ TargetAllocs.clear();<br>
+<br>
+ return Parent.getEndpoint().template callB<orcrpctpc::ReleaseMem>(RMR);<br>
+ }<br>
+<br>
+ private:<br>
+ OrcRPCTPCJITLinkMemoryManager<OrcRPCTPCImplT> &Parent;<br>
+ HostAllocMap HostAllocs;<br>
+ TargetAllocMap TargetAllocs;<br>
+ };<br>
+<br>
+ OrcRPCTPCJITLinkMemoryManager(OrcRPCTPCImplT &Parent) : Parent(Parent) {}<br>
+<br>
+ Expected<std::unique_ptr<Allocation>><br>
+ allocate(const SegmentsRequestMap &Request) override {<br>
+ orcrpctpc::ReserveMemRequest RMR;<br>
+ HostAllocMap HostAllocs;<br>
+<br>
+ for (auto &KV : Request) {<br>
+ RMR.push_back({orcrpctpc::toWireProtectionFlags(<br>
+ static_cast<sys::Memory::ProtectionFlags>(KV.first)),<br>
+ KV.second.getContentSize() + KV.second.getZeroFillSize(),<br>
+ KV.second.getAlignment()});<br>
+ HostAllocs[KV.first] = {<br>
+ std::make_unique<char[]>(KV.second.getContentSize()),<br>
+ KV.second.getContentSize()};<br>
+ }<br>
+<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << "Orc remote memmgr got request:\n";<br>
+ for (auto &KV : Request)<br>
+ dbgs() << " permissions: "<br>
+ << ((KV.first & sys::Memory::MF_READ) ? 'R' : '-')<br>
+ << ((KV.first & sys::Memory::MF_WRITE) ? 'W' : '-')<br>
+ << ((KV.first & sys::Memory::MF_EXEC) ? 'X' : '-')<br>
+ << ", content size: "<br>
+ << formatv("{0:x16}", KV.second.getContentSize())<br>
+ << " + zero-fill-size: "<br>
+ << formatv("{0:x16}", KV.second.getZeroFillSize())<br>
+ << ", align: " << KV.second.getAlignment() << "\n";<br>
+ });<br>
+<br>
+ // FIXME: LLVM RPC needs to be fixed to support alt<br>
+ // serialization/deserialization on return types. For now just<br>
+ // translate from std::map to DenseMap manually.<br>
+ auto TmpTargetAllocs =<br>
+ Parent.getEndpoint().template callB<orcrpctpc::ReserveMem>(RMR);<br>
+ if (!TmpTargetAllocs)<br>
+ return TmpTargetAllocs.takeError();<br>
+<br>
+ if (TmpTargetAllocs->size() != RMR.size())<br>
+ return make_error<StringError>(<br>
+ "Number of target allocations does not match request",<br>
+ inconvertibleErrorCode());<br>
+<br>
+ TargetAllocMap TargetAllocs;<br>
+ for (auto &E : *TmpTargetAllocs)<br>
+ TargetAllocs[orcrpctpc::fromWireProtectionFlags(E.Prot)] = {<br>
+ E.Address, E.AllocatedSize};<br>
+<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ auto HAI = HostAllocs.begin();<br>
+ for (auto &KV : TargetAllocs)<br>
+ dbgs() << " permissions: "<br>
+ << ((KV.first & sys::Memory::MF_READ) ? 'R' : '-')<br>
+ << ((KV.first & sys::Memory::MF_WRITE) ? 'W' : '-')<br>
+ << ((KV.first & sys::Memory::MF_EXEC) ? 'X' : '-')<br>
+ << " assigned local " << (void *)HAI->second.Mem.get()<br>
+ << ", target " << formatv("{0:x16}", KV.second.Address) << "\n";<br>
+ });<br>
+<br>
+ return std::make_unique<OrcRPCAllocation>(*this, std::move(HostAllocs),<br>
+ std::move(TargetAllocs));<br>
+ }<br>
+<br>
+private:<br>
+ void reportError(Error Err) { Parent.reportError(std::move(Err)); }<br>
+<br>
+ decltype(std::declval<OrcRPCTPCImplT>().getEndpoint()) getEndpoint() {<br>
+ return Parent.getEndpoint();<br>
+ }<br>
+<br>
+ OrcRPCTPCImplT &Parent;<br>
+};<br>
+<br>
+/// TargetProcessControl::MemoryAccess implementation for a process connected<br>
+/// via an ORC RPC endpoint.<br>
+template <typename OrcRPCTPCImplT><br>
+class OrcRPCTPCMemoryAccess : public TargetProcessControl::MemoryAccess {<br>
+public:<br>
+ OrcRPCTPCMemoryAccess(OrcRPCTPCImplT &Parent) : Parent(Parent) {}<br>
+<br>
+ void writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws,<br>
+ WriteResultFn OnWriteComplete) override {<br>
+ writeViaRPC<orcrpctpc::WriteUInt8s>(Ws, std::move(OnWriteComplete));<br>
+ }<br>
+<br>
+ void writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws,<br>
+ WriteResultFn OnWriteComplete) override {<br>
+ writeViaRPC<orcrpctpc::WriteUInt16s>(Ws, std::move(OnWriteComplete));<br>
+ }<br>
+<br>
+ void writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws,<br>
+ WriteResultFn OnWriteComplete) override {<br>
+ writeViaRPC<orcrpctpc::WriteUInt32s>(Ws, std::move(OnWriteComplete));<br>
+ }<br>
+<br>
+ void writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws,<br>
+ WriteResultFn OnWriteComplete) override {<br>
+ writeViaRPC<orcrpctpc::WriteUInt64s>(Ws, std::move(OnWriteComplete));<br>
+ }<br>
+<br>
+ void writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws,<br>
+ WriteResultFn OnWriteComplete) override {<br>
+ writeViaRPC<orcrpctpc::WriteBuffers>(Ws, std::move(OnWriteComplete));<br>
+ }<br>
+<br>
+private:<br>
+ template <typename WriteRPCFunction, typename WriteElementT><br>
+ void writeViaRPC(ArrayRef<WriteElementT> Ws, WriteResultFn OnWriteComplete) {<br>
+ if (auto Err = Parent.getEndpoint().template callAsync<WriteRPCFunction>(<br>
+ [OWC = std::move(OnWriteComplete)](Error Err2) mutable -> Error {<br>
+ OWC(std::move(Err2));<br>
+ return Error::success();<br>
+ },<br>
+ Ws)) {<br>
+ Parent.reportError(std::move(Err));<br>
+ Parent.getEndpoint().abandonPendingResponses();<br>
+ }<br>
+ }<br>
+<br>
+ OrcRPCTPCImplT &Parent;<br>
+};<br>
+<br>
+// TargetProcessControl for a process connected via an ORC RPC Endpoint.<br>
+template <typename RPCEndpointT><br>
+class OrcRPCTargetProcessControlBase : public TargetProcessControl {<br>
+public:<br>
+ using ErrorReporter = unique_function<void(Error)>;<br>
+<br>
+ using OnCloseConnectionFunction = unique_function<Error(Error)>;<br>
+<br>
+ OrcRPCTargetProcessControlBase(std::shared_ptr<SymbolStringPool> SSP,<br>
+ RPCEndpointT &EP, ErrorReporter ReportError)<br>
+ : TargetProcessControl(std::move(SSP)),<br>
+ ReportError(std::move(ReportError)), EP(EP) {}<br>
+<br>
+ void reportError(Error Err) { ReportError(std::move(Err)); }<br>
+<br>
+ RPCEndpointT &getEndpoint() { return EP; }<br>
+<br>
+ Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override {<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << "Loading dylib \"" << (DylibPath ? DylibPath : "") << "\" ";<br>
+ if (!DylibPath)<br>
+ dbgs() << "(process symbols)";<br>
+ dbgs() << "\n";<br>
+ });<br>
+ if (!DylibPath)<br>
+ DylibPath = "";<br>
+ auto H = EP.template callB<orcrpctpc::LoadDylib>(DylibPath);<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ if (H)<br>
+ dbgs() << " got handle " << formatv("{0:x16}", *H) << "\n";<br>
+ else<br>
+ dbgs() << " error, unable to load\n";<br>
+ });<br>
+ return H;<br>
+ }<br>
+<br>
+ Expected<std::vector<tpctypes::LookupResult>><br>
+ lookupSymbols(ArrayRef<tpctypes::LookupRequest> Request) override {<br>
+ std::vector<orcrpctpc::RemoteLookupRequest> RR;<br>
+ for (auto &E : Request) {<br>
+ RR.push_back({});<br>
+ RR.back().first = E.Handle;<br>
+ for (auto &KV : E.Symbols)<br>
+ RR.back().second.push_back(<br>
+ {(*KV.first).str(),<br>
+ KV.second == SymbolLookupFlags::WeaklyReferencedSymbol});<br>
+ }<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << "Compound lookup:\n";<br>
+ for (auto &R : Request) {<br>
+ dbgs() << " In " << formatv("{0:x16}", R.Handle) << ": {";<br>
+ bool First = true;<br>
+ for (auto &KV : R.Symbols) {<br>
+ dbgs() << (First ? "" : ",") << " " << *KV.first;<br>
+ First = false;<br>
+ }<br>
+ dbgs() << " }\n";<br>
+ }<br>
+ });<br>
+ return EP.template callB<orcrpctpc::LookupSymbols>(RR);<br>
+ }<br>
+<br>
+ Expected<int32_t> runAsMain(JITTargetAddress MainFnAddr,<br>
+ ArrayRef<std::string> Args) override {<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << "Running as main: " << formatv("{0:x16}", MainFnAddr)<br>
+ << ", args = [";<br>
+ for (unsigned I = 0; I != Args.size(); ++I)<br>
+ dbgs() << (I ? "," : "") << " \"" << Args[I] << "\"";<br>
+ dbgs() << "]\n";<br>
+ });<br>
+ auto Result = EP.template callB<orcrpctpc::RunMain>(MainFnAddr, Args);<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << " call to " << formatv("{0:x16}", MainFnAddr);<br>
+ if (Result)<br>
+ dbgs() << " returned result " << *Result << "\n";<br>
+ else<br>
+ dbgs() << " failed\n";<br>
+ });<br>
+ return Result;<br>
+ }<br>
+<br>
+ Expected<tpctypes::WrapperFunctionResult><br>
+ runWrapper(JITTargetAddress WrapperFnAddr,<br>
+ ArrayRef<uint8_t> ArgBuffer) override {<br>
+ DEBUG_WITH_TYPE("orc", {<br>
+ dbgs() << "Running as wrapper function "<br>
+ << formatv("{0:x16}", WrapperFnAddr) << " with "<br>
+ << formatv("{0:x16}", ArgBuffer.size()) << " argument buffer\n";<br>
+ });<br>
+ auto Result =<br>
+ EP.template callB<orcrpctpc::RunWrapper>(WrapperFnAddr, ArgBuffer);<br>
+ // dbgs() << "Returned from runWrapper...\n";<br>
+ return Result;<br>
+ }<br>
+<br>
+ Error closeConnection(OnCloseConnectionFunction OnCloseConnection) {<br>
+ DEBUG_WITH_TYPE("orc", dbgs() << "Closing connection to remote\n");<br>
+ return EP.template callAsync<orcrpctpc::CloseConnection>(<br>
+ std::move(OnCloseConnection));<br>
+ }<br>
+<br>
+ Error closeConnectionAndWait() {<br>
+ std::promise<MSVCPError> P;<br>
+ auto F = P.get_future();<br>
+ if (auto Err = closeConnection([&](Error Err2) -> Error {<br>
+ P.set_value(std::move(Err2));<br>
+ return Error::success();<br>
+ })) {<br>
+ EP.abandonAllPendingResponses();<br>
+ return joinErrors(std::move(Err), F.get());<br>
+ }<br>
+ return F.get();<br>
+ }<br>
+<br>
+protected:<br>
+ /// Subclasses must call this during construction to initialize the<br>
+ /// TargetTriple and PageSize members.<br>
+ Error initializeORCRPCTPCBase() {<br>
+ if (auto TripleOrErr = EP.template callB<orcrpctpc::GetTargetTriple>())<br>
+ TargetTriple = Triple(*TripleOrErr);<br>
+ else<br>
+ return TripleOrErr.takeError();<br>
+<br>
+ if (auto PageSizeOrErr = EP.template callB<orcrpctpc::GetPageSize>())<br>
+ PageSize = *PageSizeOrErr;<br>
+ else<br>
+ return PageSizeOrErr.takeError();<br>
+<br>
+ return Error::success();<br>
+ }<br>
+<br>
+private:<br>
+ ErrorReporter ReportError;<br>
+ RPCEndpointT &EP;<br>
+};<br>
+<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_EXECUTIONENGINE_ORC_ORCRPCTARGETPROCESSCONTROL_H<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h b/llvm/include/llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h<br>
index 25edb289a5f9..9faa1afe546c 100644<br>
--- a/llvm/include/llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h<br>
@@ -15,6 +15,9 @@<br>
<br>
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"<br>
<br>
+#include "llvm/Support/FormatVariadic.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
#if !defined(_MSC_VER) && !defined(__MINGW32__)<br>
#include <unistd.h><br>
#else<br>
@@ -31,11 +34,13 @@ class FDRawByteChannel final : public RawByteChannel {<br>
FDRawByteChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}<br>
<br>
llvm::Error readBytes(char *Dst, unsigned Size) override {<br>
+ // dbgs() << "Reading " << Size << " bytes: [";<br>
assert(Dst && "Attempt to read into null.");<br>
ssize_t Completed = 0;<br>
while (Completed < static_cast<ssize_t>(Size)) {<br>
ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);<br>
if (Read <= 0) {<br>
+ // dbgs() << " <<<\n";<br>
auto ErrNo = errno;<br>
if (ErrNo == EAGAIN || ErrNo == EINTR)<br>
continue;<br>
@@ -43,17 +48,22 @@ class FDRawByteChannel final : public RawByteChannel {<br>
return llvm::errorCodeToError(<br>
std::error_code(errno, std::generic_category()));<br>
}<br>
+ // for (size_t I = 0; I != Read; ++I)<br>
+ // dbgs() << " " << formatv("{0:x2}", Dst[Completed + I]);<br>
Completed += Read;<br>
}<br>
+ // dbgs() << " ]\n";<br>
return llvm::Error::success();<br>
}<br>
<br>
llvm::Error appendBytes(const char *Src, unsigned Size) override {<br>
+ // dbgs() << "Appending " << Size << " bytes: [";<br>
assert(Src && "Attempt to append from null.");<br>
ssize_t Completed = 0;<br>
while (Completed < static_cast<ssize_t>(Size)) {<br>
ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);<br>
if (Written < 0) {<br>
+ // dbgs() << " <<<\n";<br>
auto ErrNo = errno;<br>
if (ErrNo == EAGAIN || ErrNo == EINTR)<br>
continue;<br>
@@ -61,8 +71,11 @@ class FDRawByteChannel final : public RawByteChannel {<br>
return llvm::errorCodeToError(<br>
std::error_code(errno, std::generic_category()));<br>
}<br>
+ // for (size_t I = 0; I != Written; ++I)<br>
+ // dbgs() << " " << formatv("{0:x2}", Src[Completed + I]);<br>
Completed += Written;<br>
}<br>
+ // dbgs() << " ]\n";<br>
return llvm::Error::success();<br>
}<br>
<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h b/llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h<br>
index 948a1b061e3b..0dc05f4d1c17 100644<br>
--- a/llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h<br>
@@ -9,6 +9,8 @@<br>
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H<br>
#define LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H<br>
<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/ADT/DenseMap.h"<br>
#include "llvm/ExecutionEngine/Orc/OrcError.h"<br>
#include "llvm/Support/thread.h"<br>
#include <map><br>
@@ -166,6 +168,19 @@ class RPCTypeName<std::tuple<ArgTs...>> {<br>
}<br>
};<br>
<br>
+template <typename T> class RPCTypeName<Optional<T>> {<br>
+public:<br>
+ static const char *getName() {<br>
+ static std::string Name = [] {<br>
+ std::string Name;<br>
+ raw_string_ostream(Name)<br>
+ << "Optional<" << RPCTypeName<T>::getName() << ">";<br>
+ return Name;<br>
+ }();<br>
+ return Name.data();<br>
+ }<br>
+};<br>
+<br>
template <typename T><br>
class RPCTypeName<std::vector<T>> {<br>
public:<br>
@@ -574,6 +589,31 @@ class SerializationTraits<ChannelT, std::tuple<ArgTs...>> {<br>
}<br>
};<br>
<br>
+template <typename ChannelT, typename T><br>
+class SerializationTraits<ChannelT, Optional<T>> {<br>
+public:<br>
+ /// Serialize an Optional<T>.<br>
+ static Error serialize(ChannelT &C, const Optional<T> &O) {<br>
+ if (auto Err = serializeSeq(C, O != None))<br>
+ return Err;<br>
+ if (O)<br>
+ if (auto Err = serializeSeq(C, *O))<br>
+ return Err;<br>
+ return Error::success();<br>
+ }<br>
+<br>
+ /// Deserialize an Optional<T>.<br>
+ static Error deserialize(ChannelT &C, Optional<T> &O) {<br>
+ bool HasValue = false;<br>
+ if (auto Err = deserializeSeq(C, HasValue))<br>
+ return Err;<br>
+ if (HasValue)<br>
+ if (auto Err = deserializeSeq(C, *O))<br>
+ return Err;<br>
+ return Error::success();<br>
+ };<br>
+};<br>
+<br>
/// SerializationTraits default specialization for std::vector.<br>
template <typename ChannelT, typename T><br>
class SerializationTraits<ChannelT, std::vector<T>> {<br>
@@ -609,6 +649,22 @@ class SerializationTraits<ChannelT, std::vector<T>> {<br>
}<br>
};<br>
<br>
+/// Enable vector serialization from an ArrayRef.<br>
+template <typename ChannelT, typename T><br>
+class SerializationTraits<ChannelT, std::vector<T>, ArrayRef<T>> {<br>
+public:<br>
+ static Error serialize(ChannelT &C, ArrayRef<T> V) {<br>
+ if (auto Err = serializeSeq(C, static_cast<uint64_t>(V.size())))<br>
+ return Err;<br>
+<br>
+ for (const auto &E : V)<br>
+ if (auto Err = serializeSeq(C, E))<br>
+ return Err;<br>
+<br>
+ return Error::success();<br>
+ }<br>
+};<br>
+<br>
template <typename ChannelT, typename T, typename T2><br>
class SerializationTraits<ChannelT, std::set<T>, std::set<T2>> {<br>
public:<br>
@@ -695,6 +751,55 @@ class SerializationTraits<ChannelT, std::map<K, V>, std::map<K2, V2>> {<br>
}<br>
};<br>
<br>
+template <typename ChannelT, typename K, typename V, typename K2, typename V2><br>
+class SerializationTraits<ChannelT, std::map<K, V>, DenseMap<K2, V2>> {<br>
+public:<br>
+ /// Serialize a std::map<K, V> from DenseMap<K2, V2>.<br>
+ static Error serialize(ChannelT &C, const DenseMap<K2, V2> &M) {<br>
+ if (auto Err = serializeSeq(C, static_cast<uint64_t>(M.size())))<br>
+ return Err;<br>
+<br>
+ for (auto &E : M) {<br>
+ if (auto Err =<br>
+ SerializationTraits<ChannelT, K, K2>::serialize(C, E.first))<br>
+ return Err;<br>
+<br>
+ if (auto Err =<br>
+ SerializationTraits<ChannelT, V, V2>::serialize(C, E.second))<br>
+ return Err;<br>
+ }<br>
+<br>
+ return Error::success();<br>
+ }<br>
+<br>
+ /// Serialize a std::map<K, V> from DenseMap<K2, V2>.<br>
+ static Error deserialize(ChannelT &C, DenseMap<K2, V2> &M) {<br>
+ assert(M.empty() && "Expected default-constructed map to deserialize into");<br>
+<br>
+ uint64_t Count = 0;<br>
+ if (auto Err = deserializeSeq(C, Count))<br>
+ return Err;<br>
+<br>
+ while (Count-- != 0) {<br>
+ std::pair<K2, V2> Val;<br>
+ if (auto Err =<br>
+ SerializationTraits<ChannelT, K, K2>::deserialize(C, Val.first))<br>
+ return Err;<br>
+<br>
+ if (auto Err =<br>
+ SerializationTraits<ChannelT, V, V2>::deserialize(C, Val.second))<br>
+ return Err;<br>
+<br>
+ auto Added = M.insert(Val).second;<br>
+ if (!Added)<br>
+ return make_error<StringError>("Duplicate element in deserialized map",<br>
+ orcError(OrcErrorCode::UnknownORCError));<br>
+ }<br>
+<br>
+ return Error::success();<br>
+ }<br>
+};<br>
+<br>
} // end namespace rpc<br>
} // end namespace orc<br>
} // end namespace llvm<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h<br>
new file mode 100644<br>
index 000000000000..9f958989f46d<br>
--- /dev/null<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h<br>
@@ -0,0 +1,174 @@<br>
+//===--- TargetProcessControlTypes.h -- Shared Core/TPC types ---*- C++ -*-===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// TargetProcessControl types that are used by both the Orc and<br>
+// OrcTargetProcess libraries.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H<br>
+#define LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H<br>
+<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/ExecutionEngine/JITSymbol.h"<br>
+#include "llvm/ExecutionEngine/Orc/Core.h"<br>
+<br>
+#include <vector><br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+namespace tpctypes {<br>
+<br>
+template <typename T> struct UIntWrite {<br>
+ UIntWrite() = default;<br>
+ UIntWrite(JITTargetAddress Address, T Value)<br>
+ : Address(Address), Value(Value) {}<br>
+<br>
+ JITTargetAddress Address = 0;<br>
+ T Value = 0;<br>
+};<br>
+<br>
+/// Describes a write to a uint8_t.<br>
+using UInt8Write = UIntWrite<uint8_t>;<br>
+<br>
+/// Describes a write to a uint16_t.<br>
+using UInt16Write = UIntWrite<uint16_t>;<br>
+<br>
+/// Describes a write to a uint32_t.<br>
+using UInt32Write = UIntWrite<uint32_t>;<br>
+<br>
+/// Describes a write to a uint64_t.<br>
+using UInt64Write = UIntWrite<uint64_t>;<br>
+<br>
+/// Describes a write to a buffer.<br>
+/// For use with TargetProcessControl::MemoryAccess objects.<br>
+struct BufferWrite {<br>
+ BufferWrite() = default;<br>
+ BufferWrite(JITTargetAddress Address, StringRef Buffer)<br>
+ : Address(Address), Buffer(Buffer) {}<br>
+<br>
+ JITTargetAddress Address = 0;<br>
+ StringRef Buffer;<br>
+};<br>
+<br>
+/// A handle used to represent a loaded dylib in the target process.<br>
+using DylibHandle = JITTargetAddress;<br>
+<br>
+/// A pair of a dylib and a set of symbols to be looked up.<br>
+struct LookupRequest {<br>
+ LookupRequest(DylibHandle Handle, const SymbolLookupSet &Symbols)<br>
+ : Handle(Handle), Symbols(Symbols) {}<br>
+ DylibHandle Handle;<br>
+ const SymbolLookupSet &Symbols;<br>
+};<br>
+<br>
+using LookupResult = std::vector<JITTargetAddress>;<br>
+<br>
+/// Either a uint8_t array or a uint8_t*.<br>
+union CWrapperFunctionResultData {<br>
+ uint8_t Value[8];<br>
+ uint8_t *ValuePtr;<br>
+};<br>
+<br>
+/// C ABI compatible wrapper function result.<br>
+///<br>
+/// This can be safely returned from extern "C" functions, but should be used<br>
+/// to construct a WrapperFunctionResult for safety.<br>
+struct CWrapperFunctionResult {<br>
+ uint64_t Size;<br>
+ CWrapperFunctionResultData Data;<br>
+ void (*Destroy)(CWrapperFunctionResultData Data, uint64_t Size);<br>
+};<br>
+<br>
+/// C++ wrapper function result: Same as CWrapperFunctionResult but<br>
+/// auto-releases memory.<br>
+class WrapperFunctionResult {<br>
+public:<br>
+ /// Create a default WrapperFunctionResult.<br>
+ WrapperFunctionResult() { zeroInit(R); }<br>
+<br>
+ /// Create a WrapperFunctionResult from a CWrapperFunctionResult. This<br>
+ /// instance takes ownership of the result object and will automatically<br>
+ /// call the Destroy member upon destruction.<br>
+ WrapperFunctionResult(CWrapperFunctionResult R) : R(R) {}<br>
+<br>
+ WrapperFunctionResult(const WrapperFunctionResult &) = delete;<br>
+ WrapperFunctionResult &operator=(const WrapperFunctionResult &) = delete;<br>
+<br>
+ WrapperFunctionResult(WrapperFunctionResult &&Other) {<br>
+ zeroInit(R);<br>
+ std::swap(R, Other.R);<br>
+ }<br>
+<br>
+ WrapperFunctionResult &operator=(WrapperFunctionResult &&Other) {<br>
+ CWrapperFunctionResult Tmp;<br>
+ zeroInit(Tmp);<br>
+ std::swap(Tmp, Other.R);<br>
+ std::swap(R, Tmp);<br>
+ return *this;<br>
+ }<br>
+<br>
+ ~WrapperFunctionResult() {<br>
+ if (R.Destroy)<br>
+ R.Destroy(R.Data, R.Size);<br>
+ }<br>
+<br>
+ /// Relinquish ownership of and return the CWrapperFunctionResult.<br>
+ CWrapperFunctionResult release() {<br>
+ CWrapperFunctionResult Tmp;<br>
+ zeroInit(Tmp);<br>
+ std::swap(R, Tmp);<br>
+ return Tmp;<br>
+ }<br>
+<br>
+ /// Get an ArrayRef covering the data in the result.<br>
+ ArrayRef<uint8_t> getData() const {<br>
+ if (R.Size <= 8)<br>
+ return ArrayRef<uint8_t>(R.Data.Value, R.Size);<br>
+ return ArrayRef<uint8_t>(R.Data.ValuePtr, R.Size);<br>
+ }<br>
+<br>
+ /// Create a WrapperFunctionResult from the given integer, provided its<br>
+ /// size is no greater than 64 bits.<br>
+ template <typename T,<br>
+ typename _ = std::enable_if_t<std::is_integral<T>::value &&<br>
+ sizeof(T) <= sizeof(uint64_t)>><br>
+ static WrapperFunctionResult from(T Value) {<br>
+ CWrapperFunctionResult R;<br>
+ R.Size = sizeof(T);<br>
+ memcpy(&R.Data.Value, Value, R.Size);<br>
+ R.Destroy = nullptr;<br>
+ return R;<br>
+ }<br>
+<br>
+ /// Create a WrapperFunctionResult from the given string.<br>
+ static WrapperFunctionResult from(StringRef S);<br>
+<br>
+ /// Always free Data.ValuePtr by calling free on it.<br>
+ static void destroyWithFree(CWrapperFunctionResultData Data, uint64_t Size);<br>
+<br>
+ /// Always free Data.ValuePtr by calling delete[] on it.<br>
+ static void destroyWithDeleteArray(CWrapperFunctionResultData Data,<br>
+ uint64_t Size);<br>
+<br>
+private:<br>
+ void zeroInit(CWrapperFunctionResult &R) {<br>
+ R.Size = 0;<br>
+ R.Data.ValuePtr = nullptr;<br>
+ R.Destroy = nullptr;<br>
+ }<br>
+<br>
+ CWrapperFunctionResult R;<br>
+};<br>
+<br>
+} // end namespace tpctypes<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h b/llvm/include/llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h<br>
index 3b5c4b9cf8cd..07720f5c0f33 100644<br>
--- a/llvm/include/llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h<br>
@@ -31,7 +31,7 @@ class TPCDynamicLibrarySearchGenerator : public DefinitionGenerator {<br>
/// will be searched for. If the predicate is not given then all symbols will<br>
/// be searched for.<br>
TPCDynamicLibrarySearchGenerator(TargetProcessControl &TPC,<br>
- TargetProcessControl::DylibHandle H,<br>
+ tpctypes::DylibHandle H,<br>
SymbolPredicate Allow = SymbolPredicate())<br>
: TPC(TPC), H(H), Allow(std::move(Allow)) {}<br>
<br>
@@ -56,7 +56,7 @@ class TPCDynamicLibrarySearchGenerator : public DefinitionGenerator {<br>
<br>
private:<br>
TargetProcessControl &TPC;<br>
- TargetProcessControl::DylibHandle H;<br>
+ tpctypes::DylibHandle H;<br>
SymbolPredicate Allow;<br>
};<br>
<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h b/llvm/include/llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h<br>
new file mode 100644<br>
index 000000000000..519f818907f9<br>
--- /dev/null<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h<br>
@@ -0,0 +1,54 @@<br>
+//===-- TPCEHFrameRegistrar.h - TPC based eh-frame registration -*- C++ -*-===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// TargetProcessControl based eh-frame registration.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_EXECUTIONENGINE_ORC_TPCEHFRAMEREGISTRAR_H<br>
+#define LLVM_EXECUTIONENGINE_ORC_TPCEHFRAMEREGISTRAR_H<br>
+<br>
+#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"<br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+/// Register/Deregisters EH frames in a remote process via a<br>
+/// TargetProcessControl instance.<br>
+class TPCEHFrameRegistrar : public jitlink::EHFrameRegistrar {<br>
+public:<br>
+ /// Create from a TargetProcessControl instance alone. This will use<br>
+ /// the TPC's lookupSymbols method to find the registration/deregistration<br>
+ /// funciton addresses by name.<br>
+ static Expected<std::unique_ptr<TPCEHFrameRegistrar>><br>
+ Create(TargetProcessControl &TPC);<br>
+<br>
+ /// Create a TPCEHFrameRegistrar with the given TargetProcessControl<br>
+ /// object and registration/deregistration function addresses.<br>
+ TPCEHFrameRegistrar(TargetProcessControl &TPC,<br>
+ JITTargetAddress RegisterEHFrameWrapperFnAddr,<br>
+ JITTargetAddress DeregisterEHFRameWrapperFnAddr)<br>
+ : TPC(TPC), RegisterEHFrameWrapperFnAddr(RegisterEHFrameWrapperFnAddr),<br>
+ DeregisterEHFrameWrapperFnAddr(DeregisterEHFRameWrapperFnAddr) {}<br>
+<br>
+ Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,<br>
+ size_t EHFrameSectionSize) override;<br>
+ Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,<br>
+ size_t EHFrameSectionSize) override;<br>
+<br>
+private:<br>
+ TargetProcessControl &TPC;<br>
+ JITTargetAddress RegisterEHFrameWrapperFnAddr;<br>
+ JITTargetAddress DeregisterEHFrameWrapperFnAddr;<br>
+};<br>
+<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_EXECUTIONENGINE_ORC_TPCEHFRAMEREGISTRAR_H<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h<br>
new file mode 100644<br>
index 000000000000..2b759dea6333<br>
--- /dev/null<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h<br>
@@ -0,0 +1,614 @@<br>
+//===-- OrcRPCTPCServer.h -- OrcRPCTargetProcessControl Server --*- C++ -*-===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// OrcRPCTargetProcessControl server class.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H<br>
+#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H<br>
+<br>
+#include "llvm/ADT/BitmaskEnum.h"<br>
+#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"<br>
+#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"<br>
+#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"<br>
+#include "llvm/Support/DynamicLibrary.h"<br>
+#include "llvm/Support/FormatVariadic.h"<br>
+#include "llvm/Support/Host.h"<br>
+#include "llvm/Support/MathExtras.h"<br>
+#include "llvm/Support/Memory.h"<br>
+#include "llvm/Support/Process.h"<br>
+<br>
+#include <atomic><br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+namespace orcrpctpc {<br>
+<br>
+enum WireProtectionFlags : uint8_t {<br>
+ WPF_None = 0,<br>
+ WPF_Read = 1U << 0,<br>
+ WPF_Write = 1U << 1,<br>
+ WPF_Exec = 1U << 2,<br>
+ LLVM_MARK_AS_BITMASK_ENUM(WPF_Exec)<br>
+};<br>
+<br>
+/// Convert from sys::Memory::ProtectionFlags<br>
+inline WireProtectionFlags<br>
+toWireProtectionFlags(sys::Memory::ProtectionFlags PF) {<br>
+ WireProtectionFlags WPF = WPF_None;<br>
+ if (PF & sys::Memory::MF_READ)<br>
+ WPF |= WPF_Read;<br>
+ if (PF & sys::Memory::MF_WRITE)<br>
+ WPF |= WPF_Write;<br>
+ if (PF & sys::Memory::MF_EXEC)<br>
+ WPF |= WPF_Exec;<br>
+ return WPF;<br>
+}<br>
+<br>
+inline sys::Memory::ProtectionFlags<br>
+fromWireProtectionFlags(WireProtectionFlags WPF) {<br>
+ int PF = 0;<br>
+ if (WPF & WPF_Read)<br>
+ PF |= sys::Memory::MF_READ;<br>
+ if (WPF & WPF_Write)<br>
+ PF |= sys::Memory::MF_WRITE;<br>
+ if (WPF & WPF_Exec)<br>
+ PF |= sys::Memory::MF_EXEC;<br>
+ return static_cast<sys::Memory::ProtectionFlags>(PF);<br>
+}<br>
+<br>
+struct ReserveMemRequestElement {<br>
+ WireProtectionFlags Prot = WPF_None;<br>
+ uint64_t Size = 0;<br>
+ uint64_t Alignment = 0;<br>
+};<br>
+<br>
+using ReserveMemRequest = std::vector<ReserveMemRequestElement>;<br>
+<br>
+struct ReserveMemResultElement {<br>
+ WireProtectionFlags Prot = WPF_None;<br>
+ JITTargetAddress Address = 0;<br>
+ uint64_t AllocatedSize = 0;<br>
+};<br>
+<br>
+using ReserveMemResult = std::vector<ReserveMemResultElement>;<br>
+<br>
+struct ReleaseOrFinalizeMemRequestElement {<br>
+ WireProtectionFlags Prot = WPF_None;<br>
+ JITTargetAddress Address = 0;<br>
+ uint64_t Size = 0;<br>
+};<br>
+<br>
+using ReleaseOrFinalizeMemRequest =<br>
+ std::vector<ReleaseOrFinalizeMemRequestElement>;<br>
+<br>
+} // end namespace orcrpctpc<br>
+<br>
+namespace rpc {<br>
+<br>
+template <> class RPCTypeName<tpctypes::UInt8Write> {<br>
+public:<br>
+ static const char *getName() { return "UInt8Write"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<tpctypes::UInt16Write> {<br>
+public:<br>
+ static const char *getName() { return "UInt16Write"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<tpctypes::UInt32Write> {<br>
+public:<br>
+ static const char *getName() { return "UInt32Write"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<tpctypes::UInt64Write> {<br>
+public:<br>
+ static const char *getName() { return "UInt64Write"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<tpctypes::BufferWrite> {<br>
+public:<br>
+ static const char *getName() { return "BufferWrite"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<orcrpctpc::ReserveMemRequestElement> {<br>
+public:<br>
+ static const char *getName() { return "ReserveMemRequestElement"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<orcrpctpc::ReserveMemResultElement> {<br>
+public:<br>
+ static const char *getName() { return "ReserveMemResultElement"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<orcrpctpc::ReleaseOrFinalizeMemRequestElement> {<br>
+public:<br>
+ static const char *getName() { return "ReleaseOrFinalizeMemRequestElement"; }<br>
+};<br>
+<br>
+template <> class RPCTypeName<tpctypes::WrapperFunctionResult> {<br>
+public:<br>
+ static const char *getName() { return "WrapperFunctionResult"; }<br>
+};<br>
+<br>
+template <typename ChannelT, typename WriteT><br>
+class SerializationTraits<<br>
+ ChannelT, WriteT, WriteT,<br>
+ std::enable_if_t<std::is_same<WriteT, tpctypes::UInt8Write>::value ||<br>
+ std::is_same<WriteT, tpctypes::UInt16Write>::value ||<br>
+ std::is_same<WriteT, tpctypes::UInt32Write>::value ||<br>
+ std::is_same<WriteT, tpctypes::UInt64Write>::value>> {<br>
+public:<br>
+ static Error serialize(ChannelT &C, const WriteT &W) {<br>
+ return serializeSeq(C, W.Address, W.Value);<br>
+ }<br>
+ static Error deserialize(ChannelT &C, WriteT &W) {<br>
+ return deserializeSeq(C, W.Address, W.Value);<br>
+ }<br>
+};<br>
+<br>
+template <typename ChannelT><br>
+class SerializationTraits<<br>
+ ChannelT, tpctypes::BufferWrite, tpctypes::BufferWrite,<br>
+ std::enable_if_t<std::is_base_of<RawByteChannel, ChannelT>::value>> {<br>
+public:<br>
+ static Error serialize(ChannelT &C, const tpctypes::BufferWrite &W) {<br>
+ uint64_t Size = W.Buffer.size();<br>
+ if (auto Err = serializeSeq(C, W.Address, Size))<br>
+ return Err;<br>
+<br>
+ return C.appendBytes(W.Buffer.data(), Size);<br>
+ }<br>
+ static Error deserialize(ChannelT &C, tpctypes::BufferWrite &W) {<br>
+ JITTargetAddress Address;<br>
+ uint64_t Size;<br>
+<br>
+ if (auto Err = deserializeSeq(C, Address, Size))<br>
+ return Err;<br>
+<br>
+ char *Buffer = jitTargetAddressToPointer<char *>(Address);<br>
+<br>
+ if (auto Err = C.readBytes(Buffer, Size))<br>
+ return Err;<br>
+<br>
+ W = {Address, StringRef(Buffer, Size)};<br>
+ return Error::success();<br>
+ }<br>
+};<br>
+<br>
+template <typename ChannelT><br>
+class SerializationTraits<ChannelT, orcrpctpc::ReserveMemRequestElement> {<br>
+public:<br>
+ static Error serialize(ChannelT &C,<br>
+ const orcrpctpc::ReserveMemRequestElement &E) {<br>
+ return serializeSeq(C, static_cast<uint8_t>(E.Prot), E.Size, E.Alignment);<br>
+ }<br>
+<br>
+ static Error deserialize(ChannelT &C,<br>
+ orcrpctpc::ReserveMemRequestElement &E) {<br>
+ return deserializeSeq(C, *reinterpret_cast<uint8_t *>(&E.Prot), E.Size,<br>
+ E.Alignment);<br>
+ }<br>
+};<br>
+<br>
+template <typename ChannelT><br>
+class SerializationTraits<ChannelT, orcrpctpc::ReserveMemResultElement> {<br>
+public:<br>
+ static Error serialize(ChannelT &C,<br>
+ const orcrpctpc::ReserveMemResultElement &E) {<br>
+ return serializeSeq(C, static_cast<uint8_t>(E.Prot), E.Address,<br>
+ E.AllocatedSize);<br>
+ }<br>
+<br>
+ static Error deserialize(ChannelT &C, orcrpctpc::ReserveMemResultElement &E) {<br>
+ return deserializeSeq(C, *reinterpret_cast<uint8_t *>(&E.Prot), E.Address,<br>
+ E.AllocatedSize);<br>
+ }<br>
+};<br>
+<br>
+template <typename ChannelT><br>
+class SerializationTraits<ChannelT,<br>
+ orcrpctpc::ReleaseOrFinalizeMemRequestElement> {<br>
+public:<br>
+ static Error<br>
+ serialize(ChannelT &C,<br>
+ const orcrpctpc::ReleaseOrFinalizeMemRequestElement &E) {<br>
+ return serializeSeq(C, static_cast<uint8_t>(E.Prot), E.Address, E.Size);<br>
+ }<br>
+<br>
+ static Error deserialize(ChannelT &C,<br>
+ orcrpctpc::ReleaseOrFinalizeMemRequestElement &E) {<br>
+ return deserializeSeq(C, *reinterpret_cast<uint8_t *>(&E.Prot), E.Address,<br>
+ E.Size);<br>
+ }<br>
+};<br>
+<br>
+template <typename ChannelT><br>
+class SerializationTraits<<br>
+ ChannelT, tpctypes::WrapperFunctionResult, tpctypes::WrapperFunctionResult,<br>
+ std::enable_if_t<std::is_base_of<RawByteChannel, ChannelT>::value>> {<br>
+public:<br>
+ static Error serialize(ChannelT &C,<br>
+ const tpctypes::WrapperFunctionResult &E) {<br>
+ auto Data = E.getData();<br>
+ if (auto Err = serializeSeq(C, static_cast<uint64_t>(Data.size())))<br>
+ return Err;<br>
+ if (Data.size() == 0)<br>
+ return Error::success();<br>
+ return C.appendBytes(reinterpret_cast<const char *>(Data.data()),<br>
+ Data.size());<br>
+ }<br>
+<br>
+ static Error deserialize(ChannelT &C, tpctypes::WrapperFunctionResult &E) {<br>
+ tpctypes::CWrapperFunctionResult R;<br>
+<br>
+ R.Size = 0;<br>
+ R.Data.ValuePtr = nullptr;<br>
+ R.Destroy = nullptr;<br>
+<br>
+ if (auto Err = deserializeSeq(C, R.Size))<br>
+ return Err;<br>
+ if (R.Size == 0)<br>
+ return Error::success();<br>
+ R.Data.ValuePtr = new uint8_t[R.Size];<br>
+ if (auto Err =<br>
+ C.readBytes(reinterpret_cast<char *>(R.Data.ValuePtr), R.Size)) {<br>
+ R.Destroy = tpctypes::WrapperFunctionResult::destroyWithDeleteArray;<br>
+ return Err;<br>
+ }<br>
+<br>
+ E = tpctypes::WrapperFunctionResult(R);<br>
+ return Error::success();<br>
+ }<br>
+};<br>
+<br>
+} // end namespace rpc<br>
+<br>
+namespace orcrpctpc {<br>
+<br>
+using RemoteSymbolLookupSet = std::vector<std::pair<std::string, bool>>;<br>
+using RemoteLookupRequest =<br>
+ std::pair<tpctypes::DylibHandle, RemoteSymbolLookupSet>;<br>
+<br>
+class GetTargetTriple : public rpc::Function<GetTargetTriple, std::string()> {<br>
+public:<br>
+ static const char *getName() { return "GetTargetTriple"; }<br>
+};<br>
+<br>
+class GetPageSize : public rpc::Function<GetPageSize, uint64_t()> {<br>
+public:<br>
+ static const char *getName() { return "GetPageSize"; }<br>
+};<br>
+<br>
+class ReserveMem : public rpc::Function<ReserveMem, Expected<ReserveMemResult>(<br>
+ ReserveMemRequest)> {<br>
+public:<br>
+ static const char *getName() { return "ReserveMem"; }<br>
+};<br>
+<br>
+class FinalizeMem<br>
+ : public rpc::Function<FinalizeMem, Error(ReleaseOrFinalizeMemRequest)> {<br>
+public:<br>
+ static const char *getName() { return "FinalizeMem"; }<br>
+};<br>
+<br>
+class ReleaseMem<br>
+ : public rpc::Function<ReleaseMem, Error(ReleaseOrFinalizeMemRequest)> {<br>
+public:<br>
+ static const char *getName() { return "ReleaseMem"; }<br>
+};<br>
+<br>
+class WriteUInt8s<br>
+ : public rpc::Function<WriteUInt8s,<br>
+ Error(std::vector<tpctypes::UInt8Write>)> {<br>
+public:<br>
+ static const char *getName() { return "WriteUInt8s"; }<br>
+};<br>
+<br>
+class WriteUInt16s<br>
+ : public rpc::Function<WriteUInt16s,<br>
+ Error(std::vector<tpctypes::UInt16Write>)> {<br>
+public:<br>
+ static const char *getName() { return "WriteUInt16s"; }<br>
+};<br>
+<br>
+class WriteUInt32s<br>
+ : public rpc::Function<WriteUInt32s,<br>
+ Error(std::vector<tpctypes::UInt32Write>)> {<br>
+public:<br>
+ static const char *getName() { return "WriteUInt32s"; }<br>
+};<br>
+<br>
+class WriteUInt64s<br>
+ : public rpc::Function<WriteUInt64s,<br>
+ Error(std::vector<tpctypes::UInt64Write>)> {<br>
+public:<br>
+ static const char *getName() { return "WriteUInt64s"; }<br>
+};<br>
+<br>
+class WriteBuffers<br>
+ : public rpc::Function<WriteBuffers,<br>
+ Error(std::vector<tpctypes::BufferWrite>)> {<br>
+public:<br>
+ static const char *getName() { return "WriteBuffers"; }<br>
+};<br>
+<br>
+class LoadDylib<br>
+ : public rpc::Function<LoadDylib, Expected<tpctypes::DylibHandle>(<br>
+ std::string DylibPath)> {<br>
+public:<br>
+ static const char *getName() { return "LoadDylib"; }<br>
+};<br>
+<br>
+class LookupSymbols<br>
+ : public rpc::Function<LookupSymbols,<br>
+ Expected<std::vector<tpctypes::LookupResult>>(<br>
+ std::vector<RemoteLookupRequest>)> {<br>
+public:<br>
+ static const char *getName() { return "LookupSymbols"; }<br>
+};<br>
+<br>
+class RunMain<br>
+ : public rpc::Function<RunMain, int32_t(JITTargetAddress MainAddr,<br>
+ std::vector<std::string> Args)> {<br>
+public:<br>
+ static const char *getName() { return "RunMain"; }<br>
+};<br>
+<br>
+class RunWrapper<br>
+ : public rpc::Function<RunWrapper,<br>
+ tpctypes::WrapperFunctionResult(<br>
+ JITTargetAddress, std::vector<uint8_t>)> {<br>
+public:<br>
+ static const char *getName() { return "RunWrapper"; }<br>
+};<br>
+<br>
+class CloseConnection : public rpc::Function<CloseConnection, void()> {<br>
+public:<br>
+ static const char *getName() { return "CloseConnection"; }<br>
+};<br>
+<br>
+} // end namespace orcrpctpc<br>
+<br>
+/// TargetProcessControl for a process connected via an ORC RPC Endpoint.<br>
+template <typename RPCEndpointT> class OrcRPCTPCServer {<br>
+public:<br>
+ /// Create an OrcRPCTPCServer from the given endpoint.<br>
+ OrcRPCTPCServer(RPCEndpointT &EP) : EP(EP) {<br>
+ using ThisT = OrcRPCTPCServer<RPCEndpointT>;<br>
+<br>
+ TripleStr = sys::getProcessTriple();<br>
+ PageSize = sys::Process::getPageSizeEstimate();<br>
+<br>
+ EP.template addHandler<orcrpctpc::GetTargetTriple>(*this,<br>
+ &ThisT::getTargetTriple);<br>
+ EP.template addHandler<orcrpctpc::GetPageSize>(*this, &ThisT::getPageSize);<br>
+<br>
+ EP.template addHandler<orcrpctpc::ReserveMem>(*this, &ThisT::reserveMemory);<br>
+ EP.template addHandler<orcrpctpc::FinalizeMem>(*this,<br>
+ &ThisT::finalizeMemory);<br>
+ EP.template addHandler<orcrpctpc::ReleaseMem>(*this, &ThisT::releaseMemory);<br>
+<br>
+ EP.template addHandler<orcrpctpc::WriteUInt8s>(<br>
+ handleWriteUInt<tpctypes::UInt8Write>);<br>
+ EP.template addHandler<orcrpctpc::WriteUInt16s>(<br>
+ handleWriteUInt<tpctypes::UInt16Write>);<br>
+ EP.template addHandler<orcrpctpc::WriteUInt32s>(<br>
+ handleWriteUInt<tpctypes::UInt32Write>);<br>
+ EP.template addHandler<orcrpctpc::WriteUInt64s>(<br>
+ handleWriteUInt<tpctypes::UInt64Write>);<br>
+ EP.template addHandler<orcrpctpc::WriteBuffers>(handleWriteBuffer);<br>
+<br>
+ EP.template addHandler<orcrpctpc::LoadDylib>(*this, &ThisT::loadDylib);<br>
+ EP.template addHandler<orcrpctpc::LookupSymbols>(*this,<br>
+ &ThisT::lookupSymbols);<br>
+<br>
+ EP.template addHandler<orcrpctpc::RunMain>(*this, &ThisT::runMain);<br>
+ EP.template addHandler<orcrpctpc::RunWrapper>(*this, &ThisT::runWrapper);<br>
+<br>
+ EP.template addHandler<orcrpctpc::CloseConnection>(*this,<br>
+ &ThisT::closeConnection);<br>
+ }<br>
+<br>
+ /// Set the ProgramName to be used as the first argv element when running<br>
+ /// functions via runAsMain.<br>
+ void setProgramName(Optional<std::string> ProgramName = None) {<br>
+ this->ProgramName = std::move(ProgramName);<br>
+ }<br>
+<br>
+ /// Get the RPC endpoint for this server.<br>
+ RPCEndpointT &getEndpoint() { return EP; }<br>
+<br>
+ /// Run the server loop.<br>
+ Error run() {<br>
+ while (!Finished) {<br>
+ if (auto Err = EP.handleOne())<br>
+ return Err;<br>
+ }<br>
+ return Error::success();<br>
+ }<br>
+<br>
+private:<br>
+ std::string getTargetTriple() { return TripleStr; }<br>
+ uint64_t getPageSize() { return PageSize; }<br>
+<br>
+ template <typename WriteT><br>
+ static void handleWriteUInt(const std::vector<WriteT> &Ws) {<br>
+ using ValueT = decltype(std::declval<WriteT>().Value);<br>
+ for (auto &W : Ws)<br>
+ *jitTargetAddressToPointer<ValueT *>(W.Address) = W.Value;<br>
+ }<br>
+<br>
+ std::string getProtStr(orcrpctpc::WireProtectionFlags WPF) {<br>
+ std::string Result;<br>
+ Result += (WPF & orcrpctpc::WPF_Read) ? 'R' : '-';<br>
+ Result += (WPF & orcrpctpc::WPF_Write) ? 'W' : '-';<br>
+ Result += (WPF & orcrpctpc::WPF_Exec) ? 'X' : '-';<br>
+ return Result;<br>
+ }<br>
+<br>
+ static void handleWriteBuffer(const std::vector<tpctypes::BufferWrite> &Ws) {<br>
+ for (auto &W : Ws) {<br>
+ memcpy(jitTargetAddressToPointer<char *>(W.Address), W.Buffer.data(),<br>
+ W.Buffer.size());<br>
+ }<br>
+ }<br>
+<br>
+ Expected<orcrpctpc::ReserveMemResult><br>
+ reserveMemory(const orcrpctpc::ReserveMemRequest &Request) {<br>
+ orcrpctpc::ReserveMemResult Allocs;<br>
+ auto PF = sys::Memory::MF_READ | sys::Memory::MF_WRITE;<br>
+<br>
+ uint64_t TotalSize = 0;<br>
+<br>
+ for (const auto &E : Request) {<br>
+ uint64_t Size = alignTo(E.Size, PageSize);<br>
+ uint16_t Align = E.Alignment;<br>
+<br>
+ if ((Align > PageSize) || (PageSize % Align))<br>
+ return make_error<StringError>(<br>
+ "Page alignmen does not satisfy requested alignment",<br>
+ inconvertibleErrorCode());<br>
+<br>
+ TotalSize += Size;<br>
+ }<br>
+<br>
+ // Allocate memory slab.<br>
+ std::error_code EC;<br>
+ auto MB = sys::Memory::allocateMappedMemory(TotalSize, nullptr, PF, EC);<br>
+ if (EC)<br>
+ return make_error<StringError>("Unable to allocate memory: " +<br>
+ EC.message(),<br>
+ inconvertibleErrorCode());<br>
+<br>
+ // Zero-fill the whole thing.<br>
+ memset(MB.base(), 0, MB.allocatedSize());<br>
+<br>
+ // Carve up sections to return.<br>
+ uint64_t SectionBase = 0;<br>
+ for (const auto &E : Request) {<br>
+ uint64_t SectionSize = alignTo(E.Size, PageSize);<br>
+ Allocs.push_back({E.Prot,<br>
+ pointerToJITTargetAddress(MB.base()) + SectionBase,<br>
+ SectionSize});<br>
+ SectionBase += SectionSize;<br>
+ }<br>
+<br>
+ return Allocs;<br>
+ }<br>
+<br>
+ Error finalizeMemory(const orcrpctpc::ReleaseOrFinalizeMemRequest &FMR) {<br>
+ for (const auto &E : FMR) {<br>
+ sys::MemoryBlock MB(jitTargetAddressToPointer<void *>(E.Address), E.Size);<br>
+<br>
+ auto PF = orcrpctpc::fromWireProtectionFlags(E.Prot);<br>
+ if (auto EC =<br>
+ sys::Memory::protectMappedMemory(MB, static_cast<unsigned>(PF)))<br>
+ return make_error<StringError>("error protecting memory: " +<br>
+ EC.message(),<br>
+ inconvertibleErrorCode());<br>
+ }<br>
+ return Error::success();<br>
+ }<br>
+<br>
+ Error releaseMemory(const orcrpctpc::ReleaseOrFinalizeMemRequest &RMR) {<br>
+ for (const auto &E : RMR) {<br>
+ sys::MemoryBlock MB(jitTargetAddressToPointer<void *>(E.Address), E.Size);<br>
+<br>
+ if (auto EC = sys::Memory::releaseMappedMemory(MB))<br>
+ return make_error<StringError>("error release memory: " + EC.message(),<br>
+ inconvertibleErrorCode());<br>
+ }<br>
+ return Error::success();<br>
+ }<br>
+<br>
+ Expected<tpctypes::DylibHandle> loadDylib(const std::string &Path) {<br>
+ std::string ErrMsg;<br>
+ const char *DLPath = !Path.empty() ? Path.c_str() : nullptr;<br>
+ auto DL = sys::DynamicLibrary::getPermanentLibrary(DLPath, &ErrMsg);<br>
+ if (!DL.isValid())<br>
+ return make_error<StringError>(std::move(ErrMsg),<br>
+ inconvertibleErrorCode());<br>
+<br>
+ tpctypes::DylibHandle H = Dylibs.size();<br>
+ Dylibs[H] = std::move(DL);<br>
+ return H;<br>
+ }<br>
+<br>
+ Expected<std::vector<tpctypes::LookupResult>><br>
+ lookupSymbols(const std::vector<orcrpctpc::RemoteLookupRequest> &Request) {<br>
+ std::vector<tpctypes::LookupResult> Result;<br>
+<br>
+ for (const auto &E : Request) {<br>
+ auto I = Dylibs.find(E.first);<br>
+ if (I == Dylibs.end())<br>
+ return make_error<StringError>("Unrecognized handle",<br>
+ inconvertibleErrorCode());<br>
+ auto &DL = I->second;<br>
+ Result.push_back({});<br>
+<br>
+ for (const auto &KV : E.second) {<br>
+ auto &SymString = KV.first;<br>
+ bool WeakReference = KV.second;<br>
+<br>
+ const char *Sym = SymString.c_str();<br>
+#ifdef __APPLE__<br>
+ if (*Sym == '_')<br>
+ ++Sym;<br>
+#endif<br>
+<br>
+ void *Addr = DL.getAddressOfSymbol(Sym);<br>
+ if (!Addr && !WeakReference)<br>
+ return make_error<StringError>(Twine("Missing definition for ") + Sym,<br>
+ inconvertibleErrorCode());<br>
+<br>
+ Result.back().push_back(pointerToJITTargetAddress(Addr));<br>
+ }<br>
+ }<br>
+<br>
+ return Result;<br>
+ }<br>
+<br>
+ int32_t runMain(JITTargetAddress MainFnAddr,<br>
+ const std::vector<std::string> &Args) {<br>
+ Optional<StringRef> ProgramNameOverride;<br>
+ if (ProgramName)<br>
+ ProgramNameOverride = *ProgramName;<br>
+<br>
+ return runAsMain(<br>
+ jitTargetAddressToFunction<int (*)(int, char *[])>(MainFnAddr), Args,<br>
+ ProgramNameOverride);<br>
+ }<br>
+<br>
+ tpctypes::WrapperFunctionResult<br>
+ runWrapper(JITTargetAddress WrapperFnAddr,<br>
+ const std::vector<uint8_t> &ArgBuffer) {<br>
+ using WrapperFnTy = tpctypes::CWrapperFunctionResult (*)(<br>
+ const uint8_t *Data, uint64_t Size);<br>
+ auto *WrapperFn = jitTargetAddressToFunction<WrapperFnTy>(WrapperFnAddr);<br>
+ return WrapperFn(ArgBuffer.data(), ArgBuffer.size());<br>
+ }<br>
+<br>
+ void closeConnection() { Finished = true; }<br>
+<br>
+ std::string TripleStr;<br>
+ uint64_t PageSize = 0;<br>
+ Optional<std::string> ProgramName;<br>
+ RPCEndpointT &EP;<br>
+ std::atomic<bool> Finished{false};<br>
+ DenseMap<tpctypes::DylibHandle, sys::DynamicLibrary> Dylibs;<br>
+};<br>
+<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRPCTPCSERVER_H<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h<br>
new file mode 100644<br>
index 000000000000..811c50e3ce4d<br>
--- /dev/null<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h<br>
@@ -0,0 +1,41 @@<br>
+//===----- RegisterEHFrames.h -- Register EH frame sections -----*- C++ -*-===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// Support for dynamically registering and deregistering eh-frame sections<br>
+// in-process via libunwind.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_REGISTEREHFRAMES_H<br>
+#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_REGISTEREHFRAMES_H<br>
+<br>
+#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"<br>
+#include "llvm/Support/Error.h"<br>
+#include <vector><br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+/// Register frames in the given eh-frame section with libunwind.<br>
+Error registerEHFrameSection(const void *EHFrameSectionAddr,<br>
+ size_t EHFrameSectionSize);<br>
+<br>
+/// Unregister frames in the given eh-frame section with libunwind.<br>
+Error deregisterEHFrameSection(const void *EHFrameSectionAddr,<br>
+ size_t EHFrameSectionSize);<br>
+<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
+<br>
+extern "C" llvm::orc::tpctypes::CWrapperFunctionResult<br>
+llvm_orc_registerEHFrameSectionWrapper(uint8_t *Data, uint64_t Size);<br>
+<br>
+extern "C" llvm::orc::tpctypes::CWrapperFunctionResult<br>
+llvm_orc_deregisterEHFrameSectionWrapper(uint8_t *Data, uint64_t Size);<br>
+<br>
+#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_REGISTEREHFRAMES_H<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h<br>
new file mode 100644<br>
index 000000000000..1d2f6d2be089<br>
--- /dev/null<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h<br>
@@ -0,0 +1,38 @@<br>
+//===-- TargetExecutionUtils.h - Utils for execution in target --*- C++ -*-===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// Utilities for execution in the target process.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_TARGETEXECUTIONUTILS_H<br>
+#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_TARGETEXECUTIONUTILS_H<br>
+<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/ADT/Optional.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include <string><br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+/// Run a main function, returning the result.<br>
+///<br>
+/// If the optional ProgramName argument is given then it will be inserted<br>
+/// before the strings in Args as the first argument to the called function.<br>
+///<br>
+/// It is legal to have an empty argument list and no program name, however<br>
+/// many main functions will expect a name argument at least, and will fail<br>
+/// if none is provided.<br>
+int runAsMain(int (*Main)(int, char *[]), ArrayRef<std::string> Args,<br>
+ Optional<StringRef> ProgramName = None);<br>
+<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_TARGETEXECUTIONUTILS_H<br>
<br>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h<br>
index d3349753284e..504a5ea0f9e9 100644<br>
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h<br>
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcessControl.h<br>
@@ -18,6 +18,7 @@<br>
#include "llvm/ADT/Triple.h"<br>
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"<br>
#include "llvm/ExecutionEngine/Orc/Core.h"<br>
+#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"<br>
#include "llvm/Support/DynamicLibrary.h"<br>
#include "llvm/Support/MSVCErrorWorkarounds.h"<br>
<br>
@@ -33,76 +34,55 @@ class TargetProcessControl {<br>
/// APIs for manipulating memory in the target process.<br>
class MemoryAccess {<br>
public:<br>
- template <typename T> struct UIntWrite {<br>
- UIntWrite() = default;<br>
- UIntWrite(JITTargetAddress Address, T Value)<br>
- : Address(Address), Value(Value) {}<br>
-<br>
- JITTargetAddress Address = 0;<br>
- T Value = 0;<br>
- };<br>
-<br>
- using UInt8Write = UIntWrite<uint8_t>;<br>
- using UInt16Write = UIntWrite<uint16_t>;<br>
- using UInt32Write = UIntWrite<uint32_t>;<br>
- using UInt64Write = UIntWrite<uint64_t>;<br>
-<br>
- struct BufferWrite {<br>
- BufferWrite(JITTargetAddress Address, StringRef Buffer)<br>
- : Address(Address), Buffer(Buffer) {}<br>
-<br>
- JITTargetAddress Address = 0;<br>
- StringRef Buffer;<br>
- };<br>
-<br>
+ /// Callback function for asynchronous writes.<br>
using WriteResultFn = unique_function<void(Error)>;<br>
<br>
virtual ~MemoryAccess();<br>
<br>
- virtual void writeUInt8s(ArrayRef<UInt8Write> Ws,<br>
+ virtual void writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws,<br>
WriteResultFn OnWriteComplete) = 0;<br>
<br>
- virtual void writeUInt16s(ArrayRef<UInt16Write> Ws,<br>
+ virtual void writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws,<br>
WriteResultFn OnWriteComplete) = 0;<br>
<br>
- virtual void writeUInt32s(ArrayRef<UInt32Write> Ws,<br>
+ virtual void writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws,<br>
WriteResultFn OnWriteComplete) = 0;<br>
<br>
- virtual void writeUInt64s(ArrayRef<UInt64Write> Ws,<br>
+ virtual void writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws,<br>
WriteResultFn OnWriteComplete) = 0;<br>
<br>
- virtual void writeBuffers(ArrayRef<BufferWrite> Ws,<br>
+ virtual void writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws,<br>
WriteResultFn OnWriteComplete) = 0;<br>
<br>
- Error writeUInt8s(ArrayRef<UInt8Write> Ws) {<br>
+ Error writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws) {<br>
std::promise<MSVCPError> ResultP;<br>
auto ResultF = ResultP.get_future();<br>
writeUInt8s(Ws, [&](Error Err) { ResultP.set_value(std::move(Err)); });<br>
return ResultF.get();<br>
}<br>
<br>
- Error writeUInt16s(ArrayRef<UInt16Write> Ws) {<br>
+ Error writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws) {<br>
std::promise<MSVCPError> ResultP;<br>
auto ResultF = ResultP.get_future();<br>
writeUInt16s(Ws, [&](Error Err) { ResultP.set_value(std::move(Err)); });<br>
return ResultF.get();<br>
}<br>
<br>
- Error writeUInt32s(ArrayRef<UInt32Write> Ws) {<br>
+ Error writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws) {<br>
std::promise<MSVCPError> ResultP;<br>
auto ResultF = ResultP.get_future();<br>
writeUInt32s(Ws, [&](Error Err) { ResultP.set_value(std::move(Err)); });<br>
return ResultF.get();<br>
}<br>
<br>
- Error writeUInt64s(ArrayRef<UInt64Write> Ws) {<br>
+ Error writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws) {<br>
std::promise<MSVCPError> ResultP;<br>
auto ResultF = ResultP.get_future();<br>
writeUInt64s(Ws, [&](Error Err) { ResultP.set_value(std::move(Err)); });<br>
return ResultF.get();<br>
}<br>
<br>
- Error writeBuffers(ArrayRef<BufferWrite> Ws) {<br>
+ Error writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws) {<br>
std::promise<MSVCPError> ResultP;<br>
auto ResultF = ResultP.get_future();<br>
writeBuffers(Ws, [&](Error Err) { ResultP.set_value(std::move(Err)); });<br>
@@ -110,43 +90,30 @@ class TargetProcessControl {<br>
}<br>
};<br>
<br>
- /// A handle for a library opened via loadDylib.<br>
- ///<br>
- /// Note that this handle does not necessarily represent a JITDylib: it may<br>
- /// be a regular dynamic library or shared object (e.g. one opened via a<br>
- /// dlopen in the target process).<br>
- using DylibHandle = JITTargetAddress;<br>
-<br>
- /// Request lookup within the given DylibHandle.<br>
- struct LookupRequestElement {<br>
- LookupRequestElement(DylibHandle Handle, const SymbolLookupSet &Symbols)<br>
- : Handle(Handle), Symbols(Symbols) {}<br>
- DylibHandle Handle;<br>
- const SymbolLookupSet &Symbols;<br>
- };<br>
-<br>
- using LookupRequest = ArrayRef<LookupRequestElement>;<br>
+ virtual ~TargetProcessControl();<br>
<br>
- using LookupResult = std::vector<std::vector<JITTargetAddress>>;<br>
+ /// Intern a symbol name in the SymbolStringPool.<br>
+ SymbolStringPtr intern(StringRef SymName) { return SSP->intern(SymName); }<br>
<br>
- virtual ~TargetProcessControl();<br>
+ /// Return a shared pointer to the SymbolStringPool for this instance.<br>
+ std::shared_ptr<SymbolStringPool> getSymbolStringPool() const { return SSP; }<br>
<br>
/// Return the Triple for the target process.<br>
- const Triple &getTargetTriple() const { return TT; }<br>
+ const Triple &getTargetTriple() const { return TargetTriple; }<br>
<br>
/// Get the page size for the target process.<br>
unsigned getPageSize() const { return PageSize; }<br>
<br>
- /// Return a JITLinkMemoryManager for the target process.<br>
- jitlink::JITLinkMemoryManager &getMemMgr() const { return *MemMgr; }<br>
-<br>
/// Return a MemoryAccess object for the target process.<br>
MemoryAccess &getMemoryAccess() const { return *MemAccess; }<br>
<br>
+ /// Return a JITLinkMemoryManager for the target process.<br>
+ jitlink::JITLinkMemoryManager &getMemMgr() const { return *MemMgr; }<br>
+<br>
/// Load the dynamic library at the given path and return a handle to it.<br>
/// If LibraryPath is null this function will return the global handle for<br>
/// the target process.<br>
- virtual Expected<DylibHandle> loadDylib(const char *DylibPath) = 0;<br>
+ virtual Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) = 0;<br>
<br>
/// Search for symbols in the target process.<br>
///<br>
@@ -154,14 +121,37 @@ class TargetProcessControl {<br>
/// that correspond to the lookup order. If a required symbol is not<br>
/// found then this method will return an error. If a weakly referenced<br>
/// symbol is not found then it be assigned a '0' value in the result.<br>
- virtual Expected<LookupResult> lookupSymbols(LookupRequest Request) = 0;<br>
+ /// that correspond to the lookup order.<br>
+ virtual Expected<std::vector<tpctypes::LookupResult>><br>
+ lookupSymbols(ArrayRef<tpctypes::LookupRequest> Request) = 0;<br>
+<br>
+ /// Run function with a main-like signature.<br>
+ virtual Expected<int32_t> runAsMain(JITTargetAddress MainFnAddr,<br>
+ ArrayRef<std::string> Args) = 0;<br>
+<br>
+ /// Run a wrapper function with signature:<br>
+ ///<br>
+ /// \code{.cpp}<br>
+ /// CWrapperFunctionResult fn(uint8_t *Data, uint64_t Size);<br>
+ /// \endcode{.cpp}<br>
+ ///<br>
+ virtual Expected<tpctypes::WrapperFunctionResult><br>
+ runWrapper(JITTargetAddress WrapperFnAddr, ArrayRef<uint8_t> ArgBuffer) = 0;<br>
+<br>
+ /// Disconnect from the target process.<br>
+ ///<br>
+ /// This should be called after the JIT session is shut down.<br>
+ virtual Error disconnect() = 0;<br>
<br>
protected:<br>
+ TargetProcessControl(std::shared_ptr<SymbolStringPool> SSP)<br>
+ : SSP(std::move(SSP)) {}<br>
<br>
- Triple TT;<br>
+ std::shared_ptr<SymbolStringPool> SSP;<br>
+ Triple TargetTriple;<br>
unsigned PageSize = 0;<br>
- jitlink::JITLinkMemoryManager *MemMgr = nullptr;<br>
MemoryAccess *MemAccess = nullptr;<br>
+ jitlink::JITLinkMemoryManager *MemMgr = nullptr;<br>
};<br>
<br>
/// A TargetProcessControl implementation targeting the current process.<br>
@@ -169,33 +159,44 @@ class SelfTargetProcessControl : public TargetProcessControl,<br>
private TargetProcessControl::MemoryAccess {<br>
public:<br>
SelfTargetProcessControl(<br>
- Triple TT, unsigned PageSize,<br>
- std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);<br>
+ std::shared_ptr<SymbolStringPool> SSP, Triple TargetTriple,<br>
+ unsigned PageSize, std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);<br>
<br>
/// Create a SelfTargetProcessControl with the given memory manager.<br>
/// If no memory manager is given a jitlink::InProcessMemoryManager will<br>
/// be used by default.<br>
static Expected<std::unique_ptr<SelfTargetProcessControl>><br>
- Create(std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr = nullptr);<br>
+ Create(std::shared_ptr<SymbolStringPool> SSP,<br>
+ std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr = nullptr);<br>
+<br>
+ Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;<br>
+<br>
+ Expected<std::vector<tpctypes::LookupResult>><br>
+ lookupSymbols(ArrayRef<tpctypes::LookupRequest> Request) override;<br>
+<br>
+ Expected<int32_t> runAsMain(JITTargetAddress MainFnAddr,<br>
+ ArrayRef<std::string> Args) override;<br>
<br>
- Expected<DylibHandle> loadDylib(const char *DylibPath) override;<br>
+ Expected<tpctypes::WrapperFunctionResult><br>
+ runWrapper(JITTargetAddress WrapperFnAddr,<br>
+ ArrayRef<uint8_t> ArgBuffer) override;<br>
<br>
- Expected<LookupResult> lookupSymbols(LookupRequest Request) override;<br>
+ Error disconnect() override;<br>
<br>
private:<br>
- void writeUInt8s(ArrayRef<UInt8Write> Ws,<br>
+ void writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws,<br>
WriteResultFn OnWriteComplete) override;<br>
<br>
- void writeUInt16s(ArrayRef<UInt16Write> Ws,<br>
+ void writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws,<br>
WriteResultFn OnWriteComplete) override;<br>
<br>
- void writeUInt32s(ArrayRef<UInt32Write> Ws,<br>
+ void writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws,<br>
WriteResultFn OnWriteComplete) override;<br>
<br>
- void writeUInt64s(ArrayRef<UInt64Write> Ws,<br>
+ void writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws,<br>
WriteResultFn OnWriteComplete) override;<br>
<br>
- void writeBuffers(ArrayRef<BufferWrite> Ws,<br>
+ void writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws,<br>
WriteResultFn OnWriteComplete) override;<br>
<br>
std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/CMakeLists.txt b/llvm/lib/ExecutionEngine/CMakeLists.txt<br>
index 9b5dd44e079e..a13fcc784e4b 100644<br>
--- a/llvm/lib/ExecutionEngine/CMakeLists.txt<br>
+++ b/llvm/lib/ExecutionEngine/CMakeLists.txt<br>
@@ -21,7 +21,6 @@ endif()<br>
add_subdirectory(Interpreter)<br>
add_subdirectory(JITLink)<br>
add_subdirectory(MCJIT)<br>
-add_subdirectory(OrcError)<br>
add_subdirectory(Orc)<br>
add_subdirectory(RuntimeDyld)<br>
<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt<br>
index 86836e54f20e..20c53980b512 100644<br>
--- a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt<br>
+++ b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt<br>
@@ -22,4 +22,6 @@ add_llvm_component_library(LLVMJITLink<br>
target_link_libraries(LLVMJITLink<br>
PRIVATE<br>
LLVMObject<br>
+ LLVMOrcTargetProcess<br>
+ LLVMSupport<br>
)<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp<br>
index b94a2b36b5f1..7a89476687d2 100644<br>
--- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp<br>
+++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp<br>
@@ -11,6 +11,7 @@<br>
<br>
#include "llvm/BinaryFormat/Dwarf.h"<br>
#include "llvm/Config/config.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"<br>
#include "llvm/Support/DynamicLibrary.h"<br>
<br>
#define DEBUG_TYPE "jitlink"<br>
@@ -630,142 +631,18 @@ Expected<Symbol &> EHFrameEdgeFixer::getOrCreateSymbol(ParseContext &PC,<br>
return PC.G.addAnonymousSymbol(*B, Addr - B->getAddress(), 0, false, false);<br>
}<br>
<br>
-#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \<br>
- !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)<br>
-extern "C" void __register_frame(const void *);<br>
-extern "C" void __deregister_frame(const void *);<br>
-<br>
-Error registerFrameWrapper(const void *P) {<br>
- __register_frame(P);<br>
- return Error::success();<br>
-}<br>
-<br>
-Error deregisterFrameWrapper(const void *P) {<br>
- __deregister_frame(P);<br>
- return Error::success();<br>
-}<br>
-<br>
-#else<br>
-<br>
-// The building compiler does not have __(de)register_frame but<br>
-// it may be found at runtime in a dynamically-loaded library.<br>
-// For example, this happens when building LLVM with Visual C++<br>
-// but using the MingW runtime.<br>
-static Error registerFrameWrapper(const void *P) {<br>
- static void((*RegisterFrame)(const void *)) = 0;<br>
-<br>
- if (!RegisterFrame)<br>
- *(void **)&RegisterFrame =<br>
- llvm::sys::DynamicLibrary::SearchForAddressOfSymbol("__register_frame");<br>
-<br>
- if (RegisterFrame) {<br>
- RegisterFrame(P);<br>
- return Error::success();<br>
- }<br>
-<br>
- return make_error<JITLinkError>("could not register eh-frame: "<br>
- "__register_frame function not found");<br>
-}<br>
-<br>
-static Error deregisterFrameWrapper(const void *P) {<br>
- static void((*DeregisterFrame)(const void *)) = 0;<br>
-<br>
- if (!DeregisterFrame)<br>
- *(void **)&DeregisterFrame =<br>
- llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(<br>
- "__deregister_frame");<br>
-<br>
- if (DeregisterFrame) {<br>
- DeregisterFrame(P);<br>
- return Error::success();<br>
- }<br>
-<br>
- return make_error<JITLinkError>("could not deregister eh-frame: "<br>
- "__deregister_frame function not found");<br>
-}<br>
-#endif<br>
-<br>
-#ifdef __APPLE__<br>
-<br>
-template <typename HandleFDEFn><br>
-Error walkAppleEHFrameSection(const char *const SectionStart,<br>
- size_t SectionSize,<br>
- HandleFDEFn HandleFDE) {<br>
- const char *CurCFIRecord = SectionStart;<br>
- const char *End = SectionStart + SectionSize;<br>
- uint64_t Size = *reinterpret_cast<const uint32_t *>(CurCFIRecord);<br>
-<br>
- while (CurCFIRecord != End && Size != 0) {<br>
- const char *OffsetField = CurCFIRecord + (Size == 0xffffffff ? 12 : 4);<br>
- if (Size == 0xffffffff)<br>
- Size = *reinterpret_cast<const uint64_t *>(CurCFIRecord + 4) + 12;<br>
- else<br>
- Size += 4;<br>
- uint32_t Offset = *reinterpret_cast<const uint32_t *>(OffsetField);<br>
-<br>
- LLVM_DEBUG({<br>
- dbgs() << "Registering eh-frame section:\n";<br>
- dbgs() << "Processing " << (Offset ? "FDE" : "CIE") << " @"<br>
- << (void *)CurCFIRecord << ": [";<br>
- for (unsigned I = 0; I < Size; ++I)<br>
- dbgs() << format(" 0x%02" PRIx8, *(CurCFIRecord + I));<br>
- dbgs() << " ]\n";<br>
- });<br>
-<br>
- if (Offset != 0)<br>
- if (auto Err = HandleFDE(CurCFIRecord))<br>
- return Err;<br>
-<br>
- CurCFIRecord += Size;<br>
-<br>
- Size = *reinterpret_cast<const uint32_t *>(CurCFIRecord);<br>
- }<br>
-<br>
- return Error::success();<br>
-}<br>
-<br>
-#endif // __APPLE__<br>
-<br>
-Error registerEHFrameSection(const void *EHFrameSectionAddr,<br>
- size_t EHFrameSectionSize) {<br>
-#ifdef __APPLE__<br>
- // On Darwin __register_frame has to be called for each FDE entry.<br>
- return walkAppleEHFrameSection(static_cast<const char *>(EHFrameSectionAddr),<br>
- EHFrameSectionSize,<br>
- registerFrameWrapper);<br>
-#else<br>
- // On Linux __register_frame takes a single argument:<br>
- // a pointer to the start of the .eh_frame section.<br>
-<br>
- // How can it find the end? Because crtendS.o is linked<br>
- // in and it has an .eh_frame section with four zero chars.<br>
- return registerFrameWrapper(EHFrameSectionAddr);<br>
-#endif<br>
-}<br>
-<br>
-Error deregisterEHFrameSection(const void *EHFrameSectionAddr,<br>
- size_t EHFrameSectionSize) {<br>
-#ifdef __APPLE__<br>
- return walkAppleEHFrameSection(static_cast<const char *>(EHFrameSectionAddr),<br>
- EHFrameSectionSize,<br>
- deregisterFrameWrapper);<br>
-#else<br>
- return deregisterFrameWrapper(EHFrameSectionAddr);<br>
-#endif<br>
-}<br>
-<br>
EHFrameRegistrar::~EHFrameRegistrar() {}<br>
<br>
Error InProcessEHFrameRegistrar::registerEHFrames(<br>
JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {<br>
- return registerEHFrameSection(<br>
+ return orc::registerEHFrameSection(<br>
jitTargetAddressToPointer<void *>(EHFrameSectionAddr),<br>
EHFrameSectionSize);<br>
}<br>
<br>
Error InProcessEHFrameRegistrar::deregisterEHFrames(<br>
JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {<br>
- return deregisterEHFrameSection(<br>
+ return orc::deregisterEHFrameSection(<br>
jitTargetAddressToPointer<void *>(EHFrameSectionAddr),<br>
EHFrameSectionSize);<br>
}<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/JITLink/LLVMBuild.txt b/llvm/lib/ExecutionEngine/JITLink/LLVMBuild.txt<br>
index e7721a184b98..f73246beb224 100644<br>
--- a/llvm/lib/ExecutionEngine/JITLink/LLVMBuild.txt<br>
+++ b/llvm/lib/ExecutionEngine/JITLink/LLVMBuild.txt<br>
@@ -18,4 +18,4 @@<br>
type = Library<br>
name = JITLink<br>
parent = ExecutionEngine<br>
-required_libraries = BinaryFormat Object Support<br>
+required_libraries = BinaryFormat Object OrcTargetProcess Support<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/LLVMBuild.txt b/llvm/lib/ExecutionEngine/LLVMBuild.txt<br>
index 9bc6775f78a0..13872da4a564 100644<br>
--- a/llvm/lib/ExecutionEngine/LLVMBuild.txt<br>
+++ b/llvm/lib/ExecutionEngine/LLVMBuild.txt<br>
@@ -16,7 +16,7 @@<br>
<br>
[common]<br>
subdirectories = Interpreter MCJIT JITLink RuntimeDyld IntelJITEvents<br>
- OProfileJIT Orc OrcError PerfJITEvents<br>
+ OProfileJIT Orc PerfJITEvents<br>
<br>
[component_0]<br>
type = Library<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt<br>
index 6396fb5d1187..2ab410dbf578 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt<br>
+++ b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt<br>
@@ -23,6 +23,7 @@ add_llvm_component_library(LLVMOrcJIT<br>
TargetProcessControl.cpp<br>
ThreadSafeModule.cpp<br>
TPCDynamicLibrarySearchGenerator.cpp<br>
+ TPCEHFrameRegistrar.cpp<br>
TPCIndirectionUtils.cpp<br>
ADDITIONAL_HEADER_DIRS<br>
${LLVM_MAIN_INCLUDE_DIR}/llvm/ExecutionEngine/Orc<br>
@@ -31,6 +32,9 @@ add_llvm_component_library(LLVMOrcJIT<br>
intrinsics_gen<br>
)<br>
<br>
+add_subdirectory(Shared)<br>
+add_subdirectory(TargetProcess)<br>
+<br>
target_link_libraries(LLVMOrcJIT<br>
PRIVATE<br>
LLVMAnalysis<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp<br>
index 5f9faf693c82..6a1a41a13a1b 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp<br>
@@ -21,32 +21,6 @@<br>
namespace llvm {<br>
namespace orc {<br>
<br>
-int runAsMain(int (*Main)(int, char *[]), ArrayRef<std::string> Args,<br>
- Optional<StringRef> ProgramName) {<br>
- std::vector<std::unique_ptr<char[]>> ArgVStorage;<br>
- std::vector<char *> ArgV;<br>
-<br>
- ArgVStorage.reserve(Args.size() + (ProgramName ? 1 : 0));<br>
- ArgV.reserve(Args.size() + 1 + (ProgramName ? 1 : 0));<br>
-<br>
- if (ProgramName) {<br>
- ArgVStorage.push_back(std::make_unique<char[]>(ProgramName->size() + 1));<br>
- llvm::copy(*ProgramName, &ArgVStorage.back()[0]);<br>
- ArgVStorage.back()[ProgramName->size()] = '\0';<br>
- ArgV.push_back(ArgVStorage.back().get());<br>
- }<br>
-<br>
- for (auto &Arg : Args) {<br>
- ArgVStorage.push_back(std::make_unique<char[]>(Arg.size() + 1));<br>
- llvm::copy(Arg, &ArgVStorage.back()[0]);<br>
- ArgVStorage.back()[Arg.size()] = '\0';<br>
- ArgV.push_back(ArgVStorage.back().get());<br>
- }<br>
- ArgV.push_back(nullptr);<br>
-<br>
- return Main(Args.size() + !!ProgramName, ArgV.data());<br>
-}<br>
-<br>
CtorDtorIterator::CtorDtorIterator(const GlobalVariable *GV, bool End)<br>
: InitList(<br>
GV ? dyn_cast_or_null<ConstantArray>(GV->getInitializer()) : nullptr),<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/LLVMBuild.txt b/llvm/lib/ExecutionEngine/Orc/LLVMBuild.txt<br>
index 4a78243551ca..5d580d8fb40d 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/LLVMBuild.txt<br>
+++ b/llvm/lib/ExecutionEngine/Orc/LLVMBuild.txt<br>
@@ -14,9 +14,12 @@<br>
;<br>
;===------------------------------------------------------------------------===;<br>
<br>
+[common]<br>
+subdirectories = Shared TargetProcess<br>
+<br>
[component_0]<br>
type = Library<br>
name = OrcJIT<br>
parent = ExecutionEngine<br>
-required_libraries = Core ExecutionEngine JITLink Object OrcError MC Passes<br>
+required_libraries = Core ExecutionEngine JITLink Object OrcShared MC Passes<br>
RuntimeDyld Support Target TransformUtils<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/OrcError/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt<br>
similarity index 60%<br>
rename from llvm/lib/ExecutionEngine/OrcError/CMakeLists.txt<br>
rename to llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt<br>
index bd968d55e670..57c06d739ec7 100644<br>
--- a/llvm/lib/ExecutionEngine/OrcError/CMakeLists.txt<br>
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/CMakeLists.txt<br>
@@ -1,6 +1,7 @@<br>
-add_llvm_component_library(LLVMOrcError<br>
+add_llvm_component_library(LLVMOrcShared<br>
OrcError.cpp<br>
RPCError.cpp<br>
+ TargetProcessControlTypes.cpp<br>
ADDITIONAL_HEADER_DIRS<br>
${LLVM_MAIN_INCLUDE_DIR}/llvm/ExecutionEngine/Orc<br>
)<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/OrcError/LLVMBuild.txt b/llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt<br>
similarity index 83%<br>
rename from llvm/lib/ExecutionEngine/OrcError/LLVMBuild.txt<br>
rename to llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt<br>
index 65e7916916f3..68f2ab08c9ca 100644<br>
--- a/llvm/lib/ExecutionEngine/OrcError/LLVMBuild.txt<br>
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt<br>
@@ -1,4 +1,4 @@<br>
-;===- ./lib/ExecutionEngine/OrcError/LLVMBuild.txt -------------*- Conf -*--===;<br>
+;===- ./lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt ------------*- Conf -*--===;<br>
;<br>
; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
; See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
@@ -16,6 +16,6 @@<br>
<br>
[component_0]<br>
type = Library<br>
-name = OrcError<br>
-parent = ExecutionEngine<br>
+name = OrcShared<br>
+parent = OrcJIT<br>
required_libraries = Support<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt.rej b/llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt.rej<br>
new file mode 100644<br>
index 000000000000..49d4038c2bf5<br>
--- /dev/null<br>
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/LLVMBuild.txt.rej<br>
@@ -0,0 +1,27 @@<br>
+***************<br>
+*** 1,4 ****<br>
+- ;===- ./lib/ExecutionEngine/OrcError/LLVMBuild.txt -------------*- Conf -*--===;<br>
+ ;<br>
+ ; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+ ; See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+--- 1,4 ----<br>
++ ;===- ./tools/llvm-jitlink/llvm-jitlink-executor/LLVMBuild.txt -*- Conf -*--===;<br>
+ ;<br>
+ ; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+ ; See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+***************<br>
+*** 15,21 ****<br>
+ ;===------------------------------------------------------------------------===;<br>
+ <br>
+ [component_0]<br>
+- type = Library<br>
+- name = OrcError<br>
+- parent = ExecutionEngine<br>
+- required_libraries = Support<br>
+--- 15,20 ----<br>
+ ;===------------------------------------------------------------------------===;<br>
+ <br>
+ [component_0]<br>
++ type = Tool<br>
++ name = llvm-jitlink-executor<br>
++ parent = llvm-jitlink<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/OrcError/OrcError.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/OrcError.cpp<br>
similarity index 96%<br>
rename from llvm/lib/ExecutionEngine/OrcError/OrcError.cpp<br>
rename to llvm/lib/ExecutionEngine/Orc/Shared/OrcError.cpp<br>
index cc99e154fbec..9b1c028d7047 100644<br>
--- a/llvm/lib/ExecutionEngine/OrcError/OrcError.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/OrcError.cpp<br>
@@ -71,7 +71,7 @@ class OrcErrorCategory : public std::error_category {<br>
};<br>
<br>
static ManagedStatic<OrcErrorCategory> OrcErrCat;<br>
-}<br>
+} // namespace<br>
<br>
namespace llvm {<br>
namespace orc {<br>
@@ -84,9 +84,8 @@ std::error_code orcError(OrcErrorCode ErrCode) {<br>
return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);<br>
}<br>
<br>
-<br>
DuplicateDefinition::DuplicateDefinition(std::string SymbolName)<br>
- : SymbolName(std::move(SymbolName)) {}<br>
+ : SymbolName(std::move(SymbolName)) {}<br>
<br>
std::error_code DuplicateDefinition::convertToErrorCode() const {<br>
return orcError(OrcErrorCode::DuplicateDefinition);<br>
@@ -101,7 +100,7 @@ const std::string &DuplicateDefinition::getSymbolName() const {<br>
}<br>
<br>
JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)<br>
- : SymbolName(std::move(SymbolName)) {}<br>
+ : SymbolName(std::move(SymbolName)) {}<br>
<br>
std::error_code JITSymbolNotFound::convertToErrorCode() const {<br>
typedef std::underlying_type<OrcErrorCode>::type UT;<br>
@@ -117,5 +116,5 @@ const std::string &JITSymbolNotFound::getSymbolName() const {<br>
return SymbolName;<br>
}<br>
<br>
-}<br>
-}<br>
+} // namespace orc<br>
+} // namespace llvm<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/OrcError/RPCError.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/RPCError.cpp<br>
similarity index 99%<br>
rename from llvm/lib/ExecutionEngine/OrcError/RPCError.cpp<br>
rename to llvm/lib/ExecutionEngine/Orc/Shared/RPCError.cpp<br>
index 3cf78fd9f7ba..a13db4863953 100644<br>
--- a/llvm/lib/ExecutionEngine/OrcError/RPCError.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/RPCError.cpp<br>
@@ -14,8 +14,8 @@<br>
#include "llvm/Support/Error.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
<br>
-#include <system_error><br>
#include <string><br>
+#include <system_error><br>
<br>
char llvm::orc::rpc::RPCFatalError::ID = 0;<br>
char llvm::orc::rpc::ConnectionClosed::ID = 0;<br>
@@ -53,7 +53,6 @@ void CouldNotNegotiate::log(raw_ostream &OS) const {<br>
OS << "Could not negotiate RPC function " << Signature;<br>
}<br>
<br>
-<br>
} // end namespace rpc<br>
} // end namespace orc<br>
} // end namespace llvm<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.cpp<br>
new file mode 100644<br>
index 000000000000..0b77eac8b4a6<br>
--- /dev/null<br>
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.cpp<br>
@@ -0,0 +1,43 @@<br>
+//===---------- TargetProcessControlTypes.cpp - Shared TPC types ----------===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// TargetProcessControl types.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"<br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+namespace tpctypes {<br>
+<br>
+WrapperFunctionResult WrapperFunctionResult::from(StringRef S) {<br>
+ CWrapperFunctionResult R = {0, {.ValuePtr = nullptr}, nullptr};<br>
+ R.Size = S.size();<br>
+ if (R.Size > sizeof(uint64_t)) {<br>
+ R.Data.ValuePtr = new uint8_t[R.Size];<br>
+ memcpy(R.Data.ValuePtr, S.data(), R.Size);<br>
+ R.Destroy = destroyWithDeleteArray;<br>
+ } else<br>
+ memcpy(R.Data.Value, S.data(), R.Size);<br>
+ return R;<br>
+}<br>
+<br>
+void WrapperFunctionResult::destroyWithFree(CWrapperFunctionResultData Data,<br>
+ uint64_t Size) {<br>
+ free(Data.ValuePtr);<br>
+}<br>
+<br>
+void WrapperFunctionResult::destroyWithDeleteArray(<br>
+ CWrapperFunctionResultData Data, uint64_t Size) {<br>
+ delete[] Data.ValuePtr;<br>
+}<br>
+<br>
+} // end namespace tpctypes<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp b/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp<br>
index ab58641b3478..f275c634a6d5 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp<br>
@@ -41,7 +41,7 @@ Error TPCDynamicLibrarySearchGenerator::tryToGenerate(<br>
<br>
SymbolMap NewSymbols;<br>
<br>
- TargetProcessControl::LookupRequestElement Request(H, LookupSymbols);<br>
+ tpctypes::LookupRequest Request(H, LookupSymbols);<br>
auto Result = TPC.lookupSymbols(Request);<br>
if (!Result)<br>
return Result.takeError();<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TPCEHFrameRegistrar.cpp b/llvm/lib/ExecutionEngine/Orc/TPCEHFrameRegistrar.cpp<br>
new file mode 100644<br>
index 000000000000..4f901ce6d445<br>
--- /dev/null<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TPCEHFrameRegistrar.cpp<br>
@@ -0,0 +1,80 @@<br>
+//===------ TPCEHFrameRegistrar.cpp - TPC-based eh-frame registration -----===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h"<br>
+#include "llvm/Support/BinaryStreamWriter.h"<br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+Expected<std::unique_ptr<TPCEHFrameRegistrar>><br>
+TPCEHFrameRegistrar::Create(TargetProcessControl &TPC) {<br>
+ // FIXME: Proper mangling here -- we really need to decouple linker mangling<br>
+ // from DataLayout.<br>
+<br>
+ // Find the addresses of the registration/deregistration functions in the<br>
+ // target process.<br>
+ auto ProcessHandle = TPC.loadDylib(nullptr);<br>
+ if (!ProcessHandle)<br>
+ return ProcessHandle.takeError();<br>
+<br>
+ std::string RegisterWrapperName, DeregisterWrapperName;<br>
+ if (TPC.getTargetTriple().isOSBinFormatMachO()) {<br>
+ RegisterWrapperName += '_';<br>
+ DeregisterWrapperName += '_';<br>
+ }<br>
+ RegisterWrapperName += "llvm_orc_registerEHFrameSectionWrapper";<br>
+ DeregisterWrapperName += "llvm_orc_deregisterEHFrameSectionWrapper";<br>
+<br>
+ SymbolLookupSet RegistrationSymbols;<br>
+ RegistrationSymbols.add(TPC.intern(RegisterWrapperName));<br>
+ RegistrationSymbols.add(TPC.intern(DeregisterWrapperName));<br>
+<br>
+ auto Result = TPC.lookupSymbols({{*ProcessHandle, RegistrationSymbols}});<br>
+ if (!Result)<br>
+ return Result.takeError();<br>
+<br>
+ assert(Result->size() == 1 && "Unexpected number of dylibs in result");<br>
+ assert((*Result)[0].size() == 2 &&<br>
+ "Unexpected number of addresses in result");<br>
+<br>
+ auto RegisterEHFrameWrapperFnAddr = (*Result)[0][0];<br>
+ auto DeregisterEHFrameWrapperFnAddr = (*Result)[0][1];<br>
+<br>
+ return std::make_unique<TPCEHFrameRegistrar>(<br>
+ TPC, RegisterEHFrameWrapperFnAddr, DeregisterEHFrameWrapperFnAddr);<br>
+}<br>
+<br>
+Error TPCEHFrameRegistrar::registerEHFrames(JITTargetAddress EHFrameSectionAddr,<br>
+ size_t EHFrameSectionSize) {<br>
+ constexpr size_t ArgBufferSize = sizeof(uint64_t) + sizeof(uint64_t);<br>
+ uint8_t ArgBuffer[ArgBufferSize];<br>
+ BinaryStreamWriter ArgWriter(<br>
+ MutableArrayRef<uint8_t>(ArgBuffer, ArgBufferSize),<br>
+ support::endianness::big);<br>
+ cantFail(ArgWriter.writeInteger(static_cast<uint64_t>(EHFrameSectionAddr)));<br>
+ cantFail(ArgWriter.writeInteger(static_cast<uint64_t>(EHFrameSectionSize)));<br>
+<br>
+ return TPC.runWrapper(RegisterEHFrameWrapperFnAddr, ArgBuffer).takeError();<br>
+}<br>
+<br>
+Error TPCEHFrameRegistrar::deregisterEHFrames(<br>
+ JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {<br>
+ constexpr size_t ArgBufferSize = sizeof(uint64_t) + sizeof(uint64_t);<br>
+ uint8_t ArgBuffer[ArgBufferSize];<br>
+ BinaryStreamWriter ArgWriter(<br>
+ MutableArrayRef<uint8_t>(ArgBuffer, ArgBufferSize),<br>
+ support::endianness::big);<br>
+ cantFail(ArgWriter.writeInteger(static_cast<uint64_t>(EHFrameSectionAddr)));<br>
+ cantFail(ArgWriter.writeInteger(static_cast<uint64_t>(EHFrameSectionSize)));<br>
+<br>
+ return TPC.runWrapper(DeregisterEHFrameWrapperFnAddr, ArgBuffer).takeError();<br>
+}<br>
+<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TPCIndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/TPCIndirectionUtils.cpp<br>
index de13f064189a..d827cf7b273b 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/TPCIndirectionUtils.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TPCIndirectionUtils.cpp<br>
@@ -160,7 +160,7 @@ Error TPCIndirectStubsManager::createStubs(const StubInitsMap &StubInits) {<br>
switch (TPCIU.getABISupport().getPointerSize()) {<br>
case 4: {<br>
unsigned ASIdx = 0;<br>
- std::vector<TargetProcessControl::MemoryAccess::UInt32Write> PtrUpdates;<br>
+ std::vector<tpctypes::UInt32Write> PtrUpdates;<br>
for (auto &SI : StubInits)<br>
PtrUpdates.push_back({(*AvailableStubInfos)[ASIdx++].PointerAddress,<br>
static_cast<uint32_t>(SI.second.first)});<br>
@@ -168,7 +168,7 @@ Error TPCIndirectStubsManager::createStubs(const StubInitsMap &StubInits) {<br>
}<br>
case 8: {<br>
unsigned ASIdx = 0;<br>
- std::vector<TargetProcessControl::MemoryAccess::UInt64Write> PtrUpdates;<br>
+ std::vector<tpctypes::UInt64Write> PtrUpdates;<br>
for (auto &SI : StubInits)<br>
PtrUpdates.push_back({(*AvailableStubInfos)[ASIdx++].PointerAddress,<br>
static_cast<uint64_t>(SI.second.first)});<br>
@@ -213,11 +213,11 @@ Error TPCIndirectStubsManager::updatePointer(StringRef Name,<br>
auto &MemAccess = TPCIU.getTargetProcessControl().getMemoryAccess();<br>
switch (TPCIU.getABISupport().getPointerSize()) {<br>
case 4: {<br>
- TargetProcessControl::MemoryAccess::UInt32Write PUpdate(PtrAddr, NewAddr);<br>
+ tpctypes::UInt32Write PUpdate(PtrAddr, NewAddr);<br>
return MemAccess.writeUInt32s(PUpdate);<br>
}<br>
case 8: {<br>
- TargetProcessControl::MemoryAccess::UInt64Write PUpdate(PtrAddr, NewAddr);<br>
+ tpctypes::UInt64Write PUpdate(PtrAddr, NewAddr);<br>
return MemAccess.writeUInt64s(PUpdate);<br>
}<br>
default:<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt<br>
new file mode 100644<br>
index 000000000000..b561ce232ce4<br>
--- /dev/null<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt<br>
@@ -0,0 +1,6 @@<br>
+add_llvm_component_library(LLVMOrcTargetProcess<br>
+ RegisterEHFrames.cpp<br>
+ TargetExecutionUtils.cpp<br>
+ ADDITIONAL_HEADER_DIRS<br>
+ ${LLVM_MAIN_INCLUDE_DIR}/llvm/ExecutionEngine/Orc<br>
+ )<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/LLVMBuild.txt b/llvm/lib/ExecutionEngine/Orc/TargetProcess/LLVMBuild.txt<br>
new file mode 100644<br>
index 000000000000..781e6188a702<br>
--- /dev/null<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/LLVMBuild.txt<br>
@@ -0,0 +1,21 @@<br>
+;===- ./lib/ExecutionEngine/OrcTargetProcess/LLVMBuild.txt -----*- Conf -*--===;<br>
+;<br>
+; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+; See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+;<br>
+;===------------------------------------------------------------------------===;<br>
+;<br>
+; This is an LLVMBuild description file for the components in this subdirectory.<br>
+;<br>
+; For more information on the LLVMBuild system, please see:<br>
+;<br>
+; <a href="http://llvm.org/docs/LLVMBuild.html" rel="noreferrer" target="_blank">http://llvm.org/docs/LLVMBuild.html</a><br>
+;<br>
+;===------------------------------------------------------------------------===;<br>
+<br>
+[component_0]<br>
+type = Library<br>
+name = OrcTargetProcess<br>
+parent = OrcJIT<br>
+required_libraries = OrcShared Support<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp<br>
new file mode 100644<br>
index 000000000000..e32916dfcd96<br>
--- /dev/null<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp<br>
@@ -0,0 +1,207 @@<br>
+//===--------- RegisterEHFrames.cpp - Register EH frame sections ----------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"<br>
+<br>
+#include "llvm/ExecutionEngine/JITSymbol.h"<br>
+#include "llvm/Support/BinaryStreamReader.h"<br>
+#include "llvm/Support/Compiler.h"<br>
+#include "llvm/Support/Debug.h"<br>
+#include "llvm/Support/DynamicLibrary.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
+#include "llvm/Support/FormatVariadic.h"<br>
+<br>
+#define DEBUG_TYPE "orc"<br>
+<br>
+using namespace llvm;<br>
+using namespace llvm::orc;<br>
+using namespace llvm::orc::tpctypes;<br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \<br>
+ !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)<br>
+<br>
+extern "C" void __register_frame(const void *);<br>
+extern "C" void __deregister_frame(const void *);<br>
+<br>
+Error registerFrameWrapper(const void *P) {<br>
+ __register_frame(P);<br>
+ return Error::success();<br>
+}<br>
+<br>
+Error deregisterFrameWrapper(const void *P) {<br>
+ __deregister_frame(P);<br>
+ return Error::success();<br>
+}<br>
+<br>
+#else<br>
+<br>
+// The building compiler does not have __(de)register_frame but<br>
+// it may be found at runtime in a dynamically-loaded library.<br>
+// For example, this happens when building LLVM with Visual C++<br>
+// but using the MingW runtime.<br>
+static Error registerFrameWrapper(const void *P) {<br>
+ static void((*RegisterFrame)(const void *)) = 0;<br>
+<br>
+ if (!RegisterFrame)<br>
+ *(void **)&RegisterFrame =<br>
+ llvm::sys::DynamicLibrary::SearchForAddressOfSymbol("__register_frame");<br>
+<br>
+ if (RegisterFrame) {<br>
+ RegisterFrame(P);<br>
+ return Error::success();<br>
+ }<br>
+<br>
+ return make_error<StringError>("could not register eh-frame: "<br>
+ "__register_frame function not found",<br>
+ inconvertibleErrorCode());<br>
+}<br>
+<br>
+static Error deregisterFrameWrapper(const void *P) {<br>
+ static void((*DeregisterFrame)(const void *)) = 0;<br>
+<br>
+ if (!DeregisterFrame)<br>
+ *(void **)&DeregisterFrame =<br>
+ llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(<br>
+ "__deregister_frame");<br>
+<br>
+ if (DeregisterFrame) {<br>
+ DeregisterFrame(P);<br>
+ return Error::success();<br>
+ }<br>
+<br>
+ return make_error<StringError>("could not deregister eh-frame: "<br>
+ "__deregister_frame function not found",<br>
+ inconvertibleErrorCode());<br>
+}<br>
+#endif<br>
+<br>
+#ifdef __APPLE__<br>
+<br>
+template <typename HandleFDEFn><br>
+Error walkAppleEHFrameSection(const char *const SectionStart,<br>
+ size_t SectionSize, HandleFDEFn HandleFDE) {<br>
+ const char *CurCFIRecord = SectionStart;<br>
+ const char *End = SectionStart + SectionSize;<br>
+ uint64_t Size = *reinterpret_cast<const uint32_t *>(CurCFIRecord);<br>
+<br>
+ while (CurCFIRecord != End && Size != 0) {<br>
+ const char *OffsetField = CurCFIRecord + (Size == 0xffffffff ? 12 : 4);<br>
+ if (Size == 0xffffffff)<br>
+ Size = *reinterpret_cast<const uint64_t *>(CurCFIRecord + 4) + 12;<br>
+ else<br>
+ Size += 4;<br>
+ uint32_t Offset = *reinterpret_cast<const uint32_t *>(OffsetField);<br>
+<br>
+ LLVM_DEBUG({<br>
+ dbgs() << "Registering eh-frame section:\n";<br>
+ dbgs() << "Processing " << (Offset ? "FDE" : "CIE") << " @"<br>
+ << (void *)CurCFIRecord << ": [";<br>
+ for (unsigned I = 0; I < Size; ++I)<br>
+ dbgs() << format(" 0x%02" PRIx8, *(CurCFIRecord + I));<br>
+ dbgs() << " ]\n";<br>
+ });<br>
+<br>
+ if (Offset != 0)<br>
+ if (auto Err = HandleFDE(CurCFIRecord))<br>
+ return Err;<br>
+<br>
+ CurCFIRecord += Size;<br>
+<br>
+ Size = *reinterpret_cast<const uint32_t *>(CurCFIRecord);<br>
+ }<br>
+<br>
+ return Error::success();<br>
+}<br>
+<br>
+#endif // __APPLE__<br>
+<br>
+Error registerEHFrameSection(const void *EHFrameSectionAddr,<br>
+ size_t EHFrameSectionSize) {<br>
+#ifdef __APPLE__<br>
+ // On Darwin __register_frame has to be called for each FDE entry.<br>
+ return walkAppleEHFrameSection(static_cast<const char *>(EHFrameSectionAddr),<br>
+ EHFrameSectionSize, registerFrameWrapper);<br>
+#else<br>
+ // On Linux __register_frame takes a single argument:<br>
+ // a pointer to the start of the .eh_frame section.<br>
+<br>
+ // How can it find the end? Because crtendS.o is linked<br>
+ // in and it has an .eh_frame section with four zero chars.<br>
+ return registerFrameWrapper(EHFrameSectionAddr);<br>
+#endif<br>
+}<br>
+<br>
+Error deregisterEHFrameSection(const void *EHFrameSectionAddr,<br>
+ size_t EHFrameSectionSize) {<br>
+#ifdef __APPLE__<br>
+ return walkAppleEHFrameSection(static_cast<const char *>(EHFrameSectionAddr),<br>
+ EHFrameSectionSize, deregisterFrameWrapper);<br>
+#else<br>
+ return deregisterFrameWrapper(EHFrameSectionAddr);<br>
+#endif<br>
+}<br>
+<br>
+} // end namespace orc<br>
+} // end namespace llvm<br>
+<br>
+extern "C" CWrapperFunctionResult<br>
+llvm_orc_registerEHFrameSectionWrapper(uint8_t *Data, uint64_t Size) {<br>
+ if (Size != sizeof(uint64_t) + sizeof(uint64_t))<br>
+ return WrapperFunctionResult::from(<br>
+ "Invalid arguments to llvm_orc_registerEHFrameSectionWrapper")<br>
+ .release();<br>
+<br>
+ uint64_t EHFrameSectionAddr;<br>
+ uint64_t EHFrameSectionSize;<br>
+<br>
+ {<br>
+ BinaryStreamReader ArgReader(ArrayRef<uint8_t>(Data, Size),<br>
+ support::endianness::big);<br>
+ cantFail(ArgReader.readInteger(EHFrameSectionAddr));<br>
+ cantFail(ArgReader.readInteger(EHFrameSectionSize));<br>
+ }<br>
+<br>
+ if (auto Err = registerEHFrameSection(<br>
+ jitTargetAddressToPointer<void *>(EHFrameSectionAddr),<br>
+ EHFrameSectionSize)) {<br>
+ auto ErrMsg = toString(std::move(Err));<br>
+ return WrapperFunctionResult::from(ErrMsg).release();<br>
+ }<br>
+ return WrapperFunctionResult().release();<br>
+}<br>
+<br>
+extern "C" CWrapperFunctionResult<br>
+llvm_orc_deregisterEHFrameSectionWrapper(uint8_t *Data, uint64_t Size) {<br>
+ if (Size != sizeof(uint64_t) + sizeof(uint64_t))<br>
+ return WrapperFunctionResult::from(<br>
+ "Invalid arguments to llvm_orc_registerEHFrameSectionWrapper")<br>
+ .release();<br>
+<br>
+ uint64_t EHFrameSectionAddr;<br>
+ uint64_t EHFrameSectionSize;<br>
+<br>
+ {<br>
+ BinaryStreamReader ArgReader(ArrayRef<uint8_t>(Data, Size),<br>
+ support::endianness::big);<br>
+ cantFail(ArgReader.readInteger(EHFrameSectionAddr));<br>
+ cantFail(ArgReader.readInteger(EHFrameSectionSize));<br>
+ }<br>
+<br>
+ if (auto Err = deregisterEHFrameSection(<br>
+ jitTargetAddressToPointer<void *>(EHFrameSectionAddr),<br>
+ EHFrameSectionSize)) {<br>
+ auto ErrMsg = toString(std::move(Err));<br>
+ return WrapperFunctionResult::from(ErrMsg).release();<br>
+ }<br>
+ return WrapperFunctionResult().release();<br>
+}<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.cpp<br>
new file mode 100644<br>
index 000000000000..a8e6c049cf4b<br>
--- /dev/null<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.cpp<br>
@@ -0,0 +1,43 @@<br>
+//===--- TargetExecutionUtils.cpp - Execution utils for target processes --===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"<br>
+<br>
+#include <vector><br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+int runAsMain(int (*Main)(int, char *[]), ArrayRef<std::string> Args,<br>
+ Optional<StringRef> ProgramName) {<br>
+ std::vector<std::unique_ptr<char[]>> ArgVStorage;<br>
+ std::vector<char *> ArgV;<br>
+<br>
+ ArgVStorage.reserve(Args.size() + (ProgramName ? 1 : 0));<br>
+ ArgV.reserve(Args.size() + 1 + (ProgramName ? 1 : 0));<br>
+<br>
+ if (ProgramName) {<br>
+ ArgVStorage.push_back(std::make_unique<char[]>(ProgramName->size() + 1));<br>
+ llvm::copy(*ProgramName, &ArgVStorage.back()[0]);<br>
+ ArgVStorage.back()[ProgramName->size()] = '\0';<br>
+ ArgV.push_back(ArgVStorage.back().get());<br>
+ }<br>
+<br>
+ for (const auto &Arg : Args) {<br>
+ ArgVStorage.push_back(std::make_unique<char[]>(Arg.size() + 1));<br>
+ llvm::copy(Arg, &ArgVStorage.back()[0]);<br>
+ ArgVStorage.back()[Arg.size()] = '\0';<br>
+ ArgV.push_back(ArgVStorage.back().get());<br>
+ }<br>
+ ArgV.push_back(nullptr);<br>
+<br>
+ return Main(Args.size() + !!ProgramName, ArgV.data());<br>
+}<br>
+<br>
+} // End namespace orc.<br>
+} // End namespace llvm.<br>
<br>
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp<br>
index 1e7736d1f40d..bbbc2d60d936 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcessControl.cpp<br>
@@ -9,6 +9,7 @@<br>
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"<br>
<br>
#include "llvm/ExecutionEngine/Orc/Core.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"<br>
#include "llvm/Support/Host.h"<br>
#include "llvm/Support/Process.h"<br>
<br>
@@ -22,23 +23,25 @@ TargetProcessControl::MemoryAccess::~MemoryAccess() {}<br>
TargetProcessControl::~TargetProcessControl() {}<br>
<br>
SelfTargetProcessControl::SelfTargetProcessControl(<br>
- Triple TT, unsigned PageSize,<br>
- std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) {<br>
+ std::shared_ptr<SymbolStringPool> SSP, Triple TargetTriple,<br>
+ unsigned PageSize, std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr)<br>
+ : TargetProcessControl(std::move(SSP)) {<br>
<br>
OwnedMemMgr = std::move(MemMgr);<br>
if (!OwnedMemMgr)<br>
OwnedMemMgr = std::make_unique<jitlink::InProcessMemoryManager>();<br>
<br>
- this->TT = std::move(TT);<br>
+ this->TargetTriple = std::move(TargetTriple);<br>
this->PageSize = PageSize;<br>
this->MemMgr = OwnedMemMgr.get();<br>
this->MemAccess = this;<br>
- if (this->TT.isOSBinFormatMachO())<br>
+ if (this->TargetTriple.isOSBinFormatMachO())<br>
GlobalManglingPrefix = '_';<br>
}<br>
<br>
Expected<std::unique_ptr<SelfTargetProcessControl>><br>
SelfTargetProcessControl::Create(<br>
+ std::shared_ptr<SymbolStringPool> SSP,<br>
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr) {<br>
auto PageSize = sys::Process::getPageSize();<br>
if (!PageSize)<br>
@@ -46,11 +49,11 @@ SelfTargetProcessControl::Create(<br>
<br>
Triple TT(sys::getProcessTriple());<br>
<br>
- return std::make_unique<SelfTargetProcessControl>(std::move(TT), *PageSize,<br>
- std::move(MemMgr));<br>
+ return std::make_unique<SelfTargetProcessControl>(<br>
+ std::move(SSP), std::move(TT), *PageSize, std::move(MemMgr));<br>
}<br>
<br>
-Expected<TargetProcessControl::DylibHandle><br>
+Expected<tpctypes::DylibHandle><br>
SelfTargetProcessControl::loadDylib(const char *DylibPath) {<br>
std::string ErrMsg;<br>
auto Dylib = std::make_unique<sys::DynamicLibrary>(<br>
@@ -61,9 +64,10 @@ SelfTargetProcessControl::loadDylib(const char *DylibPath) {<br>
return pointerToJITTargetAddress(DynamicLibraries.back().get());<br>
}<br>
<br>
-Expected<TargetProcessControl::LookupResult><br>
-SelfTargetProcessControl::lookupSymbols(LookupRequest Request) {<br>
- LookupResult R;<br>
+Expected<std::vector<tpctypes::LookupResult>><br>
+SelfTargetProcessControl::lookupSymbols(<br>
+ ArrayRef<tpctypes::LookupRequest> Request) {<br>
+ std::vector<tpctypes::LookupResult> R;<br>
<br>
for (auto &Elem : Request) {<br>
auto *Dylib = jitTargetAddressToPointer<sys::DynamicLibrary *>(Elem.Handle);<br>
@@ -92,35 +96,53 @@ SelfTargetProcessControl::lookupSymbols(LookupRequest Request) {<br>
return R;<br>
}<br>
<br>
-void SelfTargetProcessControl::writeUInt8s(ArrayRef<UInt8Write> Ws,<br>
+Expected<int32_t><br>
+SelfTargetProcessControl::runAsMain(JITTargetAddress MainFnAddr,<br>
+ ArrayRef<std::string> Args) {<br>
+ using MainTy = int (*)(int, char *[]);<br>
+ return orc::runAsMain(jitTargetAddressToFunction<MainTy>(MainFnAddr), Args);<br>
+}<br>
+<br>
+Expected<tpctypes::WrapperFunctionResult><br>
+SelfTargetProcessControl::runWrapper(JITTargetAddress WrapperFnAddr,<br>
+ ArrayRef<uint8_t> ArgBuffer) {<br>
+ using WrapperFnTy =<br>
+ tpctypes::CWrapperFunctionResult (*)(const uint8_t *Data, uint64_t Size);<br>
+ auto *WrapperFn = jitTargetAddressToFunction<WrapperFnTy>(WrapperFnAddr);<br>
+ return WrapperFn(ArgBuffer.data(), ArgBuffer.size());<br>
+};<br>
+<br>
+Error SelfTargetProcessControl::disconnect() { return Error::success(); }<br>
+<br>
+void SelfTargetProcessControl::writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws,<br>
WriteResultFn OnWriteComplete) {<br>
for (auto &W : Ws)<br>
*jitTargetAddressToPointer<uint8_t *>(W.Address) = W.Value;<br>
OnWriteComplete(Error::success());<br>
}<br>
<br>
-void SelfTargetProcessControl::writeUInt16s(ArrayRef<UInt16Write> Ws,<br>
+void SelfTargetProcessControl::writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws,<br>
WriteResultFn OnWriteComplete) {<br>
for (auto &W : Ws)<br>
*jitTargetAddressToPointer<uint16_t *>(W.Address) = W.Value;<br>
OnWriteComplete(Error::success());<br>
}<br>
<br>
-void SelfTargetProcessControl::writeUInt32s(ArrayRef<UInt32Write> Ws,<br>
+void SelfTargetProcessControl::writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws,<br>
WriteResultFn OnWriteComplete) {<br>
for (auto &W : Ws)<br>
*jitTargetAddressToPointer<uint32_t *>(W.Address) = W.Value;<br>
OnWriteComplete(Error::success());<br>
}<br>
<br>
-void SelfTargetProcessControl::writeUInt64s(ArrayRef<UInt64Write> Ws,<br>
+void SelfTargetProcessControl::writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws,<br>
WriteResultFn OnWriteComplete) {<br>
for (auto &W : Ws)<br>
*jitTargetAddressToPointer<uint64_t *>(W.Address) = W.Value;<br>
OnWriteComplete(Error::success());<br>
}<br>
<br>
-void SelfTargetProcessControl::writeBuffers(ArrayRef<BufferWrite> Ws,<br>
+void SelfTargetProcessControl::writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws,<br>
WriteResultFn OnWriteComplete) {<br>
for (auto &W : Ws)<br>
memcpy(jitTargetAddressToPointer<char *>(W.Address), W.Buffer.data(),<br>
<br>
diff --git a/llvm/tools/lli/CMakeLists.txt b/llvm/tools/lli/CMakeLists.txt<br>
index bc6ef213b8fd..098e9dd3e743 100644<br>
--- a/llvm/tools/lli/CMakeLists.txt<br>
+++ b/llvm/tools/lli/CMakeLists.txt<br>
@@ -11,8 +11,9 @@ set(LLVM_LINK_COMPONENTS<br>
MC<br>
MCJIT<br>
Object<br>
- OrcError<br>
+ OrcShared<br>
OrcJIT<br>
+ OrcTargetProcess<br>
Passes<br>
RuntimeDyld<br>
SelectionDAG<br>
<br>
diff --git a/llvm/tools/lli/ChildTarget/CMakeLists.txt b/llvm/tools/lli/ChildTarget/CMakeLists.txt<br>
index d3d15bef6c5b..c5795eebd71a 100644<br>
--- a/llvm/tools/lli/ChildTarget/CMakeLists.txt<br>
+++ b/llvm/tools/lli/ChildTarget/CMakeLists.txt<br>
@@ -1,5 +1,5 @@<br>
set(LLVM_LINK_COMPONENTS<br>
- OrcError<br>
+ OrcShared<br>
OrcJIT<br>
RuntimeDyld<br>
Support<br>
<br>
diff --git a/llvm/tools/lli/LLVMBuild.txt b/llvm/tools/lli/LLVMBuild.txt<br>
index 133543a26fce..0d473cbe9238 100644<br>
--- a/llvm/tools/lli/LLVMBuild.txt<br>
+++ b/llvm/tools/lli/LLVMBuild.txt<br>
@@ -28,6 +28,9 @@ required_libraries =<br>
Instrumentation<br>
Interpreter<br>
MCJIT<br>
+ OrcJIT<br>
+ OrcShared<br>
+ OrcTargetProcess<br>
Native<br>
NativeCodeGen<br>
SelectionDAG<br>
<br>
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp<br>
index 1ebd1435f2f3..e9b48a8542ec 100644<br>
--- a/llvm/tools/lli/lli.cpp<br>
+++ b/llvm/tools/lli/lli.cpp<br>
@@ -31,6 +31,7 @@<br>
#include "llvm/ExecutionEngine/Orc/MachOPlatform.h"<br>
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h"<br>
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"<br>
#include "llvm/ExecutionEngine/SectionMemoryManager.h"<br>
#include "llvm/IR/IRBuilder.h"<br>
#include "llvm/IR/LLVMContext.h"<br>
<br>
diff --git a/llvm/tools/llvm-jitlink/CMakeLists.txt b/llvm/tools/llvm-jitlink/CMakeLists.txt<br>
index bfe691d976ba..8d511b17fca2 100644<br>
--- a/llvm/tools/llvm-jitlink/CMakeLists.txt<br>
+++ b/llvm/tools/llvm-jitlink/CMakeLists.txt<br>
@@ -1,3 +1,7 @@<br>
+if ( LLVM_INCLUDE_UTILS )<br>
+ add_subdirectory(llvm-jitlink-executor)<br>
+endif()<br>
+<br>
set(LLVM_LINK_COMPONENTS<br>
AllTargetsDescs<br>
AllTargetsDisassemblers<br>
@@ -8,6 +12,8 @@ set(LLVM_LINK_COMPONENTS<br>
MC<br>
Object<br>
OrcJIT<br>
+ OrcShared<br>
+ OrcTargetProcess<br>
RuntimeDyld<br>
Support<br>
)<br>
<br>
diff --git a/llvm/tools/llvm-jitlink/LLVMBuild.txt b/llvm/tools/llvm-jitlink/LLVMBuild.txt<br>
index 224bab58c215..8aa0ef8161e6 100644<br>
--- a/llvm/tools/llvm-jitlink/LLVMBuild.txt<br>
+++ b/llvm/tools/llvm-jitlink/LLVMBuild.txt<br>
@@ -18,5 +18,5 @@<br>
type = Tool<br>
name = llvm-jitlink<br>
parent = Tools<br>
-required_libraries = JITLink BinaryFormat MC Object RuntimeDyld Support<br>
- all-targets<br>
+required_libraries = JITLink BinaryFormat MC Object OrcJIT OrcTargetProcess<br>
+ Support all-targets<br>
<br>
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt<br>
new file mode 100644<br>
index 000000000000..f6d882d1a8f0<br>
--- /dev/null<br>
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt<br>
@@ -0,0 +1,14 @@<br>
+set(LLVM_LINK_COMPONENTS<br>
+ OrcShared<br>
+ OrcTargetProcess<br>
+ Support<br>
+ )<br>
+<br>
+add_llvm_utility(llvm-jitlink-executor<br>
+ llvm-jitlink-executor.cpp<br>
+<br>
+ DEPENDS<br>
+ intrinsics_gen<br>
+)<br>
+<br>
+export_executable_symbols(llvm-jitlink-executor)<br>
<br>
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/LLVMBuild.txt b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/LLVMBuild.txt<br>
new file mode 100644<br>
index 000000000000..0d96143673dd<br>
--- /dev/null<br>
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/LLVMBuild.txt<br>
@@ -0,0 +1,21 @@<br>
+;===- ./tools/llvm-jitlink/llvm-jitlink-executor/LLVMBuild.txt -*- Conf -*--===;<br>
+;<br>
+; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+; See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+;<br>
+;===------------------------------------------------------------------------===;<br>
+;<br>
+; This is an LLVMBuild description file for the components in this subdirectory.<br>
+;<br>
+; For more information on the LLVMBuild system, please see:<br>
+;<br>
+; <a href="http://llvm.org/docs/LLVMBuild.html" rel="noreferrer" target="_blank">http://llvm.org/docs/LLVMBuild.html</a><br>
+;<br>
+;===------------------------------------------------------------------------===;<br>
+<br>
+[component_0]<br>
+type = Tool<br>
+name = llvm-jitlink-executor<br>
+parent = llvm-jitlink<br>
+required_libraries = OrcTargetProcess Support<br>
<br>
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp<br>
new file mode 100644<br>
index 000000000000..78227f3f423b<br>
--- /dev/null<br>
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp<br>
@@ -0,0 +1,127 @@<br>
+//===- llvm-jitlink-executor.cpp - Out-of-proc executor for llvm-jitlink -===//<br>
+//<br>
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br>
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank">https://llvm.org/LICENSE.txt</a> for license information.<br>
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// Simple out-of-process executor for llvm-jitlink.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h"<br>
+#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"<br>
+#include "llvm/Support/DynamicLibrary.h"<br>
+#include "llvm/Support/Error.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+#include <sstream><br>
+<br>
+#ifdef LLVM_ON_UNIX<br>
+<br>
+#include <netinet/in.h><br>
+#include <sys/socket.h><br>
+<br>
+#endif<br>
+<br>
+using namespace llvm;<br>
+using namespace llvm::orc;<br>
+<br>
+ExitOnError ExitOnErr;<br>
+<br>
+LLVM_ATTRIBUTE_USED void linkComponents() {<br>
+ errs() << (void *)&llvm_orc_registerEHFrameSectionWrapper<br>
+ << (void *)&llvm_orc_deregisterEHFrameSectionWrapper;<br>
+}<br>
+<br>
+void printErrorAndExit(Twine ErrMsg) {<br>
+ errs() << "error: " << ErrMsg.str() << "\n\n"<br>
+ << "Usage:\n"<br>
+ << " llvm-jitlink-executor filedescs=<infd>,<outfd> [args...]\n"<br>
+ << " llvm-jitlink-executor listen=<host>:<port> [args...]\n";<br>
+ exit(1);<br>
+}<br>
+<br>
+int openListener(std::string Host, int Port) {<br>
+#ifndef LLVM_ON_UNIX<br>
+ // FIXME: Add TCP support for Windows.<br>
+ printErrorAndExit("listen option not supported");<br>
+#else<br>
+ int SockFD = socket(PF_INET, SOCK_STREAM, 0);<br>
+ struct sockaddr_in ServerAddr, ClientAddr;<br>
+ socklen_t ClientAddrLen = sizeof(ClientAddr);<br>
+ memset(&ServerAddr, 0, sizeof(ServerAddr));<br>
+ ServerAddr.sin_family = PF_INET;<br>
+ ServerAddr.sin_family = INADDR_ANY;<br>
+ ServerAddr.sin_port = htons(Port);<br>
+<br>
+ {<br>
+ // lose the "Address already in use" error message<br>
+ int Yes = 1;<br>
+ if (setsockopt(SockFD, SOL_SOCKET, SO_REUSEADDR, &Yes, sizeof(int)) == -1) {<br>
+ errs() << "Error calling setsockopt.\n";<br>
+ exit(1);<br>
+ }<br>
+ }<br>
+<br>
+ if (bind(SockFD, (struct sockaddr *)&ServerAddr, sizeof(ServerAddr)) < 0) {<br>
+ errs() << "Error on binding.\n";<br>
+ exit(1);<br>
+ }<br>
+<br>
+ listen(SockFD, 1);<br>
+ return accept(SockFD, (struct sockaddr *)&ClientAddr, &ClientAddrLen);<br>
+#endif<br>
+}<br>
+<br>
+int main(int argc, char *argv[]) {<br>
+<br>
+ ExitOnErr.setBanner(std::string(argv[0]) + ": ");<br>
+<br>
+ int InFD = 0;<br>
+ int OutFD = 0;<br>
+<br>
+ if (argc < 2)<br>
+ printErrorAndExit("insufficient arguments");<br>
+ else {<br>
+ StringRef Arg1 = argv[1];<br>
+ StringRef SpecifierType, Specifier;<br>
+ std::tie(SpecifierType, Specifier) = Arg1.split('=');<br>
+ if (SpecifierType == "filedescs") {<br>
+ StringRef FD1Str, FD2Str;<br>
+ std::tie(FD1Str, FD2Str) = Specifier.split(',');<br>
+ if (FD1Str.getAsInteger(10, InFD))<br>
+ printErrorAndExit(FD1Str + " is not a valid file descriptor");<br>
+ if (FD2Str.getAsInteger(10, OutFD))<br>
+ printErrorAndExit(FD2Str + " is not a valid file descriptor");<br>
+ } else if (SpecifierType == "listen") {<br>
+ StringRef Host, PortStr;<br>
+ std::tie(Host, PortStr) = Specifier.split(':');<br>
+<br>
+ int Port = 0;<br>
+ if (PortStr.getAsInteger(10, Port))<br>
+ printErrorAndExit("port" + PortStr + " is not a valid integer");<br>
+<br>
+ InFD = OutFD = openListener(Host.str(), Port);<br>
+ } else<br>
+ printErrorAndExit("invalid specifier type \"" + SpecifierType + "\"");<br>
+ }<br>
+<br>
+ ExitOnErr.setBanner(std::string(argv[0]) + ":");<br>
+<br>
+ using JITLinkExecutorEndpoint =<br>
+ rpc::MultiThreadedRPCEndpoint<rpc::FDRawByteChannel>;<br>
+<br>
+ rpc::registerStringError<rpc::FDRawByteChannel>();<br>
+<br>
+ rpc::FDRawByteChannel C(InFD, OutFD);<br>
+ JITLinkExecutorEndpoint EP(C, true);<br>
+ OrcRPCTPCServer<JITLinkExecutorEndpoint> Server(EP);<br>
+ Server.setProgramName(std::string("llvm-jitlink-executor"));<br>
+<br>
+ ExitOnErr(Server.run());<br>
+<br>
+ return 0;<br>
+}<br>
<br>
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp<br>
index 8c3b99824fe3..4e899cf2d156 100644<br>
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp<br>
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp<br>
@@ -15,9 +15,9 @@<br>
#include "llvm-jitlink.h"<br>
<br>
#include "llvm/BinaryFormat/Magic.h"<br>
-#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"<br>
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"<br>
#include "llvm/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.h"<br>
+#include "llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h"<br>
#include "llvm/MC/MCAsmInfo.h"<br>
#include "llvm/MC/MCContext.h"<br>
#include "llvm/MC/MCDisassembler/MCDisassembler.h"<br>
@@ -41,6 +41,13 @@<br>
#include <list><br>
#include <string><br>
<br>
+#ifdef LLVM_ON_UNIX<br>
+#include <netdb.h><br>
+#include <netinet/in.h><br>
+#include <sys/socket.h><br>
+#include <unistd.h><br>
+#endif // LLVM_ON_UNIX<br>
+<br>
#define DEBUG_TYPE "llvm_jitlink"<br>
<br>
using namespace llvm;<br>
@@ -138,6 +145,14 @@ static cl::opt<bool> PhonyExternals(<br>
cl::desc("resolve all otherwise unresolved externals to null"),<br>
cl::init(false));<br>
<br>
+static cl::opt<std::string> OutOfProcessExecutor(<br>
+ "oop-executor", cl::desc("Launch an out-of-process executor to run code"),<br>
+ cl::ValueOptional);<br>
+<br>
+static cl::opt<std::string> OutOfProcessExecutorConnect(<br>
+ "oop-executor-connect",<br>
+ cl::desc("Connect to an out-of-process executor via TCP"));<br>
+<br>
ExitOnError ExitOnErr;<br>
<br>
namespace llvm {<br>
@@ -561,6 +576,165 @@ Error LLVMJITLinkObjectLinkingLayer::add(ResourceTrackerSP RT,<br>
return JD.define(std::move(MU), std::move(RT));<br>
}<br>
<br>
+Expected<std::unique_ptr<TargetProcessControl>><br>
+LLVMJITLinkRemoteTargetProcessControl::LaunchExecutor() {<br>
+#ifndef LLVM_ON_UNIX<br>
+ // FIXME: Add support for Windows.<br>
+ return make_error<StringError>("-" + OutOfProcessExecutor.ArgStr +<br>
+ " not supported on non-unix platforms",<br>
+ inconvertibleErrorCode());<br>
+#else<br>
+<br>
+ rpc::registerStringError<LLVMJITLinkChannel>();<br>
+<br>
+ constexpr int ReadEnd = 0;<br>
+ constexpr int WriteEnd = 1;<br>
+<br>
+ // Pipe FDs.<br>
+ int ToExecutor[2];<br>
+ int FromExecutor[2];<br>
+<br>
+ pid_t ChildPID;<br>
+<br>
+ // Create pipes to/from the executor..<br>
+ if (pipe(ToExecutor) != 0 || pipe(FromExecutor) != 0)<br>
+ return make_error<StringError>("Unable to create pipe for executor",<br>
+ inconvertibleErrorCode());<br>
+<br>
+ ChildPID = fork();<br>
+<br>
+ if (ChildPID == 0) {<br>
+ // In the child...<br>
+<br>
+ // Close the parent ends of the pipes<br>
+ close(ToExecutor[WriteEnd]);<br>
+ close(FromExecutor[ReadEnd]);<br>
+<br>
+ // Execute the child process.<br>
+ std::unique_ptr<char[]> ExecutorPath, FDSpecifier;<br>
+ {<br>
+ ExecutorPath = std::make_unique<char[]>(OutOfProcessExecutor.size() + 1);<br>
+ strcpy(ExecutorPath.get(), OutOfProcessExecutor.data());<br>
+<br>
+ std::string FDSpecifierStr("filedescs=");<br>
+ FDSpecifierStr += utostr(ToExecutor[ReadEnd]);<br>
+ FDSpecifierStr += ',';<br>
+ FDSpecifierStr += utostr(FromExecutor[WriteEnd]);<br>
+ FDSpecifier = std::make_unique<char[]>(FDSpecifierStr.size() + 1);<br>
+ strcpy(FDSpecifier.get(), FDSpecifierStr.c_str());<br>
+ }<br>
+<br>
+ char *const Args[] = {ExecutorPath.get(), FDSpecifier.get(), nullptr};<br>
+ int RC = execvp(ExecutorPath.get(), Args);<br>
+ if (RC != 0) {<br>
+ errs() << "unable to launch out-of-process executor \""<br>
+ << ExecutorPath.get() << "\"\n";<br>
+ exit(1);<br>
+ }<br>
+ }<br>
+ // else we're the parent...<br>
+<br>
+ // Close the child ends of the pipes<br>
+ close(ToExecutor[ReadEnd]);<br>
+ close(FromExecutor[WriteEnd]);<br>
+<br>
+ // Return an RPC channel connected to our end of the pipes.<br>
+ auto SSP = std::make_shared<SymbolStringPool>();<br>
+ auto Channel = std::make_unique<rpc::FDRawByteChannel>(FromExecutor[ReadEnd],<br>
+ ToExecutor[WriteEnd]);<br>
+ auto Endpoint = std::make_unique<LLVMJITLinkRPCEndpoint>(*Channel, true);<br>
+<br>
+ auto ReportError = [](Error Err) {<br>
+ logAllUnhandledErrors(std::move(Err), errs(), "");<br>
+ };<br>
+<br>
+ Error Err = Error::success();<br>
+ std::unique_ptr<LLVMJITLinkRemoteTargetProcessControl> RTPC(<br>
+ new LLVMJITLinkRemoteTargetProcessControl(<br>
+ std::move(SSP), std::move(Channel), std::move(Endpoint),<br>
+ std::move(ReportError), Err));<br>
+ if (Err)<br>
+ return std::move(Err);<br>
+ return std::move(RTPC);<br>
+#endif<br>
+}<br>
+<br>
+Expected<std::unique_ptr<TargetProcessControl>><br>
+LLVMJITLinkRemoteTargetProcessControl::ConnectToExecutor() {<br>
+#ifndef LLVM_ON_UNIX<br>
+ // FIXME: Add TCP support for Windows.<br>
+ return make_error<StringError>("-" + OutOfProcessExecutorConnect.ArgStr +<br>
+ " not supported on non-unix platforms",<br>
+ inconvertibleErrorCode());<br>
+#else<br>
+<br>
+ rpc::registerStringError<LLVMJITLinkChannel>();<br>
+<br>
+ StringRef HostNameStr, PortStr;<br>
+ std::tie(HostNameStr, PortStr) =<br>
+ StringRef(OutOfProcessExecutorConnect).split(':');<br>
+<br>
+ if (HostNameStr.empty())<br>
+ return make_error<StringError>("host name for -" +<br>
+ OutOfProcessExecutorConnect.ArgStr +<br>
+ " can not be empty",<br>
+ inconvertibleErrorCode());<br>
+ if (PortStr.empty())<br>
+ return make_error<StringError>(<br>
+ "port for -" + OutOfProcessExecutorConnect.ArgStr + " can not be empty",<br>
+ inconvertibleErrorCode());<br>
+<br>
+ std::string HostName = HostNameStr.str();<br>
+ int Port = 0;<br>
+ if (PortStr.getAsInteger(10, Port))<br>
+ return make_error<StringError>("port number " + PortStr +<br>
+ " is not a valid integer",<br>
+ inconvertibleErrorCode());<br>
+<br>
+ int SockFD = socket(PF_INET, SOCK_STREAM, 0);<br>
+ hostent *Server = gethostbyname(HostName.c_str());<br>
+ sockaddr_in ServAddr;<br>
+ memset(&ServAddr, 0, sizeof(ServAddr));<br>
+ ServAddr.sin_family = PF_INET;<br>
+ memmove(&Server->h_addr, &ServAddr.sin_addr.s_addr, Server->h_length);<br>
+ ServAddr.sin_port = htons(Port);<br>
+ if (connect(SockFD, reinterpret_cast<sockaddr *>(&ServAddr),<br>
+ sizeof(ServAddr)) < 0)<br>
+ return make_error<StringError>("Failed to connect to " + HostName + ":" +<br>
+ Twine(Port),<br>
+ inconvertibleErrorCode());<br>
+<br>
+ auto SSP = std::make_shared<SymbolStringPool>();<br>
+ auto Channel = std::make_unique<rpc::FDRawByteChannel>(SockFD, SockFD);<br>
+ auto Endpoint = std::make_unique<LLVMJITLinkRPCEndpoint>(*Channel, true);<br>
+<br>
+ auto ReportError = [](Error Err) {<br>
+ logAllUnhandledErrors(std::move(Err), errs(), "");<br>
+ };<br>
+<br>
+ Error Err = Error::success();<br>
+ std::unique_ptr<LLVMJITLinkRemoteTargetProcessControl> RTPC(<br>
+ new LLVMJITLinkRemoteTargetProcessControl(<br>
+ std::move(SSP), std::move(Channel), std::move(Endpoint),<br>
+ std::move(ReportError), Err));<br>
+ if (Err)<br>
+ return std::move(Err);<br>
+ return std::move(RTPC);<br>
+#endif<br>
+}<br>
+<br>
+Error LLVMJITLinkRemoteTargetProcessControl::disconnect() {<br>
+ std::promise<MSVCPError> P;<br>
+ auto F = P.get_future();<br>
+ auto Err = closeConnection([&](Error Err) -> Error {<br>
+ P.set_value(std::move(Err));<br>
+ Finished = true;<br>
+ return Error::success();<br>
+ });<br>
+ ListenerThread.join();<br>
+ return joinErrors(std::move(Err), F.get());<br>
+};<br>
+<br>
class PhonyExternalsGenerator : public DefinitionGenerator {<br>
public:<br>
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,<br>
@@ -574,13 +748,30 @@ class PhonyExternalsGenerator : public DefinitionGenerator {<br>
};<br>
<br>
Expected<std::unique_ptr<Session>> Session::Create(Triple TT) {<br>
- Error Err = Error::success();<br>
<br>
auto PageSize = sys::Process::getPageSize();<br>
if (!PageSize)<br>
return PageSize.takeError();<br>
<br>
- std::unique_ptr<Session> S(new Session(std::move(TT), *PageSize, Err));<br>
+ /// If -oop-executor is passed then launch the executor.<br>
+ std::unique_ptr<TargetProcessControl> TPC;<br>
+ if (OutOfProcessExecutor.getNumOccurrences()) {<br>
+ if (auto RTPC = LLVMJITLinkRemoteTargetProcessControl::LaunchExecutor())<br>
+ TPC = std::move(*RTPC);<br>
+ else<br>
+ return RTPC.takeError();<br>
+ } else if (OutOfProcessExecutorConnect.getNumOccurrences()) {<br>
+ if (auto RTPC = LLVMJITLinkRemoteTargetProcessControl::ConnectToExecutor())<br>
+ TPC = std::move(*RTPC);<br>
+ else<br>
+ return RTPC.takeError();<br>
+ } else<br>
+ TPC = std::make_unique<SelfTargetProcessControl>(<br>
+ std::make_shared<SymbolStringPool>(), std::move(TT), *PageSize,<br>
+ createMemoryManager());<br>
+<br>
+ Error Err = Error::success();<br>
+ std::unique_ptr<Session> S(new Session(std::move(TPC), Err));<br>
if (Err)<br>
return std::move(Err);<br>
return std::move(S);<br>
@@ -593,10 +784,8 @@ Session::~Session() {<br>
<br>
// FIXME: Move to createJITDylib if/when we start using Platform support in<br>
// llvm-jitlink.<br>
-Session::Session(Triple TT, uint64_t PageSize, Error &Err)<br>
- : TPC(std::make_unique<SelfTargetProcessControl>(std::move(TT), PageSize,<br>
- createMemoryManager())),<br>
- ObjLayer(*this, TPC->getMemMgr()) {<br>
+Session::Session(std::unique_ptr<TargetProcessControl> TPC, Error &Err)<br>
+ : TPC(std::move(TPC)), ObjLayer(*this, this->TPC->getMemMgr()) {<br>
<br>
/// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the<br>
/// Session.<br>
@@ -630,9 +819,9 @@ Session::Session(Triple TT, uint64_t PageSize, Error &Err)<br>
return;<br>
}<br>
<br>
- if (!NoExec && !TT.isOSWindows())<br>
+ if (!NoExec && !this->TPC->getTargetTriple().isOSWindows())<br>
ObjLayer.addPlugin(std::make_unique<EHFrameRegistrationPlugin>(<br>
- ES, std::make_unique<InProcessEHFrameRegistrar>()));<br>
+ ES, ExitOnErr(TPCEHFrameRegistrar::Create(*this->TPC))));<br>
<br>
ObjLayer.addPlugin(std::make_unique<JITLinkSessionPlugin>(*this));<br>
<br>
@@ -785,22 +974,28 @@ Session::findSymbolInfo(StringRef SymbolName, Twine ErrorMsgStem) {<br>
} // end namespace llvm<br>
<br>
static Triple getFirstFileTriple() {<br>
- assert(!InputFiles.empty() && "InputFiles can not be empty");<br>
- auto ObjBuffer =<br>
- ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFiles.front())));<br>
- auto Obj = ExitOnErr(<br>
- object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef()));<br>
- return Obj->makeTriple();<br>
+ static Triple FirstTT = []() {<br>
+ assert(!InputFiles.empty() && "InputFiles can not be empty");<br>
+ auto ObjBuffer =<br>
+ ExitOnErr(errorOrToExpected(MemoryBuffer::getFile(InputFiles.front())));<br>
+ auto Obj = ExitOnErr(<br>
+ object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef()));<br>
+ return Obj->makeTriple();<br>
+ }();<br>
+<br>
+ return FirstTT;<br>
}<br>
<br>
-static Error sanitizeArguments(const Session &S) {<br>
+static Error sanitizeArguments(const Triple &TT, const char *ArgV0) {<br>
+ // Set the entry point name if not specified.<br>
if (EntryPointName.empty()) {<br>
- if (S.TPC->getTargetTriple().getObjectFormat() == Triple::MachO)<br>
+ if (TT.getObjectFormat() == Triple::MachO)<br>
EntryPointName = "_main";<br>
else<br>
EntryPointName = "main";<br>
}<br>
<br>
+ // -noexec and --args should not be used together.<br>
if (NoExec && !InputArgv.empty())<br>
outs() << "Warning: --args passed to -noexec run will be ignored.\n";<br>
<br>
@@ -812,14 +1007,35 @@ static Error sanitizeArguments(const Session &S) {<br>
inconvertibleErrorCode());<br>
}<br>
<br>
+ // Only one of -oop-executor and -oop-executor-connect can be used.<br>
+ if (!!OutOfProcessExecutor.getNumOccurrences() &&<br>
+ !!OutOfProcessExecutorConnect.getNumOccurrences())<br>
+ return make_error<StringError>(<br>
+ "Only one of -" + OutOfProcessExecutor.ArgStr + " and -" +<br>
+ OutOfProcessExecutorConnect.ArgStr + " can be specified",<br>
+ inconvertibleErrorCode());<br>
+<br>
+ // If -oop-executor was used but no value was specified then use a sensible<br>
+ // default.<br>
+ if (!!OutOfProcessExecutor.getNumOccurrences() &&<br>
+ OutOfProcessExecutor.empty()) {<br>
+ SmallString<256> OOPExecutorPath(sys::fs::getMainExecutable(<br>
+ ArgV0, reinterpret_cast<void *>(&sanitizeArguments)));<br>
+ sys::path::remove_filename(OOPExecutorPath);<br>
+ if (OOPExecutorPath.back() != '/')<br>
+ OOPExecutorPath += '/';<br>
+ OOPExecutorPath += "llvm-jitlink-executor";<br>
+ OutOfProcessExecutor = OOPExecutorPath.str().str();<br>
+ }<br>
+<br>
return Error::success();<br>
}<br>
<br>
static Error loadProcessSymbols(Session &S) {<br>
- auto InternedEntryPointName = S.ES.intern(EntryPointName);<br>
- auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) {<br>
- return Name != InternedEntryPointName;<br>
- };<br>
+ auto FilterMainEntryPoint =<br>
+ [EPName = S.ES.intern(EntryPointName)](SymbolStringPtr Name) {<br>
+ return Name != EPName;<br>
+ };<br>
S.MainJD->addGenerator(<br>
ExitOnErr(orc::TPCDynamicLibrarySearchGenerator::GetForTargetProcess(<br>
*S.TPC, std::move(FilterMainEntryPoint))));<br>
@@ -827,15 +1043,12 @@ static Error loadProcessSymbols(Session &S) {<br>
return Error::success();<br>
}<br>
<br>
-static Error loadDylibs() {<br>
- // FIXME: This should all be handled inside DynamicLibrary.<br>
+static Error loadDylibs(Session &S) {<br>
for (const auto &Dylib : Dylibs) {<br>
- if (!sys::fs::is_regular_file(Dylib))<br>
- return make_error<StringError>("\"" + Dylib + "\" is not a regular file",<br>
- inconvertibleErrorCode());<br>
- std::string ErrMsg;<br>
- if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg))<br>
- return make_error<StringError>(ErrMsg, inconvertibleErrorCode());<br>
+ auto G = orc::TPCDynamicLibrarySearchGenerator::Load(*S.TPC, Dylib.c_str());<br>
+ if (!G)<br>
+ return G.takeError();<br>
+ S.MainJD->addGenerator(std::move(*G));<br>
}<br>
<br>
return Error::success();<br>
@@ -1072,9 +1285,9 @@ int main(int argc, char *argv[]) {<br>
std::unique_ptr<JITLinkTimers> Timers =<br>
ShowTimes ? std::make_unique<JITLinkTimers>() : nullptr;<br>
<br>
- auto S = ExitOnErr(Session::Create(getFirstFileTriple()));<br>
+ ExitOnErr(sanitizeArguments(getFirstFileTriple(), argv[0]));<br>
<br>
- ExitOnErr(sanitizeArguments(*S));<br>
+ auto S = ExitOnErr(Session::Create(getFirstFileTriple()));<br>
<br>
{<br>
TimeRegion TR(Timers ? &Timers->LoadObjectsTimer : nullptr);<br>
@@ -1083,7 +1296,7 @@ int main(int argc, char *argv[]) {<br>
<br>
if (!NoProcessSymbols)<br>
ExitOnErr(loadProcessSymbols(*S));<br>
- ExitOnErr(loadDylibs());<br>
+ ExitOnErr(loadDylibs(*S));<br>
<br>
if (PhonyExternals)<br>
addPhonyExternalsGenerator(*S);<br>
@@ -1110,11 +1323,12 @@ int main(int argc, char *argv[]) {<br>
<br>
int Result = 0;<br>
{<br>
- using MainTy = int (*)(int, char *[]);<br>
- auto EntryFn = jitTargetAddressToFunction<MainTy>(EntryPoint.getAddress());<br>
TimeRegion TR(Timers ? &Timers->RunTimer : nullptr);<br>
- Result = runAsMain(EntryFn, InputArgv, StringRef(InputFiles.front()));<br>
+ Result = ExitOnErr(S->TPC->runAsMain(EntryPoint.getAddress(), InputArgv));<br>
}<br>
<br>
+ ExitOnErr(S->ES.endSession());<br>
+ ExitOnErr(S->TPC->disconnect());<br>
+<br>
return Result;<br>
}<br>
<br>
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.h b/llvm/tools/llvm-jitlink/llvm-jitlink.h<br>
index f0ede14050fd..5132eb204be1 100644<br>
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.h<br>
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.h<br>
@@ -18,6 +18,9 @@<br>
#include "llvm/ADT/Triple.h"<br>
#include "llvm/ExecutionEngine/Orc/Core.h"<br>
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"<br>
+#include "llvm/ExecutionEngine/Orc/OrcRPCTargetProcessControl.h"<br>
+#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"<br>
+#include "llvm/ExecutionEngine/Orc/RPC/RPCUtils.h"<br>
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"<br>
#include "llvm/ExecutionEngine/RuntimeDyldChecker.h"<br>
#include "llvm/Support/Error.h"<br>
@@ -45,9 +48,71 @@ class LLVMJITLinkObjectLinkingLayer : public orc::ObjectLinkingLayer {<br>
Session &S;<br>
};<br>
<br>
+using LLVMJITLinkChannel = orc::rpc::FDRawByteChannel;<br>
+using LLVMJITLinkRPCEndpoint =<br>
+ orc::rpc::MultiThreadedRPCEndpoint<LLVMJITLinkChannel>;<br>
+using LLVMJITLinkRemoteMemoryManager =<br>
+ orc::OrcRPCTPCJITLinkMemoryManager<LLVMJITLinkRPCEndpoint>;<br>
+using LLVMJITLinkRemoteMemoryAccess =<br>
+ orc::OrcRPCTPCMemoryAccess<LLVMJITLinkRPCEndpoint>;<br>
+<br>
+class LLVMJITLinkRemoteTargetProcessControl<br>
+ : public orc::OrcRPCTargetProcessControlBase<LLVMJITLinkRPCEndpoint> {<br>
+public:<br>
+ using BaseT = orc::OrcRPCTargetProcessControlBase<LLVMJITLinkRPCEndpoint>;<br>
+ static Expected<std::unique_ptr<TargetProcessControl>> LaunchExecutor();<br>
+<br>
+ static Expected<std::unique_ptr<TargetProcessControl>> ConnectToExecutor();<br>
+<br>
+ Error disconnect() override;<br>
+<br>
+private:<br>
+ using LLVMJITLinkRemoteMemoryAccess =<br>
+ orc::OrcRPCTPCMemoryAccess<LLVMJITLinkRemoteTargetProcessControl>;<br>
+<br>
+ using LLVMJITLinkRemoteMemoryManager =<br>
+ orc::OrcRPCTPCJITLinkMemoryManager<LLVMJITLinkRemoteTargetProcessControl>;<br>
+<br>
+ LLVMJITLinkRemoteTargetProcessControl(<br>
+ std::shared_ptr<orc::SymbolStringPool> SSP,<br>
+ std::unique_ptr<LLVMJITLinkChannel> Channel,<br>
+ std::unique_ptr<LLVMJITLinkRPCEndpoint> Endpoint,<br>
+ ErrorReporter ReportError, Error &Err)<br>
+ : BaseT(std::move(SSP), *Endpoint, std::move(ReportError)),<br>
+ Channel(std::move(Channel)), Endpoint(std::move(Endpoint)) {<br>
+ ErrorAsOutParameter _(&Err);<br>
+<br>
+ ListenerThread = std::thread([&]() {<br>
+ while (!Finished) {<br>
+ if (auto Err = this->Endpoint->handleOne()) {<br>
+ reportError(std::move(Err));<br>
+ return;<br>
+ }<br>
+ }<br>
+ });<br>
+<br>
+ if (auto Err2 = initializeORCRPCTPCBase()) {<br>
+ Err = joinErrors(std::move(Err2), disconnect());<br>
+ return;<br>
+ }<br>
+<br>
+ OwnedMemAccess = std::make_unique<LLVMJITLinkRemoteMemoryAccess>(*this);<br>
+ MemAccess = OwnedMemAccess.get();<br>
+ OwnedMemMgr = std::make_unique<LLVMJITLinkRemoteMemoryManager>(*this);<br>
+ MemMgr = OwnedMemMgr.get();<br>
+ }<br>
+<br>
+ std::unique_ptr<LLVMJITLinkChannel> Channel;<br>
+ std::unique_ptr<LLVMJITLinkRPCEndpoint> Endpoint;<br>
+ std::unique_ptr<TargetProcessControl::MemoryAccess> OwnedMemAccess;<br>
+ std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;<br>
+ std::atomic<bool> Finished{false};<br>
+ std::thread ListenerThread;<br>
+};<br>
+<br>
struct Session {<br>
- orc::ExecutionSession ES;<br>
std::unique_ptr<orc::TargetProcessControl> TPC;<br>
+ orc::ExecutionSession ES;<br>
orc::JITDylib *MainJD;<br>
LLVMJITLinkObjectLinkingLayer ObjLayer;<br>
std::vector<orc::JITDylib *> JDSearchOrder;<br>
@@ -93,7 +158,7 @@ struct Session {<br>
DenseMap<StringRef, StringRef> CanonicalWeakDefs;<br>
<br>
private:<br>
- Session(Triple TT, uint64_t PageSize, Error &Err);<br>
+ Session(std::unique_ptr<orc::TargetProcessControl> TPC, Error &Err);<br>
};<br>
<br>
/// Record symbols, GOT entries, stubs, and sections for ELF file.<br>
<br>
diff --git a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt<br>
index 28eb128ac55d..58aacfc25bf3 100644<br>
--- a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt<br>
+++ b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt<br>
@@ -2,6 +2,8 @@ set(LLVM_LINK_COMPONENTS<br>
${LLVM_TARGETS_TO_BUILD}<br>
JITLink<br>
Object<br>
+ OrcShared<br>
+ OrcTargetProcess<br>
RuntimeDyld<br>
Support<br>
)<br>
<br>
diff --git a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt<br>
index b382e4c4d731..48d6888fad11 100644<br>
--- a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt<br>
+++ b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt<br>
@@ -3,8 +3,8 @@ set(LLVM_LINK_COMPONENTS<br>
Core<br>
ExecutionEngine<br>
Object<br>
- OrcError<br>
OrcJIT<br>
+ OrcShared<br>
Passes<br>
RuntimeDyld<br>
Support<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>
</blockquote></div>