ChildTarget.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //===----------- ChildTarget.cpp - Out-of-proc executor for lli -----------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Simple out-of-process executor for lli.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/ADT/StringRef.h"
  13. #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
  14. #include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
  15. #include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h"
  16. #include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h"
  17. #include "llvm/Support/DynamicLibrary.h"
  18. #include "llvm/Support/Error.h"
  19. #include "llvm/Support/MathExtras.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. #include <cstring>
  22. #include <sstream>
  23. using namespace llvm;
  24. using namespace llvm::orc;
  25. ExitOnError ExitOnErr;
  26. int main(int argc, char *argv[]) {
  27. #if LLVM_ENABLE_THREADS
  28. if (argc != 3) {
  29. errs() << "Usage: " << argv[0] << " <input fd> <output fd>\n";
  30. return 1;
  31. }
  32. if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
  33. errs() << "Error loading program symbols.\n";
  34. return 1;
  35. }
  36. ExitOnErr.setBanner(std::string(argv[0]) + ": ");
  37. int InFD = 0;
  38. int OutFD = 0;
  39. {
  40. std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]);
  41. InFDStream >> InFD;
  42. OutFDStream >> OutFD;
  43. }
  44. auto Server =
  45. ExitOnErr(SimpleRemoteEPCServer::Create<FDSimpleRemoteEPCTransport>(
  46. [](SimpleRemoteEPCServer::Setup &S) -> Error {
  47. S.setDispatcher(
  48. std::make_unique<SimpleRemoteEPCServer::ThreadDispatcher>());
  49. S.bootstrapSymbols() =
  50. SimpleRemoteEPCServer::defaultBootstrapSymbols();
  51. S.services().push_back(
  52. std::make_unique<rt_bootstrap::SimpleExecutorMemoryManager>());
  53. return Error::success();
  54. },
  55. InFD, OutFD));
  56. ExitOnErr(Server->waitForDisconnect());
  57. return 0;
  58. #else
  59. errs() << argv[0]
  60. << " error: this tool requires threads, but LLVM was "
  61. "built with LLVM_ENABLE_THREADS=Off\n";
  62. return 1;
  63. #endif
  64. }