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 | |
20 | namespace llvm { |
21 | namespace XCOFFYAML { |
22 | |
23 | struct { |
24 | llvm::yaml::Hex16 ; |
25 | uint16_t ; |
26 | int32_t ; |
27 | llvm::yaml::Hex64 ; |
28 | int32_t ; |
29 | uint16_t ; |
30 | llvm::yaml::Hex16 ; |
31 | }; |
32 | |
33 | struct { |
34 | std::optional<llvm::yaml::Hex16> ; |
35 | std::optional<llvm::yaml::Hex16> ; |
36 | std::optional<llvm::yaml::Hex64> ; |
37 | std::optional<llvm::yaml::Hex64> ; |
38 | std::optional<llvm::yaml::Hex64> ; |
39 | std::optional<uint16_t> ; |
40 | std::optional<uint16_t> ; |
41 | std::optional<uint16_t> ; |
42 | std::optional<uint16_t> ; |
43 | std::optional<uint16_t> ; |
44 | std::optional<uint16_t> ; |
45 | std::optional<llvm::yaml::Hex16> ; |
46 | std::optional<llvm::yaml::Hex16> ; |
47 | std::optional<llvm::yaml::Hex16> ; |
48 | std::optional<llvm::yaml::Hex8> ; |
49 | std::optional<llvm::yaml::Hex8> ; |
50 | std::optional<llvm::yaml::Hex8> ; |
51 | std::optional<llvm::yaml::Hex8> ; |
52 | std::optional<llvm::yaml::Hex8> ; |
53 | std::optional<llvm::yaml::Hex8> FlagAndTDataAlignment; |
54 | std::optional<llvm::yaml::Hex64> ; |
55 | std::optional<llvm::yaml::Hex64> ; |
56 | std::optional<llvm::yaml::Hex64> ; |
57 | std::optional<llvm::yaml::Hex64> ; |
58 | std::optional<llvm::yaml::Hex64> ; |
59 | std::optional<llvm::yaml::Hex64> ; |
60 | std::optional<uint16_t> ; |
61 | std::optional<uint16_t> ; |
62 | std::optional<llvm::yaml::Hex16> ; |
63 | }; |
64 | |
65 | struct Relocation { |
66 | llvm::yaml::Hex64 VirtualAddress; |
67 | llvm::yaml::Hex64 SymbolIndex; |
68 | llvm::yaml::Hex8 Info; |
69 | llvm::yaml::Hex8 Type; |
70 | }; |
71 | |
72 | struct 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 | |
86 | enum 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 | |
96 | struct AuxSymbolEnt { |
97 | AuxSymbolType Type; |
98 | |
99 | explicit AuxSymbolEnt(AuxSymbolType T) : Type(T) {} |
100 | virtual ~AuxSymbolEnt(); |
101 | }; |
102 | |
103 | struct 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 | |
113 | struct 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 | |
136 | struct 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 | |
148 | struct 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 | |
159 | struct 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 | |
172 | struct 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 | |
182 | struct 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 | |
193 | struct 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 | |
204 | struct 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 | |
212 | struct Object { |
213 | FileHeader ; |
214 | std::optional<AuxiliaryHeader> ; |
215 | std::vector<Section> Sections; |
216 | std::vector<Symbol> Symbols; |
217 | StringTable StrTbl; |
218 | Object(); |
219 | }; |
220 | } // namespace XCOFFYAML |
221 | } // namespace llvm |
222 | |
223 | LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Symbol) |
224 | LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Relocation) |
225 | LLVM_YAML_IS_SEQUENCE_VECTOR(XCOFFYAML::Section) |
226 | LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::XCOFFYAML::AuxSymbolEnt>) |
227 | |
228 | namespace llvm { |
229 | namespace yaml { |
230 | |
231 | template <> struct ScalarBitSetTraits<XCOFF::SectionTypeFlags> { |
232 | static void bitset(IO &IO, XCOFF::SectionTypeFlags &Value); |
233 | }; |
234 | |
235 | template <> struct ScalarEnumerationTraits<XCOFF::StorageClass> { |
236 | static void enumeration(IO &IO, XCOFF::StorageClass &Value); |
237 | }; |
238 | |
239 | template <> struct ScalarEnumerationTraits<XCOFF::StorageMappingClass> { |
240 | static void enumeration(IO &IO, XCOFF::StorageMappingClass &Value); |
241 | }; |
242 | |
243 | template <> struct ScalarEnumerationTraits<XCOFF::SymbolType> { |
244 | static void enumeration(IO &IO, XCOFF::SymbolType &Value); |
245 | }; |
246 | |
247 | template <> struct ScalarEnumerationTraits<XCOFF::CFileStringType> { |
248 | static void enumeration(IO &IO, XCOFF::CFileStringType &Type); |
249 | }; |
250 | |
251 | template <> struct ScalarEnumerationTraits<XCOFFYAML::AuxSymbolType> { |
252 | static void enumeration(IO &IO, XCOFFYAML::AuxSymbolType &Type); |
253 | }; |
254 | |
255 | template <> struct MappingTraits<XCOFFYAML::FileHeader> { |
256 | static void (IO &IO, XCOFFYAML::FileHeader &H); |
257 | }; |
258 | |
259 | template <> struct MappingTraits<XCOFFYAML::AuxiliaryHeader> { |
260 | static void (IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr); |
261 | }; |
262 | |
263 | template <> struct MappingTraits<std::unique_ptr<XCOFFYAML::AuxSymbolEnt>> { |
264 | static void mapping(IO &IO, std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym); |
265 | }; |
266 | |
267 | template <> struct MappingTraits<XCOFFYAML::Symbol> { |
268 | static void mapping(IO &IO, XCOFFYAML::Symbol &S); |
269 | }; |
270 | |
271 | template <> struct MappingTraits<XCOFFYAML::Relocation> { |
272 | static void mapping(IO &IO, XCOFFYAML::Relocation &R); |
273 | }; |
274 | |
275 | template <> struct MappingTraits<XCOFFYAML::Section> { |
276 | static void mapping(IO &IO, XCOFFYAML::Section &Sec); |
277 | }; |
278 | |
279 | template <> struct MappingTraits<XCOFFYAML::StringTable> { |
280 | static void mapping(IO &IO, XCOFFYAML::StringTable &Str); |
281 | }; |
282 | |
283 | template <> 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 | |