16
16
#define LLVM_BINARYFORMAT_SFRAME_H
17
17
18
18
#include " llvm/ADT/BitmaskEnum.h"
19
- #include " llvm/Support/Compiler.h"
20
19
#include " llvm/Support/DataTypes.h"
20
+ #include " llvm/Support/Endian.h"
21
21
22
22
namespace llvm ::sframe {
23
23
24
24
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE ();
25
25
26
- constexpr uint16_t MagicSignature = 0xdee2 ;
26
+ constexpr uint16_t Magic = 0xdee2 ;
27
27
28
28
enum class Version : uint8_t {
29
29
V1 = 1 ,
@@ -75,35 +75,39 @@ enum class BaseReg : uint8_t {
75
75
SP = 1 ,
76
76
};
77
77
78
- LLVM_PACKED_START
78
+ namespace detail {
79
+ template <typename T, endianness E>
80
+ using packed =
81
+ support::detail::packed_endian_specific_integral<T, E, support::unaligned>;
82
+ }
79
83
80
- struct Preamble {
81
- uint16_t Magic;
82
- enum Version Version;
83
- enum Flags Flags;
84
+ template <endianness E> struct Preamble {
85
+ detail::packed< uint16_t , E> Magic;
86
+ detail::packed< enum Version, E> Version;
87
+ detail::packed< enum Flags, E> Flags;
84
88
};
85
89
86
- struct Header {
87
- struct Preamble Preamble;
88
- ABI ABIArch;
89
- int8_t CFAFixedFPOffset;
90
- int8_t CFAFixedRAOffset;
91
- uint8_t AuxHdrLen;
92
- uint32_t NumFDEs;
93
- uint32_t NumFREs;
94
- uint32_t FRELen;
95
- uint32_t FDEOff;
96
- uint32_t FREOff;
90
+ template <endianness E> struct Header {
91
+ struct Preamble <E> Preamble;
92
+ detail::packed< ABI, E> ABIArch;
93
+ detail::packed< int8_t , E> CFAFixedFPOffset;
94
+ detail::packed< int8_t , E> CFAFixedRAOffset;
95
+ detail::packed< uint8_t , E> AuxHdrLen;
96
+ detail::packed< uint32_t , E> NumFDEs;
97
+ detail::packed< uint32_t , E> NumFREs;
98
+ detail::packed< uint32_t , E> FRELen;
99
+ detail::packed< uint32_t , E> FDEOff;
100
+ detail::packed< uint32_t , E> FREOff;
97
101
};
98
102
99
- struct FuncDescEntry {
100
- int32_t StartAddress;
101
- uint32_t Size;
102
- uint32_t StartFREOff;
103
- uint32_t NumFREs;
104
- uint8_t Info;
105
- uint8_t RepSize;
106
- uint16_t Padding2;
103
+ template <endianness E> struct FuncDescEntry {
104
+ detail::packed< int32_t , E> StartAddress;
105
+ detail::packed< uint32_t , E> Size;
106
+ detail::packed< uint32_t , E> StartFREOff;
107
+ detail::packed< uint32_t , E> NumFREs;
108
+ detail::packed< uint8_t , E> Info;
109
+ detail::packed< uint8_t , E> RepSize;
110
+ detail::packed< uint16_t , E> Padding2;
107
111
108
112
uint8_t getPAuthKey () const { return (Info >> 5 ) & 1 ; }
109
113
FDEType getFDEType () const { return static_cast <FDEType>((Info >> 4 ) & 1 ); }
@@ -117,8 +121,8 @@ struct FuncDescEntry {
117
121
}
118
122
};
119
123
120
- struct FREInfo {
121
- uint8_t Info;
124
+ template <endianness E> struct FREInfo {
125
+ detail::packed< uint8_t , E> Info;
122
126
123
127
bool isReturnAddressSigned () const { return Info >> 7 ; }
124
128
FREOffset getOffsetSize () const {
@@ -145,22 +149,14 @@ struct FREInfo {
145
149
}
146
150
};
147
151
148
- struct FrameRowEntryAddr1 {
149
- uint8_t StartAddress;
150
- FREInfo Info;
152
+ template < typename T, endianness E> struct FrameRowEntry {
153
+ detail::packed<T, E> StartAddress;
154
+ FREInfo<E> Info;
151
155
};
152
156
153
- struct FrameRowEntryAddr2 {
154
- uint16_t StartAddress;
155
- FREInfo Info;
156
- };
157
-
158
- struct FrameRowEntryAddr4 {
159
- uint32_t StartAddress;
160
- FREInfo Info;
161
- };
162
-
163
- LLVM_PACKED_END
157
+ template <endianness E> using FrameRowEntryAddr1 = FrameRowEntry<uint8_t , E>;
158
+ template <endianness E> using FrameRowEntryAddr2 = FrameRowEntry<uint16_t , E>;
159
+ template <endianness E> using FrameRowEntryAddr4 = FrameRowEntry<uint32_t , E>;
164
160
165
161
} // namespace llvm::sframe
166
162
0 commit comments