llvm.org GIT mirror llvm / 18903ff
Move ObjectYAML code to a new library. It is only ever used by obj2yaml and yaml2obj. No point in linking it everywhere. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262368 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
27 changed file(s) with 2096 addition(s) and 2074 deletion(s). Raw diff Collapse all Expand all
+0
-94
include/llvm/MC/YAML.h less more
None #ifndef LLVM_MC_YAML_H
1 #define LLVM_MC_YAML_H
2
3 #include "llvm/Support/YAMLTraits.h"
4
5 namespace llvm {
6 namespace yaml {
7 /// \brief Specialized YAMLIO scalar type for representing a binary blob.
8 ///
9 /// A typical use case would be to represent the content of a section in a
10 /// binary file.
11 /// This class has custom YAMLIO traits for convenient reading and writing.
12 /// It renders as a string of hex digits in a YAML file.
13 /// For example, it might render as `DEADBEEFCAFEBABE` (YAML does not
14 /// require the quotation marks, so for simplicity when outputting they are
15 /// omitted).
16 /// When reading, any string whose content is an even number of hex digits
17 /// will be accepted.
18 /// For example, all of the following are acceptable:
19 /// `DEADBEEF`, `"DeADbEeF"`, `"\x44EADBEEF"` (Note: '\x44' == 'D')
20 ///
21 /// A significant advantage of using this class is that it never allocates
22 /// temporary strings or buffers for any of its functionality.
23 ///
24 /// Example:
25 ///
26 /// The YAML mapping:
27 /// \code
28 /// Foo: DEADBEEFCAFEBABE
29 /// \endcode
30 ///
31 /// Could be modeled in YAMLIO by the struct:
32 /// \code
33 /// struct FooHolder {
34 /// BinaryRef Foo;
35 /// };
36 /// namespace llvm {
37 /// namespace yaml {
38 /// template <>
39 /// struct MappingTraits {
40 /// static void mapping(IO &IO, FooHolder &FH) {
41 /// IO.mapRequired("Foo", FH.Foo);
42 /// }
43 /// };
44 /// } // end namespace yaml
45 /// } // end namespace llvm
46 /// \endcode
47 class BinaryRef {
48 friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS);
49 /// \brief Either raw binary data, or a string of hex bytes (must always
50 /// be an even number of characters).
51 ArrayRef Data;
52 /// \brief Discriminator between the two states of the `Data` member.
53 bool DataIsHexString;
54
55 public:
56 BinaryRef(ArrayRef Data) : Data(Data), DataIsHexString(false) {}
57 BinaryRef(StringRef Data)
58 : Data(reinterpret_cast(Data.data()), Data.size()),
59 DataIsHexString(true) {}
60 BinaryRef() : DataIsHexString(true) {}
61 /// \brief The number of bytes that are represented by this BinaryRef.
62 /// This is the number of bytes that writeAsBinary() will write.
63 ArrayRef::size_type binary_size() const {
64 if (DataIsHexString)
65 return Data.size() / 2;
66 return Data.size();
67 }
68 /// \brief Write the contents (regardless of whether it is binary or a
69 /// hex string) as binary to the given raw_ostream.
70 void writeAsBinary(raw_ostream &OS) const;
71 /// \brief Write the contents (regardless of whether it is binary or a
72 /// hex string) as hex to the given raw_ostream.
73 ///
74 /// For example, a possible output could be `DEADBEEFCAFEBABE`.
75 void writeAsHex(raw_ostream &OS) const;
76 };
77
78 inline bool operator==(const BinaryRef &LHS, const BinaryRef &RHS) {
79 // Special case for default constructed BinaryRef.
80 if (LHS.Data.empty() && RHS.Data.empty())
81 return true;
82
83 return LHS.DataIsHexString == RHS.DataIsHexString && LHS.Data == RHS.Data;
84 }
85
86 template <> struct ScalarTraits {
87 static void output(const BinaryRef &, void *, llvm::raw_ostream &);
88 static StringRef input(StringRef, void *, BinaryRef &);
89 static bool mustQuote(StringRef S) { return needsQuotes(S); }
90 };
91 }
92 }
93 #endif
+0
-223
include/llvm/Object/COFFYAML.h less more
None //===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares classes for handling the YAML representation of COFF.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_OBJECT_COFFYAML_H
14 #define LLVM_OBJECT_COFFYAML_H
15
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/MC/YAML.h"
18 #include "llvm/Support/COFF.h"
19
20 namespace llvm {
21
22 namespace COFF {
23 inline Characteristics operator|(Characteristics a, Characteristics b) {
24 uint32_t Ret = static_cast(a) | static_cast(b);
25 return static_cast(Ret);
26 }
27
28 inline SectionCharacteristics operator|(SectionCharacteristics a,
29 SectionCharacteristics b) {
30 uint32_t Ret = static_cast(a) | static_cast(b);
31 return static_cast(Ret);
32 }
33
34 inline DLLCharacteristics operator|(DLLCharacteristics a,
35 DLLCharacteristics b) {
36 uint16_t Ret = static_cast(a) | static_cast(b);
37 return static_cast(Ret);
38 }
39 }
40
41 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
42 // to use yaml::IO, we use these structures which are closer to the source.
43 namespace COFFYAML {
44 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
45 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
46 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
47
48 struct Relocation {
49 uint32_t VirtualAddress;
50 uint16_t Type;
51 StringRef SymbolName;
52 };
53
54 struct Section {
55 COFF::section Header;
56 unsigned Alignment;
57 yaml::BinaryRef SectionData;
58 std::vector Relocations;
59 StringRef Name;
60 Section();
61 };
62
63 struct Symbol {
64 COFF::symbol Header;
65 COFF::SymbolBaseType SimpleType;
66 COFF::SymbolComplexType ComplexType;
67 Optional FunctionDefinition;
68 Optional bfAndefSymbol;
69 Optional WeakExternal;
70 StringRef File;
71 Optional SectionDefinition;
72 Optional CLRToken;
73 StringRef Name;
74 Symbol();
75 };
76
77 struct PEHeader {
78 COFF::PE32Header Header;
79 Optional DataDirectories[COFF::NUM_DATA_DIRECTORIES];
80 };
81
82 struct Object {
83 Optional OptionalHeader;
84 COFF::header Header;
85 std::vector
Sections;
86 std::vector Symbols;
87 Object();
88 };
89 }
90 }
91
92 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
93 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
94 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
95
96 namespace llvm {
97 namespace yaml {
98
99 template <>
100 struct ScalarEnumerationTraits {
101 static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
102 };
103
104 template <>
105 struct ScalarEnumerationTraits {
106 static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
107 };
108
109 template <>
110 struct ScalarEnumerationTraits {
111 static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
112 };
113
114 template <>
115 struct ScalarEnumerationTraits {
116 static void enumeration(IO &IO, COFF::MachineTypes &Value);
117 };
118
119 template <>
120 struct ScalarEnumerationTraits {
121 static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
122 };
123
124 template <>
125 struct ScalarEnumerationTraits {
126 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
127 };
128
129 template <>
130 struct ScalarEnumerationTraits {
131 static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
132 };
133
134 template <>
135 struct ScalarEnumerationTraits {
136 static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
137 };
138
139 template <>
140 struct ScalarEnumerationTraits {
141 static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
142 };
143
144 template <>
145 struct ScalarEnumerationTraits {
146 static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
147 };
148
149 template <>
150 struct ScalarBitSetTraits {
151 static void bitset(IO &IO, COFF::Characteristics &Value);
152 };
153
154 template <>
155 struct ScalarBitSetTraits {
156 static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
157 };
158
159 template <>
160 struct ScalarBitSetTraits {
161 static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
162 };
163
164 template <>
165 struct MappingTraits {
166 static void mapping(IO &IO, COFFYAML::Relocation &Rel);
167 };
168
169 template <>
170 struct MappingTraits {
171 static void mapping(IO &IO, COFFYAML::PEHeader &PH);
172 };
173
174 template <>
175 struct MappingTraits {
176 static void mapping(IO &IO, COFF::DataDirectory &DD);
177 };
178
179 template <>
180 struct MappingTraits {
181 static void mapping(IO &IO, COFF::header &H);
182 };
183
184 template <> struct MappingTraits {
185 static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
186 };
187
188 template <> struct MappingTraits {
189 static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
190 };
191
192 template <> struct MappingTraits {
193 static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
194 };
195
196 template <> struct MappingTraits {
197 static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
198 };
199
200 template <> struct MappingTraits {
201 static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
202 };
203
204 template <>
205 struct MappingTraits {
206 static void mapping(IO &IO, COFFYAML::Symbol &S);
207 };
208
209 template <>
210 struct MappingTraits {
211 static void mapping(IO &IO, COFFYAML::Section &Sec);
212 };
213
214 template <>
215 struct MappingTraits {
216 static void mapping(IO &IO, COFFYAML::Object &Obj);
217 };
218
219 } // end namespace yaml
220 } // end namespace llvm
221
222 #endif
+0
-319
include/llvm/Object/ELFYAML.h less more
None //===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file declares classes for handling the YAML representation
11 /// of ELF.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_OBJECT_ELFYAML_H
16 #define LLVM_OBJECT_ELFYAML_H
17
18 #include "llvm/MC/YAML.h"
19 #include "llvm/Support/ELF.h"
20
21 namespace llvm {
22 namespace ELFYAML {
23
24 // These types are invariant across 32/64-bit ELF, so for simplicity just
25 // directly give them their exact sizes. We don't need to worry about
26 // endianness because these are just the types in the YAMLIO structures,
27 // and are appropriately converted to the necessary endianness when
28 // reading/generating binary object files.
29 // The naming of these types is intended to be ELF_PREFIX, where PREFIX is
30 // the common prefix of the respective constants. E.g. ELF_EM corresponds
31 // to the `e_machine` constants, like `EM_X86_64`.
32 // In the future, these would probably be better suited by C++11 enum
33 // class's with appropriate fixed underlying type.
34 LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET)
35 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM)
36 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS)
37 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
38 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
39 // Just use 64, since it can hold 32-bit values too.
40 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
41 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
42 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL)
43 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)
44 // Just use 64, since it can hold 32-bit values too.
45 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
46 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
47 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
48 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
49
50 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
51 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
52 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
53 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
54 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
55 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_ISA)
56
57 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
58 // since 64-bit can hold 32-bit values too.
59 struct FileHeader {
60 ELF_ELFCLASS Class;
61 ELF_ELFDATA Data;
62 ELF_ELFOSABI OSABI;
63 ELF_ET Type;
64 ELF_EM Machine;
65 ELF_EF Flags;
66 llvm::yaml::Hex64 Entry;
67 };
68 struct Symbol {
69 StringRef Name;
70 ELF_STT Type;
71 StringRef Section;
72 llvm::yaml::Hex64 Value;
73 llvm::yaml::Hex64 Size;
74 uint8_t Other;
75 };
76 struct LocalGlobalWeakSymbols {
77 std::vector Local;
78 std::vector Global;
79 std::vector Weak;
80 };
81
82 struct SectionOrType {
83 StringRef sectionNameOrType;
84 };
85
86 struct Section {
87 enum class SectionKind {
88 Group,
89 RawContent,
90 Relocation,
91 NoBits,
92 MipsABIFlags
93 };
94 SectionKind Kind;
95 StringRef Name;
96 ELF_SHT Type;
97 ELF_SHF Flags;
98 llvm::yaml::Hex64 Address;
99 StringRef Link;
100 StringRef Info;
101 llvm::yaml::Hex64 AddressAlign;
102 Section(SectionKind Kind) : Kind(Kind) {}
103 virtual ~Section();
104 };
105 struct RawContentSection : Section {
106 yaml::BinaryRef Content;
107 llvm::yaml::Hex64 Size;
108 RawContentSection() : Section(SectionKind::RawContent) {}
109 static bool classof(const Section *S) {
110 return S->Kind == SectionKind::RawContent;
111 }
112 };
113
114 struct NoBitsSection : Section {
115 llvm::yaml::Hex64 Size;
116 NoBitsSection() : Section(SectionKind::NoBits) {}
117 static bool classof(const Section *S) {
118 return S->Kind == SectionKind::NoBits;
119 }
120 };
121
122 struct Group : Section {
123 // Members of a group contain a flag and a list of section indices
124 // that are part of the group.
125 std::vector Members;
126 Group() : Section(SectionKind::Group) {}
127 static bool classof(const Section *S) {
128 return S->Kind == SectionKind::Group;
129 }
130 };
131
132 struct Relocation {
133 llvm::yaml::Hex64 Offset;
134 int64_t Addend;
135 ELF_REL Type;
136 StringRef Symbol;
137 };
138 struct RelocationSection : Section {
139 std::vector Relocations;
140 RelocationSection() : Section(SectionKind::Relocation) {}
141 static bool classof(const Section *S) {
142 return S->Kind == SectionKind::Relocation;
143 }
144 };
145
146 // Represents .MIPS.abiflags section
147 struct MipsABIFlags : Section {
148 llvm::yaml::Hex16 Version;
149 MIPS_ISA ISALevel;
150 llvm::yaml::Hex8 ISARevision;
151 MIPS_AFL_REG GPRSize;
152 MIPS_AFL_REG CPR1Size;
153 MIPS_AFL_REG CPR2Size;
154 MIPS_ABI_FP FpABI;
155 MIPS_AFL_EXT ISAExtension;
156 MIPS_AFL_ASE ASEs;
157 MIPS_AFL_FLAGS1 Flags1;
158 llvm::yaml::Hex32 Flags2;
159 MipsABIFlags() : Section(SectionKind::MipsABIFlags) {}
160 static bool classof(const Section *S) {
161 return S->Kind == SectionKind::MipsABIFlags;
162 }
163 };
164
165 struct Object {
166 FileHeader Header;
167 std::vector> Sections;
168 // Although in reality the symbols reside in a section, it is a lot
169 // cleaner and nicer if we read them from the YAML as a separate
170 // top-level key, which automatically ensures that invariants like there
171 // being a single SHT_SYMTAB section are upheld.
172 LocalGlobalWeakSymbols Symbols;
173 };
174
175 } // end namespace ELFYAML
176 } // end namespace llvm
177
178 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr)
179 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
180 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation)
181 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType)
182
183 namespace llvm {
184 namespace yaml {
185
186 template <>
187 struct ScalarEnumerationTraits {
188 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
189 };
190
191 template <>
192 struct ScalarEnumerationTraits {
193 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
194 };
195
196 template <>
197 struct ScalarEnumerationTraits {
198 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
199 };
200
201 template <>
202 struct ScalarEnumerationTraits {
203 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
204 };
205
206 template <>
207 struct ScalarEnumerationTraits {
208 static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
209 };
210
211 template <>
212 struct ScalarBitSetTraits {
213 static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
214 };
215
216 template <>
217 struct ScalarEnumerationTraits {
218 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
219 };
220
221 template <>
222 struct ScalarBitSetTraits {
223 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
224 };
225
226 template <>
227 struct ScalarEnumerationTraits {
228 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
229 };
230
231 template <>
232 struct ScalarEnumerationTraits {
233 static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
234 };
235
236 template <>
237 struct ScalarBitSetTraits {
238 static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
239 };
240
241 template <>
242 struct ScalarEnumerationTraits {
243 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
244 };
245
246 template <>
247 struct ScalarEnumerationTraits {
248 static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
249 };
250
251 template <>
252 struct ScalarEnumerationTraits {
253 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value);
254 };
255
256 template <>
257 struct ScalarEnumerationTraits {
258 static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value);
259 };
260
261 template <>
262 struct ScalarEnumerationTraits {
263 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value);
264 };
265
266 template <>
267 struct ScalarEnumerationTraits {
268 static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value);
269 };
270
271 template <>
272 struct ScalarBitSetTraits {
273 static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value);
274 };
275
276 template <>
277 struct ScalarBitSetTraits {
278 static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value);
279 };
280
281 template <>
282 struct MappingTraits {
283 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
284 };
285
286 template <>
287 struct MappingTraits {
288 static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
289 };
290
291 template <>
292 struct MappingTraits {
293 static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
294 };
295
296 template <> struct MappingTraits {
297 static void mapping(IO &IO, ELFYAML::Relocation &Rel);
298 };
299
300 template <>
301 struct MappingTraits> {
302 static void mapping(IO &IO, std::unique_ptr &Section);
303 static StringRef validate(IO &io, std::unique_ptr &Section);
304 };
305
306 template <>
307 struct MappingTraits {
308 static void mapping(IO &IO, ELFYAML::Object &Object);
309 };
310
311 template <> struct MappingTraits {
312 static void mapping(IO &IO, ELFYAML::SectionOrType §ionOrType);
313 };
314
315 } // end namespace yaml
316 } // end namespace llvm
317
318 #endif
0 //===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares classes for handling the YAML representation of COFF.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_OBJECTYAML_COFFYAML_H
14 #define LLVM_OBJECTYAML_COFFYAML_H
15
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ObjectYAML/YAML.h"
18 #include "llvm/Support/COFF.h"
19
20 namespace llvm {
21
22 namespace COFF {
23 inline Characteristics operator|(Characteristics a, Characteristics b) {
24 uint32_t Ret = static_cast(a) | static_cast(b);
25 return static_cast(Ret);
26 }
27
28 inline SectionCharacteristics operator|(SectionCharacteristics a,
29 SectionCharacteristics b) {
30 uint32_t Ret = static_cast(a) | static_cast(b);
31 return static_cast(Ret);
32 }
33
34 inline DLLCharacteristics operator|(DLLCharacteristics a,
35 DLLCharacteristics b) {
36 uint16_t Ret = static_cast(a) | static_cast(b);
37 return static_cast(Ret);
38 }
39 }
40
41 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
42 // to use yaml::IO, we use these structures which are closer to the source.
43 namespace COFFYAML {
44 LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType)
45 LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics)
46 LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType)
47
48 struct Relocation {
49 uint32_t VirtualAddress;
50 uint16_t Type;
51 StringRef SymbolName;
52 };
53
54 struct Section {
55 COFF::section Header;
56 unsigned Alignment;
57 yaml::BinaryRef SectionData;
58 std::vector Relocations;
59 StringRef Name;
60 Section();
61 };
62
63 struct Symbol {
64 COFF::symbol Header;
65 COFF::SymbolBaseType SimpleType;
66 COFF::SymbolComplexType ComplexType;
67 Optional FunctionDefinition;
68 Optional bfAndefSymbol;
69 Optional WeakExternal;
70 StringRef File;
71 Optional SectionDefinition;
72 Optional CLRToken;
73 StringRef Name;
74 Symbol();
75 };
76
77 struct PEHeader {
78 COFF::PE32Header Header;
79 Optional DataDirectories[COFF::NUM_DATA_DIRECTORIES];
80 };
81
82 struct Object {
83 Optional OptionalHeader;
84 COFF::header Header;
85 std::vector
Sections;
86 std::vector Symbols;
87 Object();
88 };
89 }
90 }
91
92 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
93 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
94 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
95
96 namespace llvm {
97 namespace yaml {
98
99 template <>
100 struct ScalarEnumerationTraits {
101 static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value);
102 };
103
104 template <>
105 struct ScalarEnumerationTraits {
106 static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value);
107 };
108
109 template <>
110 struct ScalarEnumerationTraits {
111 static void enumeration(IO &IO, COFFYAML::COMDATType &Value);
112 };
113
114 template <>
115 struct ScalarEnumerationTraits {
116 static void enumeration(IO &IO, COFF::MachineTypes &Value);
117 };
118
119 template <>
120 struct ScalarEnumerationTraits {
121 static void enumeration(IO &IO, COFF::SymbolBaseType &Value);
122 };
123
124 template <>
125 struct ScalarEnumerationTraits {
126 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value);
127 };
128
129 template <>
130 struct ScalarEnumerationTraits {
131 static void enumeration(IO &IO, COFF::SymbolComplexType &Value);
132 };
133
134 template <>
135 struct ScalarEnumerationTraits {
136 static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value);
137 };
138
139 template <>
140 struct ScalarEnumerationTraits {
141 static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value);
142 };
143
144 template <>
145 struct ScalarEnumerationTraits {
146 static void enumeration(IO &IO, COFF::WindowsSubsystem &Value);
147 };
148
149 template <>
150 struct ScalarBitSetTraits {
151 static void bitset(IO &IO, COFF::Characteristics &Value);
152 };
153
154 template <>
155 struct ScalarBitSetTraits {
156 static void bitset(IO &IO, COFF::SectionCharacteristics &Value);
157 };
158
159 template <>
160 struct ScalarBitSetTraits {
161 static void bitset(IO &IO, COFF::DLLCharacteristics &Value);
162 };
163
164 template <>
165 struct MappingTraits {
166 static void mapping(IO &IO, COFFYAML::Relocation &Rel);
167 };
168
169 template <>
170 struct MappingTraits {
171 static void mapping(IO &IO, COFFYAML::PEHeader &PH);
172 };
173
174 template <>
175 struct MappingTraits {
176 static void mapping(IO &IO, COFF::DataDirectory &DD);
177 };
178
179 template <>
180 struct MappingTraits {
181 static void mapping(IO &IO, COFF::header &H);
182 };
183
184 template <> struct MappingTraits {
185 static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD);
186 };
187
188 template <> struct MappingTraits {
189 static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS);
190 };
191
192 template <> struct MappingTraits {
193 static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE);
194 };
195
196 template <> struct MappingTraits {
197 static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD);
198 };
199
200 template <> struct MappingTraits {
201 static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT);
202 };
203
204 template <>
205 struct MappingTraits {
206 static void mapping(IO &IO, COFFYAML::Symbol &S);
207 };
208
209 template <>
210 struct MappingTraits {
211 static void mapping(IO &IO, COFFYAML::Section &Sec);
212 };
213
214 template <>
215 struct MappingTraits {
216 static void mapping(IO &IO, COFFYAML::Object &Obj);
217 };
218
219 } // end namespace yaml
220 } // end namespace llvm
221
222 #endif
0 //===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file declares classes for handling the YAML representation
11 /// of ELF.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_OBJECTYAML_ELFYAML_H
16 #define LLVM_OBJECTYAML_ELFYAML_H
17
18 #include "llvm/ObjectYAML/YAML.h"
19 #include "llvm/Support/ELF.h"
20
21 namespace llvm {
22 namespace ELFYAML {
23
24 // These types are invariant across 32/64-bit ELF, so for simplicity just
25 // directly give them their exact sizes. We don't need to worry about
26 // endianness because these are just the types in the YAMLIO structures,
27 // and are appropriately converted to the necessary endianness when
28 // reading/generating binary object files.
29 // The naming of these types is intended to be ELF_PREFIX, where PREFIX is
30 // the common prefix of the respective constants. E.g. ELF_EM corresponds
31 // to the `e_machine` constants, like `EM_X86_64`.
32 // In the future, these would probably be better suited by C++11 enum
33 // class's with appropriate fixed underlying type.
34 LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET)
35 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM)
36 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS)
37 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
38 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
39 // Just use 64, since it can hold 32-bit values too.
40 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
41 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
42 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL)
43 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)
44 // Just use 64, since it can hold 32-bit values too.
45 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
46 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
47 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
48 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
49
50 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
51 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
52 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
53 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
54 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
55 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_ISA)
56
57 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
58 // since 64-bit can hold 32-bit values too.
59 struct FileHeader {
60 ELF_ELFCLASS Class;
61 ELF_ELFDATA Data;
62 ELF_ELFOSABI OSABI;
63 ELF_ET Type;
64 ELF_EM Machine;
65 ELF_EF Flags;
66 llvm::yaml::Hex64 Entry;
67 };
68 struct Symbol {
69 StringRef Name;
70 ELF_STT Type;
71 StringRef Section;
72 llvm::yaml::Hex64 Value;
73 llvm::yaml::Hex64 Size;
74 uint8_t Other;
75 };
76 struct LocalGlobalWeakSymbols {
77 std::vector Local;
78 std::vector Global;
79 std::vector Weak;
80 };
81
82 struct SectionOrType {
83 StringRef sectionNameOrType;
84 };
85
86 struct Section {
87 enum class SectionKind {
88 Group,
89 RawContent,
90 Relocation,
91 NoBits,
92 MipsABIFlags
93 };
94 SectionKind Kind;
95 StringRef Name;
96 ELF_SHT Type;
97 ELF_SHF Flags;
98 llvm::yaml::Hex64 Address;
99 StringRef Link;
100 StringRef Info;
101 llvm::yaml::Hex64 AddressAlign;
102 Section(SectionKind Kind) : Kind(Kind) {}
103 virtual ~Section();
104 };
105 struct RawContentSection : Section {
106 yaml::BinaryRef Content;
107 llvm::yaml::Hex64 Size;
108 RawContentSection() : Section(SectionKind::RawContent) {}
109 static bool classof(const Section *S) {
110 return S->Kind == SectionKind::RawContent;
111 }
112 };
113
114 struct NoBitsSection : Section {
115 llvm::yaml::Hex64 Size;
116 NoBitsSection() : Section(SectionKind::NoBits) {}
117 static bool classof(const Section *S) {
118 return S->Kind == SectionKind::NoBits;
119 }
120 };
121
122 struct Group : Section {
123 // Members of a group contain a flag and a list of section indices
124 // that are part of the group.
125 std::vector Members;
126 Group() : Section(SectionKind::Group) {}
127 static bool classof(const Section *S) {
128 return S->Kind == SectionKind::Group;
129 }
130 };
131
132 struct Relocation {
133 llvm::yaml::Hex64 Offset;
134 int64_t Addend;
135 ELF_REL Type;
136 StringRef Symbol;
137 };
138 struct RelocationSection : Section {
139 std::vector Relocations;
140 RelocationSection() : Section(SectionKind::Relocation) {}
141 static bool classof(const Section *S) {
142 return S->Kind == SectionKind::Relocation;
143 }
144 };
145
146 // Represents .MIPS.abiflags section
147 struct MipsABIFlags : Section {
148 llvm::yaml::Hex16 Version;
149 MIPS_ISA ISALevel;
150 llvm::yaml::Hex8 ISARevision;
151 MIPS_AFL_REG GPRSize;
152 MIPS_AFL_REG CPR1Size;
153 MIPS_AFL_REG CPR2Size;
154 MIPS_ABI_FP FpABI;
155 MIPS_AFL_EXT ISAExtension;
156 MIPS_AFL_ASE ASEs;
157 MIPS_AFL_FLAGS1 Flags1;
158 llvm::yaml::Hex32 Flags2;
159 MipsABIFlags() : Section(SectionKind::MipsABIFlags) {}
160 static bool classof(const Section *S) {
161 return S->Kind == SectionKind::MipsABIFlags;
162 }
163 };
164
165 struct Object {
166 FileHeader Header;
167 std::vector> Sections;
168 // Although in reality the symbols reside in a section, it is a lot
169 // cleaner and nicer if we read them from the YAML as a separate
170 // top-level key, which automatically ensures that invariants like there
171 // being a single SHT_SYMTAB section are upheld.
172 LocalGlobalWeakSymbols Symbols;
173 };
174
175 } // end namespace ELFYAML
176 } // end namespace llvm
177
178 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr)
179 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
180 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation)
181 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType)
182
183 namespace llvm {
184 namespace yaml {
185
186 template <>
187 struct ScalarEnumerationTraits {
188 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
189 };
190
191 template <>
192 struct ScalarEnumerationTraits {
193 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
194 };
195
196 template <>
197 struct ScalarEnumerationTraits {
198 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
199 };
200
201 template <>
202 struct ScalarEnumerationTraits {
203 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
204 };
205
206 template <>
207 struct ScalarEnumerationTraits {
208 static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
209 };
210
211 template <>
212 struct ScalarBitSetTraits {
213 static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
214 };
215
216 template <>
217 struct ScalarEnumerationTraits {
218 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
219 };
220
221 template <>
222 struct ScalarBitSetTraits {
223 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
224 };
225
226 template <>
227 struct ScalarEnumerationTraits {
228 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
229 };
230
231 template <>
232 struct ScalarEnumerationTraits {
233 static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
234 };
235
236 template <>
237 struct ScalarBitSetTraits {
238 static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
239 };
240
241 template <>
242 struct ScalarEnumerationTraits {
243 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
244 };
245
246 template <>
247 struct ScalarEnumerationTraits {
248 static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
249 };
250
251 template <>
252 struct ScalarEnumerationTraits {
253 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value);
254 };
255
256 template <>
257 struct ScalarEnumerationTraits {
258 static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value);
259 };
260
261 template <>
262 struct ScalarEnumerationTraits {
263 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value);
264 };
265
266 template <>
267 struct ScalarEnumerationTraits {
268 static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value);
269 };
270
271 template <>
272 struct ScalarBitSetTraits {
273 static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value);
274 };
275
276 template <>
277 struct ScalarBitSetTraits {
278 static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value);
279 };
280
281 template <>
282 struct MappingTraits {
283 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
284 };
285
286 template <>
287 struct MappingTraits {
288 static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
289 };
290
291 template <>
292 struct MappingTraits {
293 static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
294 };
295
296 template <> struct MappingTraits {
297 static void mapping(IO &IO, ELFYAML::Relocation &Rel);
298 };
299
300 template <>
301 struct MappingTraits> {
302 static void mapping(IO &IO, std::unique_ptr &Section);
303 static StringRef validate(IO &io, std::unique_ptr &Section);
304 };
305
306 template <>
307 struct MappingTraits {
308 static void mapping(IO &IO, ELFYAML::Object &Object);
309 };
310
311 template <> struct MappingTraits {
312 static void mapping(IO &IO, ELFYAML::SectionOrType §ionOrType);
313 };
314
315 } // end namespace yaml
316 } // end namespace llvm
317
318 #endif
0 //===- YAML.h ---------------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_OBJECTYAML_YAML_H
10 #define LLVM_OBJECTYAML_YAML_H
11
12 #include "llvm/Support/YAMLTraits.h"
13
14 namespace llvm {
15 namespace yaml {
16 /// \brief Specialized YAMLIO scalar type for representing a binary blob.
17 ///
18 /// A typical use case would be to represent the content of a section in a
19 /// binary file.
20 /// This class has custom YAMLIO traits for convenient reading and writing.
21 /// It renders as a string of hex digits in a YAML file.
22 /// For example, it might render as `DEADBEEFCAFEBABE` (YAML does not
23 /// require the quotation marks, so for simplicity when outputting they are
24 /// omitted).
25 /// When reading, any string whose content is an even number of hex digits
26 /// will be accepted.
27 /// For example, all of the following are acceptable:
28 /// `DEADBEEF`, `"DeADbEeF"`, `"\x44EADBEEF"` (Note: '\x44' == 'D')
29 ///
30 /// A significant advantage of using this class is that it never allocates
31 /// temporary strings or buffers for any of its functionality.
32 ///
33 /// Example:
34 ///
35 /// The YAML mapping:
36 /// \code
37 /// Foo: DEADBEEFCAFEBABE
38 /// \endcode
39 ///
40 /// Could be modeled in YAMLIO by the struct:
41 /// \code
42 /// struct FooHolder {
43 /// BinaryRef Foo;
44 /// };
45 /// namespace llvm {
46 /// namespace yaml {
47 /// template <>
48 /// struct MappingTraits {
49 /// static void mapping(IO &IO, FooHolder &FH) {
50 /// IO.mapRequired("Foo", FH.Foo);
51 /// }
52 /// };
53 /// } // end namespace yaml
54 /// } // end namespace llvm
55 /// \endcode
56 class BinaryRef {
57 friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS);
58 /// \brief Either raw binary data, or a string of hex bytes (must always
59 /// be an even number of characters).
60 ArrayRef Data;
61 /// \brief Discriminator between the two states of the `Data` member.
62 bool DataIsHexString;
63
64 public:
65 BinaryRef(ArrayRef Data) : Data(Data), DataIsHexString(false) {}
66 BinaryRef(StringRef Data)
67 : Data(reinterpret_cast(Data.data()), Data.size()),
68 DataIsHexString(true) {}
69 BinaryRef() : DataIsHexString(true) {}
70 /// \brief The number of bytes that are represented by this BinaryRef.
71 /// This is the number of bytes that writeAsBinary() will write.
72 ArrayRef::size_type binary_size() const {
73 if (DataIsHexString)
74 return Data.size() / 2;
75 return Data.size();
76 }
77 /// \brief Write the contents (regardless of whether it is binary or a
78 /// hex string) as binary to the given raw_ostream.
79 void writeAsBinary(raw_ostream &OS) const;
80 /// \brief Write the contents (regardless of whether it is binary or a
81 /// hex string) as hex to the given raw_ostream.
82 ///
83 /// For example, a possible output could be `DEADBEEFCAFEBABE`.
84 void writeAsHex(raw_ostream &OS) const;
85 };
86
87 inline bool operator==(const BinaryRef &LHS, const BinaryRef &RHS) {
88 // Special case for default constructed BinaryRef.
89 if (LHS.Data.empty() && RHS.Data.empty())
90 return true;
91
92 return LHS.DataIsHexString == RHS.DataIsHexString && LHS.Data == RHS.Data;
93 }
94
95 template <> struct ScalarTraits {
96 static void output(const BinaryRef &, void *, llvm::raw_ostream &);
97 static StringRef input(StringRef, void *, BinaryRef &);
98 static bool mustQuote(StringRef S) { return needsQuotes(S); }
99 };
100 }
101 }
102 #endif
99 add_subdirectory(LTO)
1010 add_subdirectory(MC)
1111 add_subdirectory(Object)
12 add_subdirectory(ObjectYAML)
1213 add_subdirectory(Option)
1314 add_subdirectory(DebugInfo)
1415 add_subdirectory(ExecutionEngine)
4747 SubtargetFeature.cpp
4848 WinCOFFObjectWriter.cpp
4949 WinCOFFStreamer.cpp
50 YAML.cpp
5150
5251 ADDITIONAL_HEADER_DIRS
5352 ${LLVM_MAIN_INCLUDE_DIR}/llvm/MC
+0
-61
lib/MC/YAML.cpp less more
None //===- YAML.cpp - YAMLIO utilities for object files -----------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines utility classes for handling the YAML representation of
10 // object files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/MC/YAML.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include
18
19 using namespace llvm;
20
21 void yaml::ScalarTraits::output(
22 const yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
23 Val.writeAsHex(Out);
24 }
25
26 StringRef yaml::ScalarTraits::input(StringRef Scalar, void *,
27 yaml::BinaryRef &Val) {
28 if (Scalar.size() % 2 != 0)
29 return "BinaryRef hex string must contain an even number of nybbles.";
30 // TODO: Can we improve YAMLIO to permit a more accurate diagnostic here?
31 // (e.g. a caret pointing to the offending character).
32 for (unsigned I = 0, N = Scalar.size(); I != N; ++I)
33 if (!isxdigit(Scalar[I]))
34 return "BinaryRef hex string must contain only hex digits.";
35 Val = yaml::BinaryRef(Scalar);
36 return StringRef();
37 }
38
39 void yaml::BinaryRef::writeAsBinary(raw_ostream &OS) const {
40 if (!DataIsHexString) {
41 OS.write((const char *)Data.data(), Data.size());
42 return;
43 }
44 for (unsigned I = 0, N = Data.size(); I != N; I += 2) {
45 uint8_t Byte;
46 StringRef((const char *)&Data[I], 2).getAsInteger(16, Byte);
47 OS.write(Byte);
48 }
49 }
50
51 void yaml::BinaryRef::writeAsHex(raw_ostream &OS) const {
52 if (binary_size() == 0)
53 return;
54 if (DataIsHexString) {
55 OS.write((const char *)Data.data(), Data.size());
56 return;
57 }
58 for (uint8_t Byte : Data)
59 OS << hexdigit(Byte >> 4) << hexdigit(Byte & 0xf);
60 }
22 ArchiveWriter.cpp
33 Binary.cpp
44 COFFObjectFile.cpp
5 COFFYAML.cpp
65 ELF.cpp
76 ELFObjectFile.cpp
8 ELFYAML.cpp
97 Error.cpp
108 IRObjectFile.cpp
119 MachOObjectFile.cpp
+0
-503
lib/Object/COFFYAML.cpp less more
None //===- COFFYAML.cpp - COFF YAMLIO implementation --------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of COFF.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Object/COFFYAML.h"
14
15 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
16 namespace llvm {
17
18 namespace COFFYAML {
19 Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
20 Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
21 Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
22 }
23
24 namespace yaml {
25 void ScalarEnumerationTraits::enumeration(
26 IO &IO, COFFYAML::COMDATType &Value) {
27 IO.enumCase(Value, "0", 0);
28 ECase(IMAGE_COMDAT_SELECT_NODUPLICATES);
29 ECase(IMAGE_COMDAT_SELECT_ANY);
30 ECase(IMAGE_COMDAT_SELECT_SAME_SIZE);
31 ECase(IMAGE_COMDAT_SELECT_EXACT_MATCH);
32 ECase(IMAGE_COMDAT_SELECT_ASSOCIATIVE);
33 ECase(IMAGE_COMDAT_SELECT_LARGEST);
34 ECase(IMAGE_COMDAT_SELECT_NEWEST);
35 }
36
37 void
38 ScalarEnumerationTraits::enumeration(
39 IO &IO, COFFYAML::WeakExternalCharacteristics &Value) {
40 IO.enumCase(Value, "0", 0);
41 ECase(IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
42 ECase(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
43 ECase(IMAGE_WEAK_EXTERN_SEARCH_ALIAS);
44 }
45
46 void ScalarEnumerationTraits::enumeration(
47 IO &IO, COFFYAML::AuxSymbolType &Value) {
48 ECase(IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF);
49 }
50
51 void ScalarEnumerationTraits::enumeration(
52 IO &IO, COFF::MachineTypes &Value) {
53 ECase(IMAGE_FILE_MACHINE_UNKNOWN);
54 ECase(IMAGE_FILE_MACHINE_AM33);
55 ECase(IMAGE_FILE_MACHINE_AMD64);
56 ECase(IMAGE_FILE_MACHINE_ARM);
57 ECase(IMAGE_FILE_MACHINE_ARMNT);
58 ECase(IMAGE_FILE_MACHINE_ARM64);
59 ECase(IMAGE_FILE_MACHINE_EBC);
60 ECase(IMAGE_FILE_MACHINE_I386);
61 ECase(IMAGE_FILE_MACHINE_IA64);
62 ECase(IMAGE_FILE_MACHINE_M32R);
63 ECase(IMAGE_FILE_MACHINE_MIPS16);
64 ECase(IMAGE_FILE_MACHINE_MIPSFPU);
65 ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
66 ECase(IMAGE_FILE_MACHINE_POWERPC);
67 ECase(IMAGE_FILE_MACHINE_POWERPCFP);
68 ECase(IMAGE_FILE_MACHINE_R4000);
69 ECase(IMAGE_FILE_MACHINE_SH3);
70 ECase(IMAGE_FILE_MACHINE_SH3DSP);
71 ECase(IMAGE_FILE_MACHINE_SH4);
72 ECase(IMAGE_FILE_MACHINE_SH5);
73 ECase(IMAGE_FILE_MACHINE_THUMB);
74 ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
75 }
76
77 void ScalarEnumerationTraits::enumeration(
78 IO &IO, COFF::SymbolBaseType &Value) {
79 ECase(IMAGE_SYM_TYPE_NULL);
80 ECase(IMAGE_SYM_TYPE_VOID);
81 ECase(IMAGE_SYM_TYPE_CHAR);
82 ECase(IMAGE_SYM_TYPE_SHORT);
83 ECase(IMAGE_SYM_TYPE_INT);
84 ECase(IMAGE_SYM_TYPE_LONG);
85 ECase(IMAGE_SYM_TYPE_FLOAT);
86 ECase(IMAGE_SYM_TYPE_DOUBLE);
87 ECase(IMAGE_SYM_TYPE_STRUCT);
88 ECase(IMAGE_SYM_TYPE_UNION);
89 ECase(IMAGE_SYM_TYPE_ENUM);
90 ECase(IMAGE_SYM_TYPE_MOE);
91 ECase(IMAGE_SYM_TYPE_BYTE);
92 ECase(IMAGE_SYM_TYPE_WORD);
93 ECase(IMAGE_SYM_TYPE_UINT);
94 ECase(IMAGE_SYM_TYPE_DWORD);
95 }
96
97 void ScalarEnumerationTraits::enumeration(
98 IO &IO, COFF::SymbolStorageClass &Value) {
99 ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
100 ECase(IMAGE_SYM_CLASS_NULL);
101 ECase(IMAGE_SYM_CLASS_AUTOMATIC);
102 ECase(IMAGE_SYM_CLASS_EXTERNAL);
103 ECase(IMAGE_SYM_CLASS_STATIC);
104 ECase(IMAGE_SYM_CLASS_REGISTER);
105 ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
106 ECase(IMAGE_SYM_CLASS_LABEL);
107 ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
108 ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
109 ECase(IMAGE_SYM_CLASS_ARGUMENT);
110 ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
111 ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
112 ECase(IMAGE_SYM_CLASS_UNION_TAG);
113 ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
114 ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
115 ECase(IMAGE_SYM_CLASS_ENUM_TAG);
116 ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
117 ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
118 ECase(IMAGE_SYM_CLASS_BIT_FIELD);
119 ECase(IMAGE_SYM_CLASS_BLOCK);
120 ECase(IMAGE_SYM_CLASS_FUNCTION);
121 ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
122 ECase(IMAGE_SYM_CLASS_FILE);
123 ECase(IMAGE_SYM_CLASS_SECTION);
124 ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
125 ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
126 }
127
128 void ScalarEnumerationTraits::enumeration(
129 IO &IO, COFF::SymbolComplexType &Value) {
130 ECase(IMAGE_SYM_DTYPE_NULL);
131 ECase(IMAGE_SYM_DTYPE_POINTER);
132 ECase(IMAGE_SYM_DTYPE_FUNCTION);
133 ECase(IMAGE_SYM_DTYPE_ARRAY);
134 }
135
136 void ScalarEnumerationTraits::enumeration(
137 IO &IO, COFF::RelocationTypeI386 &Value) {
138 ECase(IMAGE_REL_I386_ABSOLUTE);
139 ECase(IMAGE_REL_I386_DIR16);
140 ECase(IMAGE_REL_I386_REL16);
141 ECase(IMAGE_REL_I386_DIR32);
142 ECase(IMAGE_REL_I386_DIR32NB);
143 ECase(IMAGE_REL_I386_SEG12);
144 ECase(IMAGE_REL_I386_SECTION);
145 ECase(IMAGE_REL_I386_SECREL);
146 ECase(IMAGE_REL_I386_TOKEN);
147 ECase(IMAGE_REL_I386_SECREL7);
148 ECase(IMAGE_REL_I386_REL32);
149 }
150
151 void ScalarEnumerationTraits::enumeration(
152 IO &IO, COFF::RelocationTypeAMD64 &Value) {
153 ECase(IMAGE_REL_AMD64_ABSOLUTE);
154 ECase(IMAGE_REL_AMD64_ADDR64);
155 ECase(IMAGE_REL_AMD64_ADDR32);
156 ECase(IMAGE_REL_AMD64_ADDR32NB);
157 ECase(IMAGE_REL_AMD64_REL32);
158 ECase(IMAGE_REL_AMD64_REL32_1);
159 ECase(IMAGE_REL_AMD64_REL32_2);
160 ECase(IMAGE_REL_AMD64_REL32_3);
161 ECase(IMAGE_REL_AMD64_REL32_4);
162 ECase(IMAGE_REL_AMD64_REL32_5);
163 ECase(IMAGE_REL_AMD64_SECTION);
164 ECase(IMAGE_REL_AMD64_SECREL);
165 ECase(IMAGE_REL_AMD64_SECREL7);
166 ECase(IMAGE_REL_AMD64_TOKEN);
167 ECase(IMAGE_REL_AMD64_SREL32);
168 ECase(IMAGE_REL_AMD64_PAIR);
169 ECase(IMAGE_REL_AMD64_SSPAN32);
170 }
171
172 void ScalarEnumerationTraits::enumeration(
173 IO &IO, COFF::WindowsSubsystem &Value) {
174 ECase(IMAGE_SUBSYSTEM_UNKNOWN);
175 ECase(IMAGE_SUBSYSTEM_NATIVE);
176 ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
177 ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
178 ECase(IMAGE_SUBSYSTEM_OS2_CUI);
179 ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
180 ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
181 ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
182 ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
183 ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
184 ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
185 ECase(IMAGE_SUBSYSTEM_EFI_ROM);
186 ECase(IMAGE_SUBSYSTEM_XBOX);
187 ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
188 }
189 #undef ECase
190
191 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
192 void ScalarBitSetTraits::bitset(
193 IO &IO, COFF::Characteristics &Value) {
194 BCase(IMAGE_FILE_RELOCS_STRIPPED);
195 BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
196 BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
197 BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
198 BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
199 BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
200 BCase(IMAGE_FILE_BYTES_REVERSED_LO);
201 BCase(IMAGE_FILE_32BIT_MACHINE);
202 BCase(IMAGE_FILE_DEBUG_STRIPPED);
203 BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
204 BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
205 BCase(IMAGE_FILE_SYSTEM);
206 BCase(IMAGE_FILE_DLL);
207 BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
208 BCase(IMAGE_FILE_BYTES_REVERSED_HI);
209 }
210
211 void ScalarBitSetTraits::bitset(
212 IO &IO, COFF::SectionCharacteristics &Value) {
213 BCase(IMAGE_SCN_TYPE_NOLOAD);
214 BCase(IMAGE_SCN_TYPE_NO_PAD);
215 BCase(IMAGE_SCN_CNT_CODE);
216 BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
217 BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
218 BCase(IMAGE_SCN_LNK_OTHER);
219 BCase(IMAGE_SCN_LNK_INFO);
220 BCase(IMAGE_SCN_LNK_REMOVE);
221 BCase(IMAGE_SCN_LNK_COMDAT);
222 BCase(IMAGE_SCN_GPREL);
223 BCase(IMAGE_SCN_MEM_PURGEABLE);
224 BCase(IMAGE_SCN_MEM_16BIT);
225 BCase(IMAGE_SCN_MEM_LOCKED);
226 BCase(IMAGE_SCN_MEM_PRELOAD);
227 BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
228 BCase(IMAGE_SCN_MEM_DISCARDABLE);
229 BCase(IMAGE_SCN_MEM_NOT_CACHED);
230 BCase(IMAGE_SCN_MEM_NOT_PAGED);
231 BCase(IMAGE_SCN_MEM_SHARED);
232 BCase(IMAGE_SCN_MEM_EXECUTE);
233 BCase(IMAGE_SCN_MEM_READ);
234 BCase(IMAGE_SCN_MEM_WRITE);
235 }
236
237 void ScalarBitSetTraits::bitset(
238 IO &IO, COFF::DLLCharacteristics &Value) {
239 BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA);
240 BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);
241 BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY);
242 BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
243 BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION);
244 BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH);
245 BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND);
246 BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER);
247 BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER);
248 BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF);
249 BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE);
250 }
251 #undef BCase
252
253 namespace {
254 struct NSectionSelectionType {
255 NSectionSelectionType(IO &)
256 : SelectionType(COFFYAML::COMDATType(0)) {}
257 NSectionSelectionType(IO &, uint8_t C)
258 : SelectionType(COFFYAML::COMDATType(C)) {}
259 uint8_t denormalize(IO &) { return SelectionType; }
260 COFFYAML::COMDATType SelectionType;
261 };
262
263 struct NWeakExternalCharacteristics {
264 NWeakExternalCharacteristics(IO &)
265 : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
266 NWeakExternalCharacteristics(IO &, uint32_t C)
267 : Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
268 uint32_t denormalize(IO &) { return Characteristics; }
269 COFFYAML::WeakExternalCharacteristics Characteristics;
270 };
271
272 struct NSectionCharacteristics {
273 NSectionCharacteristics(IO &)
274 : Characteristics(COFF::SectionCharacteristics(0)) {}
275 NSectionCharacteristics(IO &, uint32_t C)
276 : Characteristics(COFF::SectionCharacteristics(C)) {}
277 uint32_t denormalize(IO &) { return Characteristics; }
278 COFF::SectionCharacteristics Characteristics;
279 };
280
281 struct NAuxTokenType {
282 NAuxTokenType(IO &)
283 : AuxType(COFFYAML::AuxSymbolType(0)) {}
284 NAuxTokenType(IO &, uint8_t C)
285 : AuxType(COFFYAML::AuxSymbolType(C)) {}
286 uint32_t denormalize(IO &) { return AuxType; }
287 COFFYAML::AuxSymbolType AuxType;
288 };
289
290 struct NStorageClass {
291 NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
292 NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
293 uint8_t denormalize(IO &) { return StorageClass; }
294
295 COFF::SymbolStorageClass StorageClass;
296 };
297
298 struct NMachine {
299 NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
300 NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
301 uint16_t denormalize(IO &) { return Machine; }
302 COFF::MachineTypes Machine;
303 };
304
305 struct NHeaderCharacteristics {
306 NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
307 NHeaderCharacteristics(IO &, uint16_t C)
308 : Characteristics(COFF::Characteristics(C)) {}
309 uint16_t denormalize(IO &) { return Characteristics; }
310
311 COFF::Characteristics Characteristics;
312 };
313
314 template
315 struct NType {
316 NType(IO &) : Type(RelocType(0)) {}
317 NType(IO &, uint16_t T) : Type(RelocType(T)) {}
318 uint16_t denormalize(IO &) { return Type; }
319 RelocType Type;
320 };
321
322 struct NWindowsSubsystem {
323 NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
324 NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
325 uint16_t denormalize(IO &) { return Subsystem; }
326
327 COFF::WindowsSubsystem Subsystem;
328 };
329
330 struct NDLLCharacteristics {
331 NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
332 NDLLCharacteristics(IO &, uint16_t C)
333 : Characteristics(COFF::DLLCharacteristics(C)) {}
334 uint16_t denormalize(IO &) { return Characteristics; }
335
336 COFF::DLLCharacteristics Characteristics;
337 };
338
339 }
340
341 void MappingTraits::mapping(IO &IO,
342 COFFYAML::Relocation &Rel) {
343 IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
344 IO.mapRequired("SymbolName", Rel.SymbolName);
345
346 COFF::header &H = *static_cast(IO.getContext());
347 if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
348 MappingNormalization, uint16_t> NT(
349 IO, Rel.Type);
350 IO.mapRequired("Type", NT->Type);
351 } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
352 MappingNormalization, uint16_t> NT(
353 IO, Rel.Type);
354 IO.mapRequired("Type", NT->Type);
355 } else {
356 IO.mapRequired("Type", Rel.Type);
357 }
358 }
359
360 void MappingTraits::mapping(IO &IO,
361 COFF::DataDirectory &DD) {
362 IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
363 IO.mapRequired("Size", DD.Size);
364 }
365
366 void MappingTraits::mapping(IO &IO,
367 COFFYAML::PEHeader &PH) {
368 MappingNormalization NWS(IO,
369 PH.Header.Subsystem);
370 MappingNormalization NDC(
371 IO, PH.Header.DLLCharacteristics);
372
373 IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
374 IO.mapRequired("ImageBase", PH.Header.ImageBase);
375 IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
376 IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
377 IO.mapRequired("MajorOperatingSystemVersion",
378 PH.Header.MajorOperatingSystemVersion);
379 IO.mapRequired("MinorOperatingSystemVersion",
380 PH.Header.MinorOperatingSystemVersion);
381 IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
382 IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
383 IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
384 IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
385 IO.mapRequired("Subsystem", NWS->Subsystem);
386 IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
387 IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
388 IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
389 IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
390 IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
391
392 IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
393 IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
394 IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
395 IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
396 IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
397 IO.mapOptional("BaseRelocationTable",
398 PH.DataDirectories[COFF::BASE_RELOCATION_TABLE]);
399 IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG]);
400 IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
401 IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
402 IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
403 IO.mapOptional("LoadConfigTable",
404 PH.DataDirectories[COFF::LOAD_CONFIG_TABLE]);
405 IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
406 IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
407 IO.mapOptional("DelayImportDescriptor",
408 PH.DataDirectories[COFF::DELAY_IMPORT_DESCRIPTOR]);
409 IO.mapOptional("ClrRuntimeHeader",
410 PH.DataDirectories[COFF::CLR_RUNTIME_HEADER]);
411 }
412
413 void MappingTraits::mapping(IO &IO, COFF::header &H) {
414 MappingNormalization NM(IO, H.Machine);
415 MappingNormalization NC(IO,
416 H.Characteristics);
417
418 IO.mapRequired("Machine", NM->Machine);
419 IO.mapOptional("Characteristics", NC->Characteristics);
420 IO.setContext(static_cast(&H));
421 }
422
423 void MappingTraits::mapping(
424 IO &IO, COFF::AuxiliaryFunctionDefinition &AFD) {
425 IO.mapRequired("TagIndex", AFD.TagIndex);
426 IO.mapRequired("TotalSize", AFD.TotalSize);
427 IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
428 IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
429 }
430
431 void MappingTraits::mapping(
432 IO &IO, COFF::AuxiliarybfAndefSymbol &AAS) {
433 IO.mapRequired("Linenumber", AAS.Linenumber);
434 IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
435 }
436
437 void MappingTraits::mapping(
438 IO &IO, COFF::AuxiliaryWeakExternal &AWE) {
439 MappingNormalization NWEC(
440 IO, AWE.Characteristics);
441 IO.mapRequired("TagIndex", AWE.TagIndex);
442 IO.mapRequired("Characteristics", NWEC->Characteristics);
443 }
444
445 void MappingTraits::mapping(
446 IO &IO, COFF::AuxiliarySectionDefinition &ASD) {
447 MappingNormalization NSST(
448 IO, ASD.Selection);
449
450 IO.mapRequired("Length", ASD.Length);
451 IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
452 IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
453 IO.mapRequired("CheckSum", ASD.CheckSum);
454 IO.mapRequired("Number", ASD.Number);
455 IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
456 }
457
458 void MappingTraits::mapping(
459 IO &IO, COFF::AuxiliaryCLRToken &ACT) {
460 MappingNormalization NATT(IO, ACT.AuxType);
461 IO.mapRequired("AuxType", NATT->AuxType);
462 IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
463 }
464
465 void MappingTraits::mapping(IO &IO, COFFYAML::Symbol &S) {
466 MappingNormalization NS(IO, S.Header.StorageClass);
467
468 IO.mapRequired("Name", S.Name);
469 IO.mapRequired("Value", S.Header.Value);
470 IO.mapRequired("SectionNumber", S.Header.SectionNumber);
471 IO.mapRequired("SimpleType", S.SimpleType);
472 IO.mapRequired("ComplexType", S.ComplexType);
473 IO.mapRequired("StorageClass", NS->StorageClass);
474 IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
475 IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
476 IO.mapOptional("WeakExternal", S.WeakExternal);
477 IO.mapOptional("File", S.File, StringRef());
478 IO.mapOptional("SectionDefinition", S.SectionDefinition);
479 IO.mapOptional("CLRToken", S.CLRToken);
480 }
481
482 void MappingTraits::mapping(IO &IO, COFFYAML::Section &Sec) {
483 MappingNormalization NC(
484 IO, Sec.Header.Characteristics);
485 IO.mapRequired("Name", Sec.Name);
486 IO.mapRequired("Characteristics", NC->Characteristics);
487 IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
488 IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
489 IO.mapOptional("Alignment", Sec.Alignment);
490 IO.mapRequired("SectionData", Sec.SectionData);
491 IO.mapOptional("Relocations", Sec.Relocations);
492 }
493
494 void MappingTraits::mapping(IO &IO, COFFYAML::Object &Obj) {
495 IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
496 IO.mapRequired("header", Obj.Header);
497 IO.mapRequired("sections", Obj.Sections);
498 IO.mapRequired("symbols", Obj.Symbols);
499 }
500
501 }
502 }
+0
-828
lib/Object/ELFYAML.cpp less more
None //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of ELF.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Object/ELFYAML.h"
14 #include "llvm/Support/Casting.h"
15 #include "llvm/Support/MipsABIFlags.h"
16
17 namespace llvm {
18
19 ELFYAML::Section::~Section() {}
20
21 namespace yaml {
22
23 void
24 ScalarEnumerationTraits::enumeration(IO &IO,
25 ELFYAML::ELF_ET &Value) {
26 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
27 ECase(ET_NONE)
28 ECase(ET_REL)
29 ECase(ET_EXEC)
30 ECase(ET_DYN)
31 ECase(ET_CORE)
32 #undef ECase
33 IO.enumFallback(Value);
34 }
35
36 void
37 ScalarEnumerationTraits::enumeration(IO &IO,
38 ELFYAML::ELF_EM &Value) {
39 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
40 ECase(EM_NONE)
41 ECase(EM_M32)
42 ECase(EM_SPARC)
43 ECase(EM_386)
44 ECase(EM_68K)
45 ECase(EM_88K)
46 ECase(EM_IAMCU)
47 ECase(EM_860)
48 ECase(EM_MIPS)
49 ECase(EM_S370)
50 ECase(EM_MIPS_RS3_LE)
51 ECase(EM_PARISC)
52 ECase(EM_VPP500)
53 ECase(EM_SPARC32PLUS)
54 ECase(EM_960)
55 ECase(EM_PPC)
56 ECase(EM_PPC64)
57 ECase(EM_S390)
58 ECase(EM_SPU)
59 ECase(EM_V800)
60 ECase(EM_FR20)
61 ECase(EM_RH32)
62 ECase(EM_RCE)
63 ECase(EM_ARM)
64 ECase(EM_ALPHA)
65 ECase(EM_SH)
66 ECase(EM_SPARCV9)
67 ECase(EM_TRICORE)
68 ECase(EM_ARC)
69 ECase(EM_H8_300)
70 ECase(EM_H8_300H)
71 ECase(EM_H8S)
72 ECase(EM_H8_500)
73 ECase(EM_IA_64)
74 ECase(EM_MIPS_X)
75 ECase(EM_COLDFIRE)
76 ECase(EM_68HC12)
77 ECase(EM_MMA)
78 ECase(EM_PCP)
79 ECase(EM_NCPU)
80 ECase(EM_NDR1)
81 ECase(EM_STARCORE)
82 ECase(EM_ME16)
83 ECase(EM_ST100)
84 ECase(EM_TINYJ)
85 ECase(EM_X86_64)
86 ECase(EM_PDSP)
87 ECase(EM_PDP10)
88 ECase(EM_PDP11)
89 ECase(EM_FX66)
90 ECase(EM_ST9PLUS)
91 ECase(EM_ST7)
92 ECase(EM_68HC16)
93 ECase(EM_68HC11)
94 ECase(EM_68HC08)
95 ECase(EM_68HC05)
96 ECase(EM_SVX)
97 ECase(EM_ST19)
98 ECase(EM_VAX)
99 ECase(EM_CRIS)
100 ECase(EM_JAVELIN)
101 ECase(EM_FIREPATH)
102 ECase(EM_ZSP)
103 ECase(EM_MMIX)
104 ECase(EM_HUANY)
105 ECase(EM_PRISM)
106 ECase(EM_AVR)
107 ECase(EM_FR30)
108 ECase(EM_D10V)
109 ECase(EM_D30V)
110 ECase(EM_V850)
111 ECase(EM_M32R)
112 ECase(EM_MN10300)
113 ECase(EM_MN10200)
114 ECase(EM_PJ)
115 ECase(EM_OPENRISC)
116 ECase(EM_ARC_COMPACT)
117 ECase(EM_XTENSA)
118 ECase(EM_VIDEOCORE)
119 ECase(EM_TMM_GPP)
120 ECase(EM_NS32K)
121 ECase(EM_TPC)
122 ECase(EM_SNP1K)
123 ECase(EM_ST200)
124 ECase(EM_IP2K)
125 ECase(EM_MAX)
126 ECase(EM_CR)
127 ECase(EM_F2MC16)
128 ECase(EM_MSP430)
129 ECase(EM_BLACKFIN)
130 ECase(EM_SE_C33)
131 ECase(EM_SEP)
132 ECase(EM_ARCA)
133 ECase(EM_UNICORE)
134 ECase(EM_EXCESS)
135 ECase(EM_DXP)
136 ECase(EM_ALTERA_NIOS2)
137 ECase(EM_CRX)
138 ECase(EM_XGATE)
139 ECase(EM_C166)
140 ECase(EM_M16C)
141 ECase(EM_DSPIC30F)
142 ECase(EM_CE)
143 ECase(EM_M32C)
144 ECase(EM_TSK3000)
145 ECase(EM_RS08)
146 ECase(EM_SHARC)
147 ECase(EM_ECOG2)
148 ECase(EM_SCORE7)
149 ECase(EM_DSP24)
150 ECase(EM_VIDEOCORE3)
151 ECase(EM_LATTICEMICO32)
152 ECase(EM_SE_C17)
153 ECase(EM_TI_C6000)
154 ECase(EM_TI_C2000)
155 ECase(EM_TI_C5500)
156 ECase(EM_MMDSP_PLUS)
157 ECase(EM_CYPRESS_M8C)
158 ECase(EM_R32C)
159 ECase(EM_TRIMEDIA)
160 ECase(EM_HEXAGON)
161 ECase(EM_8051)
162 ECase(EM_STXP7X)
163 ECase(EM_NDS32)
164 ECase(EM_ECOG1)
165 ECase(EM_ECOG1X)
166 ECase(EM_MAXQ30)
167 ECase(EM_XIMO16)
168 ECase(EM_MANIK)
169 ECase(EM_CRAYNV2)
170 ECase(EM_RX)
171 ECase(EM_METAG)
172 ECase(EM_MCST_ELBRUS)
173 ECase(EM_ECOG16)
174 ECase(EM_CR16)
175 ECase(EM_ETPU)
176 ECase(EM_SLE9X)
177 ECase(EM_L10M)
178 ECase(EM_K10M)
179 ECase(EM_AARCH64)
180 ECase(EM_AVR32)
181 ECase(EM_STM8)
182 ECase(EM_TILE64)
183 ECase(EM_TILEPRO)
184 ECase(EM_CUDA)
185 ECase(EM_TILEGX)
186 ECase(EM_CLOUDSHIELD)
187 ECase(EM_COREA_1ST)
188 ECase(EM_COREA_2ND)
189 ECase(EM_ARC_COMPACT2)
190 ECase(EM_OPEN8)
191 ECase(EM_RL78)
192 ECase(EM_VIDEOCORE5)
193 ECase(EM_78KOR)
194 ECase(EM_56800EX)
195 ECase(EM_AMDGPU)
196 #undef ECase
197 }
198
199 void ScalarEnumerationTraits::enumeration(
200 IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
201 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
202 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
203 // here.
204 ECase(ELFCLASS32)
205 ECase(ELFCLASS64)
206 #undef ECase
207 }
208
209 void ScalarEnumerationTraits::enumeration(
210 IO &IO, ELFYAML::ELF_ELFDATA &Value) {
211 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
212 // Since the semantics of ELFDATANONE is "invalid", just don't accept it
213 // here.
214 ECase(ELFDATA2LSB)
215 ECase(ELFDATA2MSB)
216 #undef ECase
217 }
218
219 void ScalarEnumerationTraits::enumeration(
220 IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
221 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
222 ECase(ELFOSABI_NONE)
223 ECase(ELFOSABI_HPUX)
224 ECase(ELFOSABI_NETBSD)
225 ECase(ELFOSABI_GNU)
226 ECase(ELFOSABI_GNU)
227 ECase(ELFOSABI_HURD)
228 ECase(ELFOSABI_SOLARIS)
229 ECase(ELFOSABI_AIX)
230 ECase(ELFOSABI_IRIX)
231 ECase(ELFOSABI_FREEBSD)
232 ECase(ELFOSABI_TRU64)
233 ECase(ELFOSABI_MODESTO)
234 ECase(ELFOSABI_OPENBSD)
235 ECase(ELFOSABI_OPENVMS)
236 ECase(ELFOSABI_NSK)
237 ECase(ELFOSABI_AROS)
238 ECase(ELFOSABI_FENIXOS)
239 ECase(ELFOSABI_CLOUDABI)
240 ECase(ELFOSABI_C6000_ELFABI)
241 ECase(ELFOSABI_C6000_LINUX)
242 ECase(ELFOSABI_ARM)
243 ECase(ELFOSABI_STANDALONE)
244 #undef ECase
245 }
246
247 void ScalarBitSetTraits::bitset(IO &IO,
248 ELFYAML::ELF_EF &Value) {
249 const auto *Object = static_cast(IO.getContext());
250 assert(Object && "The IO context is not initialized");
251 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
252 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M);
253 switch (Object->Header.Machine) {
254 case ELF::EM_ARM:
255 BCase(EF_ARM_SOFT_FLOAT)
256 BCase(EF_ARM_VFP_FLOAT)
257 BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK)
258 BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK)
259 BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK)
260 BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK)
261 BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK)
262 BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK)
263 break;
264 case ELF::EM_MIPS:
265 BCase(EF_MIPS_NOREORDER)
266 BCase(EF_MIPS_PIC)
267 BCase(EF_MIPS_CPIC)
268 BCase(EF_MIPS_ABI2)
269 BCase(EF_MIPS_32BITMODE)
270 BCase(EF_MIPS_FP64)
271 BCase(EF_MIPS_NAN2008)
272 BCase(EF_MIPS_MICROMIPS)
273 BCase(EF_MIPS_ARCH_ASE_M16)
274 BCase(EF_MIPS_ARCH_ASE_MDMX)
275 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI)
276 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI)
277 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI)
278 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI)
279 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH)
280 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH)
281 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH)
282 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH)
283 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH)
284 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH)
285 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH)
286 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH)
287 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH)
288 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH)
289 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH)
290 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH)
291 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH)
292 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH)
293 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH)
294 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH)
295 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH)
296 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH)
297 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH)
298 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH)
299 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH)
300 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH)
301 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH)
302 BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH)
303 BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH)
304 BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH)
305 BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH)
306 BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH)
307 BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH)
308 break;
309 case ELF::EM_HEXAGON:
310 BCase(EF_HEXAGON_MACH_V2)
311 BCase(EF_HEXAGON_MACH_V3)
312 BCase(EF_HEXAGON_MACH_V4)
313 BCase(EF_HEXAGON_MACH_V5)
314 BCase(EF_HEXAGON_ISA_V2)
315 BCase(EF_HEXAGON_ISA_V3)
316 BCase(EF_HEXAGON_ISA_V4)
317 BCase(EF_HEXAGON_ISA_V5)
318 break;
319 case ELF::EM_AVR:
320 BCase(EF_AVR_ARCH_AVR1)
321 BCase(EF_AVR_ARCH_AVR2)
322 BCase(EF_AVR_ARCH_AVR25)
323 BCase(EF_AVR_ARCH_AVR3)
324 BCase(EF_AVR_ARCH_AVR31)
325 BCase(EF_AVR_ARCH_AVR35)
326 BCase(EF_AVR_ARCH_AVR4)
327 BCase(EF_AVR_ARCH_AVR51)
328 BCase(EF_AVR_ARCH_AVR6)
329 BCase(EF_AVR_ARCH_AVRTINY)
330 BCase(EF_AVR_ARCH_XMEGA1)
331 BCase(EF_AVR_ARCH_XMEGA2)
332 BCase(EF_AVR_ARCH_XMEGA3)
333 BCase(EF_AVR_ARCH_XMEGA4)
334 BCase(EF_AVR_ARCH_XMEGA5)
335 BCase(EF_AVR_ARCH_XMEGA6)
336 BCase(EF_AVR_ARCH_XMEGA7)
337 break;
338 case ELF::EM_AMDGPU:
339 case ELF::EM_X86_64:
340 break;
341 default:
342 llvm_unreachable("Unsupported architecture");
343 }
344 #undef BCase
345 #undef BCaseMask
346 }
347
348 void ScalarEnumerationTraits::enumeration(
349 IO &IO, ELFYAML::ELF_SHT &Value) {
350 const auto *Object = static_cast(IO.getContext());
351 assert(Object && "The IO context is not initialized");
352 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
353 ECase(SHT_NULL)
354 ECase(SHT_PROGBITS)
355 // No SHT_SYMTAB. Use the top-level `Symbols` key instead.
356 // FIXME: Issue a diagnostic with this information.
357 ECase(SHT_STRTAB)
358 ECase(SHT_RELA)
359 ECase(SHT_HASH)
360 ECase(SHT_DYNAMIC)
361 ECase(SHT_NOTE)
362 ECase(SHT_NOBITS)
363 ECase(SHT_REL)
364 ECase(SHT_SHLIB)
365 ECase(SHT_DYNSYM)
366 ECase(SHT_INIT_ARRAY)
367 ECase(SHT_FINI_ARRAY)
368 ECase(SHT_PREINIT_ARRAY)
369 ECase(SHT_GROUP)
370 ECase(SHT_SYMTAB_SHNDX)
371 ECase(SHT_LOOS)
372 ECase(SHT_GNU_ATTRIBUTES)
373 ECase(SHT_GNU_HASH)
374 ECase(SHT_GNU_verdef)
375 ECase(SHT_GNU_verneed)
376 ECase(SHT_GNU_versym)
377 ECase(SHT_HIOS)
378 ECase(SHT_LOPROC)
379 switch (Object->Header.Machine) {
380 case ELF::EM_ARM:
381 ECase(SHT_ARM_EXIDX)
382 ECase(SHT_ARM_PREEMPTMAP)
383 ECase(SHT_ARM_ATTRIBUTES)
384 ECase(SHT_ARM_DEBUGOVERLAY)
385 ECase(SHT_ARM_OVERLAYSECTION)
386 break;
387 case ELF::EM_HEXAGON:
388 ECase(SHT_HEX_ORDERED)
389 break;
390 case ELF::EM_X86_64:
391 ECase(SHT_X86_64_UNWIND)
392 break;
393 case ELF::EM_MIPS:
394 ECase(SHT_MIPS_REGINFO)
395 ECase(SHT_MIPS_OPTIONS)
396 ECase(SHT_MIPS_ABIFLAGS)
397 break;
398 default:
399 // Nothing to do.
400 break;
401 }
402 #undef ECase
403 }
404
405 void ScalarBitSetTraits::bitset(IO &IO,
406 ELFYAML::ELF_SHF &Value) {
407 const auto *Object = static_cast(IO.getContext());
408 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
409 BCase(SHF_WRITE)
410 BCase(SHF_ALLOC)
411 BCase(SHF_EXCLUDE)
412 BCase(SHF_EXECINSTR)
413 BCase(SHF_MERGE)
414 BCase(SHF_STRINGS)
415 BCase(SHF_INFO_LINK)
416 BCase(SHF_LINK_ORDER)
417 BCase(SHF_OS_NONCONFORMING)
418 BCase(SHF_GROUP)
419 BCase(SHF_TLS)
420 switch(Object->Header.Machine) {
421 case ELF::EM_AMDGPU:
422 BCase(SHF_AMDGPU_HSA_GLOBAL)
423 BCase(SHF_AMDGPU_HSA_READONLY)
424 BCase(SHF_AMDGPU_HSA_CODE)
425 BCase(SHF_AMDGPU_HSA_AGENT)
426 break;
427 case ELF::EM_HEXAGON:
428 BCase(SHF_HEX_GPREL)
429 break;
430 case ELF::EM_MIPS:
431 BCase(SHF_MIPS_NODUPES)
432 BCase(SHF_MIPS_NAMES)
433 BCase(SHF_MIPS_LOCAL)
434 BCase(SHF_MIPS_NOSTRIP)
435 BCase(SHF_MIPS_GPREL)
436 BCase(SHF_MIPS_MERGE)
437 BCase(SHF_MIPS_ADDR)
438 BCase(SHF_MIPS_STRING)
439 break;
440 case ELF::EM_X86_64:
441 BCase(SHF_X86_64_LARGE)
442 break;
443 default:
444 // Nothing to do.
445 break;
446 }
447 #undef BCase
448 }
449
450 void ScalarEnumerationTraits::enumeration(
451 IO &IO, ELFYAML::ELF_STT &Value) {
452 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
453 ECase(STT_NOTYPE)
454 ECase(STT_OBJECT)
455 ECase(STT_FUNC)
456 ECase(STT_SECTION)
457 ECase(STT_FILE)
458 ECase(STT_COMMON)
459 ECase(STT_TLS)
460 ECase(STT_GNU_IFUNC)
461 #undef ECase
462 }
463
464 void ScalarEnumerationTraits::enumeration(
465 IO &IO, ELFYAML::ELF_STV &Value) {
466 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
467 ECase(STV_DEFAULT)
468 ECase(STV_INTERNAL)
469 ECase(STV_HIDDEN)
470 ECase(STV_PROTECTED)
471 #undef ECase
472 }
473
474 void ScalarBitSetTraits::bitset(IO &IO,
475 ELFYAML::ELF_STO &Value) {
476 const auto *Object = static_cast(IO.getContext());
477 assert(Object && "The IO context is not initialized");
478 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
479 switch (Object->Header.Machine) {
480 case ELF::EM_MIPS:
481 BCase(STO_MIPS_OPTIONAL)
482 BCase(STO_MIPS_PLT)
483 BCase(STO_MIPS_PIC)
484 BCase(STO_MIPS_MICROMIPS)
485 break;
486 default:
487 break; // Nothing to do
488 }
489 #undef BCase
490 #undef BCaseMask
491 }
492
493 void ScalarEnumerationTraits::enumeration(
494 IO &IO, ELFYAML::ELF_RSS &Value) {
495 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
496 ECase(RSS_UNDEF)
497 ECase(RSS_GP)
498 ECase(RSS_GP0)
499 ECase(RSS_LOC)
500 #undef ECase
501 }
502
503 void ScalarEnumerationTraits::enumeration(
504 IO &IO, ELFYAML::ELF_REL &Value) {
505 const auto *Object = static_cast(IO.getContext());
506 assert(Object && "The IO context is not initialized");
507 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
508 switch (Object->Header.Machine) {
509 case ELF::EM_X86_64:
510 #include "llvm/Support/ELFRelocs/x86_64.def"
511 break;
512 case ELF::EM_MIPS:
513 #include "llvm/Support/ELFRelocs/Mips.def"
514 break;
515 case ELF::EM_HEXAGON:
516 #include "llvm/Support/ELFRelocs/Hexagon.def"
517 break;
518 case ELF::EM_386:
519 case ELF::EM_IAMCU:
520 #include "llvm/Support/ELFRelocs/i386.def"
521 break;
522 case ELF::EM_AARCH64:
523 #include "llvm/Support/ELFRelocs/AArch64.def"
524 break;
525 case ELF::EM_ARM:
526 #include "llvm/Support/ELFRelocs/ARM.def"
527 break;
528 default:
529 llvm_unreachable("Unsupported architecture");
530 }
531 #undef ELF_RELOC
532 }
533
534 void ScalarEnumerationTraits::enumeration(
535 IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
536 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X);
537 ECase(REG_NONE)
538 ECase(REG_32)
539 ECase(REG_64)
540 ECase(REG_128)
541 #undef ECase
542 }
543
544 void ScalarEnumerationTraits::enumeration(
545 IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
546 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X);
547 ECase(FP_ANY)
548 ECase(FP_DOUBLE)
549 ECase(FP_SINGLE)
550 ECase(FP_SOFT)
551 ECase(FP_OLD_64)
552 ECase(FP_XX)
553 ECase(FP_64)
554 ECase(FP_64A)
555 #undef ECase
556 }
557
558 void ScalarEnumerationTraits::enumeration(
559 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
560 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X);
561 ECase(EXT_NONE)
562 ECase(EXT_XLR)
563 ECase(EXT_OCTEON2)
564 ECase(EXT_OCTEONP)
565 ECase(EXT_LOONGSON_3A)
566 ECase(EXT_OCTEON)
567 ECase(EXT_5900)
568 ECase(EXT_4650)
569 ECase(EXT_4010)
570 ECase(EXT_4100)
571 ECase(EXT_3900)
572 ECase(EXT_10000)
573 ECase(EXT_SB1)
574 ECase(EXT_4111)
575 ECase(EXT_4120)
576 ECase(EXT_5400)
577 ECase(EXT_5500)
578 ECase(EXT_LOONGSON_2E)
579 ECase(EXT_LOONGSON_2F)
580 ECase(EXT_OCTEON3)
581 #undef ECase
582 }
583
584 void ScalarEnumerationTraits::enumeration(
585 IO &IO, ELFYAML::MIPS_ISA &Value) {
586 IO.enumCase(Value, "MIPS1", 1);
587 IO.enumCase(Value, "MIPS2", 2);
588 IO.enumCase(Value, "MIPS3", 3);
589 IO.enumCase(Value, "MIPS4", 4);
590 IO.enumCase(Value, "MIPS5", 5);
591 IO.enumCase(Value, "MIPS32", 32);
592 IO.enumCase(Value, "MIPS64", 64);
593 }
594
595 void ScalarBitSetTraits::bitset(
596 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
597 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X);
598 BCase(DSP)
599 BCase(DSPR2)
600 BCase(EVA)
601 BCase(MCU)
602 BCase(MDMX)
603 BCase(MIPS3D)
604 BCase(MT)
605 BCase(SMARTMIPS)
606 BCase(VIRT)
607 BCase(MSA)
608 BCase(MIPS16)
609 BCase(MICROMIPS)
610 BCase(XPA)
611 #undef BCase
612 }
613
614 void ScalarBitSetTraits::bitset(
615 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
616 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X);
617 BCase(ODDSPREG)
618 #undef BCase
619 }
620
621 void MappingTraits::mapping(IO &IO,
622 ELFYAML::FileHeader &FileHdr) {
623 IO.mapRequired("Class", FileHdr.Class);
624 IO.mapRequired("Data", FileHdr.Data);
625 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
626 IO.mapRequired("Type", FileHdr.Type);
627 IO.mapRequired("Machine", FileHdr.Machine);
628 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
629 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
630 }
631
632 namespace {
633 struct NormalizedOther {
634 NormalizedOther(IO &)
635 : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
636 NormalizedOther(IO &, uint8_t Original)
637 : Visibility(Original & 0x3), Other(Original & ~0x3) {}
638
639 uint8_t denormalize(IO &) { return Visibility | Other; }
640
641 ELFYAML::ELF_STV Visibility;
642 ELFYAML::ELF_STO Other;
643 };
644 }
645
646 void MappingTraits::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
647 IO.mapOptional("Name", Symbol.Name, StringRef());
648 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
649 IO.mapOptional("Section", Symbol.Section, StringRef());
650 IO.mapOptional("Value", Symbol.Value, Hex64(0));
651 IO.mapOptional("Size", Symbol.Size, Hex64(0));
652
653 MappingNormalization Keys(IO, Symbol.Other);
654 IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
655 IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
656 }
657
658 void MappingTraits::mapping(
659 IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
660 IO.mapOptional("Local", Symbols.Local);
661 IO.mapOptional("Global", Symbols.Global);
662 IO.mapOptional("Weak", Symbols.Weak);
663 }
664
665 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
666 IO.mapOptional("Name", Section.Name, StringRef());
667 IO.mapRequired("Type", Section.Type);
668 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
669 IO.mapOptional("Address", Section.Address, Hex64(0));
670 IO.mapOptional("Link", Section.Link, StringRef());
671 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
672 IO.mapOptional("Info", Section.Info, StringRef());
673 }
674
675 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
676 commonSectionMapping(IO, Section);
677 IO.mapOptional("Content", Section.Content);
678 IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
679 }
680
681 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
682 commonSectionMapping(IO, Section);
683 IO.mapOptional("Size", Section.Size, Hex64(0));
684 }
685
686 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
687 commonSectionMapping(IO, Section);
688 IO.mapOptional("Relocations", Section.Relocations);
689 }
690
691 static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
692 commonSectionMapping(IO, group);
693 IO.mapRequired("Members", group.Members);
694 }
695
696 void MappingTraits::mapping(
697 IO &IO, ELFYAML::SectionOrType §ionOrType) {
698 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
699 }
700
701 static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) {
702 commonSectionMapping(IO, Section);
703 IO.mapOptional("Version", Section.Version, Hex16(0));
704 IO.mapRequired("ISA", Section.ISALevel);
705 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
706 IO.mapOptional("ISAExtension", Section.ISAExtension,
707 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
708 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
709 IO.mapOptional("FpABI", Section.FpABI,
710 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
711 IO.mapOptional("GPRSize", Section.GPRSize,
712 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
713 IO.mapOptional("CPR1Size", Section.CPR1Size,
714 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
715 IO.mapOptional("CPR2Size", Section.CPR2Size,
716 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
717 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
718 IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
719 }
720
721 void MappingTraits>::mapping(
722 IO &IO, std::unique_ptr &Section) {
723 ELFYAML::ELF_SHT sectionType;
724 if (IO.outputting())
725 sectionType = Section->Type;
726 else
727 IO.mapRequired("Type", sectionType);
728
729 switch (sectionType) {
730 case ELF::SHT_REL:
731 case ELF::SHT_RELA:
732 if (!IO.outputting())
733 Section.reset(new ELFYAML::RelocationSection());
734 sectionMapping(IO, *cast(Section.get()));
735 break;
736 case ELF::SHT_GROUP:
737 if (!IO.outputting())
738 Section.reset(new ELFYAML::Group());
739 groupSectionMapping(IO, *cast(Section.get()));
740 break;
741 case ELF::SHT_NOBITS:
742 if (!IO.outputting())
743 Section.reset(new ELFYAML::NoBitsSection());
744 sectionMapping(IO, *cast(Section.get()));
745 break;
746 case ELF::SHT_MIPS_ABIFLAGS:
747 if (!IO.outputting())
748 Section.reset(new ELFYAML::MipsABIFlags());
749 sectionMapping(IO, *cast(Section.get()));
750 break;
751 default:
752 if (!IO.outputting())
753 Section.reset(new ELFYAML::RawContentSection());
754 sectionMapping(IO, *cast(Section.get()));
755 }
756 }
757
758 StringRef MappingTraits>::validate(
759 IO &io, std::unique_ptr &Section) {
760 const auto *RawSection = dyn_cast(Section.get());
761 if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
762 return StringRef();
763 return "Section size must be greater or equal to the content size";
764 }
765
766 namespace {
767 struct NormalizedMips64RelType {
768 NormalizedMips64RelType(IO &)
769 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
770 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
771 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
772 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
773 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
774 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
775 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
776
777 ELFYAML::ELF_REL denormalize(IO &) {
778 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
779 return Res;
780 }
781
782 ELFYAML::ELF_REL Type;
783 ELFYAML::ELF_REL Type2;
784 ELFYAML::ELF_REL Type3;
785 ELFYAML::ELF_RSS SpecSym;
786 };
787 }
788
789 void MappingTraits::mapping(IO &IO,
790 ELFYAML::Relocation &Rel) {
791 const auto *Object = static_cast(IO.getContext());
792 assert(Object && "The IO context is not initialized");
793
794 IO.mapRequired("Offset", Rel.Offset);
795 IO.mapRequired("Symbol", Rel.Symbol);
796
797 if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
798 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
799 MappingNormalization Key(
800 IO, Rel.Type);
801 IO.mapRequired("Type", Key->Type);
802 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
803 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
804 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
805 } else
806 IO.mapRequired("Type", Rel.Type);
807
808 IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
809 }
810
811 void MappingTraits::mapping(IO &IO, ELFYAML::Object &Object) {
812 assert(!IO.getContext() && "The IO context is initialized already");
813 IO.setContext(&Object);
814 IO.mapRequired("FileHeader", Object.Header);
815 IO.mapOptional("Sections", Object.Sections);
816 IO.mapOptional("Symbols", Object.Symbols);
817 IO.setContext(nullptr);
818 }
819
820 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
821 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
822 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
823 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
824 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
825
826 } // end namespace yaml
827 } // end namespace llvm
0 add_llvm_library(LLVMObjectYAML
1 YAML.cpp
2 COFFYAML.cpp
3 ELFYAML.cpp
4 )
0 //===- COFFYAML.cpp - COFF YAMLIO implementation --------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of COFF.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ObjectYAML/COFFYAML.h"
14
15 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
16 namespace llvm {
17
18 namespace COFFYAML {
19 Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
20 Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
21 Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
22 }
23
24 namespace yaml {
25 void ScalarEnumerationTraits::enumeration(
26 IO &IO, COFFYAML::COMDATType &Value) {
27 IO.enumCase(Value, "0", 0);
28 ECase(IMAGE_COMDAT_SELECT_NODUPLICATES);
29 ECase(IMAGE_COMDAT_SELECT_ANY);
30 ECase(IMAGE_COMDAT_SELECT_SAME_SIZE);
31 ECase(IMAGE_COMDAT_SELECT_EXACT_MATCH);
32 ECase(IMAGE_COMDAT_SELECT_ASSOCIATIVE);
33 ECase(IMAGE_COMDAT_SELECT_LARGEST);
34 ECase(IMAGE_COMDAT_SELECT_NEWEST);
35 }
36
37 void
38 ScalarEnumerationTraits::enumeration(
39 IO &IO, COFFYAML::WeakExternalCharacteristics &Value) {
40 IO.enumCase(Value, "0", 0);
41 ECase(IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
42 ECase(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
43 ECase(IMAGE_WEAK_EXTERN_SEARCH_ALIAS);
44 }
45
46 void ScalarEnumerationTraits::enumeration(
47 IO &IO, COFFYAML::AuxSymbolType &Value) {
48 ECase(IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF);
49 }
50
51 void ScalarEnumerationTraits::enumeration(
52 IO &IO, COFF::MachineTypes &Value) {
53 ECase(IMAGE_FILE_MACHINE_UNKNOWN);
54 ECase(IMAGE_FILE_MACHINE_AM33);
55 ECase(IMAGE_FILE_MACHINE_AMD64);
56 ECase(IMAGE_FILE_MACHINE_ARM);
57 ECase(IMAGE_FILE_MACHINE_ARMNT);
58 ECase(IMAGE_FILE_MACHINE_ARM64);
59 ECase(IMAGE_FILE_MACHINE_EBC);
60 ECase(IMAGE_FILE_MACHINE_I386);
61 ECase(IMAGE_FILE_MACHINE_IA64);
62 ECase(IMAGE_FILE_MACHINE_M32R);
63 ECase(IMAGE_FILE_MACHINE_MIPS16);
64 ECase(IMAGE_FILE_MACHINE_MIPSFPU);
65 ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
66 ECase(IMAGE_FILE_MACHINE_POWERPC);
67 ECase(IMAGE_FILE_MACHINE_POWERPCFP);
68 ECase(IMAGE_FILE_MACHINE_R4000);
69 ECase(IMAGE_FILE_MACHINE_SH3);
70 ECase(IMAGE_FILE_MACHINE_SH3DSP);
71 ECase(IMAGE_FILE_MACHINE_SH4);
72 ECase(IMAGE_FILE_MACHINE_SH5);
73 ECase(IMAGE_FILE_MACHINE_THUMB);
74 ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
75 }
76
77 void ScalarEnumerationTraits::enumeration(
78 IO &IO, COFF::SymbolBaseType &Value) {
79 ECase(IMAGE_SYM_TYPE_NULL);
80 ECase(IMAGE_SYM_TYPE_VOID);
81 ECase(IMAGE_SYM_TYPE_CHAR);
82 ECase(IMAGE_SYM_TYPE_SHORT);
83 ECase(IMAGE_SYM_TYPE_INT);
84 ECase(IMAGE_SYM_TYPE_LONG);
85 ECase(IMAGE_SYM_TYPE_FLOAT);
86 ECase(IMAGE_SYM_TYPE_DOUBLE);
87 ECase(IMAGE_SYM_TYPE_STRUCT);
88 ECase(IMAGE_SYM_TYPE_UNION);
89 ECase(IMAGE_SYM_TYPE_ENUM);
90 ECase(IMAGE_SYM_TYPE_MOE);
91 ECase(IMAGE_SYM_TYPE_BYTE);
92 ECase(IMAGE_SYM_TYPE_WORD);
93 ECase(IMAGE_SYM_TYPE_UINT);
94 ECase(IMAGE_SYM_TYPE_DWORD);
95 }
96
97 void ScalarEnumerationTraits::enumeration(
98 IO &IO, COFF::SymbolStorageClass &Value) {
99 ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
100 ECase(IMAGE_SYM_CLASS_NULL);
101 ECase(IMAGE_SYM_CLASS_AUTOMATIC);
102 ECase(IMAGE_SYM_CLASS_EXTERNAL);
103 ECase(IMAGE_SYM_CLASS_STATIC);
104 ECase(IMAGE_SYM_CLASS_REGISTER);
105 ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
106 ECase(IMAGE_SYM_CLASS_LABEL);
107 ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
108 ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
109 ECase(IMAGE_SYM_CLASS_ARGUMENT);
110 ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
111 ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
112 ECase(IMAGE_SYM_CLASS_UNION_TAG);
113 ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
114 ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
115 ECase(IMAGE_SYM_CLASS_ENUM_TAG);
116 ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
117 ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
118 ECase(IMAGE_SYM_CLASS_BIT_FIELD);
119 ECase(IMAGE_SYM_CLASS_BLOCK);
120 ECase(IMAGE_SYM_CLASS_FUNCTION);
121 ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
122 ECase(IMAGE_SYM_CLASS_FILE);
123 ECase(IMAGE_SYM_CLASS_SECTION);
124 ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
125 ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
126 }
127
128 void ScalarEnumerationTraits::enumeration(
129 IO &IO, COFF::SymbolComplexType &Value) {
130 ECase(IMAGE_SYM_DTYPE_NULL);
131 ECase(IMAGE_SYM_DTYPE_POINTER);
132 ECase(IMAGE_SYM_DTYPE_FUNCTION);
133 ECase(IMAGE_SYM_DTYPE_ARRAY);
134 }
135
136 void ScalarEnumerationTraits::enumeration(
137 IO &IO, COFF::RelocationTypeI386 &Value) {
138 ECase(IMAGE_REL_I386_ABSOLUTE);
139 ECase(IMAGE_REL_I386_DIR16);
140 ECase(IMAGE_REL_I386_REL16);
141 ECase(IMAGE_REL_I386_DIR32);
142 ECase(IMAGE_REL_I386_DIR32NB);
143 ECase(IMAGE_REL_I386_SEG12);
144 ECase(IMAGE_REL_I386_SECTION);
145 ECase(IMAGE_REL_I386_SECREL);
146 ECase(IMAGE_REL_I386_TOKEN);
147 ECase(IMAGE_REL_I386_SECREL7);
148 ECase(IMAGE_REL_I386_REL32);
149 }
150
151 void ScalarEnumerationTraits::enumeration(
152 IO &IO, COFF::RelocationTypeAMD64 &Value) {
153 ECase(IMAGE_REL_AMD64_ABSOLUTE);
154 ECase(IMAGE_REL_AMD64_ADDR64);
155 ECase(IMAGE_REL_AMD64_ADDR32);
156 ECase(IMAGE_REL_AMD64_ADDR32NB);
157 ECase(IMAGE_REL_AMD64_REL32);
158 ECase(IMAGE_REL_AMD64_REL32_1);
159 ECase(IMAGE_REL_AMD64_REL32_2);
160 ECase(IMAGE_REL_AMD64_REL32_3);
161 ECase(IMAGE_REL_AMD64_REL32_4);
162 ECase(IMAGE_REL_AMD64_REL32_5);
163 ECase(IMAGE_REL_AMD64_SECTION);
164 ECase(IMAGE_REL_AMD64_SECREL);
165 ECase(IMAGE_REL_AMD64_SECREL7);
166 ECase(IMAGE_REL_AMD64_TOKEN);
167 ECase(IMAGE_REL_AMD64_SREL32);
168 ECase(IMAGE_REL_AMD64_PAIR);
169 ECase(IMAGE_REL_AMD64_SSPAN32);
170 }
171
172 void ScalarEnumerationTraits::enumeration(
173 IO &IO, COFF::WindowsSubsystem &Value) {
174 ECase(IMAGE_SUBSYSTEM_UNKNOWN);
175 ECase(IMAGE_SUBSYSTEM_NATIVE);
176 ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
177 ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
178 ECase(IMAGE_SUBSYSTEM_OS2_CUI);
179 ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
180 ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
181 ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
182 ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
183 ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
184 ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
185 ECase(IMAGE_SUBSYSTEM_EFI_ROM);
186 ECase(IMAGE_SUBSYSTEM_XBOX);
187 ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
188 }
189 #undef ECase
190
191 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
192 void ScalarBitSetTraits::bitset(
193 IO &IO, COFF::Characteristics &Value) {
194 BCase(IMAGE_FILE_RELOCS_STRIPPED);
195 BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
196 BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
197 BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
198 BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
199 BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
200 BCase(IMAGE_FILE_BYTES_REVERSED_LO);
201 BCase(IMAGE_FILE_32BIT_MACHINE);
202 BCase(IMAGE_FILE_DEBUG_STRIPPED);
203 BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
204 BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
205 BCase(IMAGE_FILE_SYSTEM);
206 BCase(IMAGE_FILE_DLL);
207 BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
208 BCase(IMAGE_FILE_BYTES_REVERSED_HI);
209 }
210
211 void ScalarBitSetTraits::bitset(
212 IO &IO, COFF::SectionCharacteristics &Value) {
213 BCase(IMAGE_SCN_TYPE_NOLOAD);
214 BCase(IMAGE_SCN_TYPE_NO_PAD);
215 BCase(IMAGE_SCN_CNT_CODE);
216 BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
217 BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
218 BCase(IMAGE_SCN_LNK_OTHER);
219 BCase(IMAGE_SCN_LNK_INFO);
220 BCase(IMAGE_SCN_LNK_REMOVE);
221 BCase(IMAGE_SCN_LNK_COMDAT);
222 BCase(IMAGE_SCN_GPREL);
223 BCase(IMAGE_SCN_MEM_PURGEABLE);
224 BCase(IMAGE_SCN_MEM_16BIT);
225 BCase(IMAGE_SCN_MEM_LOCKED);
226 BCase(IMAGE_SCN_MEM_PRELOAD);
227 BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
228 BCase(IMAGE_SCN_MEM_DISCARDABLE);
229 BCase(IMAGE_SCN_MEM_NOT_CACHED);
230 BCase(IMAGE_SCN_MEM_NOT_PAGED);
231 BCase(IMAGE_SCN_MEM_SHARED);
232 BCase(IMAGE_SCN_MEM_EXECUTE);
233 BCase(IMAGE_SCN_MEM_READ);
234 BCase(IMAGE_SCN_MEM_WRITE);
235 }
236
237 void ScalarBitSetTraits::bitset(
238 IO &IO, COFF::DLLCharacteristics &Value) {
239 BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA);
240 BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);
241 BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY);
242 BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
243 BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION);
244 BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH);
245 BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND);
246 BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER);
247 BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER);
248 BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF);
249 BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE);
250 }
251 #undef BCase
252
253 namespace {
254 struct NSectionSelectionType {
255 NSectionSelectionType(IO &)
256 : SelectionType(COFFYAML::COMDATType(0)) {}
257 NSectionSelectionType(IO &, uint8_t C)
258 : SelectionType(COFFYAML::COMDATType(C)) {}
259 uint8_t denormalize(IO &) { return SelectionType; }
260 COFFYAML::COMDATType SelectionType;
261 };
262
263 struct NWeakExternalCharacteristics {
264 NWeakExternalCharacteristics(IO &)
265 : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
266 NWeakExternalCharacteristics(IO &, uint32_t C)
267 : Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
268 uint32_t denormalize(IO &) { return Characteristics; }
269 COFFYAML::WeakExternalCharacteristics Characteristics;
270 };
271
272 struct NSectionCharacteristics {
273 NSectionCharacteristics(IO &)
274 : Characteristics(COFF::SectionCharacteristics(0)) {}
275 NSectionCharacteristics(IO &, uint32_t C)
276 : Characteristics(COFF::SectionCharacteristics(C)) {}
277 uint32_t denormalize(IO &) { return Characteristics; }
278 COFF::SectionCharacteristics Characteristics;
279 };
280
281 struct NAuxTokenType {
282 NAuxTokenType(IO &)
283 : AuxType(COFFYAML::AuxSymbolType(0)) {}
284 NAuxTokenType(IO &, uint8_t C)
285 : AuxType(COFFYAML::AuxSymbolType(C)) {}
286 uint32_t denormalize(IO &) { return AuxType; }
287 COFFYAML::AuxSymbolType AuxType;
288 };
289
290 struct NStorageClass {
291 NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
292 NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
293 uint8_t denormalize(IO &) { return StorageClass; }
294
295 COFF::SymbolStorageClass StorageClass;
296 };
297
298 struct NMachine {
299 NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
300 NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
301 uint16_t denormalize(IO &) { return Machine; }
302 COFF::MachineTypes Machine;
303 };
304
305 struct NHeaderCharacteristics {
306 NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
307 NHeaderCharacteristics(IO &, uint16_t C)
308 : Characteristics(COFF::Characteristics(C)) {}
309 uint16_t denormalize(IO &) { return Characteristics; }
310
311 COFF::Characteristics Characteristics;
312 };
313
314 template
315 struct NType {
316 NType(IO &) : Type(RelocType(0)) {}
317 NType(IO &, uint16_t T) : Type(RelocType(T)) {}
318 uint16_t denormalize(IO &) { return Type; }
319 RelocType Type;
320 };
321
322 struct NWindowsSubsystem {
323 NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
324 NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
325 uint16_t denormalize(IO &) { return Subsystem; }
326
327 COFF::WindowsSubsystem Subsystem;
328 };
329
330 struct NDLLCharacteristics {
331 NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
332 NDLLCharacteristics(IO &, uint16_t C)
333 : Characteristics(COFF::DLLCharacteristics(C)) {}
334 uint16_t denormalize(IO &) { return Characteristics; }
335
336 COFF::DLLCharacteristics Characteristics;
337 };
338
339 }
340
341 void MappingTraits::mapping(IO &IO,
342 COFFYAML::Relocation &Rel) {
343 IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
344 IO.mapRequired("SymbolName", Rel.SymbolName);
345
346 COFF::header &H = *static_cast(IO.getContext());
347 if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
348 MappingNormalization, uint16_t> NT(
349 IO, Rel.Type);
350 IO.mapRequired("Type", NT->Type);
351 } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
352 MappingNormalization, uint16_t> NT(
353 IO, Rel.Type);
354 IO.mapRequired("Type", NT->Type);
355 } else {
356 IO.mapRequired("Type", Rel.Type);
357 }
358 }
359
360 void MappingTraits::mapping(IO &IO,
361 COFF::DataDirectory &DD) {
362 IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
363 IO.mapRequired("Size", DD.Size);
364 }
365
366 void MappingTraits::mapping(IO &IO,
367 COFFYAML::PEHeader &PH) {
368 MappingNormalization NWS(IO,
369 PH.Header.Subsystem);
370 MappingNormalization NDC(
371 IO, PH.Header.DLLCharacteristics);
372
373 IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
374 IO.mapRequired("ImageBase", PH.Header.ImageBase);
375 IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
376 IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
377 IO.mapRequired("MajorOperatingSystemVersion",
378 PH.Header.MajorOperatingSystemVersion);
379 IO.mapRequired("MinorOperatingSystemVersion",
380 PH.Header.MinorOperatingSystemVersion);
381 IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
382 IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
383 IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
384 IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
385 IO.mapRequired("Subsystem", NWS->Subsystem);
386 IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
387 IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
388 IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
389 IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
390 IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
391
392 IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
393 IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
394 IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
395 IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
396 IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
397 IO.mapOptional("BaseRelocationTable",
398 PH.DataDirectories[COFF::BASE_RELOCATION_TABLE]);
399 IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG]);
400 IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
401 IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
402 IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
403 IO.mapOptional("LoadConfigTable",
404 PH.DataDirectories[COFF::LOAD_CONFIG_TABLE]);
405 IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
406 IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
407 IO.mapOptional("DelayImportDescriptor",
408 PH.DataDirectories[COFF::DELAY_IMPORT_DESCRIPTOR]);
409 IO.mapOptional("ClrRuntimeHeader",
410 PH.DataDirectories[COFF::CLR_RUNTIME_HEADER]);
411 }
412
413 void MappingTraits::mapping(IO &IO, COFF::header &H) {
414 MappingNormalization NM(IO, H.Machine);
415 MappingNormalization NC(IO,
416 H.Characteristics);
417
418 IO.mapRequired("Machine", NM->Machine);
419 IO.mapOptional("Characteristics", NC->Characteristics);
420 IO.setContext(static_cast(&H));
421 }
422
423 void MappingTraits::mapping(
424 IO &IO, COFF::AuxiliaryFunctionDefinition &AFD) {
425 IO.mapRequired("TagIndex", AFD.TagIndex);
426 IO.mapRequired("TotalSize", AFD.TotalSize);
427 IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
428 IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
429 }
430
431 void MappingTraits::mapping(
432 IO &IO, COFF::AuxiliarybfAndefSymbol &AAS) {
433 IO.mapRequired("Linenumber", AAS.Linenumber);
434 IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
435 }
436
437 void MappingTraits::mapping(
438 IO &IO, COFF::AuxiliaryWeakExternal &AWE) {
439 MappingNormalization NWEC(
440 IO, AWE.Characteristics);
441 IO.mapRequired("TagIndex", AWE.TagIndex);
442 IO.mapRequired("Characteristics", NWEC->Characteristics);
443 }
444
445 void MappingTraits::mapping(
446 IO &IO, COFF::AuxiliarySectionDefinition &ASD) {
447 MappingNormalization NSST(
448 IO, ASD.Selection);
449
450 IO.mapRequired("Length", ASD.Length);
451 IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
452 IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
453 IO.mapRequired("CheckSum", ASD.CheckSum);
454 IO.mapRequired("Number", ASD.Number);
455 IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
456 }
457
458 void MappingTraits::mapping(
459 IO &IO, COFF::AuxiliaryCLRToken &ACT) {
460 MappingNormalization NATT(IO, ACT.AuxType);
461 IO.mapRequired("AuxType", NATT->AuxType);
462 IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
463 }
464
465 void MappingTraits::mapping(IO &IO, COFFYAML::Symbol &S) {
466 MappingNormalization NS(IO, S.Header.StorageClass);
467
468 IO.mapRequired("Name", S.Name);
469 IO.mapRequired("Value", S.Header.Value);
470 IO.mapRequired("SectionNumber", S.Header.SectionNumber);
471 IO.mapRequired("SimpleType", S.SimpleType);
472 IO.mapRequired("ComplexType", S.ComplexType);
473 IO.mapRequired("StorageClass", NS->StorageClass);
474 IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
475 IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
476 IO.mapOptional("WeakExternal", S.WeakExternal);
477 IO.mapOptional("File", S.File, StringRef());
478 IO.mapOptional("SectionDefinition", S.SectionDefinition);
479 IO.mapOptional("CLRToken", S.CLRToken);
480 }
481
482 void MappingTraits::mapping(IO &IO, COFFYAML::Section &Sec) {
483 MappingNormalization NC(
484 IO, Sec.Header.Characteristics);
485 IO.mapRequired("Name", Sec.Name);
486 IO.mapRequired("Characteristics", NC->Characteristics);
487 IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
488 IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
489 IO.mapOptional("Alignment", Sec.Alignment);
490 IO.mapRequired("SectionData", Sec.SectionData);
491 IO.mapOptional("Relocations", Sec.Relocations);
492 }
493
494 void MappingTraits::mapping(IO &IO, COFFYAML::Object &Obj) {
495 IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
496 IO.mapRequired("header", Obj.Header);
497 IO.mapRequired("sections", Obj.Sections);
498 IO.mapRequired("symbols", Obj.Symbols);
499 }
500
501 }
502 }
0 //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of ELF.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ObjectYAML/ELFYAML.h"
14 #include "llvm/Support/Casting.h"
15 #include "llvm/Support/MipsABIFlags.h"
16
17 namespace llvm {
18
19 ELFYAML::Section::~Section() {}
20
21 namespace yaml {
22
23 void
24 ScalarEnumerationTraits::enumeration(IO &IO,
25 ELFYAML::ELF_ET &Value) {
26 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
27 ECase(ET_NONE)
28 ECase(ET_REL)
29 ECase(ET_EXEC)
30 ECase(ET_DYN)
31 ECase(ET_CORE)
32 #undef ECase
33 IO.enumFallback(Value);
34 }
35
36 void
37 ScalarEnumerationTraits::enumeration(IO &IO,
38 ELFYAML::ELF_EM &Value) {
39 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
40 ECase(EM_NONE)
41 ECase(EM_M32)
42 ECase(EM_SPARC)
43 ECase(EM_386)
44 ECase(EM_68K)
45 ECase(EM_88K)
46 ECase(EM_IAMCU)
47 ECase(EM_860)
48 ECase(EM_MIPS)
49 ECase(EM_S370)
50 ECase(EM_MIPS_RS3_LE)
51 ECase(EM_PARISC)
52 ECase(EM_VPP500)
53 ECase(EM_SPARC32PLUS)
54 ECase(EM_960)
55 ECase(EM_PPC)
56 ECase(EM_PPC64)
57 ECase(EM_S390)
58 ECase(EM_SPU)
59 ECase(EM_V800)
60 ECase(EM_FR20)
61 ECase(EM_RH32)
62 ECase(EM_RCE)
63 ECase(EM_ARM)
64 ECase(EM_ALPHA)
65 ECase(EM_SH)
66 ECase(EM_SPARCV9)
67 ECase(EM_TRICORE)
68 ECase(EM_ARC)
69 ECase(EM_H8_300)
70 ECase(EM_H8_300H)
71 ECase(EM_H8S)
72 ECase(EM_H8_500)
73 ECase(EM_IA_64)
74 ECase(EM_MIPS_X)
75 ECase(EM_COLDFIRE)
76 ECase(EM_68HC12)
77 ECase(EM_MMA)
78 ECase(EM_PCP)
79 ECase(EM_NCPU)
80 ECase(EM_NDR1)
81 ECase(EM_STARCORE)
82 ECase(EM_ME16)
83 ECase(EM_ST100)
84 ECase(EM_TINYJ)
85 ECase(EM_X86_64)
86 ECase(EM_PDSP)
87 ECase(EM_PDP10)
88 ECase(EM_PDP11)
89 ECase(EM_FX66)
90 ECase(EM_ST9PLUS)
91 ECase(EM_ST7)
92 ECase(EM_68HC16)
93 ECase(EM_68HC11)
94 ECase(EM_68HC08)
95 ECase(EM_68HC05)
96 ECase(EM_SVX)
97 ECase(EM_ST19)
98 ECase(EM_VAX)
99 ECase(EM_CRIS)
100 ECase(EM_JAVELIN)
101 ECase(EM_FIREPATH)
102 ECase(EM_ZSP)
103 ECase(EM_MMIX)
104 ECase(EM_HUANY)
105 ECase(EM_PRISM)
106 ECase(EM_AVR)
107 ECase(EM_FR30)
108 ECase(EM_D10V)
109 ECase(EM_D30V)
110 ECase(EM_V850)
111 ECase(EM_M32R)
112 ECase(EM_MN10300)
113 ECase(EM_MN10200)
114 ECase(EM_PJ)
115 ECase(EM_OPENRISC)
116 ECase(EM_ARC_COMPACT)
117 ECase(EM_XTENSA)
118 ECase(EM_VIDEOCORE)
119 ECase(EM_TMM_GPP)
120 ECase(EM_NS32K)
121 ECase(EM_TPC)
122 ECase(EM_SNP1K)
123 ECase(EM_ST200)
124 ECase(EM_IP2K)
125 ECase(EM_MAX)
126 ECase(EM_CR)
127 ECase(EM_F2MC16)
128 ECase(EM_MSP430)
129 ECase(EM_BLACKFIN)
130 ECase(EM_SE_C33)
131 ECase(EM_SEP)
132 ECase(EM_ARCA)
133 ECase(EM_UNICORE)
134 ECase(EM_EXCESS)
135 ECase(EM_DXP)
136 ECase(EM_ALTERA_NIOS2)
137 ECase(EM_CRX)
138 ECase(EM_XGATE)
139 ECase(EM_C166)
140 ECase(EM_M16C)
141 ECase(EM_DSPIC30F)
142 ECase(EM_CE)
143 ECase(EM_M32C)
144 ECase(EM_TSK3000)
145 ECase(EM_RS08)
146 ECase(EM_SHARC)
147 ECase(EM_ECOG2)
148 ECase(EM_SCORE7)
149 ECase(EM_DSP24)
150 ECase(EM_VIDEOCORE3)
151 ECase(EM_LATTICEMICO32)
152 ECase(EM_SE_C17)
153 ECase(EM_TI_C6000)
154 ECase(EM_TI_C2000)
155 ECase(EM_TI_C5500)
156 ECase(EM_MMDSP_PLUS)
157 ECase(EM_CYPRESS_M8C)
158 ECase(EM_R32C)
159 ECase(EM_TRIMEDIA)
160 ECase(EM_HEXAGON)
161 ECase(EM_8051)
162 ECase(EM_STXP7X)
163 ECase(EM_NDS32)
164 ECase(EM_ECOG1)
165 ECase(EM_ECOG1X)
166 ECase(EM_MAXQ30)
167 ECase(EM_XIMO16)
168 ECase(EM_MANIK)
169 ECase(EM_CRAYNV2)
170 ECase(EM_RX)
171 ECase(EM_METAG)
172 ECase(EM_MCST_ELBRUS)
173 ECase(EM_ECOG16)
174 ECase(EM_CR16)
175 ECase(EM_ETPU)
176 ECase(EM_SLE9X)
177 ECase(EM_L10M)
178 ECase(EM_K10M)
179 ECase(EM_AARCH64)
180 ECase(EM_AVR32)
181 ECase(EM_STM8)
182 ECase(EM_TILE64)
183 ECase(EM_TILEPRO)
184 ECase(EM_CUDA)
185 ECase(EM_TILEGX)
186 ECase(EM_CLOUDSHIELD)
187 ECase(EM_COREA_1ST)
188 ECase(EM_COREA_2ND)
189 ECase(EM_ARC_COMPACT2)
190 ECase(EM_OPEN8)
191 ECase(EM_RL78)
192 ECase(EM_VIDEOCORE5)
193 ECase(EM_78KOR)
194 ECase(EM_56800EX)
195 ECase(EM_AMDGPU)
196 #undef ECase
197 }
198
199 void ScalarEnumerationTraits::enumeration(
200 IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
201 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
202 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
203 // here.
204 ECase(ELFCLASS32)
205 ECase(ELFCLASS64)
206 #undef ECase
207 }
208
209 void ScalarEnumerationTraits::enumeration(
210 IO &IO, ELFYAML::ELF_ELFDATA &Value) {
211 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
212 // Since the semantics of ELFDATANONE is "invalid", just don't accept it
213 // here.
214 ECase(ELFDATA2LSB)
215 ECase(ELFDATA2MSB)
216 #undef ECase
217 }
218
219 void ScalarEnumerationTraits::enumeration(
220 IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
221 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
222 ECase(ELFOSABI_NONE)
223 ECase(ELFOSABI_HPUX)
224 ECase(ELFOSABI_NETBSD)
225 ECase(ELFOSABI_GNU)
226 ECase(ELFOSABI_GNU)
227 ECase(ELFOSABI_HURD)
228 ECase(ELFOSABI_SOLARIS)
229 ECase(ELFOSABI_AIX)
230 ECase(ELFOSABI_IRIX)
231 ECase(ELFOSABI_FREEBSD)
232 ECase(ELFOSABI_TRU64)
233 ECase(ELFOSABI_MODESTO)
234 ECase(ELFOSABI_OPENBSD)
235 ECase(ELFOSABI_OPENVMS)
236 ECase(ELFOSABI_NSK)
237 ECase(ELFOSABI_AROS)
238 ECase(ELFOSABI_FENIXOS)
239 ECase(ELFOSABI_CLOUDABI)
240 ECase(ELFOSABI_C6000_ELFABI)
241 ECase(ELFOSABI_C6000_LINUX)
242 ECase(ELFOSABI_ARM)
243 ECase(ELFOSABI_STANDALONE)
244 #undef ECase
245 }
246
247 void ScalarBitSetTraits::bitset(IO &IO,
248 ELFYAML::ELF_EF &Value) {
249 const auto *Object = static_cast(IO.getContext());
250 assert(Object && "The IO context is not initialized");
251 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
252 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M);
253 switch (Object->Header.Machine) {
254 case ELF::EM_ARM:
255 BCase(EF_ARM_SOFT_FLOAT)
256 BCase(EF_ARM_VFP_FLOAT)
257 BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK)
258 BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK)
259 BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK)
260 BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK)
261 BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK)
262 BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK)
263 break;
264 case ELF::EM_MIPS:
265 BCase(EF_MIPS_NOREORDER)
266 BCase(EF_MIPS_PIC)
267 BCase(EF_MIPS_CPIC)
268 BCase(EF_MIPS_ABI2)
269 BCase(EF_MIPS_32BITMODE)
270 BCase(EF_MIPS_FP64)
271 BCase(EF_MIPS_NAN2008)
272 BCase(EF_MIPS_MICROMIPS)
273 BCase(EF_MIPS_ARCH_ASE_M16)
274 BCase(EF_MIPS_ARCH_ASE_MDMX)
275 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI)
276 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI)
277 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI)
278 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI)
279 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH)
280 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH)
281 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH)
282 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH)
283 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH)
284 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH)
285 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH)
286 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH)
287 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH)
288 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH)
289 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH)
290 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH)
291 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH)
292 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH)
293 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH)
294 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH)
295 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH)
296 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH)
297 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH)
298 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH)
299 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH)
300 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH)
301 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH)
302 BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH)
303 BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH)
304 BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH)
305 BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH)
306 BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH)
307 BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH)
308 break;
309 case ELF::EM_HEXAGON:
310 BCase(EF_HEXAGON_MACH_V2)
311 BCase(EF_HEXAGON_MACH_V3)
312 BCase(EF_HEXAGON_MACH_V4)
313 BCase(EF_HEXAGON_MACH_V5)
314 BCase(EF_HEXAGON_ISA_V2)
315 BCase(EF_HEXAGON_ISA_V3)
316 BCase(EF_HEXAGON_ISA_V4)
317 BCase(EF_HEXAGON_ISA_V5)
318 break;
319 case ELF::EM_AVR:
320 BCase(EF_AVR_ARCH_AVR1)
321 BCase(EF_AVR_ARCH_AVR2)
322 BCase(EF_AVR_ARCH_AVR25)
323 BCase(EF_AVR_ARCH_AVR3)
324 BCase(EF_AVR_ARCH_AVR31)
325 BCase(EF_AVR_ARCH_AVR35)
326 BCase(EF_AVR_ARCH_AVR4)
327 BCase(EF_AVR_ARCH_AVR51)
328 BCase(EF_AVR_ARCH_AVR6)
329 BCase(EF_AVR_ARCH_AVRTINY)
330 BCase(EF_AVR_ARCH_XMEGA1)
331 BCase(EF_AVR_ARCH_XMEGA2)
332 BCase(EF_AVR_ARCH_XMEGA3)
333 BCase(EF_AVR_ARCH_XMEGA4)
334 BCase(EF_AVR_ARCH_XMEGA5)
335 BCase(EF_AVR_ARCH_XMEGA6)
336 BCase(EF_AVR_ARCH_XMEGA7)
337 break;
338 case ELF::EM_AMDGPU:
339 case ELF::EM_X86_64:
340 break;
341 default:
342 llvm_unreachable("Unsupported architecture");
343 }
344 #undef BCase
345 #undef BCaseMask
346 }
347
348 void ScalarEnumerationTraits::enumeration(
349 IO &IO, ELFYAML::ELF_SHT &Value) {
350 const auto *Object = static_cast(IO.getContext());
351 assert(Object && "The IO context is not initialized");
352 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
353 ECase(SHT_NULL)
354 ECase(SHT_PROGBITS)
355 // No SHT_SYMTAB. Use the top-level `Symbols` key instead.
356 // FIXME: Issue a diagnostic with this information.
357 ECase(SHT_STRTAB)
358 ECase(SHT_RELA)
359 ECase(SHT_HASH)
360 ECase(SHT_DYNAMIC)
361 ECase(SHT_NOTE)
362 ECase(SHT_NOBITS)
363 ECase(SHT_REL)
364 ECase(SHT_SHLIB)
365 ECase(SHT_DYNSYM)
366 ECase(SHT_INIT_ARRAY)
367 ECase(SHT_FINI_ARRAY)
368 ECase(SHT_PREINIT_ARRAY)
369 ECase(SHT_GROUP)
370 ECase(SHT_SYMTAB_SHNDX)
371 ECase(SHT_LOOS)
372 ECase(SHT_GNU_ATTRIBUTES)
373 ECase(SHT_GNU_HASH)
374 ECase(SHT_GNU_verdef)
375 ECase(SHT_GNU_verneed)
376 ECase(SHT_GNU_versym)
377 ECase(SHT_HIOS)
378 ECase(SHT_LOPROC)
379 switch (Object->Header.Machine) {
380 case ELF::EM_ARM:
381 ECase(SHT_ARM_EXIDX)
382 ECase(SHT_ARM_PREEMPTMAP)
383 ECase(SHT_ARM_ATTRIBUTES)
384 ECase(SHT_ARM_DEBUGOVERLAY)
385 ECase(SHT_ARM_OVERLAYSECTION)
386 break;
387 case ELF::EM_HEXAGON:
388 ECase(SHT_HEX_ORDERED)
389 break;
390 case ELF::EM_X86_64:
391 ECase(SHT_X86_64_UNWIND)
392 break;
393 case ELF::EM_MIPS:
394 ECase(SHT_MIPS_REGINFO)
395 ECase(SHT_MIPS_OPTIONS)
396 ECase(SHT_MIPS_ABIFLAGS)
397 break;
398 default:
399 // Nothing to do.
400 break;
401 }
402 #undef ECase
403 }
404
405 void ScalarBitSetTraits::bitset(IO &IO,
406 ELFYAML::ELF_SHF &Value) {
407 const auto *Object = static_cast(IO.getContext());
408 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
409 BCase(SHF_WRITE)
410 BCase(SHF_ALLOC)
411 BCase(SHF_EXCLUDE)
412 BCase(SHF_EXECINSTR)
413 BCase(SHF_MERGE)
414 BCase(SHF_STRINGS)
415 BCase(SHF_INFO_LINK)
416 BCase(SHF_LINK_ORDER)
417 BCase(SHF_OS_NONCONFORMING)
418 BCase(SHF_GROUP)
419 BCase(SHF_TLS)
420 switch(Object->Header.Machine) {
421 case ELF::EM_AMDGPU:
422 BCase(SHF_AMDGPU_HSA_GLOBAL)
423 BCase(SHF_AMDGPU_HSA_READONLY)
424 BCase(SHF_AMDGPU_HSA_CODE)
425 BCase(SHF_AMDGPU_HSA_AGENT)
426 break;
427 case ELF::EM_HEXAGON:
428 BCase(SHF_HEX_GPREL)
429 break;
430 case ELF::EM_MIPS:
431 BCase(SHF_MIPS_NODUPES)
432 BCase(SHF_MIPS_NAMES)