1616#define LLVM_BINARYFORMAT_SFRAME_H
1717
1818#include " llvm/ADT/BitmaskEnum.h"
19- #include " llvm/Support/Compiler.h"
2019#include " llvm/Support/DataTypes.h"
20+ #include " llvm/Support/Endian.h"
2121
2222namespace llvm ::sframe {
2323
2424LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE ();
2525
26- constexpr uint16_t MagicSignature = 0xdee2 ;
26+ constexpr uint16_t Magic = 0xdee2 ;
2727
2828enum class Version : uint8_t {
2929 V1 = 1 ,
@@ -75,35 +75,39 @@ enum class BaseReg : uint8_t {
7575 SP = 1 ,
7676};
7777
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+ }
7983
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;
8488};
8589
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;
97101};
98102
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;
107111
108112 uint8_t getPAuthKey () const { return (Info >> 5 ) & 1 ; }
109113 FDEType getFDEType () const { return static_cast <FDEType>((Info >> 4 ) & 1 ); }
@@ -117,8 +121,8 @@ struct FuncDescEntry {
117121 }
118122};
119123
120- struct FREInfo {
121- uint8_t Info;
124+ template <endianness E> struct FREInfo {
125+ detail::packed< uint8_t , E> Info;
122126
123127 bool isReturnAddressSigned () const { return Info >> 7 ; }
124128 FREOffset getOffsetSize () const {
@@ -145,22 +149,14 @@ struct FREInfo {
145149 }
146150};
147151
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;
151155};
152156
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>;
164160
165161} // namespace llvm::sframe
166162
0 commit comments