llvm-jitlink.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //===---- llvm-jitlink.h - Session and format-specific decls ----*- C++ -*-===//
  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. // llvm-jitlink Session class and tool utilities.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
  13. #define LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
  14. #include "llvm/ADT/Optional.h"
  15. #include "llvm/ADT/StringSet.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/ExecutionEngine/Orc/Core.h"
  18. #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
  19. #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
  20. #include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
  21. #include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
  22. #include "llvm/Support/Error.h"
  23. #include "llvm/Support/Regex.h"
  24. #include "llvm/Support/raw_ostream.h"
  25. #include <vector>
  26. namespace llvm {
  27. struct Session;
  28. struct Session {
  29. orc::ExecutionSession ES;
  30. orc::JITDylib *MainJD = nullptr;
  31. orc::ObjectLinkingLayer ObjLayer;
  32. orc::JITDylibSearchOrder JDSearchOrder;
  33. ~Session();
  34. static Expected<std::unique_ptr<Session>> Create(Triple TT);
  35. void dumpSessionInfo(raw_ostream &OS);
  36. void modifyPassConfig(const Triple &FTT,
  37. jitlink::PassConfiguration &PassConfig);
  38. using MemoryRegionInfo = RuntimeDyldChecker::MemoryRegionInfo;
  39. struct FileInfo {
  40. StringMap<MemoryRegionInfo> SectionInfos;
  41. StringMap<MemoryRegionInfo> StubInfos;
  42. StringMap<MemoryRegionInfo> GOTEntryInfos;
  43. };
  44. using SymbolInfoMap = StringMap<MemoryRegionInfo>;
  45. using FileInfoMap = StringMap<FileInfo>;
  46. Expected<FileInfo &> findFileInfo(StringRef FileName);
  47. Expected<MemoryRegionInfo &> findSectionInfo(StringRef FileName,
  48. StringRef SectionName);
  49. Expected<MemoryRegionInfo &> findStubInfo(StringRef FileName,
  50. StringRef TargetName);
  51. Expected<MemoryRegionInfo &> findGOTEntryInfo(StringRef FileName,
  52. StringRef TargetName);
  53. bool isSymbolRegistered(StringRef Name);
  54. Expected<MemoryRegionInfo &> findSymbolInfo(StringRef SymbolName,
  55. Twine ErrorMsgStem);
  56. SymbolInfoMap SymbolInfos;
  57. FileInfoMap FileInfos;
  58. uint64_t SizeBeforePruning = 0;
  59. uint64_t SizeAfterFixups = 0;
  60. StringSet<> HarnessFiles;
  61. StringSet<> HarnessExternals;
  62. StringSet<> HarnessDefinitions;
  63. DenseMap<StringRef, StringRef> CanonicalWeakDefs;
  64. private:
  65. Session(std::unique_ptr<orc::ExecutorProcessControl> EPC, Error &Err);
  66. };
  67. /// Record symbols, GOT entries, stubs, and sections for ELF file.
  68. Error registerELFGraphInfo(Session &S, jitlink::LinkGraph &G);
  69. /// Record symbols, GOT entries, stubs, and sections for MachO file.
  70. Error registerMachOGraphInfo(Session &S, jitlink::LinkGraph &G);
  71. } // end namespace llvm
  72. #endif // LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H