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