Path: blob/main/contrib/llvm-project/llvm/tools/lli/ChildTarget/ChildTarget.cpp
35292 views
//===----------- ChildTarget.cpp - Out-of-proc executor for lli -----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Simple out-of-process executor for lli.9//10//===----------------------------------------------------------------------===//1112#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"13#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"14#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h"15#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h"16#include "llvm/Support/DynamicLibrary.h"17#include "llvm/Support/Error.h"18#include "llvm/Support/MathExtras.h"19#include "llvm/Support/raw_ostream.h"20#include <cstring>21#include <sstream>2223using namespace llvm;24using namespace llvm::orc;2526ExitOnError ExitOnErr;2728int main(int argc, char *argv[]) {29#if LLVM_ENABLE_THREADS3031if (argc != 3) {32errs() << "Usage: " << argv[0] << " <input fd> <output fd>\n";33return 1;34}3536if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {37errs() << "Error loading program symbols.\n";38return 1;39}4041ExitOnErr.setBanner(std::string(argv[0]) + ": ");4243int InFD = 0;44int OutFD = 0;45{46std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]);47InFDStream >> InFD;48OutFDStream >> OutFD;49}5051auto Server =52ExitOnErr(SimpleRemoteEPCServer::Create<FDSimpleRemoteEPCTransport>(53[](SimpleRemoteEPCServer::Setup &S) -> Error {54S.setDispatcher(55std::make_unique<SimpleRemoteEPCServer::ThreadDispatcher>());56S.bootstrapSymbols() =57SimpleRemoteEPCServer::defaultBootstrapSymbols();58S.services().push_back(59std::make_unique<rt_bootstrap::SimpleExecutorMemoryManager>());60return Error::success();61},62InFD, OutFD));6364ExitOnErr(Server->waitForDisconnect());6566return 0;6768#else69errs() << argv[0]70<< " error: this tool requires threads, but LLVM was "71"built with LLVM_ENABLE_THREADS=Off\n";72return 1;73#endif74}757677