16498b0e9SLang Hames //===----------- ChildTarget.cpp - Out-of-proc executor for lli -----------===// 26498b0e9SLang Hames // 36498b0e9SLang Hames // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 46498b0e9SLang Hames // See https://llvm.org/LICENSE.txt for license information. 56498b0e9SLang Hames // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 66498b0e9SLang Hames // 76498b0e9SLang Hames //===----------------------------------------------------------------------===// 86498b0e9SLang Hames // 96498b0e9SLang Hames // Simple out-of-process executor for lli. 106498b0e9SLang Hames // 116498b0e9SLang Hames //===----------------------------------------------------------------------===// 12c2ebf3f5SAndrew Kaylor 136498b0e9SLang Hames #include "llvm/ADT/StringRef.h" 146498b0e9SLang Hames #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h" 156498b0e9SLang Hames #include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h" 166498b0e9SLang Hames #include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h" 176498b0e9SLang Hames #include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h" 186498b0e9SLang Hames #include "llvm/Support/DynamicLibrary.h" 196498b0e9SLang Hames #include "llvm/Support/Error.h" 206498b0e9SLang Hames #include "llvm/Support/MathExtras.h" 216498b0e9SLang Hames #include "llvm/Support/raw_ostream.h" 226498b0e9SLang Hames #include <cstring> 236498b0e9SLang Hames #include <sstream> 2499951a56SLang Hames 25c2ebf3f5SAndrew Kaylor using namespace llvm; 269d7a269fSLang Hames using namespace llvm::orc; 27c2ebf3f5SAndrew Kaylor 28ef5a0ee2SLang Hames ExitOnError ExitOnErr; 29ef5a0ee2SLang Hames main(int argc,char * argv[])309d7a269fSLang Hamesint main(int argc, char *argv[]) { 316498b0e9SLang Hames #if LLVM_ENABLE_THREADS 32c2ebf3f5SAndrew Kaylor 339d7a269fSLang Hames if (argc != 3) { 349d7a269fSLang Hames errs() << "Usage: " << argv[0] << " <input fd> <output fd>\n"; 359d7a269fSLang Hames return 1; 36ad6aa47cSAlp Toker } 37c2ebf3f5SAndrew Kaylor 389d7a269fSLang Hames if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) { 399d7a269fSLang Hames errs() << "Error loading program symbols.\n"; 409d7a269fSLang Hames return 1; 419d7a269fSLang Hames } 429d7a269fSLang Hames 436498b0e9SLang Hames ExitOnErr.setBanner(std::string(argv[0]) + ": "); 44c2ebf3f5SAndrew Kaylor 456498b0e9SLang Hames int InFD = 0; 466498b0e9SLang Hames int OutFD = 0; 476498b0e9SLang Hames { 486498b0e9SLang Hames std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]); 496498b0e9SLang Hames InFDStream >> InFD; 506498b0e9SLang Hames OutFDStream >> OutFD; 516498b0e9SLang Hames } 5252c47241SLang Hames 536498b0e9SLang Hames auto Server = 546498b0e9SLang Hames ExitOnErr(SimpleRemoteEPCServer::Create<FDSimpleRemoteEPCTransport>( 556498b0e9SLang Hames [](SimpleRemoteEPCServer::Setup &S) -> Error { 566498b0e9SLang Hames S.setDispatcher( 57*8fe3d9dfSLang Hames std::make_unique<SimpleRemoteEPCServer::ThreadDispatcher>()); 586498b0e9SLang Hames S.bootstrapSymbols() = 596498b0e9SLang Hames SimpleRemoteEPCServer::defaultBootstrapSymbols(); 606498b0e9SLang Hames S.services().push_back( 616498b0e9SLang Hames std::make_unique<rt_bootstrap::SimpleExecutorMemoryManager>()); 626498b0e9SLang Hames return Error::success(); 636498b0e9SLang Hames }, 646498b0e9SLang Hames InFD, OutFD)); 6552c47241SLang Hames 666498b0e9SLang Hames ExitOnErr(Server->waitForDisconnect()); 679d7a269fSLang Hames 68c2ebf3f5SAndrew Kaylor return 0; 696498b0e9SLang Hames 706498b0e9SLang Hames #else 716498b0e9SLang Hames errs() << argv[0] 726498b0e9SLang Hames << " error: this tool requires threads, but LLVM was " 736498b0e9SLang Hames "built with LLVM_ENABLE_THREADS=Off\n"; 746498b0e9SLang Hames return 1; 756498b0e9SLang Hames #endif 76c2ebf3f5SAndrew Kaylor } 77