Path: blob/main/contrib/llvm-project/llvm/lib/ExecutionEngine/JITLink/EHFrameSupportImpl.h
35271 views
//===------- EHFrameSupportImpl.h - JITLink eh-frame utils ------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// EHFrame registration support for JITLink.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORTIMPL_H13#define LLVM_LIB_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORTIMPL_H1415#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"1617#include "llvm/ExecutionEngine/JITLink/JITLink.h"18#include "llvm/Support/BinaryStreamReader.h"1920namespace llvm {21namespace jitlink {2223/// A LinkGraph pass that adds missing FDE-to-CIE, FDE-to-PC and FDE-to-LSDA24/// edges.25class EHFrameEdgeFixer {26public:27/// Create an eh-frame edge fixer.28/// If a given edge-kind is not supported on the target architecture then29/// Edge::Invalid should be used.30EHFrameEdgeFixer(StringRef EHFrameSectionName, unsigned PointerSize,31Edge::Kind Pointer32, Edge::Kind Pointer64,32Edge::Kind Delta32, Edge::Kind Delta64,33Edge::Kind NegDelta32);34Error operator()(LinkGraph &G);3536private:3738struct AugmentationInfo {39bool AugmentationDataPresent = false;40bool EHDataFieldPresent = false;41uint8_t Fields[4] = {0x0, 0x0, 0x0, 0x0};42};4344struct CIEInformation {45CIEInformation() = default;46CIEInformation(Symbol &CIESymbol) : CIESymbol(&CIESymbol) {}47Symbol *CIESymbol = nullptr;48bool AugmentationDataPresent = false;49bool LSDAPresent = false;50uint8_t LSDAEncoding = 0;51uint8_t AddressEncoding = 0;52};5354struct EdgeTarget {55EdgeTarget() = default;56EdgeTarget(const Edge &E) : Target(&E.getTarget()), Addend(E.getAddend()) {}5758Symbol *Target = nullptr;59Edge::AddendT Addend = 0;60};6162struct BlockEdgesInfo {63DenseMap<Edge::OffsetT, EdgeTarget> TargetMap;64DenseSet<Edge::OffsetT> Multiple;65};6667using CIEInfosMap = DenseMap<orc::ExecutorAddr, CIEInformation>;6869struct ParseContext {70ParseContext(LinkGraph &G) : G(G) {}7172Expected<CIEInformation *> findCIEInfo(orc::ExecutorAddr Address) {73auto I = CIEInfos.find(Address);74if (I == CIEInfos.end())75return make_error<JITLinkError>("No CIE found at address " +76formatv("{0:x16}", Address));77return &I->second;78}7980LinkGraph &G;81CIEInfosMap CIEInfos;82BlockAddressMap AddrToBlock;83DenseMap<orc::ExecutorAddr, Symbol *> AddrToSym;84};8586Error processBlock(ParseContext &PC, Block &B);87Error processCIE(ParseContext &PC, Block &B, size_t CIEDeltaFieldOffset,88const BlockEdgesInfo &BlockEdges);89Error processFDE(ParseContext &PC, Block &B, size_t CIEDeltaFieldOffset,90uint32_t CIEDelta, const BlockEdgesInfo &BlockEdges);9192Expected<AugmentationInfo>93parseAugmentationString(BinaryStreamReader &RecordReader);9495Expected<uint8_t> readPointerEncoding(BinaryStreamReader &RecordReader,96Block &InBlock, const char *FieldName);97Error skipEncodedPointer(uint8_t PointerEncoding,98BinaryStreamReader &RecordReader);99Expected<Symbol *> getOrCreateEncodedPointerEdge(100ParseContext &PC, const BlockEdgesInfo &BlockEdges,101uint8_t PointerEncoding, BinaryStreamReader &RecordReader,102Block &BlockToFix, size_t PointerFieldOffset, const char *FieldName);103104Expected<Symbol &> getOrCreateSymbol(ParseContext &PC,105orc::ExecutorAddr Addr);106107StringRef EHFrameSectionName;108unsigned PointerSize;109Edge::Kind Pointer32;110Edge::Kind Pointer64;111Edge::Kind Delta32;112Edge::Kind Delta64;113Edge::Kind NegDelta32;114};115116/// Add a 32-bit null-terminator to the end of the eh-frame section.117class EHFrameNullTerminator {118public:119EHFrameNullTerminator(StringRef EHFrameSectionName);120Error operator()(LinkGraph &G);121122private:123static char NullTerminatorBlockContent[];124StringRef EHFrameSectionName;125};126127} // end namespace jitlink128} // end namespace llvm129130#endif // LLVM_LIB_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORTIMPL_H131132133