| 1 | //===- JITLinkReentryTrampolines.h -- JITLink-based trampolines -*- 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 | // Emit reentry trampolines via JITLink. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_EXECUTIONENGINE_ORC_JITLINKREENTRYTRAMPOLINES_H |
| 14 | #define LLVM_EXECUTIONENGINE_ORC_JITLINKREENTRYTRAMPOLINES_H |
| 15 | |
| 16 | #include "llvm/ADT/FunctionExtras.h" |
| 17 | #include "llvm/ExecutionEngine/Orc/Core.h" |
| 18 | #include "llvm/ExecutionEngine/Orc/LazyReexports.h" |
| 19 | #include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h" |
| 20 | #include "llvm/Support/Compiler.h" |
| 21 | #include "llvm/Support/Error.h" |
| 22 | |
| 23 | namespace llvm::jitlink { |
| 24 | class Block; |
| 25 | class LinkGraph; |
| 26 | class Section; |
| 27 | class Symbol; |
| 28 | } // namespace llvm::jitlink |
| 29 | |
| 30 | namespace llvm::orc { |
| 31 | |
| 32 | class ObjectLinkingLayer; |
| 33 | class RedirectableSymbolManager; |
| 34 | |
| 35 | /// Produces trampolines on request using JITLink. |
| 36 | class JITLinkReentryTrampolines { |
| 37 | public: |
| 38 | using EmitTrampolineFn = unique_function<jitlink::Symbol &( |
| 39 | jitlink::LinkGraph &G, jitlink::Section &Sec, |
| 40 | jitlink::Symbol &ReentrySym)>; |
| 41 | using OnTrampolinesReadyFn = unique_function<void( |
| 42 | Expected<std::vector<ExecutorSymbolDef>> EntryAddrs)>; |
| 43 | |
| 44 | /// Create trampolines using the default reentry trampoline function for |
| 45 | /// the session triple. |
| 46 | LLVM_ABI static Expected<std::unique_ptr<JITLinkReentryTrampolines>> |
| 47 | Create(ObjectLinkingLayer &ObjLinkingLayer); |
| 48 | |
| 49 | LLVM_ABI JITLinkReentryTrampolines(ObjectLinkingLayer &ObjLinkingLayer, |
| 50 | EmitTrampolineFn EmitTrampoline); |
| 51 | JITLinkReentryTrampolines(JITLinkReentryTrampolines &&) = delete; |
| 52 | JITLinkReentryTrampolines &operator=(JITLinkReentryTrampolines &&) = delete; |
| 53 | |
| 54 | LLVM_ABI void emit(ResourceTrackerSP RT, size_t NumTrampolines, |
| 55 | OnTrampolinesReadyFn OnTrampolinesReady); |
| 56 | |
| 57 | private: |
| 58 | class TrampolineAddrScraperPlugin; |
| 59 | |
| 60 | ObjectLinkingLayer &ObjLinkingLayer; |
| 61 | TrampolineAddrScraperPlugin *TrampolineAddrScraper = nullptr; |
| 62 | EmitTrampolineFn EmitTrampoline; |
| 63 | std::atomic<size_t> ReentryGraphIdx{0}; |
| 64 | }; |
| 65 | |
| 66 | LLVM_ABI Expected<std::unique_ptr<LazyReexportsManager>> |
| 67 | createJITLinkLazyReexportsManager(ObjectLinkingLayer &ObjLinkingLayer, |
| 68 | RedirectableSymbolManager &RSMgr, |
| 69 | JITDylib &PlatformJD, |
| 70 | LazyReexportsManager::Listener *L = nullptr); |
| 71 | |
| 72 | } // namespace llvm::orc |
| 73 | |
| 74 | #endif // LLVM_EXECUTIONENGINE_ORC_JITLINKREENTRYTRAMPOLINES_H |
| 75 |