LLVM  15.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 
21 namespace llvm {
22 namespace jitlink {
23 
24 /// A LinkGraph pass that adds missing FDE-to-CIE, FDE-to-PC and FDE-to-LSDA
25 /// edges.
27 public:
28  /// Create an eh-frame edge fixer.
29  /// If a given edge-kind is not supported on the target architecture then
30  /// Edge::Invalid should be used.
31  EHFrameEdgeFixer(StringRef EHFrameSectionName, unsigned PointerSize,
32  Edge::Kind Pointer32, Edge::Kind Pointer64,
33  Edge::Kind Delta32, Edge::Kind Delta64,
34  Edge::Kind NegDelta32);
36 
37 private:
38 
39  struct AugmentationInfo {
40  bool AugmentationDataPresent = false;
41  bool EHDataFieldPresent = false;
42  uint8_t Fields[4] = {0x0, 0x0, 0x0, 0x0};
43  };
44 
45  struct CIEInformation {
46  CIEInformation() = default;
47  CIEInformation(Symbol &CIESymbol) : CIESymbol(&CIESymbol) {}
48  Symbol *CIESymbol = nullptr;
49  bool AugmentationDataPresent = false;
50  bool LSDAPresent = false;
51  uint8_t LSDAEncoding = 0;
52  uint8_t AddressEncoding = 0;
53  };
54 
55  struct EdgeTarget {
56  EdgeTarget() = default;
57  EdgeTarget(const Edge &E) : Target(&E.getTarget()), Addend(E.getAddend()) {}
58 
59  Symbol *Target = nullptr;
60  Edge::AddendT Addend = 0;
61  };
62 
65 
66  struct ParseContext {
67  ParseContext(LinkGraph &G) : G(G) {}
68 
69  Expected<CIEInformation *> findCIEInfo(orc::ExecutorAddr Address) {
70  auto I = CIEInfos.find(Address);
71  if (I == CIEInfos.end())
72  return make_error<JITLinkError>("No CIE found at address " +
73  formatv("{0:x16}", Address));
74  return &I->second;
75  }
76 
77  LinkGraph &G;
78  CIEInfosMap CIEInfos;
79  BlockAddressMap AddrToBlock;
81  };
82 
83  Error processBlock(ParseContext &PC, Block &B);
84  Error processCIE(ParseContext &PC, Block &B, size_t RecordOffset,
85  size_t RecordLength, size_t CIEDeltaFieldOffset,
86  const BlockEdgeMap &BlockEdges);
87  Error processFDE(ParseContext &PC, Block &B, size_t RecordOffset,
88  size_t RecordLength, size_t CIEDeltaFieldOffset,
89  uint32_t CIEDelta, const BlockEdgeMap &BlockEdges);
90 
92  parseAugmentationString(BinaryStreamReader &RecordReader);
93 
94  Expected<uint8_t> readPointerEncoding(BinaryStreamReader &RecordReader,
95  Block &InBlock, const char *FieldName);
96  Error skipEncodedPointer(uint8_t PointerEncoding,
97  BinaryStreamReader &RecordReader);
98  Expected<Symbol *> getOrCreateEncodedPointerEdge(
99  ParseContext &PC, const BlockEdgeMap &BlockEdges, uint8_t PointerEncoding,
100  BinaryStreamReader &RecordReader, Block &BlockToFix,
101  size_t PointerFieldOffset, const char *FieldName);
102 
103  Expected<Symbol &> getOrCreateSymbol(ParseContext &PC,
105 
106  StringRef EHFrameSectionName;
107  unsigned PointerSize;
108  Edge::Kind Pointer32;
109  Edge::Kind Pointer64;
110  Edge::Kind Delta32;
111  Edge::Kind Delta64;
112  Edge::Kind NegDelta32;
113 };
114 
115 /// Add a 32-bit null-terminator to the end of the eh-frame section.
117 public:
118  EHFrameNullTerminator(StringRef EHFrameSectionName);
120 
121 private:
122  static char NullTerminatorBlockContent[];
123  StringRef EHFrameSectionName;
124 };
125 
126 } // end namespace jitlink
127 } // end namespace llvm
128 
129 #endif // LLVM_LIB_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORTIMPL_H
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:30
BinaryStreamReader.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:140
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
EHFrameSupport.h
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
InBlock
static bool InBlock(const Value *V, const BasicBlock *BB)
Definition: SelectionDAGBuilder.cpp:2144
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::DenseMap
Definition: DenseMap.h:716
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155