[MIPS GlobalISel] Select MSA vector generic and builtin add
[llvm-complete.git] / include / llvm / ObjectYAML / ELFYAML.h
blob0898a0e7d5324698f7b8b0efd2787d56328ee45d
1 //===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file declares classes for handling the YAML representation
11 /// of ELF.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_OBJECTYAML_ELFYAML_H
16 #define LLVM_OBJECTYAML_ELFYAML_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ObjectYAML/YAML.h"
20 #include "llvm/Support/YAMLTraits.h"
21 #include <cstdint>
22 #include <memory>
23 #include <vector>
25 namespace llvm {
26 namespace ELFYAML {
28 StringRef dropUniqueSuffix(StringRef S);
30 // These types are invariant across 32/64-bit ELF, so for simplicity just
31 // directly give them their exact sizes. We don't need to worry about
32 // endianness because these are just the types in the YAMLIO structures,
33 // and are appropriately converted to the necessary endianness when
34 // reading/generating binary object files.
35 // The naming of these types is intended to be ELF_PREFIX, where PREFIX is
36 // the common prefix of the respective constants. E.g. ELF_EM corresponds
37 // to the `e_machine` constants, like `EM_X86_64`.
38 // In the future, these would probably be better suited by C++11 enum
39 // class's with appropriate fixed underlying type.
40 LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET)
41 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PT)
42 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM)
43 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS)
44 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
45 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
46 // Just use 64, since it can hold 32-bit values too.
47 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
48 // Just use 64, since it can hold 32-bit values too.
49 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_DYNTAG)
50 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PF)
51 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
52 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL)
53 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)
54 // Just use 64, since it can hold 32-bit values too.
55 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
56 LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN)
57 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB)
58 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
60 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
61 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
62 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
63 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
64 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
65 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_ISA)
67 // For now, hardcode 64 bits everywhere that 32 or 64 would be needed
68 // since 64-bit can hold 32-bit values too.
69 struct FileHeader {
70 ELF_ELFCLASS Class;
71 ELF_ELFDATA Data;
72 ELF_ELFOSABI OSABI;
73 llvm::yaml::Hex8 ABIVersion;
74 ELF_ET Type;
75 ELF_EM Machine;
76 ELF_EF Flags;
77 llvm::yaml::Hex64 Entry;
79 Optional<llvm::yaml::Hex16> SHEntSize;
80 Optional<llvm::yaml::Hex64> SHOff;
81 Optional<llvm::yaml::Hex16> SHNum;
82 Optional<llvm::yaml::Hex16> SHStrNdx;
85 struct SectionName {
86 StringRef Section;
89 struct ProgramHeader {
90 ELF_PT Type;
91 ELF_PF Flags;
92 llvm::yaml::Hex64 VAddr;
93 llvm::yaml::Hex64 PAddr;
94 Optional<llvm::yaml::Hex64> Align;
95 Optional<llvm::yaml::Hex64> FileSize;
96 Optional<llvm::yaml::Hex64> MemSize;
97 Optional<llvm::yaml::Hex64> Offset;
98 std::vector<SectionName> Sections;
101 struct Symbol {
102 StringRef Name;
103 Optional<uint32_t> NameIndex;
104 ELF_STT Type;
105 StringRef Section;
106 Optional<ELF_SHN> Index;
107 ELF_STB Binding;
108 llvm::yaml::Hex64 Value;
109 llvm::yaml::Hex64 Size;
110 Optional<uint8_t> Other;
113 struct SectionOrType {
114 StringRef sectionNameOrType;
117 struct DynamicEntry {
118 ELF_DYNTAG Tag;
119 llvm::yaml::Hex64 Val;
122 struct StackSizeEntry {
123 llvm::yaml::Hex64 Address;
124 llvm::yaml::Hex64 Size;
127 struct Section {
128 enum class SectionKind {
129 Dynamic,
130 Group,
131 RawContent,
132 Relocation,
133 NoBits,
134 Hash,
135 Verdef,
136 Verneed,
137 StackSizes,
138 SymtabShndxSection,
139 Symver,
140 MipsABIFlags,
141 Addrsig
143 SectionKind Kind;
144 StringRef Name;
145 ELF_SHT Type;
146 Optional<ELF_SHF> Flags;
147 llvm::yaml::Hex64 Address;
148 StringRef Link;
149 llvm::yaml::Hex64 AddressAlign;
150 Optional<llvm::yaml::Hex64> EntSize;
152 // Usually sections are not created implicitly, but loaded from YAML.
153 // When they are, this flag is used to signal about that.
154 bool IsImplicit;
156 Section(SectionKind Kind, bool IsImplicit = false)
157 : Kind(Kind), IsImplicit(IsImplicit) {}
158 virtual ~Section();
160 // The following members are used to override section fields which is
161 // useful for creating invalid objects.
163 // This can be used to override the offset stored in the sh_name field.
164 // It does not affect the name stored in the string table.
165 Optional<llvm::yaml::Hex64> ShName;
167 // This can be used to override the sh_offset field. It does not place the
168 // section data at the offset specified.
169 Optional<llvm::yaml::Hex64> ShOffset;
171 // This can be used to override the sh_size field. It does not affect the
172 // content written.
173 Optional<llvm::yaml::Hex64> ShSize;
176 struct StackSizesSection : Section {
177 Optional<yaml::BinaryRef> Content;
178 Optional<llvm::yaml::Hex64> Size;
179 Optional<std::vector<StackSizeEntry>> Entries;
181 StackSizesSection() : Section(SectionKind::StackSizes) {}
183 static bool classof(const Section *S) {
184 return S->Kind == SectionKind::StackSizes;
187 static bool nameMatches(StringRef Name) {
188 return Name == ".stack_sizes";
192 struct DynamicSection : Section {
193 std::vector<DynamicEntry> Entries;
194 Optional<yaml::BinaryRef> Content;
196 DynamicSection() : Section(SectionKind::Dynamic) {}
198 static bool classof(const Section *S) {
199 return S->Kind == SectionKind::Dynamic;
203 struct RawContentSection : Section {
204 Optional<yaml::BinaryRef> Content;
205 Optional<llvm::yaml::Hex64> Size;
206 Optional<llvm::yaml::Hex64> Info;
208 RawContentSection() : Section(SectionKind::RawContent) {}
210 static bool classof(const Section *S) {
211 return S->Kind == SectionKind::RawContent;
215 struct NoBitsSection : Section {
216 llvm::yaml::Hex64 Size;
218 NoBitsSection() : Section(SectionKind::NoBits) {}
220 static bool classof(const Section *S) {
221 return S->Kind == SectionKind::NoBits;
225 struct HashSection : Section {
226 Optional<yaml::BinaryRef> Content;
227 Optional<llvm::yaml::Hex64> Size;
228 Optional<std::vector<uint32_t>> Bucket;
229 Optional<std::vector<uint32_t>> Chain;
231 HashSection() : Section(SectionKind::Hash) {}
233 static bool classof(const Section *S) { return S->Kind == SectionKind::Hash; }
236 struct VernauxEntry {
237 uint32_t Hash;
238 uint16_t Flags;
239 uint16_t Other;
240 StringRef Name;
243 struct VerneedEntry {
244 uint16_t Version;
245 StringRef File;
246 std::vector<VernauxEntry> AuxV;
249 struct VerneedSection : Section {
250 std::vector<VerneedEntry> VerneedV;
251 llvm::yaml::Hex64 Info;
253 VerneedSection() : Section(SectionKind::Verneed) {}
255 static bool classof(const Section *S) {
256 return S->Kind == SectionKind::Verneed;
260 struct AddrsigSymbol {
261 AddrsigSymbol(StringRef N) : Name(N), Index(None) {}
262 AddrsigSymbol(llvm::yaml::Hex32 Ndx) : Name(None), Index(Ndx) {}
263 AddrsigSymbol() : Name(None), Index(None) {}
265 Optional<StringRef> Name;
266 Optional<llvm::yaml::Hex32> Index;
269 struct AddrsigSection : Section {
270 Optional<yaml::BinaryRef> Content;
271 Optional<llvm::yaml::Hex64> Size;
272 Optional<std::vector<AddrsigSymbol>> Symbols;
274 AddrsigSection() : Section(SectionKind::Addrsig) {}
275 static bool classof(const Section *S) {
276 return S->Kind == SectionKind::Addrsig;
280 struct SymverSection : Section {
281 std::vector<uint16_t> Entries;
283 SymverSection() : Section(SectionKind::Symver) {}
285 static bool classof(const Section *S) {
286 return S->Kind == SectionKind::Symver;
290 struct VerdefEntry {
291 uint16_t Version;
292 uint16_t Flags;
293 uint16_t VersionNdx;
294 uint32_t Hash;
295 std::vector<StringRef> VerNames;
298 struct VerdefSection : Section {
299 std::vector<VerdefEntry> Entries;
300 llvm::yaml::Hex64 Info;
302 VerdefSection() : Section(SectionKind::Verdef) {}
304 static bool classof(const Section *S) {
305 return S->Kind == SectionKind::Verdef;
309 struct Group : Section {
310 // Members of a group contain a flag and a list of section indices
311 // that are part of the group.
312 std::vector<SectionOrType> Members;
313 StringRef Signature; /* Info */
315 Group() : Section(SectionKind::Group) {}
317 static bool classof(const Section *S) {
318 return S->Kind == SectionKind::Group;
322 struct Relocation {
323 llvm::yaml::Hex64 Offset;
324 int64_t Addend;
325 ELF_REL Type;
326 Optional<StringRef> Symbol;
329 struct RelocationSection : Section {
330 std::vector<Relocation> Relocations;
331 StringRef RelocatableSec; /* Info */
333 RelocationSection() : Section(SectionKind::Relocation) {}
335 static bool classof(const Section *S) {
336 return S->Kind == SectionKind::Relocation;
340 struct SymtabShndxSection : Section {
341 std::vector<uint32_t> Entries;
343 SymtabShndxSection() : Section(SectionKind::SymtabShndxSection) {}
345 static bool classof(const Section *S) {
346 return S->Kind == SectionKind::SymtabShndxSection;
350 // Represents .MIPS.abiflags section
351 struct MipsABIFlags : Section {
352 llvm::yaml::Hex16 Version;
353 MIPS_ISA ISALevel;
354 llvm::yaml::Hex8 ISARevision;
355 MIPS_AFL_REG GPRSize;
356 MIPS_AFL_REG CPR1Size;
357 MIPS_AFL_REG CPR2Size;
358 MIPS_ABI_FP FpABI;
359 MIPS_AFL_EXT ISAExtension;
360 MIPS_AFL_ASE ASEs;
361 MIPS_AFL_FLAGS1 Flags1;
362 llvm::yaml::Hex32 Flags2;
364 MipsABIFlags() : Section(SectionKind::MipsABIFlags) {}
366 static bool classof(const Section *S) {
367 return S->Kind == SectionKind::MipsABIFlags;
371 struct Object {
372 FileHeader Header;
373 std::vector<ProgramHeader> ProgramHeaders;
374 std::vector<std::unique_ptr<Section>> Sections;
375 // Although in reality the symbols reside in a section, it is a lot
376 // cleaner and nicer if we read them from the YAML as a separate
377 // top-level key, which automatically ensures that invariants like there
378 // being a single SHT_SYMTAB section are upheld.
379 Optional<std::vector<Symbol>> Symbols;
380 std::vector<Symbol> DynamicSymbols;
383 } // end namespace ELFYAML
384 } // end namespace llvm
386 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::AddrsigSymbol)
387 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::StackSizeEntry)
388 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::DynamicEntry)
389 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ProgramHeader)
390 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Section>)
391 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
392 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VerdefEntry)
393 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VernauxEntry)
394 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VerneedEntry)
395 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation)
396 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType)
397 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionName)
399 namespace llvm {
400 namespace yaml {
402 template <>
403 struct ScalarEnumerationTraits<ELFYAML::ELF_ET> {
404 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
407 template <> struct ScalarEnumerationTraits<ELFYAML::ELF_PT> {
408 static void enumeration(IO &IO, ELFYAML::ELF_PT &Value);
411 template <>
412 struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
413 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
416 template <>
417 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> {
418 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
421 template <>
422 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> {
423 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
426 template <>
427 struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> {
428 static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
431 template <>
432 struct ScalarBitSetTraits<ELFYAML::ELF_EF> {
433 static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
436 template <> struct ScalarBitSetTraits<ELFYAML::ELF_PF> {
437 static void bitset(IO &IO, ELFYAML::ELF_PF &Value);
440 template <>
441 struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> {
442 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
445 template <>
446 struct ScalarBitSetTraits<ELFYAML::ELF_SHF> {
447 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
450 template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> {
451 static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value);
454 template <> struct ScalarEnumerationTraits<ELFYAML::ELF_STB> {
455 static void enumeration(IO &IO, ELFYAML::ELF_STB &Value);
458 template <>
459 struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
460 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
463 template <>
464 struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
465 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
468 template <>
469 struct ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG> {
470 static void enumeration(IO &IO, ELFYAML::ELF_DYNTAG &Value);
473 template <>
474 struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> {
475 static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
478 template <>
479 struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG> {
480 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value);
483 template <>
484 struct ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP> {
485 static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value);
488 template <>
489 struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT> {
490 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value);
493 template <>
494 struct ScalarEnumerationTraits<ELFYAML::MIPS_ISA> {
495 static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value);
498 template <>
499 struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE> {
500 static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value);
503 template <>
504 struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1> {
505 static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value);
508 template <>
509 struct MappingTraits<ELFYAML::FileHeader> {
510 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
513 template <> struct MappingTraits<ELFYAML::ProgramHeader> {
514 static void mapping(IO &IO, ELFYAML::ProgramHeader &FileHdr);
517 template <>
518 struct MappingTraits<ELFYAML::Symbol> {
519 static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
520 static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
523 template <> struct MappingTraits<ELFYAML::StackSizeEntry> {
524 static void mapping(IO &IO, ELFYAML::StackSizeEntry &Rel);
527 template <> struct MappingTraits<ELFYAML::DynamicEntry> {
528 static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel);
531 template <> struct MappingTraits<ELFYAML::VerdefEntry> {
532 static void mapping(IO &IO, ELFYAML::VerdefEntry &E);
535 template <> struct MappingTraits<ELFYAML::VerneedEntry> {
536 static void mapping(IO &IO, ELFYAML::VerneedEntry &E);
539 template <> struct MappingTraits<ELFYAML::VernauxEntry> {
540 static void mapping(IO &IO, ELFYAML::VernauxEntry &E);
543 template <> struct MappingTraits<ELFYAML::AddrsigSymbol> {
544 static void mapping(IO &IO, ELFYAML::AddrsigSymbol &Sym);
547 template <> struct MappingTraits<ELFYAML::Relocation> {
548 static void mapping(IO &IO, ELFYAML::Relocation &Rel);
551 template <>
552 struct MappingTraits<std::unique_ptr<ELFYAML::Section>> {
553 static void mapping(IO &IO, std::unique_ptr<ELFYAML::Section> &Section);
554 static StringRef validate(IO &io, std::unique_ptr<ELFYAML::Section> &Section);
557 template <>
558 struct MappingTraits<ELFYAML::Object> {
559 static void mapping(IO &IO, ELFYAML::Object &Object);
562 template <> struct MappingTraits<ELFYAML::SectionOrType> {
563 static void mapping(IO &IO, ELFYAML::SectionOrType &sectionOrType);
566 template <> struct MappingTraits<ELFYAML::SectionName> {
567 static void mapping(IO &IO, ELFYAML::SectionName &sectionName);
570 } // end namespace yaml
571 } // end namespace llvm
573 #endif // LLVM_OBJECTYAML_ELFYAML_H