LLVM 22.0.0git
ELFYAML.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_OBJECTYAML_ELFYAML_H
16#define LLVM_OBJECTYAML_ELFYAML_H
17
18#include "llvm/ADT/StringRef.h"
24#include <cstdint>
25#include <memory>
26#include <optional>
27#include <vector>
28
29namespace llvm {
30namespace ELFYAML {
31
33std::string appendUniqueSuffix(StringRef Name, const Twine& Msg);
34
35// These types are invariant across 32/64-bit ELF, so for simplicity just
36// directly give them their exact sizes. We don't need to worry about
37// endianness because these are just the types in the YAMLIO structures,
38// and are appropriately converted to the necessary endianness when
39// reading/generating binary object files.
40// The naming of these types is intended to be ELF_PREFIX, where PREFIX is
41// the common prefix of the respective constants. E.g. ELF_EM corresponds
42// to the `e_machine` constants, like `EM_X86_64`.
43// In the future, these would probably be better suited by C++11 enum
44// class's with appropriate fixed underlying type.
51// Just use 64, since it can hold 32-bit values too.
53// Just use 64, since it can hold 32-bit values too.
59// Just use 64, since it can hold 32-bit values too.
65
70LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
72
74LLVM_YAML_STRONG_TYPEDEF(int64_t, YAMLIntUInt)
75
76template <class ELFT>
77unsigned getDefaultShEntSize(unsigned EMachine, ELF_SHT SecType,
78 StringRef SecName) {
79 if (EMachine == ELF::EM_MIPS && SecType == ELF::SHT_MIPS_ABIFLAGS)
81
82 switch (SecType) {
83 case ELF::SHT_SYMTAB:
84 case ELF::SHT_DYNSYM:
85 return sizeof(typename ELFT::Sym);
86 case ELF::SHT_GROUP:
87 return sizeof(typename ELFT::Word);
88 case ELF::SHT_REL:
89 return sizeof(typename ELFT::Rel);
90 case ELF::SHT_RELA:
91 return sizeof(typename ELFT::Rela);
92 case ELF::SHT_RELR:
93 return sizeof(typename ELFT::Relr);
95 return sizeof(typename ELFT::Dyn);
96 case ELF::SHT_HASH:
97 return sizeof(typename ELFT::Word);
99 return sizeof(typename ELFT::Word);
101 return sizeof(typename ELFT::Half);
104 default:
105 if (SecName == ".debug_str")
106 return 1;
107 return 0;
108 }
109}
110
111// For now, hardcode 64 bits everywhere that 32 or 64 would be needed
112// since 64-bit can hold 32-bit values too.
114 ELF_ELFCLASS Class;
115 ELF_ELFDATA Data;
116 ELF_ELFOSABI OSABI;
117 llvm::yaml::Hex8 ABIVersion;
118 ELF_ET Type;
119 std::optional<ELF_EM> Machine;
120 std::optional<ELF_EF> Flags;
121 llvm::yaml::Hex64 Entry;
122 std::optional<StringRef> SectionHeaderStringTable;
123
124 std::optional<llvm::yaml::Hex64> EPhOff;
125 std::optional<llvm::yaml::Hex16> EPhEntSize;
126 std::optional<llvm::yaml::Hex16> EPhNum;
127 std::optional<llvm::yaml::Hex16> EShEntSize;
128 std::optional<llvm::yaml::Hex64> EShOff;
129 std::optional<llvm::yaml::Hex16> EShNum;
130 std::optional<llvm::yaml::Hex16> EShStrNdx;
131};
132
136
137struct Symbol {
139 ELF_STT Type;
140 std::optional<StringRef> Section;
141 std::optional<ELF_SHN> Index;
142 ELF_STB Binding;
143 std::optional<llvm::yaml::Hex64> Value;
144 std::optional<llvm::yaml::Hex64> Size;
145 std::optional<uint8_t> Other;
146
147 std::optional<uint32_t> StName;
148};
149
153
155 ELF_DYNTAG Tag;
156 llvm::yaml::Hex64 Val;
157};
158
160 struct BBEntry {
162 llvm::yaml::Hex64 AddressOffset;
163 llvm::yaml::Hex64 Size;
164 llvm::yaml::Hex64 Metadata;
165 std::optional<std::vector<llvm::yaml::Hex64>> CallsiteEndOffsets;
166 std::optional<llvm::yaml::Hex64> Hash;
167 };
169 llvm::yaml::Hex8 Feature;
170
172 llvm::yaml::Hex64 BaseAddress;
173 std::optional<uint64_t> NumBlocks;
174 std::optional<std::vector<BBEntry>> BBEntries;
175 };
176
177 std::optional<uint64_t> NumBBRanges;
178 std::optional<std::vector<BBRangeEntry>> BBRanges;
179
180 llvm::yaml::Hex64 getFunctionAddress() const {
181 if (!BBRanges || BBRanges->empty())
182 return 0;
183 return BBRanges->front().BaseAddress;
184 }
185
186 // Returns if any BB entries have non-empty callsite offsets.
188 if (!BBRanges)
189 return false;
191 if (!BBR.BBEntries)
192 continue;
193 for (const ELFYAML::BBAddrMapEntry::BBEntry &BBE : *BBR.BBEntries)
194 if (BBE.CallsiteEndOffsets && !BBE.CallsiteEndOffsets->empty())
195 return true;
196 }
197 return false;
198 }
199};
200
202 struct PGOBBEntry {
205 llvm::yaml::Hex32 BrProb;
206 };
207 std::optional<uint64_t> BBFreq;
208 std::optional<std::vector<SuccessorEntry>> Successors;
209 };
210 std::optional<uint64_t> FuncEntryCount;
211 std::optional<std::vector<PGOBBEntry>> PGOBBEntries;
212};
213
215 llvm::yaml::Hex64 Address;
216 llvm::yaml::Hex64 Size;
217};
218
224
225struct Chunk {
254
257 std::optional<llvm::yaml::Hex64> Offset;
258
259 // Usually chunks are not created implicitly, but rather loaded from YAML.
260 // This flag is used to signal whether this is the case or not.
262
263 Chunk(ChunkKind K, bool Implicit) : Kind(K), IsImplicit(Implicit) {}
264 virtual ~Chunk();
265};
266
267struct Section : public Chunk {
268 ELF_SHT Type;
269 std::optional<ELF_SHF> Flags;
270 std::optional<llvm::yaml::Hex64> Address;
271 std::optional<StringRef> Link;
272 llvm::yaml::Hex64 AddressAlign;
273 std::optional<llvm::yaml::Hex64> EntSize;
274
275 std::optional<yaml::BinaryRef> Content;
276 std::optional<llvm::yaml::Hex64> Size;
277
278 // Holds the original section index.
280
282
283 static bool classof(const Chunk *S) {
285 }
286
287 // Some derived sections might have their own special entries. This method
288 // returns a vector of <entry name, is used> pairs. It is used for section
289 // validation.
290 virtual std::vector<std::pair<StringRef, bool>> getEntries() const {
291 return {};
292 };
293
294 // The following members are used to override section fields which is
295 // useful for creating invalid objects.
296
297 // This can be used to override the sh_addralign field.
298 std::optional<llvm::yaml::Hex64> ShAddrAlign;
299
300 // This can be used to override the offset stored in the sh_name field.
301 // It does not affect the name stored in the string table.
302 std::optional<llvm::yaml::Hex64> ShName;
303
304 // This can be used to override the sh_offset field. It does not place the
305 // section data at the offset specified.
306 std::optional<llvm::yaml::Hex64> ShOffset;
307
308 // This can be used to override the sh_size field. It does not affect the
309 // content written.
310 std::optional<llvm::yaml::Hex64> ShSize;
311
312 // This can be used to override the sh_flags field.
313 std::optional<llvm::yaml::Hex64> ShFlags;
314
315 // This can be used to override the sh_type field. It is useful when we
316 // want to use specific YAML keys for a section of a particular type to
317 // describe the content, but still want to have a different final type
318 // for the section.
319 std::optional<ELF_SHT> ShType;
320};
321
322// Fill is a block of data which is placed outside of sections. It is
323// not present in the sections header table, but it might affect the output file
324// size and program headers produced.
325struct Fill : Chunk {
326 std::optional<yaml::BinaryRef> Pattern;
327 llvm::yaml::Hex64 Size;
328
329 Fill() : Chunk(ChunkKind::Fill, /*Implicit=*/false) {}
330
331 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Fill; }
332};
333
337
338 static bool classof(const Chunk *S) {
340 }
341
342 std::optional<std::vector<SectionHeader>> Sections;
343 std::optional<std::vector<SectionHeader>> Excluded;
344 std::optional<bool> NoHeaders;
345
346 size_t getNumHeaders(size_t SectionsNum) const {
347 if (IsImplicit || isDefault())
348 return SectionsNum;
349 if (NoHeaders)
350 return (*NoHeaders) ? 0 : SectionsNum;
351 return (Sections ? Sections->size() : 0) + /*Null section*/ 1;
352 }
353
354 bool isDefault() const { return !Sections && !Excluded && !NoHeaders; }
355
356 static constexpr StringRef TypeStr = "SectionHeaderTable";
357};
358
360 std::optional<std::vector<BBAddrMapEntry>> Entries;
361 std::optional<std::vector<PGOAnalysisMapEntry>> PGOAnalyses;
362
364
365 std::vector<std::pair<StringRef, bool>> getEntries() const override {
366 return {{"Entries", Entries.has_value()}};
367 };
368
369 static bool classof(const Chunk *S) {
370 return S->Kind == ChunkKind::BBAddrMap;
371 }
372};
373
375 std::optional<std::vector<StackSizeEntry>> Entries;
376
378
379 std::vector<std::pair<StringRef, bool>> getEntries() const override {
380 return {{"Entries", Entries.has_value()}};
381 };
382
383 static bool classof(const Chunk *S) {
384 return S->Kind == ChunkKind::StackSizes;
385 }
386
388 return Name == ".stack_sizes";
389 }
390};
391
393 std::optional<std::vector<DynamicEntry>> Entries;
394
396
397 std::vector<std::pair<StringRef, bool>> getEntries() const override {
398 return {{"Entries", Entries.has_value()}};
399 };
400
401 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Dynamic; }
402};
403
405 std::optional<llvm::yaml::Hex64> Info;
406
408
409 static bool classof(const Chunk *S) {
410 return S->Kind == ChunkKind::RawContent;
411 }
412
413 // Is used when a content is read as an array of bytes.
414 std::optional<std::vector<uint8_t>> ContentBuf;
415};
416
419
420 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::NoBits; }
421};
422
424 std::optional<std::vector<ELFYAML::NoteEntry>> Notes;
425
427
428 std::vector<std::pair<StringRef, bool>> getEntries() const override {
429 return {{"Notes", Notes.has_value()}};
430 };
431
432 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Note; }
433};
434
436 std::optional<std::vector<uint32_t>> Bucket;
437 std::optional<std::vector<uint32_t>> Chain;
438
439 std::vector<std::pair<StringRef, bool>> getEntries() const override {
440 return {{"Bucket", Bucket.has_value()}, {"Chain", Chain.has_value()}};
441 };
442
443 // The following members are used to override section fields.
444 // This is useful for creating invalid objects.
445 std::optional<llvm::yaml::Hex64> NBucket;
446 std::optional<llvm::yaml::Hex64> NChain;
447
449
450 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Hash; }
451};
452
454 // The number of hash buckets.
455 // Not used when dumping the object, but can be used to override
456 // the real number of buckets when emiting an object from a YAML document.
457 std::optional<llvm::yaml::Hex32> NBuckets;
458
459 // Index of the first symbol in the dynamic symbol table
460 // included in the hash table.
461 llvm::yaml::Hex32 SymNdx;
462
463 // The number of words in the Bloom filter.
464 // Not used when dumping the object, but can be used to override the real
465 // number of words in the Bloom filter when emiting an object from a YAML
466 // document.
467 std::optional<llvm::yaml::Hex32> MaskWords;
468
469 // A shift constant used by the Bloom filter.
470 llvm::yaml::Hex32 Shift2;
471};
472
474 std::optional<GnuHashHeader> Header;
475 std::optional<std::vector<llvm::yaml::Hex64>> BloomFilter;
476 std::optional<std::vector<llvm::yaml::Hex32>> HashBuckets;
477 std::optional<std::vector<llvm::yaml::Hex32>> HashValues;
478
480
481 std::vector<std::pair<StringRef, bool>> getEntries() const override {
482 return {{"Header", Header.has_value()},
483 {"BloomFilter", BloomFilter.has_value()},
484 {"HashBuckets", HashBuckets.has_value()},
485 {"HashValues", HashValues.has_value()}};
486 };
487
488 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::GnuHash; }
489};
490
497
501 std::vector<VernauxEntry> AuxV;
502};
503
505 std::optional<std::vector<VerneedEntry>> VerneedV;
506 std::optional<llvm::yaml::Hex64> Info;
507
509
510 std::vector<std::pair<StringRef, bool>> getEntries() const override {
511 return {{"Dependencies", VerneedV.has_value()}};
512 };
513
514 static bool classof(const Chunk *S) {
515 return S->Kind == ChunkKind::Verneed;
516 }
517};
518
520 std::optional<std::vector<YAMLFlowString>> Symbols;
521
523
524 std::vector<std::pair<StringRef, bool>> getEntries() const override {
525 return {{"Symbols", Symbols.has_value()}};
526 };
527
528 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Addrsig; }
529};
530
535
537 std::optional<std::vector<LinkerOption>> Options;
538
540
541 std::vector<std::pair<StringRef, bool>> getEntries() const override {
542 return {{"Options", Options.has_value()}};
543 };
544
545 static bool classof(const Chunk *S) {
546 return S->Kind == ChunkKind::LinkerOptions;
547 }
548};
549
551 std::optional<std::vector<YAMLFlowString>> Libs;
552
554
555 std::vector<std::pair<StringRef, bool>> getEntries() const override {
556 return {{"Libraries", Libs.has_value()}};
557 };
558
559 static bool classof(const Chunk *S) {
561 }
562};
563
564// Represents the call graph profile section entry.
566 // The weight of the edge.
568};
569
571 std::optional<std::vector<CallGraphEntryWeight>> Entries;
572
574
575 std::vector<std::pair<StringRef, bool>> getEntries() const override {
576 return {{"Entries", Entries.has_value()}};
577 };
578
579 static bool classof(const Chunk *S) {
581 }
582};
583
585 std::optional<std::vector<uint16_t>> Entries;
586
588
589 std::vector<std::pair<StringRef, bool>> getEntries() const override {
590 return {{"Entries", Entries.has_value()}};
591 };
592
593 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Symver; }
594};
595
597 std::optional<uint16_t> Version;
598 std::optional<uint16_t> Flags;
599 std::optional<uint16_t> VersionNdx;
600 std::optional<uint32_t> Hash;
601 std::optional<uint16_t> VDAux;
602 std::vector<StringRef> VerNames;
603};
604
606 std::optional<std::vector<VerdefEntry>> Entries;
607 std::optional<llvm::yaml::Hex64> Info;
608
610
611 std::vector<std::pair<StringRef, bool>> getEntries() const override {
612 return {{"Entries", Entries.has_value()}};
613 };
614
615 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Verdef; }
616};
617
619 // Members of a group contain a flag and a list of section indices
620 // that are part of the group.
621 std::optional<std::vector<SectionOrType>> Members;
622 std::optional<StringRef> Signature; /* Info */
623
625
626 std::vector<std::pair<StringRef, bool>> getEntries() const override {
627 return {{"Members", Members.has_value()}};
628 };
629
630 static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Group; }
631};
632
634 llvm::yaml::Hex64 Offset;
635 YAMLIntUInt Addend;
636 ELF_REL Type;
637 std::optional<StringRef> Symbol;
638};
639
641 std::optional<std::vector<Relocation>> Relocations;
643
645
646 std::vector<std::pair<StringRef, bool>> getEntries() const override {
647 return {{"Relocations", Relocations.has_value()}};
648 };
649
650 static bool classof(const Chunk *S) {
651 return S->Kind == ChunkKind::Relocation;
652 }
653};
654
656 std::optional<std::vector<llvm::yaml::Hex64>> Entries;
657
659
660 std::vector<std::pair<StringRef, bool>> getEntries() const override {
661 return {{"Entries", Entries.has_value()}};
662 };
663
664 static bool classof(const Chunk *S) {
665 return S->Kind == ChunkKind::Relr;
666 }
667};
668
670 std::optional<std::vector<uint32_t>> Entries;
671
673
674 std::vector<std::pair<StringRef, bool>> getEntries() const override {
675 return {{"Entries", Entries.has_value()}};
676 };
677
678 static bool classof(const Chunk *S) {
680 }
681};
682
684 llvm::yaml::Hex32 Offset;
685 llvm::yaml::Hex32 Value;
686};
687
689 std::optional<std::vector<ARMIndexTableEntry>> Entries;
690
692
693 std::vector<std::pair<StringRef, bool>> getEntries() const override {
694 return {{"Entries", Entries.has_value()}};
695 };
696
697 static bool classof(const Chunk *S) {
698 return S->Kind == ChunkKind::ARMIndexTable;
699 }
700};
701
702// Represents .MIPS.abiflags section
704 llvm::yaml::Hex16 Version;
705 MIPS_ISA ISALevel;
706 llvm::yaml::Hex8 ISARevision;
707 MIPS_AFL_REG GPRSize;
708 MIPS_AFL_REG CPR1Size;
709 MIPS_AFL_REG CPR2Size;
710 MIPS_ABI_FP FpABI;
711 MIPS_AFL_EXT ISAExtension;
712 MIPS_AFL_ASE ASEs;
713 MIPS_AFL_FLAGS1 Flags1;
714 llvm::yaml::Hex32 Flags2;
715
717
718 static bool classof(const Chunk *S) {
719 return S->Kind == ChunkKind::MipsABIFlags;
720 }
721};
722
724 ELF_PT Type;
725 ELF_PF Flags;
726 llvm::yaml::Hex64 VAddr;
727 llvm::yaml::Hex64 PAddr;
728 std::optional<llvm::yaml::Hex64> Align;
729 std::optional<llvm::yaml::Hex64> FileSize;
730 std::optional<llvm::yaml::Hex64> MemSize;
731 std::optional<llvm::yaml::Hex64> Offset;
732 std::optional<StringRef> FirstSec;
733 std::optional<StringRef> LastSec;
734
735 // This vector contains all chunks from [FirstSec, LastSec].
736 std::vector<Chunk *> Chunks;
737};
738
739struct Object {
741 std::vector<ProgramHeader> ProgramHeaders;
742
743 // An object might contain output section descriptions as well as
744 // custom data that does not belong to any section.
745 std::vector<std::unique_ptr<Chunk>> Chunks;
746
747 // Although in reality the symbols reside in a section, it is a lot
748 // cleaner and nicer if we read them from the YAML as a separate
749 // top-level key, which automatically ensures that invariants like there
750 // being a single SHT_SYMTAB section are upheld.
751 std::optional<std::vector<Symbol>> Symbols;
752 std::optional<std::vector<Symbol>> DynamicSymbols;
753 std::optional<DWARFYAML::Data> DWARF;
754
755 std::vector<Section *> getSections() {
756 std::vector<Section *> Ret;
757 for (const std::unique_ptr<Chunk> &Sec : Chunks)
758 if (auto S = dyn_cast<ELFYAML::Section>(Sec.get()))
759 Ret.push_back(S);
760 return Ret;
761 }
762
764 for (const std::unique_ptr<Chunk> &C : Chunks)
765 if (auto *S = dyn_cast<ELFYAML::SectionHeaderTable>(C.get()))
766 return *S;
767 llvm_unreachable("the section header table chunk must always be present");
768 }
769
770 ELF_ELFOSABI getOSAbi() const;
771 unsigned getMachine() const;
772};
773
775 const NoBitsSection &S);
776
777} // end namespace ELFYAML
778} // end namespace llvm
779
787 llvm::ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry)
788LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::DynamicEntry)
789LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::LinkerOption)
790LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::CallGraphEntryWeight)
791LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::NoteEntry)
792LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ProgramHeader)
793LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionHeader)
794LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Chunk>)
795LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
796LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VerdefEntry)
797LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VernauxEntry)
798LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::VerneedEntry)
799LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation)
800LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType)
801LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ARMIndexTableEntry)
802
803namespace llvm {
804namespace yaml {
805
806template <> struct ScalarTraits<ELFYAML::YAMLIntUInt> {
807 static void output(const ELFYAML::YAMLIntUInt &Val, void *Ctx,
808 raw_ostream &Out);
809 static StringRef input(StringRef Scalar, void *Ctx,
810 ELFYAML::YAMLIntUInt &Val);
811 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
812};
813
814template <>
815struct ScalarEnumerationTraits<ELFYAML::ELF_ET> {
816 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
817};
818
819template <> struct ScalarEnumerationTraits<ELFYAML::ELF_PT> {
820 static void enumeration(IO &IO, ELFYAML::ELF_PT &Value);
821};
822
823template <> struct ScalarEnumerationTraits<ELFYAML::ELF_NT> {
824 static void enumeration(IO &IO, ELFYAML::ELF_NT &Value);
825};
826
827template <>
828struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
829 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
830};
831
832template <>
833struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> {
834 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
835};
836
837template <>
838struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> {
839 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
840};
841
842template <>
843struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> {
844 static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
845};
846
847template <>
848struct ScalarBitSetTraits<ELFYAML::ELF_EF> {
849 static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
850};
851
852template <> struct ScalarBitSetTraits<ELFYAML::ELF_PF> {
853 static void bitset(IO &IO, ELFYAML::ELF_PF &Value);
854};
855
856template <>
857struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> {
858 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
859};
860
861template <>
862struct ScalarBitSetTraits<ELFYAML::ELF_SHF> {
863 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
864};
865
866template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> {
867 static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value);
868};
869
870template <> struct ScalarEnumerationTraits<ELFYAML::ELF_STB> {
871 static void enumeration(IO &IO, ELFYAML::ELF_STB &Value);
872};
873
874template <>
875struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
876 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
877};
878
879template <>
880struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
881 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
882};
883
884template <>
885struct ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG> {
886 static void enumeration(IO &IO, ELFYAML::ELF_DYNTAG &Value);
887};
888
889template <>
890struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> {
891 static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
892};
893
894template <>
895struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG> {
896 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value);
897};
898
899template <>
900struct ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP> {
901 static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value);
902};
903
904template <>
905struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT> {
906 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value);
907};
908
909template <>
910struct ScalarEnumerationTraits<ELFYAML::MIPS_ISA> {
911 static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value);
912};
913
914template <>
915struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE> {
916 static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value);
917};
918
919template <>
920struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1> {
921 static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value);
922};
923
924template <>
925struct MappingTraits<ELFYAML::FileHeader> {
926 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
927};
928
929template <> struct MappingTraits<ELFYAML::SectionHeader> {
930 static void mapping(IO &IO, ELFYAML::SectionHeader &SHdr);
931};
932
933template <> struct MappingTraits<ELFYAML::ProgramHeader> {
934 static void mapping(IO &IO, ELFYAML::ProgramHeader &FileHdr);
935 static std::string validate(IO &IO, ELFYAML::ProgramHeader &FileHdr);
936};
937
938template <>
939struct MappingTraits<ELFYAML::Symbol> {
940 static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
941 static std::string validate(IO &IO, ELFYAML::Symbol &Symbol);
942};
943
944template <> struct MappingTraits<ELFYAML::StackSizeEntry> {
945 static void mapping(IO &IO, ELFYAML::StackSizeEntry &Rel);
946};
947
948template <> struct MappingTraits<ELFYAML::BBAddrMapEntry> {
949 static void mapping(IO &IO, ELFYAML::BBAddrMapEntry &E);
950};
951
952template <> struct MappingTraits<ELFYAML::BBAddrMapEntry::BBRangeEntry> {
953 static void mapping(IO &IO, ELFYAML::BBAddrMapEntry::BBRangeEntry &E);
954};
955
956template <> struct MappingTraits<ELFYAML::BBAddrMapEntry::BBEntry> {
957 static void mapping(IO &IO, ELFYAML::BBAddrMapEntry::BBEntry &E);
958};
959
960template <> struct MappingTraits<ELFYAML::PGOAnalysisMapEntry> {
961 static void mapping(IO &IO, ELFYAML::PGOAnalysisMapEntry &Rel);
962};
963
964template <> struct MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry> {
965 static void mapping(IO &IO, ELFYAML::PGOAnalysisMapEntry::PGOBBEntry &Rel);
966};
967
968template <>
969struct MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry> {
970 static void
971 mapping(IO &IO,
972 ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry &Rel);
973};
974
975template <> struct MappingTraits<ELFYAML::GnuHashHeader> {
976 static void mapping(IO &IO, ELFYAML::GnuHashHeader &Rel);
977};
978
979template <> struct MappingTraits<ELFYAML::DynamicEntry> {
980 static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel);
981};
982
983template <> struct MappingTraits<ELFYAML::NoteEntry> {
984 static void mapping(IO &IO, ELFYAML::NoteEntry &N);
985};
986
987template <> struct MappingTraits<ELFYAML::VerdefEntry> {
988 static void mapping(IO &IO, ELFYAML::VerdefEntry &E);
989};
990
991template <> struct MappingTraits<ELFYAML::VerneedEntry> {
992 static void mapping(IO &IO, ELFYAML::VerneedEntry &E);
993};
994
995template <> struct MappingTraits<ELFYAML::VernauxEntry> {
996 static void mapping(IO &IO, ELFYAML::VernauxEntry &E);
997};
998
999template <> struct MappingTraits<ELFYAML::LinkerOption> {
1000 static void mapping(IO &IO, ELFYAML::LinkerOption &Sym);
1001};
1002
1003template <> struct MappingTraits<ELFYAML::CallGraphEntryWeight> {
1004 static void mapping(IO &IO, ELFYAML::CallGraphEntryWeight &E);
1005};
1006
1007template <> struct MappingTraits<ELFYAML::Relocation> {
1008 static void mapping(IO &IO, ELFYAML::Relocation &Rel);
1009};
1010
1011template <> struct MappingTraits<ELFYAML::ARMIndexTableEntry> {
1012 static void mapping(IO &IO, ELFYAML::ARMIndexTableEntry &E);
1013};
1014
1015template <> struct MappingTraits<std::unique_ptr<ELFYAML::Chunk>> {
1016 static void mapping(IO &IO, std::unique_ptr<ELFYAML::Chunk> &C);
1017 static std::string validate(IO &io, std::unique_ptr<ELFYAML::Chunk> &C);
1018};
1019
1020template <>
1021struct MappingTraits<ELFYAML::Object> {
1022 static void mapping(IO &IO, ELFYAML::Object &Object);
1023};
1024
1025template <> struct MappingTraits<ELFYAML::SectionOrType> {
1026 static void mapping(IO &IO, ELFYAML::SectionOrType &sectionOrType);
1027};
1028
1029} // end namespace yaml
1030} // end namespace llvm
1031
1032#endif // LLVM_OBJECTYAML_ELFYAML_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file declares classes for handling the YAML representation of DWARF Debug Info.
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
YAML I/O does conversion based on types. But often native data types are just a typedef of built in i...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
Specialized YAMLIO scalar type for representing a binary blob.
Definition YAML.h:64
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
std::string appendUniqueSuffix(StringRef Name, const Twine &Msg)
unsigned getDefaultShEntSize(unsigned EMachine, ELF_SHT SecType, StringRef SecName)
Definition ELFYAML.h:77
StringRef dropUniqueSuffix(StringRef S)
bool shouldAllocateFileSpace(ArrayRef< ProgramHeader > Phdrs, const NoBitsSection &S)
@ EM_MIPS
Definition ELF.h:146
@ SHT_GROUP
Definition ELF.h:1159
@ SHT_REL
Definition ELF.h:1153
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition ELF.h:1182
@ SHT_SYMTAB
Definition ELF.h:1146
@ SHT_RELR
Definition ELF.h:1163
@ SHT_DYNAMIC
Definition ELF.h:1150
@ SHT_SYMTAB_SHNDX
Definition ELF.h:1160
@ SHT_RELA
Definition ELF.h:1148
@ SHT_DYNSYM
Definition ELF.h:1155
@ SHT_MIPS_ABIFLAGS
Definition ELF.h:1224
@ SHT_GNU_versym
Definition ELF.h:1196
@ SHT_HASH
Definition ELF.h:1149
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
#define N
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:693
static bool classof(const Chunk *S)
Definition ELFYAML.h:697
std::optional< std::vector< ARMIndexTableEntry > > Entries
Definition ELFYAML.h:689
std::optional< std::vector< YAMLFlowString > > Symbols
Definition ELFYAML.h:520
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:524
static bool classof(const Chunk *S)
Definition ELFYAML.h:528
std::optional< llvm::yaml::Hex64 > Hash
Definition ELFYAML.h:166
std::optional< std::vector< llvm::yaml::Hex64 > > CallsiteEndOffsets
Definition ELFYAML.h:165
std::optional< uint64_t > NumBlocks
Definition ELFYAML.h:173
std::optional< std::vector< BBEntry > > BBEntries
Definition ELFYAML.h:174
llvm::yaml::Hex64 getFunctionAddress() const
Definition ELFYAML.h:180
std::optional< uint64_t > NumBBRanges
Definition ELFYAML.h:177
bool hasAnyCallsiteEndOffsets() const
Definition ELFYAML.h:187
std::optional< std::vector< BBRangeEntry > > BBRanges
Definition ELFYAML.h:178
llvm::yaml::Hex8 Feature
Definition ELFYAML.h:169
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:365
static bool classof(const Chunk *S)
Definition ELFYAML.h:369
std::optional< std::vector< BBAddrMapEntry > > Entries
Definition ELFYAML.h:360
std::optional< std::vector< PGOAnalysisMapEntry > > PGOAnalyses
Definition ELFYAML.h:361
std::optional< std::vector< CallGraphEntryWeight > > Entries
Definition ELFYAML.h:571
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:575
static bool classof(const Chunk *S)
Definition ELFYAML.h:579
Chunk(ChunkKind K, bool Implicit)
Definition ELFYAML.h:263
std::optional< llvm::yaml::Hex64 > Offset
Definition ELFYAML.h:257
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:555
static bool classof(const Chunk *S)
Definition ELFYAML.h:559
std::optional< std::vector< YAMLFlowString > > Libs
Definition ELFYAML.h:551
llvm::yaml::Hex64 Val
Definition ELFYAML.h:156
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:397
static bool classof(const Chunk *S)
Definition ELFYAML.h:401
std::optional< std::vector< DynamicEntry > > Entries
Definition ELFYAML.h:393
std::optional< llvm::yaml::Hex16 > EPhNum
Definition ELFYAML.h:126
std::optional< llvm::yaml::Hex64 > EShOff
Definition ELFYAML.h:128
std::optional< llvm::yaml::Hex64 > EPhOff
Definition ELFYAML.h:124
std::optional< llvm::yaml::Hex16 > EShEntSize
Definition ELFYAML.h:127
std::optional< llvm::yaml::Hex16 > EPhEntSize
Definition ELFYAML.h:125
llvm::yaml::Hex8 ABIVersion
Definition ELFYAML.h:117
std::optional< llvm::yaml::Hex16 > EShNum
Definition ELFYAML.h:129
llvm::yaml::Hex64 Entry
Definition ELFYAML.h:121
std::optional< ELF_EF > Flags
Definition ELFYAML.h:120
std::optional< ELF_EM > Machine
Definition ELFYAML.h:119
std::optional< StringRef > SectionHeaderStringTable
Definition ELFYAML.h:122
std::optional< llvm::yaml::Hex16 > EShStrNdx
Definition ELFYAML.h:130
llvm::yaml::Hex64 Size
Definition ELFYAML.h:327
std::optional< yaml::BinaryRef > Pattern
Definition ELFYAML.h:326
static bool classof(const Chunk *S)
Definition ELFYAML.h:331
std::optional< llvm::yaml::Hex32 > MaskWords
Definition ELFYAML.h:467
llvm::yaml::Hex32 SymNdx
Definition ELFYAML.h:461
llvm::yaml::Hex32 Shift2
Definition ELFYAML.h:470
std::optional< llvm::yaml::Hex32 > NBuckets
Definition ELFYAML.h:457
std::optional< std::vector< llvm::yaml::Hex64 > > BloomFilter
Definition ELFYAML.h:475
std::optional< std::vector< llvm::yaml::Hex32 > > HashBuckets
Definition ELFYAML.h:476
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:481
static bool classof(const Chunk *S)
Definition ELFYAML.h:488
std::optional< GnuHashHeader > Header
Definition ELFYAML.h:474
std::optional< std::vector< llvm::yaml::Hex32 > > HashValues
Definition ELFYAML.h:477
static bool classof(const Chunk *S)
Definition ELFYAML.h:630
std::optional< std::vector< SectionOrType > > Members
Definition ELFYAML.h:621
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:626
std::optional< StringRef > Signature
Definition ELFYAML.h:622
std::optional< std::vector< uint32_t > > Chain
Definition ELFYAML.h:437
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:439
std::optional< llvm::yaml::Hex64 > NChain
Definition ELFYAML.h:446
static bool classof(const Chunk *S)
Definition ELFYAML.h:450
std::optional< std::vector< uint32_t > > Bucket
Definition ELFYAML.h:436
std::optional< llvm::yaml::Hex64 > NBucket
Definition ELFYAML.h:445
std::optional< std::vector< LinkerOption > > Options
Definition ELFYAML.h:537
static bool classof(const Chunk *S)
Definition ELFYAML.h:545
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:541
llvm::yaml::Hex16 Version
Definition ELFYAML.h:704
static bool classof(const Chunk *S)
Definition ELFYAML.h:718
MIPS_AFL_FLAGS1 Flags1
Definition ELFYAML.h:713
llvm::yaml::Hex8 ISARevision
Definition ELFYAML.h:706
MIPS_AFL_EXT ISAExtension
Definition ELFYAML.h:711
llvm::yaml::Hex32 Flags2
Definition ELFYAML.h:714
static bool classof(const Chunk *S)
Definition ELFYAML.h:420
yaml::BinaryRef Desc
Definition ELFYAML.h:221
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:428
std::optional< std::vector< ELFYAML::NoteEntry > > Notes
Definition ELFYAML.h:424
static bool classof(const Chunk *S)
Definition ELFYAML.h:432
std::optional< std::vector< Symbol > > DynamicSymbols
Definition ELFYAML.h:752
unsigned getMachine() const
Definition ELFYAML.cpp:35
std::optional< DWARFYAML::Data > DWARF
Definition ELFYAML.h:753
const SectionHeaderTable & getSectionHeaderTable() const
Definition ELFYAML.h:763
FileHeader Header
Definition ELFYAML.h:740
std::vector< std::unique_ptr< Chunk > > Chunks
Definition ELFYAML.h:745
ELF_ELFOSABI getOSAbi() const
Definition ELFYAML.cpp:33
std::vector< ProgramHeader > ProgramHeaders
Definition ELFYAML.h:741
std::optional< std::vector< Symbol > > Symbols
Definition ELFYAML.h:751
std::vector< Section * > getSections()
Definition ELFYAML.h:755
std::optional< std::vector< SuccessorEntry > > Successors
Definition ELFYAML.h:208
std::optional< std::vector< PGOBBEntry > > PGOBBEntries
Definition ELFYAML.h:211
std::optional< uint64_t > FuncEntryCount
Definition ELFYAML.h:210
std::optional< llvm::yaml::Hex64 > Align
Definition ELFYAML.h:728
llvm::yaml::Hex64 PAddr
Definition ELFYAML.h:727
std::optional< llvm::yaml::Hex64 > Offset
Definition ELFYAML.h:731
llvm::yaml::Hex64 VAddr
Definition ELFYAML.h:726
std::optional< llvm::yaml::Hex64 > MemSize
Definition ELFYAML.h:730
std::optional< StringRef > FirstSec
Definition ELFYAML.h:732
std::optional< StringRef > LastSec
Definition ELFYAML.h:733
std::optional< llvm::yaml::Hex64 > FileSize
Definition ELFYAML.h:729
std::vector< Chunk * > Chunks
Definition ELFYAML.h:736
static bool classof(const Chunk *S)
Definition ELFYAML.h:409
std::optional< llvm::yaml::Hex64 > Info
Definition ELFYAML.h:405
std::optional< std::vector< uint8_t > > ContentBuf
Definition ELFYAML.h:414
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:646
std::optional< std::vector< Relocation > > Relocations
Definition ELFYAML.h:641
static bool classof(const Chunk *S)
Definition ELFYAML.h:650
std::optional< StringRef > Symbol
Definition ELFYAML.h:637
llvm::yaml::Hex64 Offset
Definition ELFYAML.h:634
static bool classof(const Chunk *S)
Definition ELFYAML.h:664
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:660
std::optional< std::vector< llvm::yaml::Hex64 > > Entries
Definition ELFYAML.h:656
std::optional< std::vector< SectionHeader > > Excluded
Definition ELFYAML.h:343
static constexpr StringRef TypeStr
Definition ELFYAML.h:356
std::optional< bool > NoHeaders
Definition ELFYAML.h:344
static bool classof(const Chunk *S)
Definition ELFYAML.h:338
SectionHeaderTable(bool IsImplicit)
Definition ELFYAML.h:335
size_t getNumHeaders(size_t SectionsNum) const
Definition ELFYAML.h:346
std::optional< std::vector< SectionHeader > > Sections
Definition ELFYAML.h:342
std::optional< llvm::yaml::Hex64 > Address
Definition ELFYAML.h:270
std::optional< StringRef > Link
Definition ELFYAML.h:271
Section(ChunkKind Kind, bool IsImplicit=false)
Definition ELFYAML.h:281
std::optional< llvm::yaml::Hex64 > Size
Definition ELFYAML.h:276
static bool classof(const Chunk *S)
Definition ELFYAML.h:283
std::optional< llvm::yaml::Hex64 > ShAddrAlign
Definition ELFYAML.h:298
llvm::yaml::Hex64 AddressAlign
Definition ELFYAML.h:272
unsigned OriginalSecNdx
Definition ELFYAML.h:279
std::optional< ELF_SHF > Flags
Definition ELFYAML.h:269
std::optional< ELF_SHT > ShType
Definition ELFYAML.h:319
std::optional< llvm::yaml::Hex64 > ShOffset
Definition ELFYAML.h:306
virtual std::vector< std::pair< StringRef, bool > > getEntries() const
Definition ELFYAML.h:290
std::optional< llvm::yaml::Hex64 > ShFlags
Definition ELFYAML.h:313
std::optional< llvm::yaml::Hex64 > ShName
Definition ELFYAML.h:302
std::optional< yaml::BinaryRef > Content
Definition ELFYAML.h:275
std::optional< llvm::yaml::Hex64 > EntSize
Definition ELFYAML.h:273
std::optional< llvm::yaml::Hex64 > ShSize
Definition ELFYAML.h:310
llvm::yaml::Hex64 Size
Definition ELFYAML.h:216
llvm::yaml::Hex64 Address
Definition ELFYAML.h:215
static bool classof(const Chunk *S)
Definition ELFYAML.h:383
static bool nameMatches(StringRef Name)
Definition ELFYAML.h:387
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:379
std::optional< std::vector< StackSizeEntry > > Entries
Definition ELFYAML.h:375
std::optional< ELF_SHN > Index
Definition ELFYAML.h:141
std::optional< StringRef > Section
Definition ELFYAML.h:140
std::optional< uint8_t > Other
Definition ELFYAML.h:145
std::optional< uint32_t > StName
Definition ELFYAML.h:147
std::optional< llvm::yaml::Hex64 > Value
Definition ELFYAML.h:143
std::optional< llvm::yaml::Hex64 > Size
Definition ELFYAML.h:144
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:674
static bool classof(const Chunk *S)
Definition ELFYAML.h:678
std::optional< std::vector< uint32_t > > Entries
Definition ELFYAML.h:670
std::optional< std::vector< uint16_t > > Entries
Definition ELFYAML.h:585
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:589
static bool classof(const Chunk *S)
Definition ELFYAML.h:593
std::optional< uint16_t > Flags
Definition ELFYAML.h:598
std::optional< uint16_t > VDAux
Definition ELFYAML.h:601
std::vector< StringRef > VerNames
Definition ELFYAML.h:602
std::optional< uint16_t > VersionNdx
Definition ELFYAML.h:599
std::optional< uint16_t > Version
Definition ELFYAML.h:597
std::optional< uint32_t > Hash
Definition ELFYAML.h:600
static bool classof(const Chunk *S)
Definition ELFYAML.h:615
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:611
std::optional< llvm::yaml::Hex64 > Info
Definition ELFYAML.h:607
std::optional< std::vector< VerdefEntry > > Entries
Definition ELFYAML.h:606
std::vector< VernauxEntry > AuxV
Definition ELFYAML.h:501
std::vector< std::pair< StringRef, bool > > getEntries() const override
Definition ELFYAML.h:510
std::optional< llvm::yaml::Hex64 > Info
Definition ELFYAML.h:506
static bool classof(const Chunk *S)
Definition ELFYAML.h:514
std::optional< std::vector< VerneedEntry > > VerneedV
Definition ELFYAML.h:505