1 //===--------- EHFrameSupport.h - JITLink eh-frame utils --------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // EHFrame registration support for JITLink.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
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"
24 /// Registers all FDEs in the given eh-frame section with the current process.
25 Error registerEHFrameSection(const void *EHFrameSectionAddr);
27 /// Deregisters all FDEs in the given eh-frame section with the current process.
28 Error deregisterEHFrameSection(const void *EHFrameSectionAddr);
30 /// Supports registration/deregistration of EH-frames in a target process.
31 class EHFrameRegistrar {
33 virtual ~EHFrameRegistrar();
34 virtual Error registerEHFrames(JITTargetAddress EHFrameSectionAddr) = 0;
35 virtual Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr) = 0;
38 /// Registers / Deregisters EH-frames in the current process.
39 class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
41 /// Get a reference to the InProcessEHFrameRegistrar singleton.
42 static InProcessEHFrameRegistrar &getInstance();
44 InProcessEHFrameRegistrar(const InProcessEHFrameRegistrar &) = delete;
45 InProcessEHFrameRegistrar &
46 operator=(const InProcessEHFrameRegistrar &) = delete;
48 InProcessEHFrameRegistrar(InProcessEHFrameRegistrar &&) = delete;
49 InProcessEHFrameRegistrar &operator=(InProcessEHFrameRegistrar &&) = delete;
51 Error registerEHFrames(JITTargetAddress EHFrameSectionAddr) override {
52 return registerEHFrameSection(
53 jitTargetAddressToPointer<void *>(EHFrameSectionAddr));
56 Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr) override {
57 return deregisterEHFrameSection(
58 jitTargetAddressToPointer<void *>(EHFrameSectionAddr));
62 InProcessEHFrameRegistrar();
65 using StoreFrameAddressFunction = std::function<void(JITTargetAddress)>;
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.
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.
74 createEHFrameRecorderPass(const Triple &TT,
75 StoreFrameAddressFunction StoreFrameAddress);
77 } // end namespace jitlink
78 } // end namespace llvm
80 #endif // LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H