]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / ExecutionEngine / JITLink / EHFrameSupport.h
1 //===--------- EHFrameSupport.h - JITLink eh-frame utils --------*- 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 // EHFrame registration support for JITLink.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
15
16 #include "llvm/ADT/Triple.h"
17 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
18 #include "llvm/ExecutionEngine/JITSymbol.h"
19 #include "llvm/Support/Error.h"
20
21 namespace llvm {
22 namespace jitlink {
23
24 /// Registers all FDEs in the given eh-frame section with the current process.
25 Error registerEHFrameSection(const void *EHFrameSectionAddr);
26
27 /// Deregisters all FDEs in the given eh-frame section with the current process.
28 Error deregisterEHFrameSection(const void *EHFrameSectionAddr);
29
30 /// Supports registration/deregistration of EH-frames in a target process.
31 class EHFrameRegistrar {
32 public:
33   virtual ~EHFrameRegistrar();
34   virtual Error registerEHFrames(JITTargetAddress EHFrameSectionAddr) = 0;
35   virtual Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr) = 0;
36 };
37
38 /// Registers / Deregisters EH-frames in the current process.
39 class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
40 public:
41   /// Get a reference to the InProcessEHFrameRegistrar singleton.
42   static InProcessEHFrameRegistrar &getInstance();
43
44   InProcessEHFrameRegistrar(const InProcessEHFrameRegistrar &) = delete;
45   InProcessEHFrameRegistrar &
46   operator=(const InProcessEHFrameRegistrar &) = delete;
47
48   InProcessEHFrameRegistrar(InProcessEHFrameRegistrar &&) = delete;
49   InProcessEHFrameRegistrar &operator=(InProcessEHFrameRegistrar &&) = delete;
50
51   Error registerEHFrames(JITTargetAddress EHFrameSectionAddr) override {
52     return registerEHFrameSection(
53         jitTargetAddressToPointer<void *>(EHFrameSectionAddr));
54   }
55
56   Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr) override {
57     return deregisterEHFrameSection(
58         jitTargetAddressToPointer<void *>(EHFrameSectionAddr));
59   }
60
61 private:
62   InProcessEHFrameRegistrar();
63 };
64
65 using StoreFrameAddressFunction = std::function<void(JITTargetAddress)>;
66
67 /// Creates a pass that records the address of the EH frame section. If no
68 /// eh-frame section is found, it will set EHFrameAddr to zero.
69 ///
70 /// Authors of JITLinkContexts can use this function to register a post-fixup
71 /// pass that records the address of the eh-frame section. This address can
72 /// be used after finalization to register and deregister the frame.
73 AtomGraphPassFunction
74 createEHFrameRecorderPass(const Triple &TT,
75                           StoreFrameAddressFunction StoreFrameAddress);
76
77 } // end namespace jitlink
78 } // end namespace llvm
79
80 #endif // LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H