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
15#include "llvm/BinaryFormat/XCOFF.h"
16#include "llvm/ObjectYAML/YAML.h"
17#include <optional>
18#include <vector>
19
20namespace llvm {
21namespace XCOFFYAML {
22
23struct FileHeader {
24 llvm::yaml::Hex16 Magic;
25 uint16_t NumberOfSections;
26 int32_t TimeStamp;
27 llvm::yaml::Hex64 SymbolTableOffset;
28 int32_t NumberOfSymTableEntries;
29 uint16_t AuxHeaderSize;
30 llvm::yaml::Hex16 Flags;
31};
32
33struct AuxiliaryHeader {
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 {
73 StringRef SectionName;
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.
81 uint32_t Flags;
82 yaml::BinaryRef SectionData;
83 std::vector<Relocation> Relocations;
84};
85
86enum AuxSymbolType : uint8_t {
87 AUX_EXCEPT = 255,
88 AUX_FCN = 254,
89 AUX_SYM = 253,
90 AUX_FILE = 252,
91 AUX_CSECT = 251,
92 AUX_SECT = 250,
93 AUX_STAT = 249
94};
95
96struct AuxSymbolEnt {
97 AuxSymbolType Type;
98
99 explicit AuxSymbolEnt(AuxSymbolType T) : Type(T) {}
100 virtual ~AuxSymbolEnt();
101};
102
103struct FileAuxEnt : AuxSymbolEnt {
104 std::optional<StringRef> FileNameOrString;
105 std::optional<XCOFF::CFileStringType> FileStringType;
106
107 FileAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FILE) {}
108 static bool classof(const AuxSymbolEnt *S) {
109 return S->Type == AuxSymbolType::AUX_FILE;
110 }
111};
112
113struct CsectAuxEnt : AuxSymbolEnt {
114 // Only for XCOFF32.
115 std::optional<uint32_t> SectionOrLength;
116 std::optional<uint32_t> StabInfoIndex;
117 std::optional<uint16_t> StabSectNum;
118 // Only for XCOFF64.
119 std::optional<uint32_t> SectionOrLengthLo;
120 std::optional<uint32_t> SectionOrLengthHi;
121 // Common fields for both XCOFF32 and XCOFF64.
122 std::optional<uint32_t> ParameterHashIndex;
123 std::optional<uint16_t> TypeChkSectNum;
124 std::optional<XCOFF::SymbolType> SymbolType;
125 std::optional<uint8_t> SymbolAlignment;
126 // The two previous values can be encoded as a single value.
127 std::optional<uint8_t> SymbolAlignmentAndType;
128 std::optional<XCOFF::StorageMappingClass> StorageMappingClass;
129
130 CsectAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_CSECT) {}
131 static bool classof(const AuxSymbolEnt *S) {
132 return S->Type == AuxSymbolType::AUX_CSECT;
133 }
134};
135
136struct FunctionAuxEnt : AuxSymbolEnt {
137 std::optional<uint32_t> OffsetToExceptionTbl; // Only for XCOFF32.
138 std::optional<uint64_t> PtrToLineNum;
139 std::optional<uint32_t> SizeOfFunction;
140 std::optional<int32_t> SymIdxOfNextBeyond;
141
142 FunctionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_FCN) {}
143 static bool classof(const AuxSymbolEnt *S) {
144 return S->Type == AuxSymbolType::AUX_FCN;
145 }
146};
147
148struct ExcpetionAuxEnt : AuxSymbolEnt {
149 std::optional<uint64_t> OffsetToExceptionTbl;
150 std::optional<uint32_t> SizeOfFunction;
151 std::optional<int32_t> SymIdxOfNextBeyond;
152
153 ExcpetionAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_EXCEPT) {}
154 static bool classof(const AuxSymbolEnt *S) {
155 return S->Type == AuxSymbolType::AUX_EXCEPT;
156 }
157}; // Only for XCOFF64.
158
159struct BlockAuxEnt : AuxSymbolEnt {
160 // Only for XCOFF32.
161 std::optional<uint16_t> LineNumHi;
162 std::optional<uint16_t> LineNumLo;
163 // Only for XCOFF64.
164 std::optional<uint32_t> LineNum;
165
166 BlockAuxEnt() : AuxSymbolEnt(AuxSymbolType::AUX_SYM) {}
167 static bool classof(const AuxSymbolEnt *S) {
168 return S->Type == AuxSymbolType::AUX_SYM;
169 }
170};
171
172struct SectAuxEntForDWARF : AuxSymbolEnt {
173 std::optional<uint32_t> LengthOfSectionPortion;
174 std::optional<uint32_t> NumberOfRelocEnt;
175
176 SectAuxEntForDWARF() : AuxSymbolEnt(AuxSymbolType::AUX_SECT) {}
177 static bool classof(const AuxSymbolEnt *S) {
178 return S->Type == AuxSymbolType::AUX_SECT;
179 }
180};
181
182struct SectAuxEntForStat : AuxSymbolEnt {
183 std::optional<uint32_t> SectionLength;
184 std::optional<uint16_t> NumberOfRelocEnt;
185 std::optional<uint16_t> NumberOfLineNum;
186
187 SectAuxEntForStat() : AuxSymbolEnt(AuxSymbolType::AUX_STAT) {}
188 static bool classof(const AuxSymbolEnt *S) {
189 return S->Type == AuxSymbolType::AUX_STAT;
190 }
191}; // Only for XCOFF32.
192
193struct Symbol {
194 StringRef SymbolName;
195 llvm::yaml::Hex64 Value; // Symbol value; storage class-dependent.
196 std::optional<StringRef> SectionName;
197 std::optional<uint16_t> SectionIndex;
198 llvm::yaml::Hex16 Type;
199 XCOFF::StorageClass StorageClass;
200 std::optional<uint8_t> NumberOfAuxEntries;
201 std::vector<std::unique_ptr<AuxSymbolEnt>> AuxEntries;
202};
203
204struct StringTable {
205 std::optional<uint32_t> ContentSize; // The total size of the string table.
206 std::optional<uint32_t> Length; // The value of the length field for the first
207 // 4 bytes of the table.
208 std::optional<std::vector<StringRef>> Strings;
209 std::optional<yaml::BinaryRef> RawContent;
210};
211
212struct Object {
213 FileHeader Header;
214 std::optional<AuxiliaryHeader> AuxHeader;
215 std::vector<Section> Sections;
216 std::vector<Symbol> Symbols;
217 StringTable StrTbl;
218 Object();
219};
220} // namespace XCOFFYAML
221} // namespace llvm
222
223LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Symbol)
224LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Relocation)
225LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Section)
226LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::XCOFFYAML::AuxSymbolEnt>)
227
228namespace llvm {
229namespace yaml {
230
231template <> struct ScalarBitSetTraits<XCOFF::SectionTypeFlags> {
232 static void bitset(IO &IO, XCOFF::SectionTypeFlags &Value);
233};
234
235template <> struct ScalarEnumerationTraits<XCOFF::StorageClass> {
236 static void enumeration(IO &IO, XCOFF::StorageClass &Value);
237};
238
239template <> struct ScalarEnumerationTraits<XCOFF::StorageMappingClass> {
240 static void enumeration(IO &IO, XCOFF::StorageMappingClass &Value);
241};
242
243template <> struct ScalarEnumerationTraits<XCOFF::SymbolType> {
244 static void enumeration(IO &IO, XCOFF::SymbolType &Value);
245};
246
247template <> struct ScalarEnumerationTraits<XCOFF::CFileStringType> {
248 static void enumeration(IO &IO, XCOFF::CFileStringType &Type);
249};
250
251template <> struct ScalarEnumerationTraits<XCOFFYAML::AuxSymbolType> {
252 static void enumeration(IO &IO, XCOFFYAML::AuxSymbolType &Type);
253};
254
255template <> struct MappingTraits<XCOFFYAML::FileHeader> {
256 static void mapping(IO &IO, XCOFFYAML::FileHeader &H);
257};
258
259template <> struct MappingTraits<XCOFFYAML::AuxiliaryHeader> {
260 static void mapping(IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr);
261};
262
263template <> struct MappingTraits<std::unique_ptr<XCOFFYAML::AuxSymbolEnt>> {
264 static void mapping(IO &IO, std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym);
265};
266
267template <> struct MappingTraits<XCOFFYAML::Symbol> {
268 static void mapping(IO &IO, XCOFFYAML::Symbol &S);
269};
270
271template <> struct MappingTraits<XCOFFYAML::Relocation> {
272 static void mapping(IO &IO, XCOFFYAML::Relocation &R);
273};
274
275template <> struct MappingTraits<XCOFFYAML::Section> {
276 static void mapping(IO &IO, XCOFFYAML::Section &Sec);
277};
278
279template <> struct MappingTraits<XCOFFYAML::StringTable> {
280 static void mapping(IO &IO, XCOFFYAML::StringTable &Str);
281};
282
283template <> struct MappingTraits<XCOFFYAML::Object> {
284 static void mapping(IO &IO, XCOFFYAML::Object &Obj);
285};
286
287} // namespace yaml
288} // namespace llvm
289
290#endif // LLVM_OBJECTYAML_XCOFFYAML_H
291

source code of llvm/include/llvm/ObjectYAML/XCOFFYAML.h