LLVM  6.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);
53 #undef ECase
54  IO.enumFallback<Hex32>(Value);
55 }
56 
58  IO &IO, ELFYAML::ELF_EM &Value) {
59 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
60  ECase(EM_NONE);
61  ECase(EM_M32);
62  ECase(EM_SPARC);
63  ECase(EM_386);
64  ECase(EM_68K);
65  ECase(EM_88K);
66  ECase(EM_IAMCU);
67  ECase(EM_860);
68  ECase(EM_MIPS);
69  ECase(EM_S370);
74  ECase(EM_960);
75  ECase(EM_PPC);
76  ECase(EM_PPC64);
77  ECase(EM_S390);
78  ECase(EM_SPU);
79  ECase(EM_V800);
80  ECase(EM_FR20);
81  ECase(EM_RH32);
82  ECase(EM_RCE);
83  ECase(EM_ARM);
84  ECase(EM_ALPHA);
85  ECase(EM_SH);
88  ECase(EM_ARC);
91  ECase(EM_H8S);
93  ECase(EM_IA_64);
97  ECase(EM_MMA);
98  ECase(EM_PCP);
99  ECase(EM_NCPU);
100  ECase(EM_NDR1);
102  ECase(EM_ME16);
103  ECase(EM_ST100);
104  ECase(EM_TINYJ);
105  ECase(EM_X86_64);
106  ECase(EM_PDSP);
107  ECase(EM_PDP10);
108  ECase(EM_PDP11);
109  ECase(EM_FX66);
110  ECase(EM_ST9PLUS);
111  ECase(EM_ST7);
112  ECase(EM_68HC16);
113  ECase(EM_68HC11);
114  ECase(EM_68HC08);
115  ECase(EM_68HC05);
116  ECase(EM_SVX);
117  ECase(EM_ST19);
118  ECase(EM_VAX);
119  ECase(EM_CRIS);
120  ECase(EM_JAVELIN);
122  ECase(EM_ZSP);
123  ECase(EM_MMIX);
124  ECase(EM_HUANY);
125  ECase(EM_PRISM);
126  ECase(EM_AVR);
127  ECase(EM_FR30);
128  ECase(EM_D10V);
129  ECase(EM_D30V);
130  ECase(EM_V850);
131  ECase(EM_M32R);
132  ECase(EM_MN10300);
133  ECase(EM_MN10200);
134  ECase(EM_PJ);
137  ECase(EM_XTENSA);
139  ECase(EM_TMM_GPP);
140  ECase(EM_NS32K);
141  ECase(EM_TPC);
142  ECase(EM_SNP1K);
143  ECase(EM_ST200);
144  ECase(EM_IP2K);
145  ECase(EM_MAX);
146  ECase(EM_CR);
147  ECase(EM_F2MC16);
148  ECase(EM_MSP430);
150  ECase(EM_SE_C33);
151  ECase(EM_SEP);
152  ECase(EM_ARCA);
153  ECase(EM_UNICORE);
154  ECase(EM_EXCESS);
155  ECase(EM_DXP);
157  ECase(EM_CRX);
158  ECase(EM_XGATE);
159  ECase(EM_C166);
160  ECase(EM_M16C);
162  ECase(EM_CE);
163  ECase(EM_M32C);
164  ECase(EM_TSK3000);
165  ECase(EM_RS08);
166  ECase(EM_SHARC);
167  ECase(EM_ECOG2);
168  ECase(EM_SCORE7);
169  ECase(EM_DSP24);
172  ECase(EM_SE_C17);
178  ECase(EM_R32C);
180  ECase(EM_HEXAGON);
181  ECase(EM_8051);
182  ECase(EM_STXP7X);
183  ECase(EM_NDS32);
184  ECase(EM_ECOG1);
185  ECase(EM_ECOG1X);
186  ECase(EM_MAXQ30);
187  ECase(EM_XIMO16);
188  ECase(EM_MANIK);
189  ECase(EM_CRAYNV2);
190  ECase(EM_RX);
191  ECase(EM_METAG);
193  ECase(EM_ECOG16);
194  ECase(EM_CR16);
195  ECase(EM_ETPU);
196  ECase(EM_SLE9X);
197  ECase(EM_L10M);
198  ECase(EM_K10M);
199  ECase(EM_AARCH64);
200  ECase(EM_AVR32);
201  ECase(EM_STM8);
202  ECase(EM_TILE64);
203  ECase(EM_TILEPRO);
204  ECase(EM_CUDA);
205  ECase(EM_TILEGX);
210  ECase(EM_OPEN8);
211  ECase(EM_RL78);
213  ECase(EM_78KOR);
214  ECase(EM_56800EX);
215  ECase(EM_AMDGPU);
216  ECase(EM_RISCV);
217  ECase(EM_LANAI);
218  ECase(EM_BPF);
219 #undef ECase
220 }
221 
223  IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
224 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
225  // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
226  // here.
227  ECase(ELFCLASS32);
228  ECase(ELFCLASS64);
229 #undef ECase
230 }
231 
233  IO &IO, ELFYAML::ELF_ELFDATA &Value) {
234 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
235  // Since the semantics of ELFDATANONE is "invalid", just don't accept it
236  // here.
239 #undef ECase
240 }
241 
243  IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
244 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
269 #undef ECase
270 }
271 
273  ELFYAML::ELF_EF &Value) {
274  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
275  assert(Object && "The IO context is not initialized");
276 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
277 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
278  switch (Object->Header.Machine) {
279  case ELF::EM_ARM:
288  break;
289  case ELF::EM_MIPS:
333  break;
334  case ELF::EM_HEXAGON:
343  break;
344  case ELF::EM_AVR:
362  break;
363  case ELF::EM_RISCV:
370  break;
371  case ELF::EM_AMDGPU:
374  break;
375  case ELF::EM_X86_64:
376  break;
377  default:
378  llvm_unreachable("Unsupported architecture");
379  }
380 #undef BCase
381 #undef BCaseMask
382 }
383 
385  IO &IO, ELFYAML::ELF_SHT &Value) {
386  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
387  assert(Object && "The IO context is not initialized");
388 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
389  ECase(SHT_NULL);
391  ECase(SHT_SYMTAB);
392  // FIXME: Issue a diagnostic with this information.
393  ECase(SHT_STRTAB);
394  ECase(SHT_RELA);
395  ECase(SHT_HASH);
397  ECase(SHT_NOTE);
398  ECase(SHT_NOBITS);
399  ECase(SHT_REL);
400  ECase(SHT_SHLIB);
401  ECase(SHT_DYNSYM);
405  ECase(SHT_GROUP);
407  ECase(SHT_LOOS);
416  ECase(SHT_HIOS);
417  ECase(SHT_LOPROC);
418  switch (Object->Header.Machine) {
419  case ELF::EM_ARM:
425  break;
426  case ELF::EM_HEXAGON:
428  break;
429  case ELF::EM_X86_64:
431  break;
432  case ELF::EM_MIPS:
436  break;
437  default:
438  // Nothing to do.
439  break;
440  }
441 #undef ECase
442 }
443 
445  ELFYAML::ELF_PF &Value) {
446 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
447  BCase(PF_X);
448  BCase(PF_W);
449  BCase(PF_R);
450 }
451 
453  ELFYAML::ELF_SHF &Value) {
454  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
455 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
456  BCase(SHF_WRITE);
457  BCase(SHF_ALLOC);
460  BCase(SHF_MERGE);
465  BCase(SHF_GROUP);
466  BCase(SHF_TLS);
468  switch (Object->Header.Machine) {
469  case ELF::EM_ARM:
471  break;
472  case ELF::EM_HEXAGON:
474  break;
475  case ELF::EM_MIPS:
484  break;
485  case ELF::EM_X86_64:
487  break;
488  default:
489  // Nothing to do.
490  break;
491  }
492 #undef BCase
493 }
494 
496  IO &IO, ELFYAML::ELF_SHN &Value) {
497 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
498  ECase(SHN_UNDEF);
500  ECase(SHN_LOPROC);
501  ECase(SHN_HIPROC);
502  ECase(SHN_LOOS);
503  ECase(SHN_HIOS);
504  ECase(SHN_ABS);
505  ECase(SHN_COMMON);
506  ECase(SHN_XINDEX);
513 #undef ECase
514  IO.enumFallback<Hex32>(Value);
515 }
516 
518  IO &IO, ELFYAML::ELF_STT &Value) {
519 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
520  ECase(STT_NOTYPE);
521  ECase(STT_OBJECT);
522  ECase(STT_FUNC);
524  ECase(STT_FILE);
525  ECase(STT_COMMON);
526  ECase(STT_TLS);
528 #undef ECase
529 }
530 
532  IO &IO, ELFYAML::ELF_STV &Value) {
533 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
536  ECase(STV_HIDDEN);
538 #undef ECase
539 }
540 
542  ELFYAML::ELF_STO &Value) {
543  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
544  assert(Object && "The IO context is not initialized");
545 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
546  switch (Object->Header.Machine) {
547  case ELF::EM_MIPS:
552  break;
553  default:
554  break; // Nothing to do
555  }
556 #undef BCase
557 #undef BCaseMask
558 }
559 
561  IO &IO, ELFYAML::ELF_RSS &Value) {
562 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
563  ECase(RSS_UNDEF);
564  ECase(RSS_GP);
565  ECase(RSS_GP0);
566  ECase(RSS_LOC);
567 #undef ECase
568 }
569 
571  IO &IO, ELFYAML::ELF_REL &Value) {
572  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
573  assert(Object && "The IO context is not initialized");
574 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
575  switch (Object->Header.Machine) {
576  case ELF::EM_X86_64:
577 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
578  break;
579  case ELF::EM_MIPS:
580 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
581  break;
582  case ELF::EM_HEXAGON:
583 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
584  break;
585  case ELF::EM_386:
586  case ELF::EM_IAMCU:
587 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
588  break;
589  case ELF::EM_AARCH64:
590 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
591  break;
592  case ELF::EM_ARM:
593 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
594  break;
595  case ELF::EM_ARC:
596 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
597  break;
598  case ELF::EM_RISCV:
599 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
600  break;
601  case ELF::EM_LANAI:
602 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
603  break;
604  case ELF::EM_AMDGPU:
605 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
606  break;
607  case ELF::EM_BPF:
608 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
609  break;
610  default:
611  llvm_unreachable("Unsupported architecture");
612  }
613 #undef ELF_RELOC
614  IO.enumFallback<Hex32>(Value);
615 }
616 
618  IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
619 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
620  ECase(REG_NONE);
621  ECase(REG_32);
622  ECase(REG_64);
623  ECase(REG_128);
624 #undef ECase
625 }
626 
628  IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
629 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
630  ECase(FP_ANY);
631  ECase(FP_DOUBLE);
632  ECase(FP_SINGLE);
633  ECase(FP_SOFT);
634  ECase(FP_OLD_64);
635  ECase(FP_XX);
636  ECase(FP_64);
637  ECase(FP_64A);
638 #undef ECase
639 }
640 
642  IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
643 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
644  ECase(EXT_NONE);
645  ECase(EXT_XLR);
646  ECase(EXT_OCTEON2);
647  ECase(EXT_OCTEONP);
648  ECase(EXT_LOONGSON_3A);
649  ECase(EXT_OCTEON);
650  ECase(EXT_5900);
651  ECase(EXT_4650);
652  ECase(EXT_4010);
653  ECase(EXT_4100);
654  ECase(EXT_3900);
655  ECase(EXT_10000);
656  ECase(EXT_SB1);
657  ECase(EXT_4111);
658  ECase(EXT_4120);
659  ECase(EXT_5400);
660  ECase(EXT_5500);
661  ECase(EXT_LOONGSON_2E);
662  ECase(EXT_LOONGSON_2F);
663  ECase(EXT_OCTEON3);
664 #undef ECase
665 }
666 
668  IO &IO, ELFYAML::MIPS_ISA &Value) {
669  IO.enumCase(Value, "MIPS1", 1);
670  IO.enumCase(Value, "MIPS2", 2);
671  IO.enumCase(Value, "MIPS3", 3);
672  IO.enumCase(Value, "MIPS4", 4);
673  IO.enumCase(Value, "MIPS5", 5);
674  IO.enumCase(Value, "MIPS32", 32);
675  IO.enumCase(Value, "MIPS64", 64);
676 }
677 
679  IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
680 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
681  BCase(DSP);
682  BCase(DSPR2);
683  BCase(EVA);
684  BCase(MCU);
685  BCase(MDMX);
686  BCase(MIPS3D);
687  BCase(MT);
688  BCase(SMARTMIPS);
689  BCase(VIRT);
690  BCase(MSA);
691  BCase(MIPS16);
692  BCase(MICROMIPS);
693  BCase(XPA);
694 #undef BCase
695 }
696 
698  IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
699 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
700  BCase(ODDSPREG);
701 #undef BCase
702 }
703 
705  ELFYAML::FileHeader &FileHdr) {
706  IO.mapRequired("Class", FileHdr.Class);
707  IO.mapRequired("Data", FileHdr.Data);
708  IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
709  IO.mapRequired("Type", FileHdr.Type);
710  IO.mapRequired("Machine", FileHdr.Machine);
711  IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
712  IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
713 }
714 
716  IO &IO, ELFYAML::ProgramHeader &Phdr) {
717  IO.mapRequired("Type", Phdr.Type);
718  IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
719  IO.mapOptional("Sections", Phdr.Sections);
720  IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
721  IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
722  IO.mapOptional("Align", Phdr.Align);
723 }
724 
725 namespace {
726 
727 struct NormalizedOther {
728  NormalizedOther(IO &)
729  : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
730  NormalizedOther(IO &, uint8_t Original)
731  : Visibility(Original & 0x3), Other(Original & ~0x3) {}
732 
733  uint8_t denormalize(IO &) { return Visibility | Other; }
734 
735  ELFYAML::ELF_STV Visibility;
736  ELFYAML::ELF_STO Other;
737 };
738 
739 } // end anonymous namespace
740 
742  IO.mapOptional("Name", Symbol.Name, StringRef());
743  IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
744  IO.mapOptional("Section", Symbol.Section, StringRef());
745  IO.mapOptional("Index", Symbol.Index);
746  IO.mapOptional("Value", Symbol.Value, Hex64(0));
747  IO.mapOptional("Size", Symbol.Size, Hex64(0));
748 
750  IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
751  IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
752 }
753 
756  if (Symbol.Index && Symbol.Section.data()) {
757  return "Index and Section cannot both be specified for Symbol";
758  }
759  if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
760  return "Large indexes are not supported";
761  }
762  if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
763  return "Use a section name to define which section a symbol is defined in";
764  }
765  return StringRef();
766 }
767 
770  IO.mapOptional("Local", Symbols.Local);
771  IO.mapOptional("Global", Symbols.Global);
772  IO.mapOptional("Weak", Symbols.Weak);
773 }
774 
776  IO.mapOptional("Name", Section.Name, StringRef());
777  IO.mapRequired("Type", Section.Type);
778  IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
779  IO.mapOptional("Address", Section.Address, Hex64(0));
780  IO.mapOptional("Link", Section.Link, StringRef());
781  IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
782  IO.mapOptional("Info", Section.Info, StringRef());
783 }
784 
786  commonSectionMapping(IO, Section);
787  IO.mapOptional("Content", Section.Content);
788  IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
789 }
790 
792  commonSectionMapping(IO, Section);
793  IO.mapOptional("Size", Section.Size, Hex64(0));
794 }
795 
797  commonSectionMapping(IO, Section);
798  IO.mapOptional("Relocations", Section.Relocations);
799 }
800 
801 static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
802  commonSectionMapping(IO, group);
803  IO.mapRequired("Members", group.Members);
804 }
805 
807  IO &IO, ELFYAML::SectionOrType &sectionOrType) {
808  IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
809 }
810 
812  IO &IO, ELFYAML::SectionName &sectionName) {
813  IO.mapRequired("Section", sectionName.Section);
814 }
815 
817  commonSectionMapping(IO, Section);
818  IO.mapOptional("Version", Section.Version, Hex16(0));
819  IO.mapRequired("ISA", Section.ISALevel);
820  IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
821  IO.mapOptional("ISAExtension", Section.ISAExtension,
822  ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
823  IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
824  IO.mapOptional("FpABI", Section.FpABI,
825  ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
826  IO.mapOptional("GPRSize", Section.GPRSize,
827  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
828  IO.mapOptional("CPR1Size", Section.CPR1Size,
829  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
830  IO.mapOptional("CPR2Size", Section.CPR2Size,
831  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
832  IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
833  IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
834 }
835 
837  IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
838  ELFYAML::ELF_SHT sectionType;
839  if (IO.outputting())
840  sectionType = Section->Type;
841  else
842  IO.mapRequired("Type", sectionType);
843 
844  switch (sectionType) {
845  case ELF::SHT_REL:
846  case ELF::SHT_RELA:
847  if (!IO.outputting())
848  Section.reset(new ELFYAML::RelocationSection());
849  sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
850  break;
851  case ELF::SHT_GROUP:
852  if (!IO.outputting())
853  Section.reset(new ELFYAML::Group());
854  groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
855  break;
856  case ELF::SHT_NOBITS:
857  if (!IO.outputting())
858  Section.reset(new ELFYAML::NoBitsSection());
859  sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
860  break;
862  if (!IO.outputting())
863  Section.reset(new ELFYAML::MipsABIFlags());
864  sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
865  break;
866  default:
867  if (!IO.outputting())
868  Section.reset(new ELFYAML::RawContentSection());
869  sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
870  }
871 }
872 
874  IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
875  const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
876  if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
877  return StringRef();
878  return "Section size must be greater or equal to the content size";
879 }
880 
881 namespace {
882 
883 struct NormalizedMips64RelType {
884  NormalizedMips64RelType(IO &)
885  : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
886  Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
887  Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
888  SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
889  NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
890  : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
891  Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
892 
893  ELFYAML::ELF_REL denormalize(IO &) {
894  ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
895  return Res;
896  }
897 
898  ELFYAML::ELF_REL Type;
899  ELFYAML::ELF_REL Type2;
900  ELFYAML::ELF_REL Type3;
901  ELFYAML::ELF_RSS SpecSym;
902 };
903 
904 } // end anonymous namespace
905 
907  ELFYAML::Relocation &Rel) {
908  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
909  assert(Object && "The IO context is not initialized");
910 
911  IO.mapRequired("Offset", Rel.Offset);
912  IO.mapOptional("Symbol", Rel.Symbol);
913 
914  if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
915  Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
917  IO, Rel.Type);
918  IO.mapRequired("Type", Key->Type);
919  IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
920  IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
921  IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
922  } else
923  IO.mapRequired("Type", Rel.Type);
924 
925  IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
926 }
927 
929  assert(!IO.getContext() && "The IO context is initialized already");
930  IO.setContext(&Object);
931  IO.mapTag("!ELF", true);
932  IO.mapRequired("FileHeader", Object.Header);
933  IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
934  IO.mapOptional("Sections", Object.Sections);
935  IO.mapOptional("Symbols", Object.Symbols);
936  IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
937  IO.setContext(nullptr);
938 }
939 
940 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
941 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
942 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
943 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
944 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
945 
946 } // end namespace yaml
947 
948 } // end namespace llvm
This file declares classes for handling the YAML representation of ELF.
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:656
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Optional< llvm::yaml::Hex64 > Align
Definition: ELFYAML.h:86
Optional< ELF_SHN > Index
Definition: ELFYAML.h:94
void * getContext()
Definition: YAMLTraits.cpp:43
llvm::yaml::Hex64 PAddr
Definition: ELFYAML.h:85
std::vector< SectionName > Sections
Definition: ELFYAML.h:87
llvm::yaml::Hex16 Version
Definition: ELFYAML.h:182
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:900
llvm::yaml::Hex64 Address
Definition: ELFYAML.h:122
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:735
FileHeader Header
Definition: ELFYAML.h:202
llvm::yaml::Hex64 Entry
Definition: ELFYAML.h:74
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:898
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
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:96
static void groupSectionMapping(IO &IO, ELFYAML::Group &group)
Definition: ELFYAML.cpp:801
void enumFallback(T &Val)
Definition: YAMLTraits.h:605
StringRef Name
Definition: ELFYAML.h:91
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:736
Key
PAL metadata keys.
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
ELFYAML::ELF_RSS SpecSym
Definition: ELFYAML.cpp:901
std::vector< Symbol > Global
Definition: ELFYAML.h:102
LocalGlobalWeakSymbols DynamicSymbols
Definition: ELFYAML.h:210
virtual bool mapTag(StringRef Tag, bool Default=false)=0
std::vector< ProgramHeader > ProgramHeaders
Definition: ELFYAML.h:203
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:590
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section)
Definition: ELFYAML.cpp:775
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)
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
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:98
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
YAML I/O does conversion based on types.
Definition: YAMLTraits.h:1346
ELF_ELFCLASS Class
Definition: ELFYAML.h:68
std::vector< SectionOrType > Members
Definition: ELFYAML.h:154
llvm::yaml::Hex64 Offset
Definition: ELFYAML.h:164
void setContext(void *)
Definition: YAMLTraits.cpp:47
#define ECase(X)
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:899
MIPS_AFL_EXT ISAExtension
Definition: ELFYAML.h:189
llvm::yaml::Hex64 Value
Definition: ELFYAML.h:95
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
virtual bool outputting()=0
MIPS_AFL_FLAGS1 Flags1
Definition: ELFYAML.h:191
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
Definition: YAMLTraits.h:115
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:785
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:646
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