LLVM 20.0.0git
XCOFFYAML.h
Go to the documentation of this file.
1//===----- XCOFFYAML.h - XCOFF YAMLIO implementation ------------*- 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// This file declares classes for handling the YAML representation of XCOFF.
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_OBJECTYAML_XCOFFYAML_H
13#define LLVM_OBJECTYAML_XCOFFYAML_H
14
17#include <optional>
18#include <vector>
19
20namespace llvm {
21namespace XCOFFYAML {
22
23struct FileHeader {
24 llvm::yaml::Hex16 Magic;
26 int32_t TimeStamp;
27 llvm::yaml::Hex64 SymbolTableOffset;
30 llvm::yaml::Hex16 Flags;
31};
32
34 std::optional<llvm::yaml::Hex16> Magic;
35 std::optional<llvm::yaml::Hex16> Version;
36 std::optional<llvm::yaml::Hex64> TextStartAddr;
37 std::optional<llvm::yaml::Hex64> DataStartAddr;
38 std::optional<llvm::yaml::Hex64> TOCAnchorAddr;
39 std::optional<uint16_t> SecNumOfEntryPoint;
40 std::optional<uint16_t> SecNumOfText;
41 std::optional<uint16_t> SecNumOfData;
42 std::optional<uint16_t> SecNumOfTOC;
43 std::optional<uint16_t> SecNumOfLoader;
44 std::optional<uint16_t> SecNumOfBSS;
45 std::optional<llvm::yaml::Hex16> MaxAlignOfText;
46 std::optional<llvm::yaml::Hex16> MaxAlignOfData;
47 std::optional<llvm::yaml::Hex16> ModuleType;
48 std::optional<llvm::yaml::Hex8> CpuFlag;
49 std::optional<llvm::yaml::Hex8> CpuType;
50 std::optional<llvm::yaml::Hex8> TextPageSize;
51 std::optional<llvm::yaml::Hex8> DataPageSize;
52 std::optional<llvm::yaml::Hex8> StackPageSize;
53 std::optional<llvm::yaml::Hex8> FlagAndTDataAlignment;
54 std::optional<llvm::yaml::Hex64> TextSize;
55 std::optional<llvm::yaml::Hex64> InitDataSize;
56 std::optional<llvm::yaml::Hex64> BssDataSize;
57 std::optional<llvm::yaml::Hex64> EntryPointAddr;
58 std::optional<llvm::yaml::Hex64> MaxStackSize;
59 std::optional<llvm::yaml::Hex64> MaxDataSize;
60 std::optional<uint16_t> SecNumOfTData;
61 std::optional<uint16_t> SecNumOfTBSS;
62 std::optional<llvm::yaml::Hex16> Flag;
63};
64
65struct Relocation {
66 llvm::yaml::Hex64 VirtualAddress;
67 llvm::yaml::Hex64 SymbolIndex;
68 llvm::yaml::Hex8 Info;
69 llvm::yaml::Hex8 Type;
70};
71
72struct Section {
74 llvm::yaml::Hex64 Address;
75 llvm::yaml::Hex64 Size;
76 llvm::yaml::Hex64 FileOffsetToData;
77 llvm::yaml::Hex64 FileOffsetToRelocations;
78 llvm::yaml::Hex64 FileOffsetToLineNumbers; // Line number pointer. Not supported yet.
79 llvm::yaml::Hex16 NumberOfRelocations;
80 llvm::yaml::Hex16 NumberOfLineNumbers; // Line number counts. Not supported yet.
82 std::optional<XCOFF::DwarfSectionSubtypeFlags> SectionSubtype;
84 std::vector<Relocation> Relocations;
85};
86
87enum AuxSymbolType : uint8_t {
89 AUX_FCN = 254,
90 AUX_SYM = 253,
91 AUX_FILE = 252,
92 AUX_CSECT = 251,
93 AUX_SECT = 250,
94 AUX_STAT = 249
95};
96
99
101 virtual ~AuxSymbolEnt();
102};
103
105 std::optional<StringRef> FileNameOrString;
106 std::optional<XCOFF::CFileStringType> FileStringType;
107
109 static bool classof(const AuxSymbolEnt *S) {
110 return S->Type == AuxSymbolType::AUX_FILE;
111 }
112};
113
115 // Only for XCOFF32.
116 std::optional<uint32_t> SectionOrLength;
117 std::optional<uint32_t> StabInfoIndex;
118 std::optional<uint16_t> StabSectNum;
119 // Only for XCOFF64.
120 std::optional<uint32_t> SectionOrLengthLo;
121 std::optional<uint32_t> SectionOrLengthHi;
122 // Common fields for both XCOFF32 and XCOFF64.
123 std::optional<uint32_t> ParameterHashIndex;
124 std::optional<uint16_t> TypeChkSectNum;
125 std::optional<XCOFF::SymbolType> SymbolType;
126 std::optional<uint8_t> SymbolAlignment;
127 // The two previous values can be encoded as a single value.
128 std::optional<uint8_t> SymbolAlignmentAndType;
129 std::optional<XCOFF::StorageMappingClass> StorageMappingClass;
130
132 static bool classof(const AuxSymbolEnt *S) {
133 return S->Type == AuxSymbolType::AUX_CSECT;
134 }
135};
136
138 std::optional<uint32_t> OffsetToExceptionTbl; // Only for XCOFF32.
139 std::optional<uint64_t> PtrToLineNum;
140 std::optional<uint32_t> SizeOfFunction;
141 std::optional<int32_t> SymIdxOfNextBeyond;
142
144 static bool classof(const AuxSymbolEnt *S) {
145 return S->Type == AuxSymbolType::AUX_FCN;
146 }
147};
148
150 std::optional<uint64_t> OffsetToExceptionTbl;
151 std::optional<uint32_t> SizeOfFunction;
152 std::optional<int32_t> SymIdxOfNextBeyond;
153
155 static bool classof(const AuxSymbolEnt *S) {
156 return S->Type == AuxSymbolType::AUX_EXCEPT;
157 }
158}; // Only for XCOFF64.
159
161 // Only for XCOFF32.
162 std::optional<uint16_t> LineNumHi;
163 std::optional<uint16_t> LineNumLo;
164 // Only for XCOFF64.
165 std::optional<uint32_t> LineNum;
166
168 static bool classof(const AuxSymbolEnt *S) {
169 return S->Type == AuxSymbolType::AUX_SYM;
170 }
171};
172
174 std::optional<uint32_t> LengthOfSectionPortion;
175 std::optional<uint32_t> NumberOfRelocEnt;
176
178 static bool classof(const AuxSymbolEnt *S) {
179 return S->Type == AuxSymbolType::AUX_SECT;
180 }
181};
182
184 std::optional<uint32_t> SectionLength;
185 std::optional<uint16_t> NumberOfRelocEnt;
186 std::optional<uint16_t> NumberOfLineNum;
187
189 static bool classof(const AuxSymbolEnt *S) {
190 return S->Type == AuxSymbolType::AUX_STAT;
191 }
192}; // Only for XCOFF32.
193
194struct Symbol {
196 llvm::yaml::Hex64 Value; // Symbol value; storage class-dependent.
197 std::optional<StringRef> SectionName;
198 std::optional<uint16_t> SectionIndex;
199 llvm::yaml::Hex16 Type;
201 std::optional<uint8_t> NumberOfAuxEntries;
202 std::vector<std::unique_ptr<AuxSymbolEnt>> AuxEntries;
203};
204
206 std::optional<uint32_t> ContentSize; // The total size of the string table.
207 std::optional<uint32_t> Length; // The value of the length field for the first
208 // 4 bytes of the table.
209 std::optional<std::vector<StringRef>> Strings;
210 std::optional<yaml::BinaryRef> RawContent;
211};
212
213struct Object {
215 std::optional<AuxiliaryHeader> AuxHeader;
216 std::vector<Section> Sections;
217 std::vector<Symbol> Symbols;
219 Object();
220};
221} // namespace XCOFFYAML
222} // namespace llvm
223
224LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Symbol)
225LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Relocation)
226LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Section)
227LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::XCOFFYAML::AuxSymbolEnt>)
228
229namespace llvm {
230namespace yaml {
231
232template <> struct ScalarBitSetTraits<XCOFF::SectionTypeFlags> {
233 static void bitset(IO &IO, XCOFF::SectionTypeFlags &Value);
234};
235
236template <> struct ScalarEnumerationTraits<XCOFF::DwarfSectionSubtypeFlags> {
237 static void enumeration(IO &IO, XCOFF::DwarfSectionSubtypeFlags &Value);
238};
239
240template <> struct ScalarEnumerationTraits<XCOFF::StorageClass> {
241 static void enumeration(IO &IO, XCOFF::StorageClass &Value);
242};
243
244template <> struct ScalarEnumerationTraits<XCOFF::StorageMappingClass> {
245 static void enumeration(IO &IO, XCOFF::StorageMappingClass &Value);
246};
247
248template <> struct ScalarEnumerationTraits<XCOFF::SymbolType> {
249 static void enumeration(IO &IO, XCOFF::SymbolType &Value);
250};
251
252template <> struct ScalarEnumerationTraits<XCOFF::CFileStringType> {
253 static void enumeration(IO &IO, XCOFF::CFileStringType &Type);
254};
255
256template <> struct ScalarEnumerationTraits<XCOFFYAML::AuxSymbolType> {
257 static void enumeration(IO &IO, XCOFFYAML::AuxSymbolType &Type);
258};
259
260template <> struct MappingTraits<XCOFFYAML::FileHeader> {
261 static void mapping(IO &IO, XCOFFYAML::FileHeader &H);
262};
263
264template <> struct MappingTraits<XCOFFYAML::AuxiliaryHeader> {
265 static void mapping(IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr);
266};
267
268template <> struct MappingTraits<std::unique_ptr<XCOFFYAML::AuxSymbolEnt>> {
269 static void mapping(IO &IO, std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym);
270};
271
272template <> struct MappingTraits<XCOFFYAML::Symbol> {
273 static void mapping(IO &IO, XCOFFYAML::Symbol &S);
274};
275
276template <> struct MappingTraits<XCOFFYAML::Relocation> {
277 static void mapping(IO &IO, XCOFFYAML::Relocation &R);
278};
279
280template <> struct MappingTraits<XCOFFYAML::Section> {
281 static void mapping(IO &IO, XCOFFYAML::Section &Sec);
282};
283
284template <> struct MappingTraits<XCOFFYAML::StringTable> {
285 static void mapping(IO &IO, XCOFFYAML::StringTable &Str);
286};
287
288template <> struct MappingTraits<XCOFFYAML::Object> {
289 static void mapping(IO &IO, XCOFFYAML::Object &Obj);
290};
291
292} // namespace yaml
293} // namespace llvm
294
295#endif // LLVM_OBJECTYAML_XCOFFYAML_H
#define H(x, y, z)
Definition: MD5.cpp:57
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
Definition: XCOFF.h:154
CFileStringType
Definition: XCOFF.h:323
StorageClass
Definition: XCOFF.h:170
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:103
SectionTypeFlags
Definition: XCOFF.h:134
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
AuxSymbolEnt(AuxSymbolType T)
Definition: XCOFFYAML.h:100
std::optional< llvm::yaml::Hex16 > ModuleType
Definition: XCOFFYAML.h:47
std::optional< llvm::yaml::Hex64 > BssDataSize
Definition: XCOFFYAML.h:56
std::optional< llvm::yaml::Hex8 > StackPageSize
Definition: XCOFFYAML.h:52
std::optional< llvm::yaml::Hex64 > TextSize
Definition: XCOFFYAML.h:54
std::optional< uint16_t > SecNumOfTOC
Definition: XCOFFYAML.h:42
std::optional< llvm::yaml::Hex8 > TextPageSize
Definition: XCOFFYAML.h:50
std::optional< uint16_t > SecNumOfEntryPoint
Definition: XCOFFYAML.h:39
std::optional< llvm::yaml::Hex64 > TextStartAddr
Definition: XCOFFYAML.h:36
std::optional< llvm::yaml::Hex64 > MaxDataSize
Definition: XCOFFYAML.h:59
std::optional< uint16_t > SecNumOfTData
Definition: XCOFFYAML.h:60
std::optional< llvm::yaml::Hex8 > CpuType
Definition: XCOFFYAML.h:49
std::optional< llvm::yaml::Hex16 > MaxAlignOfData
Definition: XCOFFYAML.h:46
std::optional< uint16_t > SecNumOfTBSS
Definition: XCOFFYAML.h:61
std::optional< llvm::yaml::Hex16 > MaxAlignOfText
Definition: XCOFFYAML.h:45
std::optional< uint16_t > SecNumOfLoader
Definition: XCOFFYAML.h:43
std::optional< llvm::yaml::Hex64 > TOCAnchorAddr
Definition: XCOFFYAML.h:38
std::optional< llvm::yaml::Hex16 > Flag
Definition: XCOFFYAML.h:62
std::optional< llvm::yaml::Hex8 > DataPageSize
Definition: XCOFFYAML.h:51
std::optional< uint16_t > SecNumOfText
Definition: XCOFFYAML.h:40
std::optional< llvm::yaml::Hex16 > Magic
Definition: XCOFFYAML.h:34
std::optional< uint16_t > SecNumOfData
Definition: XCOFFYAML.h:41
std::optional< llvm::yaml::Hex64 > InitDataSize
Definition: XCOFFYAML.h:55
std::optional< llvm::yaml::Hex64 > MaxStackSize
Definition: XCOFFYAML.h:58
std::optional< llvm::yaml::Hex16 > Version
Definition: XCOFFYAML.h:35
std::optional< llvm::yaml::Hex64 > EntryPointAddr
Definition: XCOFFYAML.h:57
std::optional< llvm::yaml::Hex8 > CpuFlag
Definition: XCOFFYAML.h:48
std::optional< llvm::yaml::Hex8 > FlagAndTDataAlignment
Definition: XCOFFYAML.h:53
std::optional< uint16_t > SecNumOfBSS
Definition: XCOFFYAML.h:44
std::optional< llvm::yaml::Hex64 > DataStartAddr
Definition: XCOFFYAML.h:37
std::optional< uint32_t > LineNum
Definition: XCOFFYAML.h:165
std::optional< uint16_t > LineNumHi
Definition: XCOFFYAML.h:162
static bool classof(const AuxSymbolEnt *S)
Definition: XCOFFYAML.h:168
std::optional< uint16_t > LineNumLo
Definition: XCOFFYAML.h:163
std::optional< uint16_t > TypeChkSectNum
Definition: XCOFFYAML.h:124
std::optional< uint32_t > ParameterHashIndex
Definition: XCOFFYAML.h:123
std::optional< uint32_t > SectionOrLength
Definition: XCOFFYAML.h:116
std::optional< uint32_t > SectionOrLengthHi
Definition: XCOFFYAML.h:121
std::optional< uint8_t > SymbolAlignmentAndType
Definition: XCOFFYAML.h:128
std::optional< uint32_t > SectionOrLengthLo
Definition: XCOFFYAML.h:120
static bool classof(const AuxSymbolEnt *S)
Definition: XCOFFYAML.h:132
std::optional< uint8_t > SymbolAlignment
Definition: XCOFFYAML.h:126
std::optional< uint16_t > StabSectNum
Definition: XCOFFYAML.h:118
std::optional< XCOFF::StorageMappingClass > StorageMappingClass
Definition: XCOFFYAML.h:129
std::optional< uint32_t > StabInfoIndex
Definition: XCOFFYAML.h:117
std::optional< XCOFF::SymbolType > SymbolType
Definition: XCOFFYAML.h:125
std::optional< int32_t > SymIdxOfNextBeyond
Definition: XCOFFYAML.h:152
std::optional< uint32_t > SizeOfFunction
Definition: XCOFFYAML.h:151
static bool classof(const AuxSymbolEnt *S)
Definition: XCOFFYAML.h:155
std::optional< uint64_t > OffsetToExceptionTbl
Definition: XCOFFYAML.h:150
std::optional< XCOFF::CFileStringType > FileStringType
Definition: XCOFFYAML.h:106
static bool classof(const AuxSymbolEnt *S)
Definition: XCOFFYAML.h:109
std::optional< StringRef > FileNameOrString
Definition: XCOFFYAML.h:105
llvm::yaml::Hex16 Magic
Definition: XCOFFYAML.h:24
llvm::yaml::Hex16 Flags
Definition: XCOFFYAML.h:30
llvm::yaml::Hex64 SymbolTableOffset
Definition: XCOFFYAML.h:27
static bool classof(const AuxSymbolEnt *S)
Definition: XCOFFYAML.h:144
std::optional< int32_t > SymIdxOfNextBeyond
Definition: XCOFFYAML.h:141
std::optional< uint32_t > OffsetToExceptionTbl
Definition: XCOFFYAML.h:138
std::optional< uint64_t > PtrToLineNum
Definition: XCOFFYAML.h:139
std::optional< uint32_t > SizeOfFunction
Definition: XCOFFYAML.h:140
std::vector< Section > Sections
Definition: XCOFFYAML.h:216
std::optional< AuxiliaryHeader > AuxHeader
Definition: XCOFFYAML.h:215
std::vector< Symbol > Symbols
Definition: XCOFFYAML.h:217
llvm::yaml::Hex8 Type
Definition: XCOFFYAML.h:69
llvm::yaml::Hex64 SymbolIndex
Definition: XCOFFYAML.h:67
llvm::yaml::Hex8 Info
Definition: XCOFFYAML.h:68
llvm::yaml::Hex64 VirtualAddress
Definition: XCOFFYAML.h:66
static bool classof(const AuxSymbolEnt *S)
Definition: XCOFFYAML.h:178
std::optional< uint32_t > NumberOfRelocEnt
Definition: XCOFFYAML.h:175
std::optional< uint32_t > LengthOfSectionPortion
Definition: XCOFFYAML.h:174
static bool classof(const AuxSymbolEnt *S)
Definition: XCOFFYAML.h:189
std::optional< uint16_t > NumberOfRelocEnt
Definition: XCOFFYAML.h:185
std::optional< uint16_t > NumberOfLineNum
Definition: XCOFFYAML.h:186
std::optional< uint32_t > SectionLength
Definition: XCOFFYAML.h:184
llvm::yaml::Hex64 FileOffsetToRelocations
Definition: XCOFFYAML.h:77
llvm::yaml::Hex64 Address
Definition: XCOFFYAML.h:74
std::optional< XCOFF::DwarfSectionSubtypeFlags > SectionSubtype
Definition: XCOFFYAML.h:82
llvm::yaml::Hex64 Size
Definition: XCOFFYAML.h:75
llvm::yaml::Hex64 FileOffsetToData
Definition: XCOFFYAML.h:76
yaml::BinaryRef SectionData
Definition: XCOFFYAML.h:83
std::vector< Relocation > Relocations
Definition: XCOFFYAML.h:84
llvm::yaml::Hex16 NumberOfLineNumbers
Definition: XCOFFYAML.h:80
llvm::yaml::Hex16 NumberOfRelocations
Definition: XCOFFYAML.h:79
llvm::yaml::Hex64 FileOffsetToLineNumbers
Definition: XCOFFYAML.h:78
std::optional< yaml::BinaryRef > RawContent
Definition: XCOFFYAML.h:210
std::optional< std::vector< StringRef > > Strings
Definition: XCOFFYAML.h:209
std::optional< uint32_t > Length
Definition: XCOFFYAML.h:207
std::optional< uint32_t > ContentSize
Definition: XCOFFYAML.h:206
std::vector< std::unique_ptr< AuxSymbolEnt > > AuxEntries
Definition: XCOFFYAML.h:202
std::optional< uint16_t > SectionIndex
Definition: XCOFFYAML.h:198
std::optional< uint8_t > NumberOfAuxEntries
Definition: XCOFFYAML.h:201
llvm::yaml::Hex64 Value
Definition: XCOFFYAML.h:196
llvm::yaml::Hex16 Type
Definition: XCOFFYAML.h:199
XCOFF::StorageClass StorageClass
Definition: XCOFFYAML.h:200
std::optional< StringRef > SectionName
Definition: XCOFFYAML.h:197