LLVM  8.0.0svn
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:
344  break;
345  case ELF::EM_AVR:
363  break;
364  case ELF::EM_RISCV:
371  break;
372  case ELF::EM_AMDGPU:
408  break;
409  case ELF::EM_X86_64:
410  break;
411  default:
412  llvm_unreachable("Unsupported architecture");
413  }
414 #undef BCase
415 #undef BCaseMask
416 }
417 
419  IO &IO, ELFYAML::ELF_SHT &Value) {
420  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
421  assert(Object && "The IO context is not initialized");
422 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
423  ECase(SHT_NULL);
425  ECase(SHT_SYMTAB);
426  // FIXME: Issue a diagnostic with this information.
427  ECase(SHT_STRTAB);
428  ECase(SHT_RELA);
429  ECase(SHT_HASH);
431  ECase(SHT_NOTE);
432  ECase(SHT_NOBITS);
433  ECase(SHT_REL);
434  ECase(SHT_SHLIB);
435  ECase(SHT_DYNSYM);
439  ECase(SHT_GROUP);
441  ECase(SHT_RELR);
442  ECase(SHT_LOOS);
455  ECase(SHT_HIOS);
456  ECase(SHT_LOPROC);
457  switch (Object->Header.Machine) {
458  case ELF::EM_ARM:
464  break;
465  case ELF::EM_HEXAGON:
467  break;
468  case ELF::EM_X86_64:
470  break;
471  case ELF::EM_MIPS:
475  break;
476  default:
477  // Nothing to do.
478  break;
479  }
480 #undef ECase
481 }
482 
484  ELFYAML::ELF_PF &Value) {
485 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
486  BCase(PF_X);
487  BCase(PF_W);
488  BCase(PF_R);
489 }
490 
492  ELFYAML::ELF_SHF &Value) {
493  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
494 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
495  BCase(SHF_WRITE);
496  BCase(SHF_ALLOC);
499  BCase(SHF_MERGE);
504  BCase(SHF_GROUP);
505  BCase(SHF_TLS);
507  switch (Object->Header.Machine) {
508  case ELF::EM_ARM:
510  break;
511  case ELF::EM_HEXAGON:
513  break;
514  case ELF::EM_MIPS:
523  break;
524  case ELF::EM_X86_64:
526  break;
527  default:
528  // Nothing to do.
529  break;
530  }
531 #undef BCase
532 }
533 
535  IO &IO, ELFYAML::ELF_SHN &Value) {
536 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
537  ECase(SHN_UNDEF);
539  ECase(SHN_LOPROC);
540  ECase(SHN_HIPROC);
541  ECase(SHN_LOOS);
542  ECase(SHN_HIOS);
543  ECase(SHN_ABS);
544  ECase(SHN_COMMON);
545  ECase(SHN_XINDEX);
552 #undef ECase
553  IO.enumFallback<Hex32>(Value);
554 }
555 
557  IO &IO, ELFYAML::ELF_STT &Value) {
558 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
559  ECase(STT_NOTYPE);
560  ECase(STT_OBJECT);
561  ECase(STT_FUNC);
563  ECase(STT_FILE);
564  ECase(STT_COMMON);
565  ECase(STT_TLS);
567 #undef ECase
568 }
569 
571  IO &IO, ELFYAML::ELF_STV &Value) {
572 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
575  ECase(STV_HIDDEN);
577 #undef ECase
578 }
579 
581  ELFYAML::ELF_STO &Value) {
582  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
583  assert(Object && "The IO context is not initialized");
584 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
585  switch (Object->Header.Machine) {
586  case ELF::EM_MIPS:
591  break;
592  default:
593  break; // Nothing to do
594  }
595 #undef BCase
596 #undef BCaseMask
597 }
598 
600  IO &IO, ELFYAML::ELF_RSS &Value) {
601 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
602  ECase(RSS_UNDEF);
603  ECase(RSS_GP);
604  ECase(RSS_GP0);
605  ECase(RSS_LOC);
606 #undef ECase
607 }
608 
610  IO &IO, ELFYAML::ELF_REL &Value) {
611  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
612  assert(Object && "The IO context is not initialized");
613 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
614  switch (Object->Header.Machine) {
615  case ELF::EM_X86_64:
616 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
617  break;
618  case ELF::EM_MIPS:
619 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
620  break;
621  case ELF::EM_HEXAGON:
622 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
623  break;
624  case ELF::EM_386:
625  case ELF::EM_IAMCU:
626 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
627  break;
628  case ELF::EM_AARCH64:
629 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
630  break;
631  case ELF::EM_ARM:
632 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
633  break;
634  case ELF::EM_ARC:
635 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
636  break;
637  case ELF::EM_RISCV:
638 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
639  break;
640  case ELF::EM_LANAI:
641 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
642  break;
643  case ELF::EM_AMDGPU:
644 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
645  break;
646  case ELF::EM_BPF:
647 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
648  break;
649  default:
650  llvm_unreachable("Unsupported architecture");
651  }
652 #undef ELF_RELOC
653  IO.enumFallback<Hex32>(Value);
654 }
655 
657  IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
658 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
659  ECase(REG_NONE);
660  ECase(REG_32);
661  ECase(REG_64);
662  ECase(REG_128);
663 #undef ECase
664 }
665 
667  IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
668 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
669  ECase(FP_ANY);
670  ECase(FP_DOUBLE);
671  ECase(FP_SINGLE);
672  ECase(FP_SOFT);
673  ECase(FP_OLD_64);
674  ECase(FP_XX);
675  ECase(FP_64);
676  ECase(FP_64A);
677 #undef ECase
678 }
679 
681  IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
682 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
683  ECase(EXT_NONE);
684  ECase(EXT_XLR);
685  ECase(EXT_OCTEON2);
686  ECase(EXT_OCTEONP);
687  ECase(EXT_LOONGSON_3A);
688  ECase(EXT_OCTEON);
689  ECase(EXT_5900);
690  ECase(EXT_4650);
691  ECase(EXT_4010);
692  ECase(EXT_4100);
693  ECase(EXT_3900);
694  ECase(EXT_10000);
695  ECase(EXT_SB1);
696  ECase(EXT_4111);
697  ECase(EXT_4120);
698  ECase(EXT_5400);
699  ECase(EXT_5500);
700  ECase(EXT_LOONGSON_2E);
701  ECase(EXT_LOONGSON_2F);
702  ECase(EXT_OCTEON3);
703 #undef ECase
704 }
705 
707  IO &IO, ELFYAML::MIPS_ISA &Value) {
708  IO.enumCase(Value, "MIPS1", 1);
709  IO.enumCase(Value, "MIPS2", 2);
710  IO.enumCase(Value, "MIPS3", 3);
711  IO.enumCase(Value, "MIPS4", 4);
712  IO.enumCase(Value, "MIPS5", 5);
713  IO.enumCase(Value, "MIPS32", 32);
714  IO.enumCase(Value, "MIPS64", 64);
715 }
716 
718  IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
719 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
720  BCase(DSP);
721  BCase(DSPR2);
722  BCase(EVA);
723  BCase(MCU);
724  BCase(MDMX);
725  BCase(MIPS3D);
726  BCase(MT);
727  BCase(SMARTMIPS);
728  BCase(VIRT);
729  BCase(MSA);
730  BCase(MIPS16);
731  BCase(MICROMIPS);
732  BCase(XPA);
733 #undef BCase
734 }
735 
737  IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
738 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
739  BCase(ODDSPREG);
740 #undef BCase
741 }
742 
744  ELFYAML::FileHeader &FileHdr) {
745  IO.mapRequired("Class", FileHdr.Class);
746  IO.mapRequired("Data", FileHdr.Data);
747  IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
748  IO.mapRequired("Type", FileHdr.Type);
749  IO.mapRequired("Machine", FileHdr.Machine);
750  IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
751  IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
752 }
753 
755  IO &IO, ELFYAML::ProgramHeader &Phdr) {
756  IO.mapRequired("Type", Phdr.Type);
757  IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
758  IO.mapOptional("Sections", Phdr.Sections);
759  IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
760  IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
761  IO.mapOptional("Align", Phdr.Align);
762 }
763 
764 namespace {
765 
766 struct NormalizedOther {
767  NormalizedOther(IO &)
768  : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
769  NormalizedOther(IO &, uint8_t Original)
770  : Visibility(Original & 0x3), Other(Original & ~0x3) {}
771 
772  uint8_t denormalize(IO &) { return Visibility | Other; }
773 
774  ELFYAML::ELF_STV Visibility;
775  ELFYAML::ELF_STO Other;
776 };
777 
778 } // end anonymous namespace
779 
781  IO.mapOptional("Name", Symbol.Name, StringRef());
782  IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
783  IO.mapOptional("Section", Symbol.Section, StringRef());
784  IO.mapOptional("Index", Symbol.Index);
785  IO.mapOptional("Value", Symbol.Value, Hex64(0));
786  IO.mapOptional("Size", Symbol.Size, Hex64(0));
787 
788  MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
789  IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
790  IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
791 }
792 
795  if (Symbol.Index && Symbol.Section.data()) {
796  return "Index and Section cannot both be specified for Symbol";
797  }
798  if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
799  return "Large indexes are not supported";
800  }
801  if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
802  return "Use a section name to define which section a symbol is defined in";
803  }
804  return StringRef();
805 }
806 
808  IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
809  IO.mapOptional("Local", Symbols.Local);
810  IO.mapOptional("Global", Symbols.Global);
811  IO.mapOptional("Weak", Symbols.Weak);
812 }
813 
815  IO.mapOptional("Name", Section.Name, StringRef());
816  IO.mapRequired("Type", Section.Type);
817  IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
818  IO.mapOptional("Address", Section.Address, Hex64(0));
819  IO.mapOptional("Link", Section.Link, StringRef());
820  IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
821  IO.mapOptional("EntSize", Section.EntSize);
822  IO.mapOptional("Info", Section.Info, StringRef());
823 }
824 
826  commonSectionMapping(IO, Section);
827  IO.mapOptional("Content", Section.Content);
828  IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
829 }
830 
832  commonSectionMapping(IO, Section);
833  IO.mapOptional("Size", Section.Size, Hex64(0));
834 }
835 
837  commonSectionMapping(IO, Section);
838  IO.mapOptional("Relocations", Section.Relocations);
839 }
840 
841 static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
842  commonSectionMapping(IO, group);
843  IO.mapRequired("Members", group.Members);
844 }
845 
847  IO &IO, ELFYAML::SectionOrType &sectionOrType) {
848  IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
849 }
850 
852  IO &IO, ELFYAML::SectionName &sectionName) {
853  IO.mapRequired("Section", sectionName.Section);
854 }
855 
857  commonSectionMapping(IO, Section);
858  IO.mapOptional("Version", Section.Version, Hex16(0));
859  IO.mapRequired("ISA", Section.ISALevel);
860  IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
861  IO.mapOptional("ISAExtension", Section.ISAExtension,
862  ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
863  IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
864  IO.mapOptional("FpABI", Section.FpABI,
865  ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
866  IO.mapOptional("GPRSize", Section.GPRSize,
867  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
868  IO.mapOptional("CPR1Size", Section.CPR1Size,
869  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
870  IO.mapOptional("CPR2Size", Section.CPR2Size,
871  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
872  IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
873  IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
874 }
875 
877  IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
878  ELFYAML::ELF_SHT sectionType;
879  if (IO.outputting())
880  sectionType = Section->Type;
881  else
882  IO.mapRequired("Type", sectionType);
883 
884  switch (sectionType) {
885  case ELF::SHT_REL:
886  case ELF::SHT_RELA:
887  if (!IO.outputting())
888  Section.reset(new ELFYAML::RelocationSection());
889  sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
890  break;
891  case ELF::SHT_GROUP:
892  if (!IO.outputting())
893  Section.reset(new ELFYAML::Group());
894  groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
895  break;
896  case ELF::SHT_NOBITS:
897  if (!IO.outputting())
898  Section.reset(new ELFYAML::NoBitsSection());
899  sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
900  break;
902  if (!IO.outputting())
903  Section.reset(new ELFYAML::MipsABIFlags());
904  sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
905  break;
906  default:
907  if (!IO.outputting())
908  Section.reset(new ELFYAML::RawContentSection());
909  sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
910  }
911 }
912 
914  IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
915  const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
916  if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
917  return StringRef();
918  return "Section size must be greater or equal to the content size";
919 }
920 
921 namespace {
922 
923 struct NormalizedMips64RelType {
924  NormalizedMips64RelType(IO &)
925  : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
926  Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
927  Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
928  SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
929  NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
930  : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
931  Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
932 
933  ELFYAML::ELF_REL denormalize(IO &) {
934  ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
935  return Res;
936  }
937 
938  ELFYAML::ELF_REL Type;
939  ELFYAML::ELF_REL Type2;
940  ELFYAML::ELF_REL Type3;
941  ELFYAML::ELF_RSS SpecSym;
942 };
943 
944 } // end anonymous namespace
945 
947  ELFYAML::Relocation &Rel) {
948  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
949  assert(Object && "The IO context is not initialized");
950 
951  IO.mapRequired("Offset", Rel.Offset);
952  IO.mapOptional("Symbol", Rel.Symbol);
953 
954  if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
955  Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
956  MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
957  IO, Rel.Type);
958  IO.mapRequired("Type", Key->Type);
959  IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
960  IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
961  IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
962  } else
963  IO.mapRequired("Type", Rel.Type);
964 
965  IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
966 }
967 
969  assert(!IO.getContext() && "The IO context is initialized already");
970  IO.setContext(&Object);
971  IO.mapTag("!ELF", true);
972  IO.mapRequired("FileHeader", Object.Header);
973  IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
974  IO.mapOptional("Sections", Object.Sections);
975  IO.mapOptional("Symbols", Object.Symbols);
976  IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
977  IO.setContext(nullptr);
978 }
979 
980 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
981 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
982 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
983 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
984 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
985 
986 } // end namespace yaml
987 
988 } // 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:491
Compute iterated dominance frontiers using a linear time algorithm.
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:86
static void enumeration(IO &IO, ELFYAML::ELF_STT &Value)
Definition: ELFYAML.cpp:556
static void enumeration(IO &IO, ELFYAML::ELF_STV &Value)
Definition: ELFYAML.cpp:570
Optional< ELF_SHN > Index
Definition: ELFYAML.h:94
static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value)
Definition: ELFYAML.cpp:534
llvm::yaml::Hex64 PAddr
Definition: ELFYAML.h:85
static void bitset(IO &IO, ELFYAML::ELF_PF &Value)
Definition: ELFYAML.cpp:483
std::vector< SectionName > Sections
Definition: ELFYAML.h:87
llvm::yaml::Hex16 Version
Definition: ELFYAML.h:183
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:940
llvm::yaml::Hex64 Address
Definition: ELFYAML.h:122
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:774
static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value)
Definition: ELFYAML.cpp:599
FileHeader Header
Definition: ELFYAML.h:203
static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value)
Definition: ELFYAML.cpp:418
llvm::yaml::Hex64 Entry
Definition: ELFYAML.h:74
static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value)
Definition: ELFYAML.cpp:736
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:210
llvm::yaml::Hex64 AddressAlign
Definition: ELFYAML.h:125
std::vector< Symbol > Weak
Definition: ELFYAML.h:103
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:143
StringRef Section
Definition: ELFYAML.h:93
static void enumeration(IO &IO, ELFYAML::ELF_EM &Value)
Definition: ELFYAML.cpp:58
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:96
static void groupSectionMapping(IO &IO, ELFYAML::Group &group)
Definition: ELFYAML.cpp:841
StringRef Name
Definition: ELFYAML.h:91
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:775
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:126
ELFYAML::ELF_RSS SpecSym
Definition: ELFYAML.cpp:941
std::vector< Symbol > Global
Definition: ELFYAML.h:102
LocalGlobalWeakSymbols DynamicSymbols
Definition: ELFYAML.h:211
static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value)
Definition: ELFYAML.cpp:706
static void bitset(IO &IO, ELFYAML::ELF_STO &Value)
Definition: ELFYAML.cpp:580
std::vector< ProgramHeader > ProgramHeaders
Definition: ELFYAML.h:204
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section)
Definition: ELFYAML.cpp:814
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:193
#define BCase(X)
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value)
Definition: ELFYAML.cpp:609
std::vector< std::unique_ptr< Section > > Sections
Definition: ELFYAML.h:205
std::vector< Symbol > Local
Definition: ELFYAML.h:101
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
llvm::yaml::Hex8 ISARevision
Definition: ELFYAML.h:185
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:155
llvm::yaml::Hex64 Offset
Definition: ELFYAML.h:165
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:717
static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value)
Definition: ELFYAML.cpp:680
#define ECase(X)
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:939
static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value)
Definition: ELFYAML.cpp:666
MIPS_AFL_EXT ISAExtension
Definition: ELFYAML.h:190
llvm::yaml::Hex64 Value
Definition: ELFYAML.h:95
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:192
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:133
static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section)
Definition: ELFYAML.cpp:825
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:656
ELF_ELFOSABI OSABI
Definition: ELFYAML.h:70
llvm::yaml::Hex64 VAddr
Definition: ELFYAML.h:84
#define BCaseMask(X, M)
Optional< StringRef > Symbol
Definition: ELFYAML.h:168
std::vector< Relocation > Relocations
Definition: ELFYAML.h:172