llvm-jitlink.h 3.4 KB

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