LLVM 20.0.0git
EHFrameSupportImpl.h
Go to the documentation of this file.
1//===------- EHFrameSupportImpl.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_LIB_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORTIMPL_H
14#define LLVM_LIB_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORTIMPL_H
15
17
20
21namespace llvm {
22namespace jitlink {
23
24/// A LinkGraph pass that adds missing FDE-to-CIE, FDE-to-PC and FDE-to-LSDA
25/// edges.
27public:
28 /// Create an eh-frame edge fixer.
29 /// Adds edges for implicit relocations on platforms where these are used
30 /// (e.g. MachO/x86-64).
31 ///
32 /// If a given edge-kind is not supported on the target architecture then
33 /// Edge::Invalid should be used.
34 EHFrameEdgeFixer(StringRef EHFrameSectionName, unsigned PointerSize,
35 Edge::Kind Pointer32, Edge::Kind Pointer64,
36 Edge::Kind Delta32, Edge::Kind Delta64,
37 Edge::Kind NegDelta32);
39
40private:
41
42 struct AugmentationInfo {
43 bool AugmentationDataPresent = false;
44 bool EHDataFieldPresent = false;
45 uint8_t Fields[4] = {0x0, 0x0, 0x0, 0x0};
46 };
47
48 struct CIEInformation {
49 CIEInformation() = default;
50 CIEInformation(Symbol &CIESymbol) : CIESymbol(&CIESymbol) {}
51 Symbol *CIESymbol = nullptr;
52 bool AugmentationDataPresent = false;
53 bool LSDAPresent = false;
54 uint8_t LSDAEncoding = 0;
55 uint8_t AddressEncoding = 0;
56 };
57
58 struct EdgeTarget {
59 EdgeTarget() = default;
60 EdgeTarget(const Edge &E) : Target(&E.getTarget()), Addend(E.getAddend()) {}
61
62 Symbol *Target = nullptr;
63 Edge::AddendT Addend = 0;
64 };
65
66 struct BlockEdgesInfo {
69 };
70
72
73 struct ParseContext {
74 ParseContext(LinkGraph &G) : G(G) {}
75
77 auto I = CIEInfos.find(Address);
78 if (I == CIEInfos.end())
79 return make_error<JITLinkError>("No CIE found at address " +
80 formatv("{0:x16}", Address));
81 return &I->second;
82 }
83
84 LinkGraph &G;
85 CIEInfosMap CIEInfos;
86 BlockAddressMap AddrToBlock;
88 };
89
90 Error processBlock(ParseContext &PC, Block &B);
91 Error processCIE(ParseContext &PC, Block &B, size_t CIEDeltaFieldOffset,
92 const BlockEdgesInfo &BlockEdges);
93 Error processFDE(ParseContext &PC, Block &B, size_t CIEDeltaFieldOffset,
94 uint32_t CIEDelta, const BlockEdgesInfo &BlockEdges);
95
97 parseAugmentationString(BinaryStreamReader &RecordReader);
98
99 Expected<uint8_t> readPointerEncoding(BinaryStreamReader &RecordReader,
100 Block &InBlock, const char *FieldName);
101 Error skipEncodedPointer(uint8_t PointerEncoding,
102 BinaryStreamReader &RecordReader);
103 Expected<Symbol *> getOrCreateEncodedPointerEdge(
104 ParseContext &PC, const BlockEdgesInfo &BlockEdges,
105 uint8_t PointerEncoding, BinaryStreamReader &RecordReader,
106 Block &BlockToFix, size_t PointerFieldOffset, const char *FieldName);
107
108 Expected<Symbol &> getOrCreateSymbol(ParseContext &PC,
110
111 StringRef EHFrameSectionName;
112 unsigned PointerSize;
113 Edge::Kind Pointer32;
114 Edge::Kind Pointer64;
115 Edge::Kind Delta32;
116 Edge::Kind Delta64;
117 Edge::Kind NegDelta32;
118};
119
120/// Add a 32-bit null-terminator to the end of the eh-frame section.
122public:
123 EHFrameNullTerminator(StringRef EHFrameSectionName);
125
126private:
127 static char NullTerminatorBlockContent[];
128 StringRef EHFrameSectionName;
129};
130
131} // end namespace jitlink
132} // end namespace llvm
133
134#endif // LLVM_LIB_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORTIMPL_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint64_t Addr
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
static bool InBlock(const Value *V, const BasicBlock *BB)
Provides read only access to a subclass of BinaryStream.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Target - Wrapper for Target specific information.
Represents an address in the executor process.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)