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 /// Supports registration/deregistration of EH-frames in a target process.
25 class EHFrameRegistrar {
26 public:
27   virtual ~EHFrameRegistrar();
28   virtual Error registerEHFrames(orc::ExecutorAddrRange EHFrameSection) = 0;
29   virtual Error deregisterEHFrames(orc::ExecutorAddrRange EHFrameSection) = 0;
30 };
31 
32 /// Registers / Deregisters EH-frames in the current process.
33 class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
34 public:
35   Error registerEHFrames(orc::ExecutorAddrRange EHFrameSection) override;
36 
37   Error deregisterEHFrames(orc::ExecutorAddrRange EHFrameSection) override;
38 };
39 
40 using StoreFrameRangeFunction = std::function<void(
41     orc::ExecutorAddr EHFrameSectionAddr, size_t EHFrameSectionSize)>;
42 
43 /// Creates a pass that records the address and size of the EH frame section.
44 /// If no eh-frame section is found then the address and size will both be given
45 /// as zero.
46 ///
47 /// Authors of JITLinkContexts can use this function to register a post-fixup
48 /// pass that records the range of the eh-frame section. This range can
49 /// be used after finalization to register and deregister the frame.
50 LinkGraphPassFunction
51 createEHFrameRecorderPass(const Triple &TT,
52                           StoreFrameRangeFunction StoreFrameRange);
53 
54 } // end namespace jitlink
55 } // end namespace llvm
56 
57 #endif // LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
58