LLVM 22.0.0git
SFrame.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/// \file
10/// This file contains data-structure definitions and constants to support
11/// unwinding based on .sframe sections. This only supports SFRAME_VERSION_2
12/// as described at https://sourceware.org/binutils/docs/sframe-spec.html
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_BINARYFORMAT_SFRAME_H
16#define LLVM_BINARYFORMAT_SFRAME_H
17
18#include "llvm/ADT/ArrayRef.h"
22#include "llvm/Support/Endian.h"
23
24namespace llvm {
25
26template <typename T> struct EnumEntry;
27
28namespace sframe {
29
31
32constexpr uint16_t Magic = 0xdee2;
33
34enum class Version : uint8_t {
35#define HANDLE_SFRAME_VERSION(CODE, NAME) NAME = CODE,
36#include "llvm/BinaryFormat/SFrameConstants.def"
37};
38
39enum class Flags : uint8_t {
40#define HANDLE_SFRAME_FLAG(CODE, NAME) NAME = CODE,
41#include "llvm/BinaryFormat/SFrameConstants.def"
42 V2AllFlags = FDESorted | FramePointer | FDEFuncStartPCRel,
43 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/0xff),
44};
45
46enum class ABI : uint8_t {
47#define HANDLE_SFRAME_ABI(CODE, NAME) NAME = CODE,
48#include "llvm/BinaryFormat/SFrameConstants.def"
49};
50
51/// SFrame FRE Types. Bits 0-3 of FuncDescEntry.Info.
52enum class FREType : uint8_t {
53#define HANDLE_SFRAME_FRE_TYPE(CODE, NAME) NAME = CODE,
54#include "llvm/BinaryFormat/SFrameConstants.def"
55};
56
57/// SFrame FDE Types. Bit 4 of FuncDescEntry.Info.
58enum class FDEType : uint8_t {
59#define HANDLE_SFRAME_FDE_TYPE(CODE, NAME) NAME = CODE,
60#include "llvm/BinaryFormat/SFrameConstants.def"
61};
62
63/// Speficies key used for signing return addresses. Bit 5 of
64/// FuncDescEntry.Info.
66#define HANDLE_SFRAME_AARCH64_PAUTH_KEY(CODE, NAME) NAME = CODE,
67#include "llvm/BinaryFormat/SFrameConstants.def"
68};
69
70/// Size of stack offsets. Bits 6-7 of FREInfo.Info.
71enum class FREOffset : uint8_t {
72#define HANDLE_SFRAME_FRE_OFFSET(CODE, NAME) NAME = CODE,
73#include "llvm/BinaryFormat/SFrameConstants.def"
74};
75
76/// Stack frame base register. Bit 0 of FREInfo.Info.
77enum class BaseReg : uint8_t {
78 FP = 0,
79 SP = 1,
80};
81
82namespace detail {
83template <typename T, endianness E>
84using packed =
86}
87
88template <endianness E> struct Preamble {
92};
93
94template <endianness E> struct Header {
105};
106
107template <endianness E> struct FDEInfo {
109
110 uint8_t getPAuthKey() const { return (Info >> 5) & 1; }
111 FDEType getFDEType() const { return static_cast<FDEType>((Info >> 4) & 1); }
112 FREType getFREType() const { return static_cast<FREType>(Info & 0xf); }
116 void setFuncInfo(uint8_t PAuthKey, FDEType FDE, FREType FRE) {
117 Info = ((PAuthKey & 1) << 5) | ((static_cast<uint8_t>(FDE) & 1) << 4) |
118 (static_cast<uint8_t>(FRE) & 0xf);
119 }
120};
121
122template <endianness E> struct FuncDescEntry {
130};
131
132template <endianness E> struct FREInfo {
134
135 bool isReturnAddressSigned() const { return Info >> 7; }
137 return static_cast<FREOffset>((Info >> 5) & 3);
138 }
139 uint8_t getOffsetCount() const { return (Info >> 1) & 0xf; }
140 BaseReg getBaseRegister() const { return static_cast<BaseReg>(Info & 1); }
143 }
147 }
150 }
153 }
155 Info = ((RA & 1) << 7) | ((static_cast<uint8_t>(Sz) & 3) << 5) |
156 ((N & 0xf) << 1) | (static_cast<uint8_t>(Reg) & 1);
157 }
158};
159
160template <typename T, endianness E> struct FrameRowEntry {
163};
164
165template <endianness E> using FrameRowEntryAddr1 = FrameRowEntry<uint8_t, E>;
166template <endianness E> using FrameRowEntryAddr2 = FrameRowEntry<uint16_t, E>;
167template <endianness E> using FrameRowEntryAddr4 = FrameRowEntry<uint32_t, E>;
168
177
178} // namespace sframe
179} // namespace llvm
180
181#endif // LLVM_BINARYFORMAT_SFRAME_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
Register Reg
#define P(N)
SI optimize exec mask operations pre RA
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
AArch64PAuthKey
Speficies key used for signing return addresses.
Definition: SFrame.h:65
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
Definition: SFrame.h:77
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
LLVM_ABI ArrayRef< EnumEntry< ABI > > getABIs()
Definition: SFrame.cpp:31
FREOffset
Size of stack offsets. Bits 6-7 of FREInfo.Info.
Definition: SFrame.h:71
FDEType
SFrame FDE Types. Bit 4 of FuncDescEntry.Info.
Definition: SFrame.h:58
LLVM_ABI ArrayRef< EnumEntry< BaseReg > > getBaseRegisters()
Definition: SFrame.cpp:72
LLVM_ABI ArrayRef< EnumEntry< FREOffset > > getFREOffsets()
Definition: SFrame.cpp:64
LLVM_ABI ArrayRef< EnumEntry< FDEType > > getFDETypes()
Definition: SFrame.cpp:47
LLVM_ABI ArrayRef< EnumEntry< Flags > > getFlags()
Definition: SFrame.cpp:23
constexpr uint16_t Magic
Definition: SFrame.h:32
LLVM_ABI ArrayRef< EnumEntry< AArch64PAuthKey > > getAArch64PAuthKeys()
Definition: SFrame.cpp:55
LLVM_ABI ArrayRef< EnumEntry< FREType > > getFRETypes()
Definition: SFrame.cpp:39
FREType
SFrame FRE Types. Bits 0-3 of FuncDescEntry.Info.
Definition: SFrame.h:52
LLVM_ABI ArrayRef< EnumEntry< Version > > getVersions()
Definition: SFrame.cpp:14
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
#define N
uint8_t getPAuthKey() const
Definition: SFrame.h:110
detail::packed< uint8_t, E > Info
Definition: SFrame.h:108
void setPAuthKey(uint8_t P)
Definition: SFrame.h:113
void setFREType(FREType R)
Definition: SFrame.h:115
FREType getFREType() const
Definition: SFrame.h:112
void setFDEType(FDEType D)
Definition: SFrame.h:114
FDEType getFDEType() const
Definition: SFrame.h:111
void setFuncInfo(uint8_t PAuthKey, FDEType FDE, FREType FRE)
Definition: SFrame.h:116
FREOffset getOffsetSize() const
Definition: SFrame.h:136
void setReturnAddressSigned(bool RA)
Definition: SFrame.h:141
detail::packed< uint8_t, E > Info
Definition: SFrame.h:133
BaseReg getBaseRegister() const
Definition: SFrame.h:140
void setBaseRegister(BaseReg Reg)
Definition: SFrame.h:151
void setFREInfo(bool RA, FREOffset Sz, uint8_t N, BaseReg Reg)
Definition: SFrame.h:154
void setOffsetSize(FREOffset Sz)
Definition: SFrame.h:144
void setOffsetCount(uint8_t N)
Definition: SFrame.h:148
uint8_t getOffsetCount() const
Definition: SFrame.h:139
bool isReturnAddressSigned() const
Definition: SFrame.h:135
detail::packed< T, E > StartAddress
Definition: SFrame.h:161
detail::packed< uint32_t, E > StartFREOff
Definition: SFrame.h:125
detail::packed< uint32_t, E > Size
Definition: SFrame.h:124
detail::packed< uint16_t, E > Padding2
Definition: SFrame.h:129
detail::packed< uint32_t, E > NumFREs
Definition: SFrame.h:126
detail::packed< int32_t, E > StartAddress
Definition: SFrame.h:123
detail::packed< uint8_t, E > RepSize
Definition: SFrame.h:128
detail::packed< uint32_t, E > NumFREs
Definition: SFrame.h:101
detail::packed< int8_t, E > CFAFixedRAOffset
Definition: SFrame.h:98
detail::packed< uint8_t, E > AuxHdrLen
Definition: SFrame.h:99
detail::packed< int8_t, E > CFAFixedFPOffset
Definition: SFrame.h:97
detail::packed< uint32_t, E > NumFDEs
Definition: SFrame.h:100
detail::packed< uint32_t, E > FDEOff
Definition: SFrame.h:103
detail::packed< ABI, E > ABIArch
Definition: SFrame.h:96
detail::packed< uint32_t, E > FREOff
Definition: SFrame.h:104
detail::packed< uint32_t, E > FRELen
Definition: SFrame.h:102
detail::packed< uint16_t, E > Magic
Definition: SFrame.h:89
detail::packed< enum Version, E > Version
Definition: SFrame.h:90
detail::packed< enum Flags, E > Flags
Definition: SFrame.h:91