summaryrefslogtreecommitdiff
path: root/llvm/tools/lli/ChildTarget/ChildTarget.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-11-19 20:06:13 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-11-19 20:06:13 +0000
commitc0981da47d5696fe36474fcf86b4ce03ae3ff818 (patch)
treef42add1021b9f2ac6a69ac7cf6c4499962739a45 /llvm/tools/lli/ChildTarget/ChildTarget.cpp
parent344a3780b2e33f6ca763666c380202b18aab72a3 (diff)
Diffstat (limited to 'llvm/tools/lli/ChildTarget/ChildTarget.cpp')
-rw-r--r--llvm/tools/lli/ChildTarget/ChildTarget.cpp93
1 files changed, 50 insertions, 43 deletions
diff --git a/llvm/tools/lli/ChildTarget/ChildTarget.cpp b/llvm/tools/lli/ChildTarget/ChildTarget.cpp
index 5772baca1d09..cf1b03a141c5 100644
--- a/llvm/tools/lli/ChildTarget/ChildTarget.cpp
+++ b/llvm/tools/lli/ChildTarget/ChildTarget.cpp
@@ -1,69 +1,76 @@
-#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
-#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h"
-#include "llvm/ExecutionEngine/Orc/Shared/FDRawByteChannel.h"
-#include "llvm/Support/Debug.h"
+//===----------- ChildTarget.cpp - Out-of-proc executor for lli -----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Simple out-of-process executor for lli.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h"
#include "llvm/Support/DynamicLibrary.h"
-#include "llvm/Support/Process.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstring>
#include <sstream>
-#include "../RemoteJITUtils.h"
-
using namespace llvm;
using namespace llvm::orc;
-using namespace llvm::sys;
-
-#ifdef __x86_64__
-typedef OrcX86_64_SysV HostOrcArch;
-#else
-typedef OrcGenericABI HostOrcArch;
-#endif
ExitOnError ExitOnErr;
int main(int argc, char *argv[]) {
+#if LLVM_ENABLE_THREADS
if (argc != 3) {
errs() << "Usage: " << argv[0] << " <input fd> <output fd>\n";
return 1;
}
- ExitOnErr.setBanner(std::string(argv[0]) + ":");
-
- int InFD;
- int OutFD;
- {
- std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]);
- InFDStream >> InFD;
- OutFDStream >> OutFD;
- }
-
if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
errs() << "Error loading program symbols.\n";
return 1;
}
- auto SymbolLookup = [](const std::string &Name) {
- return RTDyldMemoryManager::getSymbolAddressInProcess(Name);
- };
-
- auto RegisterEHFrames = [](uint8_t *Addr, uint32_t Size) {
- RTDyldMemoryManager::registerEHFramesInProcess(Addr, Size);
- };
-
- auto DeregisterEHFrames = [](uint8_t *Addr, uint32_t Size) {
- RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size);
- };
+ ExitOnErr.setBanner(std::string(argv[0]) + ": ");
- shared::FDRawByteChannel Channel(InFD, OutFD);
- typedef remote::OrcRemoteTargetServer<shared::FDRawByteChannel, HostOrcArch>
- JITServer;
- JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
+ int InFD = 0;
+ int OutFD = 0;
+ {
+ std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]);
+ InFDStream >> InFD;
+ OutFDStream >> OutFD;
+ }
- while (!Server.receivedTerminate())
- ExitOnErr(Server.handleOne());
+ auto Server =
+ ExitOnErr(SimpleRemoteEPCServer::Create<FDSimpleRemoteEPCTransport>(
+ [](SimpleRemoteEPCServer::Setup &S) -> Error {
+ S.setDispatcher(
+ std::make_unique<SimpleRemoteEPCServer::ThreadDispatcher>());
+ S.bootstrapSymbols() =
+ SimpleRemoteEPCServer::defaultBootstrapSymbols();
+ S.services().push_back(
+ std::make_unique<rt_bootstrap::SimpleExecutorMemoryManager>());
+ return Error::success();
+ },
+ InFD, OutFD));
- close(InFD);
- close(OutFD);
+ ExitOnErr(Server->waitForDisconnect());
return 0;
+
+#else
+ errs() << argv[0]
+ << " error: this tool requires threads, but LLVM was "
+ "built with LLVM_ENABLE_THREADS=Off\n";
+ return 1;
+#endif
}