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