LLVM  8.0.1
ELFYAML.cpp
Go to the documentation of this file.
1 //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines classes for handling the YAML representation of ELF.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/BinaryFormat/ELF.h"
17 #include "llvm/Support/Casting.h"
21 #include <cassert>
22 #include <cstdint>
23 
24 namespace llvm {
25 
26 ELFYAML::Section::~Section() = default;
27 
28 namespace yaml {
29 
31  IO &IO, ELFYAML::ELF_ET &Value) {
32 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
33  ECase(ET_NONE);
34  ECase(ET_REL);
35  ECase(ET_EXEC);
36  ECase(ET_DYN);
37  ECase(ET_CORE);
38 #undef ECase
39  IO.enumFallback<Hex16>(Value);
40 }
41 
43  IO &IO, ELFYAML::ELF_PT &Value) {
44 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
45  ECase(PT_NULL);
46  ECase(PT_LOAD);
49  ECase(PT_NOTE);
50  ECase(PT_SHLIB);
51  ECase(PT_PHDR);
52  ECase(PT_TLS);
54 #undef ECase
55  IO.enumFallback<Hex32>(Value);
56 }
57 
59  IO &IO, ELFYAML::ELF_EM &Value) {
60 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
61  ECase(EM_NONE);
62  ECase(EM_M32);
63  ECase(EM_SPARC);
64  ECase(EM_386);
65  ECase(EM_68K);
66  ECase(EM_88K);
67  ECase(EM_IAMCU);
68  ECase(EM_860);
69  ECase(EM_MIPS);
70  ECase(EM_S370);
75  ECase(EM_960);
76  ECase(EM_PPC);
77  ECase(EM_PPC64);
78  ECase(EM_S390);
79  ECase(EM_SPU);
80  ECase(EM_V800);
81  ECase(EM_FR20);
82  ECase(EM_RH32);
83  ECase(EM_RCE);
84  ECase(EM_ARM);
85  ECase(EM_ALPHA);
86  ECase(EM_SH);
89  ECase(EM_ARC);
92  ECase(EM_H8S);
94  ECase(EM_IA_64);
98  ECase(EM_MMA);
99  ECase(EM_PCP);
100  ECase(EM_NCPU);
101  ECase(EM_NDR1);
103  ECase(EM_ME16);
104  ECase(EM_ST100);
105  ECase(EM_TINYJ);
106  ECase(EM_X86_64);
107  ECase(EM_PDSP);
108  ECase(EM_PDP10);
109  ECase(EM_PDP11);
110  ECase(EM_FX66);
111  ECase(EM_ST9PLUS);
112  ECase(EM_ST7);
113  ECase(EM_68HC16);
114  ECase(EM_68HC11);
115  ECase(EM_68HC08);
116  ECase(EM_68HC05);
117  ECase(EM_SVX);
118  ECase(EM_ST19);
119  ECase(EM_VAX);
120  ECase(EM_CRIS);
121  ECase(EM_JAVELIN);
123  ECase(EM_ZSP);
124  ECase(EM_MMIX);
125  ECase(EM_HUANY);
126  ECase(EM_PRISM);
127  ECase(EM_AVR);
128  ECase(EM_FR30);
129  ECase(EM_D10V);
130  ECase(EM_D30V);
131  ECase(EM_V850);
132  ECase(EM_M32R);
133  ECase(EM_MN10300);
134  ECase(EM_MN10200);
135  ECase(EM_PJ);
138  ECase(EM_XTENSA);
140  ECase(EM_TMM_GPP);
141  ECase(EM_NS32K);
142  ECase(EM_TPC);
143  ECase(EM_SNP1K);
144  ECase(EM_ST200);
145  ECase(EM_IP2K);
146  ECase(EM_MAX);
147  ECase(EM_CR);
148  ECase(EM_F2MC16);
149  ECase(EM_MSP430);
151  ECase(EM_SE_C33);
152  ECase(EM_SEP);
153  ECase(EM_ARCA);
154  ECase(EM_UNICORE);
155  ECase(EM_EXCESS);
156  ECase(EM_DXP);
158  ECase(EM_CRX);
159  ECase(EM_XGATE);
160  ECase(EM_C166);
161  ECase(EM_M16C);
163  ECase(EM_CE);
164  ECase(EM_M32C);
165  ECase(EM_TSK3000);
166  ECase(EM_RS08);
167  ECase(EM_SHARC);
168  ECase(EM_ECOG2);
169  ECase(EM_SCORE7);
170  ECase(EM_DSP24);
173  ECase(EM_SE_C17);
179  ECase(EM_R32C);
181  ECase(EM_HEXAGON);
182  ECase(EM_8051);
183  ECase(EM_STXP7X);
184  ECase(EM_NDS32);
185  ECase(EM_ECOG1);
186  ECase(EM_ECOG1X);
187  ECase(EM_MAXQ30);
188  ECase(EM_XIMO16);
189  ECase(EM_MANIK);
190  ECase(EM_CRAYNV2);
191  ECase(EM_RX);
192  ECase(EM_METAG);
194  ECase(EM_ECOG16);
195  ECase(EM_CR16);
196  ECase(EM_ETPU);
197  ECase(EM_SLE9X);
198  ECase(EM_L10M);
199  ECase(EM_K10M);
200  ECase(EM_AARCH64);
201  ECase(EM_AVR32);
202  ECase(EM_STM8);
203  ECase(EM_TILE64);
204  ECase(EM_TILEPRO);
205  ECase(EM_CUDA);
206  ECase(EM_TILEGX);
211  ECase(EM_OPEN8);
212  ECase(EM_RL78);
214  ECase(EM_78KOR);
215  ECase(EM_56800EX);
216  ECase(EM_AMDGPU);
217  ECase(EM_RISCV);
218  ECase(EM_LANAI);
219  ECase(EM_BPF);
220 #undef ECase
221 }
222 
224  IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
225 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
226  // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
227  // here.
228  ECase(ELFCLASS32);
229  ECase(ELFCLASS64);
230 #undef ECase
231 }
232 
234  IO &IO, ELFYAML::ELF_ELFDATA &Value) {
235 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
236  // Since the semantics of ELFDATANONE is "invalid", just don't accept it
237  // here.
240 #undef ECase
241 }
242 
244  IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
245 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
270 #undef ECase
271 }
272 
274  ELFYAML::ELF_EF &Value) {
275  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
276  assert(Object && "The IO context is not initialized");
277 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
278 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
279  switch (Object->Header.Machine) {
280  case ELF::EM_ARM:
289  break;
290  case ELF::EM_MIPS:
334  break;
335  case ELF::EM_HEXAGON:
352  break;
353  case ELF::EM_AVR:
371  break;
372  case ELF::EM_RISCV:
379  break;
380  case ELF::EM_AMDGPU:
416  break;
417  case ELF::EM_X86_64:
418  break;
419  default:
420  llvm_unreachable("Unsupported architecture");
421  }
422 #undef BCase
423 #undef BCaseMask
424 }
425 
427  IO &IO, ELFYAML::ELF_SHT &Value) {
428  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
429  assert(Object && "The IO context is not initialized");
430 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
431  ECase(SHT_NULL);
433  ECase(SHT_SYMTAB);
434  // FIXME: Issue a diagnostic with this information.
435  ECase(SHT_STRTAB);
436  ECase(SHT_RELA);
437  ECase(SHT_HASH);
439  ECase(SHT_NOTE);
440  ECase(SHT_NOBITS);
441  ECase(SHT_REL);
442  ECase(SHT_SHLIB);
443  ECase(SHT_DYNSYM);
447  ECase(SHT_GROUP);
449  ECase(SHT_RELR);
450  ECase(SHT_LOOS);
463  ECase(SHT_HIOS);
464  ECase(SHT_LOPROC);
465  switch (Object->Header.Machine) {
466  case ELF::EM_ARM:
472  break;
473  case ELF::EM_HEXAGON:
475  break;
476  case ELF::EM_X86_64:
478  break;
479  case ELF::EM_MIPS:
483  break;
484  default:
485  // Nothing to do.
486  break;
487  }
488 #undef ECase
489 }
490 
492  ELFYAML::ELF_PF &Value) {
493 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
494  BCase(PF_X);
495  BCase(PF_W);
496  BCase(PF_R);
497 }
498 
500  ELFYAML::ELF_SHF &Value) {
501  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
502 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
503  BCase(SHF_WRITE);
504  BCase(SHF_ALLOC);
507  BCase(SHF_MERGE);
512  BCase(SHF_GROUP);
513  BCase(SHF_TLS);
515  switch (Object->Header.Machine) {
516  case ELF::EM_ARM:
518  break;
519  case ELF::EM_HEXAGON:
521  break;
522  case ELF::EM_MIPS:
531  break;
532  case ELF::EM_X86_64:
534  break;
535  default:
536  // Nothing to do.
537  break;
538  }
539 #undef BCase
540 }
541 
543  IO &IO, ELFYAML::ELF_SHN &Value) {
544 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
545  ECase(SHN_UNDEF);
547  ECase(SHN_LOPROC);
548  ECase(SHN_HIPROC);
549  ECase(SHN_LOOS);
550  ECase(SHN_HIOS);
551  ECase(SHN_ABS);
552  ECase(SHN_COMMON);
553  ECase(SHN_XINDEX);
560 #undef ECase
561  IO.enumFallback<Hex32>(Value);
562 }
563 
565  IO &IO, ELFYAML::ELF_STT &Value) {
566 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
567  ECase(STT_NOTYPE);
568  ECase(STT_OBJECT);
569  ECase(STT_FUNC);
571  ECase(STT_FILE);
572  ECase(STT_COMMON);
573  ECase(STT_TLS);
575 #undef ECase
576 }
577 
579  IO &IO, ELFYAML::ELF_STV &Value) {
580 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
583  ECase(STV_HIDDEN);
585 #undef ECase
586 }
587 
589  ELFYAML::ELF_STO &Value) {
590  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
591  assert(Object && "The IO context is not initialized");
592 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
593  switch (Object->Header.Machine) {
594  case ELF::EM_MIPS:
599  break;
600  default:
601  break; // Nothing to do
602  }
603 #undef BCase
604 #undef BCaseMask
605 }
606 
608  IO &IO, ELFYAML::ELF_RSS &Value) {
609 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
610  ECase(RSS_UNDEF);
611  ECase(RSS_GP);
612  ECase(RSS_GP0);
613  ECase(RSS_LOC);
614 #undef ECase
615 }
616 
618  IO &IO, ELFYAML::ELF_REL &Value) {
619  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
620  assert(Object && "The IO context is not initialized");
621 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
622  switch (Object->Header.Machine) {
623  case ELF::EM_X86_64:
624 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
625  break;
626  case ELF::EM_MIPS:
627 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
628  break;
629  case ELF::EM_HEXAGON:
630 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
631  break;
632  case ELF::EM_386:
633  case ELF::EM_IAMCU:
634 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
635  break;
636  case ELF::EM_AARCH64:
637 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
638  break;
639  case ELF::EM_ARM:
640 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
641  break;
642  case ELF::EM_ARC:
643 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
644  break;
645  case ELF::EM_RISCV:
646 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
647  break;
648  case ELF::EM_LANAI:
649 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
650  break;
651  case ELF::EM_AMDGPU:
652 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
653  break;
654  case ELF::EM_BPF:
655 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
656  break;
657  default:
658  llvm_unreachable("Unsupported architecture");
659  }
660 #undef ELF_RELOC
661  IO.enumFallback<Hex32>(Value);
662 }
663 
665  IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
666 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
667  ECase(REG_NONE);
668  ECase(REG_32);
669  ECase(REG_64);
670  ECase(REG_128);
671 #undef ECase
672 }
673 
675  IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
676 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
677  ECase(FP_ANY);
678  ECase(FP_DOUBLE);
679  ECase(FP_SINGLE);
680  ECase(FP_SOFT);
681  ECase(FP_OLD_64);
682  ECase(FP_XX);
683  ECase(FP_64);
684  ECase(FP_64A);
685 #undef ECase
686 }
687 
689  IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
690 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
691  ECase(EXT_NONE);
692  ECase(EXT_XLR);
693  ECase(EXT_OCTEON2);
694  ECase(EXT_OCTEONP);
695  ECase(EXT_LOONGSON_3A);
696  ECase(EXT_OCTEON);
697  ECase(EXT_5900);
698  ECase(EXT_4650);
699  ECase(EXT_4010);
700  ECase(EXT_4100);
701  ECase(EXT_3900);
702  ECase(EXT_10000);
703  ECase(EXT_SB1);
704  ECase(EXT_4111);
705  ECase(EXT_4120);
706  ECase(EXT_5400);
707  ECase(EXT_5500);
708  ECase(EXT_LOONGSON_2E);
709  ECase(EXT_LOONGSON_2F);
710  ECase(EXT_OCTEON3);
711 #undef ECase
712 }
713 
715  IO &IO, ELFYAML::MIPS_ISA &Value) {
716  IO.enumCase(Value, "MIPS1", 1);
717  IO.enumCase(Value, "MIPS2", 2);
718  IO.enumCase(Value, "MIPS3", 3);
719  IO.enumCase(Value, "MIPS4", 4);
720  IO.enumCase(Value, "MIPS5", 5);
721  IO.enumCase(Value, "MIPS32", 32);
722  IO.enumCase(Value, "MIPS64", 64);
723 }
724 
726  IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
727 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
728  BCase(DSP);
729  BCase(DSPR2);
730  BCase(EVA);
731  BCase(MCU);
732  BCase(MDMX);
733  BCase(MIPS3D);
734  BCase(MT);
735  BCase(SMARTMIPS);
736  BCase(VIRT);
737  BCase(MSA);
738  BCase(MIPS16);
739  BCase(MICROMIPS);
740  BCase(XPA);
741 #undef BCase
742 }
743 
745  IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
746 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
747  BCase(ODDSPREG);
748 #undef BCase
749 }
750 
752  ELFYAML::FileHeader &FileHdr) {
753  IO.mapRequired("Class", FileHdr.Class);
754  IO.mapRequired("Data", FileHdr.Data);
755  IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
756  IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0));
757  IO.mapRequired("Type", FileHdr.Type);
758  IO.mapRequired("Machine", FileHdr.Machine);
759  IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
760  IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
761 }
762 
764  IO &IO, ELFYAML::ProgramHeader &Phdr) {
765  IO.mapRequired("Type", Phdr.Type);
766  IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
767  IO.mapOptional("Sections", Phdr.Sections);
768  IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
769  IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
770  IO.mapOptional("Align", Phdr.Align);
771 }
772 
773 namespace {
774 
775 struct NormalizedOther {
776  NormalizedOther(IO &)
777  : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
778  NormalizedOther(IO &, uint8_t Original)
779  : Visibility(Original & 0x3), Other(Original & ~0x3) {}
780 
781  uint8_t denormalize(IO &) { return Visibility | Other; }
782 
783  ELFYAML::ELF_STV Visibility;
784  ELFYAML::ELF_STO Other;
785 };
786 
787 } // end anonymous namespace
788 
790  IO.mapOptional("Name", Symbol.Name, StringRef());
791  IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
792  IO.mapOptional("Section", Symbol.Section, StringRef());
793  IO.mapOptional("Index", Symbol.Index);
794  IO.mapOptional("Value", Symbol.Value, Hex64(0));
795  IO.mapOptional("Size", Symbol.Size, Hex64(0));
796 
797  MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
798  IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
799  IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
800 }
801 
804  if (Symbol.Index && Symbol.Section.data()) {
805  return "Index and Section cannot both be specified for Symbol";
806  }
807  if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
808  return "Large indexes are not supported";
809  }
810  if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
811  return "Use a section name to define which section a symbol is defined in";
812  }
813  return StringRef();
814 }
815 
817  IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
818  IO.mapOptional("Local", Symbols.Local);
819  IO.mapOptional("Global", Symbols.Global);
820  IO.mapOptional("Weak", Symbols.Weak);
821 }
822 
824  IO.mapOptional("Name", Section.Name, StringRef());
825  IO.mapRequired("Type", Section.Type);
826  IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
827  IO.mapOptional("Address", Section.Address, Hex64(0));
828  IO.mapOptional("Link", Section.Link, StringRef());
829  IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
830  IO.mapOptional("EntSize", Section.EntSize);
831  IO.mapOptional("Info", Section.Info, StringRef());
832 }
833 
835  commonSectionMapping(IO, Section);
836  IO.mapOptional("Content", Section.Content);
837  IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
838 }
839 
841  commonSectionMapping(IO, Section);
842  IO.mapOptional("Size", Section.Size, Hex64(0));
843 }
844 
846  commonSectionMapping(IO, Section);
847  IO.mapOptional("Relocations", Section.Relocations);
848 }
849 
850 static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
851  commonSectionMapping(IO, group);
852  IO.mapRequired("Members", group.Members);
853 }
854 
856  IO &IO, ELFYAML::SectionOrType &sectionOrType) {
857  IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
858 }
859 
861  IO &IO, ELFYAML::SectionName &sectionName) {
862  IO.mapRequired("Section", sectionName.Section);
863 }
864 
866  commonSectionMapping(IO, Section);
867  IO.mapOptional("Version", Section.Version, Hex16(0));
868  IO.mapRequired("ISA", Section.ISALevel);
869  IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
870  IO.mapOptional("ISAExtension", Section.ISAExtension,
871  ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
872  IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
873  IO.mapOptional("FpABI", Section.FpABI,
874  ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
875  IO.mapOptional("GPRSize", Section.GPRSize,
876  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
877  IO.mapOptional("CPR1Size", Section.CPR1Size,
878  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
879  IO.mapOptional("CPR2Size", Section.CPR2Size,
880  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
881  IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
882  IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
883 }
884 
886  IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
887  ELFYAML::ELF_SHT sectionType;
888  if (IO.outputting())
889  sectionType = Section->Type;
890  else
891  IO.mapRequired("Type", sectionType);
892 
893  switch (sectionType) {
894  case ELF::SHT_REL:
895  case ELF::SHT_RELA:
896  if (!IO.outputting())
897  Section.reset(new ELFYAML::RelocationSection());
898  sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
899  break;
900  case ELF::SHT_GROUP:
901  if (!IO.outputting())
902  Section.reset(new ELFYAML::Group());
903  groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
904  break;
905  case ELF::SHT_NOBITS:
906  if (!IO.outputting())
907  Section.reset(new ELFYAML::NoBitsSection());
908  sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
909  break;
911  if (!IO.outputting())
912  Section.reset(new ELFYAML::MipsABIFlags());
913  sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
914  break;
915  default:
916  if (!IO.outputting())
917  Section.reset(new ELFYAML::RawContentSection());
918  sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
919  }
920 }
921 
923  IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
924  const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
925  if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
926  return StringRef();
927  return "Section size must be greater or equal to the content size";
928 }
929 
930 namespace {
931 
932 struct NormalizedMips64RelType {
933  NormalizedMips64RelType(IO &)
934  : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
935  Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
936  Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
937  SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
938  NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
939  : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
940  Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
941 
942  ELFYAML::ELF_REL denormalize(IO &) {
943  ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
944  return Res;
945  }
946 
947  ELFYAML::ELF_REL Type;
948  ELFYAML::ELF_REL Type2;
949  ELFYAML::ELF_REL Type3;
950  ELFYAML::ELF_RSS SpecSym;
951 };
952 
953 } // end anonymous namespace
954 
956  ELFYAML::Relocation &Rel) {
957  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
958  assert(Object && "The IO context is not initialized");
959 
960  IO.mapRequired("Offset", Rel.Offset);
961  IO.mapOptional("Symbol", Rel.Symbol);
962 
963  if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
964  Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
965  MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
966  IO, Rel.Type);
967  IO.mapRequired("Type", Key->Type);
968  IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
969  IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
970  IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
971  } else
972  IO.mapRequired("Type", Rel.Type);
973 
974  IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
975 }
976 
978  assert(!IO.getContext() && "The IO context is initialized already");
979  IO.setContext(&Object);
980  IO.mapTag("!ELF", true);
981  IO.mapRequired("FileHeader", Object.Header);
982  IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
983  IO.mapOptional("Sections", Object.Sections);
984  IO.mapOptional("Symbols", Object.Symbols);
985  IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
986  IO.setContext(nullptr);
987 }
988 
989 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
990 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
991 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
992 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
993 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
994 
995 } // end namespace yaml
996 
997 } // end namespace llvm
This file declares classes for handling the YAML representation of ELF.
static void bitset(IO &IO, ELFYAML::ELF_SHF &Value)
Definition: ELFYAML.cpp:499
This class represents lattice values for constants.
Definition: AllocatorList.h:24
static void enumeration(IO &IO, ELFYAML::ELF_ET &Value)
Definition: ELFYAML.cpp:30
Optional< llvm::yaml::Hex64 > Align
Definition: ELFYAML.h:87
static void enumeration(IO &IO, ELFYAML::ELF_STT &Value)
Definition: ELFYAML.cpp:564
static void enumeration(IO &IO, ELFYAML::ELF_STV &Value)
Definition: ELFYAML.cpp:578
Optional< ELF_SHN > Index
Definition: ELFYAML.h:95
static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value)
Definition: ELFYAML.cpp:542
llvm::yaml::Hex64 PAddr
Definition: ELFYAML.h:86
static void bitset(IO &IO, ELFYAML::ELF_PF &Value)
Definition: ELFYAML.cpp:491
std::vector< SectionName > Sections
Definition: ELFYAML.h:88
llvm::yaml::Hex16 Version
Definition: ELFYAML.h:184
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:949
llvm::yaml::Hex64 Address
Definition: ELFYAML.h:123
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:783
static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value)
Definition: ELFYAML.cpp:607
FileHeader Header
Definition: ELFYAML.h:204
static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value)
Definition: ELFYAML.cpp:426
llvm::yaml::Hex64 Entry
Definition: ELFYAML.h:75
static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value)
Definition: ELFYAML.cpp:744
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
LocalGlobalWeakSymbols Symbols
Definition: ELFYAML.h:211
llvm::yaml::Hex64 AddressAlign
Definition: ELFYAML.h:126
std::vector< Symbol > Weak
Definition: ELFYAML.h:104
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:144
StringRef Section
Definition: ELFYAML.h:94
static void enumeration(IO &IO, ELFYAML::ELF_EM &Value)
Definition: ELFYAML.cpp:58
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:97
static void groupSectionMapping(IO &IO, ELFYAML::Group &group)
Definition: ELFYAML.cpp:850
StringRef Name
Definition: ELFYAML.h:92
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:784
llvm::yaml::Hex8 ABIVersion
Definition: ELFYAML.h:71
Key
PAL metadata keys.
static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value)
Definition: ELFYAML.cpp:223
Optional< llvm::yaml::Hex64 > EntSize
Definition: ELFYAML.h:127
ELFYAML::ELF_RSS SpecSym
Definition: ELFYAML.cpp:950
std::vector< Symbol > Global
Definition: ELFYAML.h:103
LocalGlobalWeakSymbols DynamicSymbols
Definition: ELFYAML.h:212
static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value)
Definition: ELFYAML.cpp:714
static void bitset(IO &IO, ELFYAML::ELF_STO &Value)
Definition: ELFYAML.cpp:588
std::vector< ProgramHeader > ProgramHeaders
Definition: ELFYAML.h:205
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section)
Definition: ELFYAML.cpp:823
static void enumeration(IO &IO, ELFYAML::ELF_PT &Value)
Definition: ELFYAML.cpp:42
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
llvm::yaml::Hex32 Flags2
Definition: ELFYAML.h:194
#define BCase(X)
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value)
Definition: ELFYAML.cpp:617
std::vector< std::unique_ptr< Section > > Sections
Definition: ELFYAML.h:206
std::vector< Symbol > Local
Definition: ELFYAML.h:102
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
llvm::yaml::Hex8 ISARevision
Definition: ELFYAML.h:186
ArrayRef< uint8_t >::size_type binary_size() const
The number of bytes that are represented by this BinaryRef.
Definition: YAML.h:82
static void bitset(IO &IO, ELFYAML::ELF_EF &Value)
Definition: ELFYAML.cpp:273
ELF_ELFCLASS Class
Definition: ELFYAML.h:68
std::vector< SectionOrType > Members
Definition: ELFYAML.h:156
llvm::yaml::Hex64 Offset
Definition: ELFYAML.h:166
static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value)
Definition: ELFYAML.cpp:243
static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value)
Definition: ELFYAML.cpp:725
static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value)
Definition: ELFYAML.cpp:688
#define ECase(X)
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:948
static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value)
Definition: ELFYAML.cpp:674
MIPS_AFL_EXT ISAExtension
Definition: ELFYAML.h:191
llvm::yaml::Hex64 Value
Definition: ELFYAML.h:96
static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value)
Definition: ELFYAML.cpp:233
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
MIPS_AFL_FLAGS1 Flags1
Definition: ELFYAML.h:193
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:134
static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section)
Definition: ELFYAML.cpp:834
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value)
Definition: ELFYAML.cpp:664
ELF_ELFOSABI OSABI
Definition: ELFYAML.h:70
llvm::yaml::Hex64 VAddr
Definition: ELFYAML.h:85
#define BCaseMask(X, M)
Optional< StringRef > Symbol
Definition: ELFYAML.h:169
std::vector< Relocation > Relocations
Definition: ELFYAML.h:173