LLVM  9.0.0svn
ELFYAML.cpp
Go to the documentation of this file.
1 //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of ELF.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/BinaryFormat/ELF.h"
16 #include "llvm/Support/Casting.h"
20 #include <cassert>
21 #include <cstdint>
22 
23 namespace llvm {
24 
25 ELFYAML::Section::~Section() = default;
26 
27 namespace yaml {
28 
30  IO &IO, ELFYAML::ELF_ET &Value) {
31 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
32  ECase(ET_NONE);
33  ECase(ET_REL);
34  ECase(ET_EXEC);
35  ECase(ET_DYN);
36  ECase(ET_CORE);
37 #undef ECase
38  IO.enumFallback<Hex16>(Value);
39 }
40 
42  IO &IO, ELFYAML::ELF_PT &Value) {
43 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
44  ECase(PT_NULL);
45  ECase(PT_LOAD);
48  ECase(PT_NOTE);
49  ECase(PT_SHLIB);
50  ECase(PT_PHDR);
51  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:
351  break;
352  case ELF::EM_AVR:
370  break;
371  case ELF::EM_RISCV:
378  break;
379  case ELF::EM_AMDGPU:
415  break;
416  case ELF::EM_X86_64:
417  break;
418  default:
419  llvm_unreachable("Unsupported architecture");
420  }
421 #undef BCase
422 #undef BCaseMask
423 }
424 
426  IO &IO, ELFYAML::ELF_SHT &Value) {
427  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
428  assert(Object && "The IO context is not initialized");
429 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
430  ECase(SHT_NULL);
432  ECase(SHT_SYMTAB);
433  // FIXME: Issue a diagnostic with this information.
434  ECase(SHT_STRTAB);
435  ECase(SHT_RELA);
436  ECase(SHT_HASH);
438  ECase(SHT_NOTE);
439  ECase(SHT_NOBITS);
440  ECase(SHT_REL);
441  ECase(SHT_SHLIB);
442  ECase(SHT_DYNSYM);
446  ECase(SHT_GROUP);
448  ECase(SHT_RELR);
449  ECase(SHT_LOOS);
462  ECase(SHT_HIOS);
463  ECase(SHT_LOPROC);
464  switch (Object->Header.Machine) {
465  case ELF::EM_ARM:
471  break;
472  case ELF::EM_HEXAGON:
474  break;
475  case ELF::EM_X86_64:
477  break;
478  case ELF::EM_MIPS:
482  break;
483  default:
484  // Nothing to do.
485  break;
486  }
487 #undef ECase
488 }
489 
491  ELFYAML::ELF_PF &Value) {
492 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
493  BCase(PF_X);
494  BCase(PF_W);
495  BCase(PF_R);
496 }
497 
499  ELFYAML::ELF_SHF &Value) {
500  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
501 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
502  BCase(SHF_WRITE);
503  BCase(SHF_ALLOC);
506  BCase(SHF_MERGE);
511  BCase(SHF_GROUP);
512  BCase(SHF_TLS);
514  switch (Object->Header.Machine) {
515  case ELF::EM_ARM:
517  break;
518  case ELF::EM_HEXAGON:
520  break;
521  case ELF::EM_MIPS:
530  break;
531  case ELF::EM_X86_64:
533  break;
534  default:
535  // Nothing to do.
536  break;
537  }
538 #undef BCase
539 }
540 
542  IO &IO, ELFYAML::ELF_SHN &Value) {
543 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
544  ECase(SHN_UNDEF);
546  ECase(SHN_LOPROC);
547  ECase(SHN_HIPROC);
548  ECase(SHN_LOOS);
549  ECase(SHN_HIOS);
550  ECase(SHN_ABS);
551  ECase(SHN_COMMON);
552  ECase(SHN_XINDEX);
559 #undef ECase
560  IO.enumFallback<Hex32>(Value);
561 }
562 
564  IO &IO, ELFYAML::ELF_STT &Value) {
565 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
566  ECase(STT_NOTYPE);
567  ECase(STT_OBJECT);
568  ECase(STT_FUNC);
570  ECase(STT_FILE);
571  ECase(STT_COMMON);
572  ECase(STT_TLS);
574 #undef ECase
575 }
576 
578  IO &IO, ELFYAML::ELF_STV &Value) {
579 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
582  ECase(STV_HIDDEN);
584 #undef ECase
585 }
586 
588  ELFYAML::ELF_STO &Value) {
589  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
590  assert(Object && "The IO context is not initialized");
591 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
592  switch (Object->Header.Machine) {
593  case ELF::EM_MIPS:
598  break;
599  default:
600  break; // Nothing to do
601  }
602 #undef BCase
603 #undef BCaseMask
604 }
605 
607  IO &IO, ELFYAML::ELF_RSS &Value) {
608 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
609  ECase(RSS_UNDEF);
610  ECase(RSS_GP);
611  ECase(RSS_GP0);
612  ECase(RSS_LOC);
613 #undef ECase
614 }
615 
617  IO &IO, ELFYAML::ELF_REL &Value) {
618  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
619  assert(Object && "The IO context is not initialized");
620 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
621  switch (Object->Header.Machine) {
622  case ELF::EM_X86_64:
623 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
624  break;
625  case ELF::EM_MIPS:
626 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
627  break;
628  case ELF::EM_HEXAGON:
629 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
630  break;
631  case ELF::EM_386:
632  case ELF::EM_IAMCU:
633 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
634  break;
635  case ELF::EM_AARCH64:
636 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
637  break;
638  case ELF::EM_ARM:
639 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
640  break;
641  case ELF::EM_ARC:
642 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
643  break;
644  case ELF::EM_RISCV:
645 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
646  break;
647  case ELF::EM_LANAI:
648 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
649  break;
650  case ELF::EM_AMDGPU:
651 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
652  break;
653  case ELF::EM_BPF:
654 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
655  break;
656  default:
657  llvm_unreachable("Unsupported architecture");
658  }
659 #undef ELF_RELOC
660  IO.enumFallback<Hex32>(Value);
661 }
662 
664  IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
665 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
666  ECase(REG_NONE);
667  ECase(REG_32);
668  ECase(REG_64);
669  ECase(REG_128);
670 #undef ECase
671 }
672 
674  IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
675 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
676  ECase(FP_ANY);
677  ECase(FP_DOUBLE);
678  ECase(FP_SINGLE);
679  ECase(FP_SOFT);
680  ECase(FP_OLD_64);
681  ECase(FP_XX);
682  ECase(FP_64);
683  ECase(FP_64A);
684 #undef ECase
685 }
686 
688  IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
689 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
690  ECase(EXT_NONE);
691  ECase(EXT_XLR);
692  ECase(EXT_OCTEON2);
693  ECase(EXT_OCTEONP);
694  ECase(EXT_LOONGSON_3A);
695  ECase(EXT_OCTEON);
696  ECase(EXT_5900);
697  ECase(EXT_4650);
698  ECase(EXT_4010);
699  ECase(EXT_4100);
700  ECase(EXT_3900);
701  ECase(EXT_10000);
702  ECase(EXT_SB1);
703  ECase(EXT_4111);
704  ECase(EXT_4120);
705  ECase(EXT_5400);
706  ECase(EXT_5500);
707  ECase(EXT_LOONGSON_2E);
708  ECase(EXT_LOONGSON_2F);
709  ECase(EXT_OCTEON3);
710 #undef ECase
711 }
712 
714  IO &IO, ELFYAML::MIPS_ISA &Value) {
715  IO.enumCase(Value, "MIPS1", 1);
716  IO.enumCase(Value, "MIPS2", 2);
717  IO.enumCase(Value, "MIPS3", 3);
718  IO.enumCase(Value, "MIPS4", 4);
719  IO.enumCase(Value, "MIPS5", 5);
720  IO.enumCase(Value, "MIPS32", 32);
721  IO.enumCase(Value, "MIPS64", 64);
722 }
723 
725  IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
726 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
727  BCase(DSP);
728  BCase(DSPR2);
729  BCase(EVA);
730  BCase(MCU);
731  BCase(MDMX);
732  BCase(MIPS3D);
733  BCase(MT);
734  BCase(SMARTMIPS);
735  BCase(VIRT);
736  BCase(MSA);
737  BCase(MIPS16);
738  BCase(MICROMIPS);
739  BCase(XPA);
740 #undef BCase
741 }
742 
744  IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
745 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
746  BCase(ODDSPREG);
747 #undef BCase
748 }
749 
751  ELFYAML::FileHeader &FileHdr) {
752  IO.mapRequired("Class", FileHdr.Class);
753  IO.mapRequired("Data", FileHdr.Data);
754  IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
755  IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0));
756  IO.mapRequired("Type", FileHdr.Type);
757  IO.mapRequired("Machine", FileHdr.Machine);
758  IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
759  IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
760 }
761 
763  IO &IO, ELFYAML::ProgramHeader &Phdr) {
764  IO.mapRequired("Type", Phdr.Type);
765  IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
766  IO.mapOptional("Sections", Phdr.Sections);
767  IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
768  IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
769  IO.mapOptional("Align", Phdr.Align);
770 }
771 
772 namespace {
773 
774 struct NormalizedOther {
775  NormalizedOther(IO &)
776  : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
777  NormalizedOther(IO &, uint8_t Original)
778  : Visibility(Original & 0x3), Other(Original & ~0x3) {}
779 
780  uint8_t denormalize(IO &) { return Visibility | Other; }
781 
782  ELFYAML::ELF_STV Visibility;
783  ELFYAML::ELF_STO Other;
784 };
785 
786 } // end anonymous namespace
787 
789  IO.mapOptional("Name", Symbol.Name, StringRef());
790  IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
791  IO.mapOptional("Section", Symbol.Section, StringRef());
792  IO.mapOptional("Index", Symbol.Index);
793  IO.mapOptional("Value", Symbol.Value, Hex64(0));
794  IO.mapOptional("Size", Symbol.Size, Hex64(0));
795 
796  MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
797  IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
798  IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
799 }
800 
803  if (Symbol.Index && Symbol.Section.data()) {
804  return "Index and Section cannot both be specified for Symbol";
805  }
806  if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
807  return "Large indexes are not supported";
808  }
809  if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
810  return "Use a section name to define which section a symbol is defined in";
811  }
812  return StringRef();
813 }
814 
816  IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
817  IO.mapOptional("Local", Symbols.Local);
818  IO.mapOptional("Global", Symbols.Global);
819  IO.mapOptional("Weak", Symbols.Weak);
820 }
821 
823  IO.mapOptional("Name", Section.Name, StringRef());
824  IO.mapRequired("Type", Section.Type);
825  IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
826  IO.mapOptional("Address", Section.Address, Hex64(0));
827  IO.mapOptional("Link", Section.Link, StringRef());
828  IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
829  IO.mapOptional("EntSize", Section.EntSize);
830  IO.mapOptional("Info", Section.Info, StringRef());
831 }
832 
834  commonSectionMapping(IO, Section);
835  IO.mapOptional("Content", Section.Content);
836  IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
837 }
838 
840  commonSectionMapping(IO, Section);
841  IO.mapOptional("Size", Section.Size, Hex64(0));
842 }
843 
845  commonSectionMapping(IO, Section);
846  IO.mapOptional("Relocations", Section.Relocations);
847 }
848 
849 static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
850  commonSectionMapping(IO, group);
851  IO.mapRequired("Members", group.Members);
852 }
853 
855  IO &IO, ELFYAML::SectionOrType &sectionOrType) {
856  IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
857 }
858 
860  IO &IO, ELFYAML::SectionName &sectionName) {
861  IO.mapRequired("Section", sectionName.Section);
862 }
863 
865  commonSectionMapping(IO, Section);
866  IO.mapOptional("Version", Section.Version, Hex16(0));
867  IO.mapRequired("ISA", Section.ISALevel);
868  IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
869  IO.mapOptional("ISAExtension", Section.ISAExtension,
870  ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
871  IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
872  IO.mapOptional("FpABI", Section.FpABI,
873  ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
874  IO.mapOptional("GPRSize", Section.GPRSize,
875  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
876  IO.mapOptional("CPR1Size", Section.CPR1Size,
877  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
878  IO.mapOptional("CPR2Size", Section.CPR2Size,
879  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
880  IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
881  IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
882 }
883 
885  IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
886  ELFYAML::ELF_SHT sectionType;
887  if (IO.outputting())
888  sectionType = Section->Type;
889  else
890  IO.mapRequired("Type", sectionType);
891 
892  switch (sectionType) {
893  case ELF::SHT_REL:
894  case ELF::SHT_RELA:
895  if (!IO.outputting())
896  Section.reset(new ELFYAML::RelocationSection());
897  sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
898  break;
899  case ELF::SHT_GROUP:
900  if (!IO.outputting())
901  Section.reset(new ELFYAML::Group());
902  groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
903  break;
904  case ELF::SHT_NOBITS:
905  if (!IO.outputting())
906  Section.reset(new ELFYAML::NoBitsSection());
907  sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
908  break;
910  if (!IO.outputting())
911  Section.reset(new ELFYAML::MipsABIFlags());
912  sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
913  break;
914  default:
915  if (!IO.outputting())
916  Section.reset(new ELFYAML::RawContentSection());
917  sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
918  }
919 }
920 
922  IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
923  const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
924  if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
925  return StringRef();
926  return "Section size must be greater or equal to the content size";
927 }
928 
929 namespace {
930 
931 struct NormalizedMips64RelType {
932  NormalizedMips64RelType(IO &)
933  : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
934  Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
935  Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
936  SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
937  NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
938  : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
939  Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
940 
941  ELFYAML::ELF_REL denormalize(IO &) {
942  ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
943  return Res;
944  }
945 
946  ELFYAML::ELF_REL Type;
947  ELFYAML::ELF_REL Type2;
948  ELFYAML::ELF_REL Type3;
949  ELFYAML::ELF_RSS SpecSym;
950 };
951 
952 } // end anonymous namespace
953 
955  ELFYAML::Relocation &Rel) {
956  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
957  assert(Object && "The IO context is not initialized");
958 
959  IO.mapRequired("Offset", Rel.Offset);
960  IO.mapOptional("Symbol", Rel.Symbol);
961 
962  if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
963  Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
964  MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
965  IO, Rel.Type);
966  IO.mapRequired("Type", Key->Type);
967  IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
968  IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
969  IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
970  } else
971  IO.mapRequired("Type", Rel.Type);
972 
973  IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
974 }
975 
977  assert(!IO.getContext() && "The IO context is initialized already");
978  IO.setContext(&Object);
979  IO.mapTag("!ELF", true);
980  IO.mapRequired("FileHeader", Object.Header);
981  IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
982  IO.mapOptional("Sections", Object.Sections);
983  IO.mapOptional("Symbols", Object.Symbols);
984  IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
985  IO.setContext(nullptr);
986 }
987 
988 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
989 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
990 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
991 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
992 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
993 
994 } // end namespace yaml
995 
996 } // 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:498
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static void enumeration(IO &IO, ELFYAML::ELF_ET &Value)
Definition: ELFYAML.cpp:29
Optional< llvm::yaml::Hex64 > Align
Definition: ELFYAML.h:86
static void enumeration(IO &IO, ELFYAML::ELF_STT &Value)
Definition: ELFYAML.cpp:563
static void enumeration(IO &IO, ELFYAML::ELF_STV &Value)
Definition: ELFYAML.cpp:577
Optional< ELF_SHN > Index
Definition: ELFYAML.h:94
static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value)
Definition: ELFYAML.cpp:541
llvm::yaml::Hex64 PAddr
Definition: ELFYAML.h:85
static void bitset(IO &IO, ELFYAML::ELF_PF &Value)
Definition: ELFYAML.cpp:490
std::vector< SectionName > Sections
Definition: ELFYAML.h:87
llvm::yaml::Hex16 Version
Definition: ELFYAML.h:183
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:948
llvm::yaml::Hex64 Address
Definition: ELFYAML.h:122
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:782
static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value)
Definition: ELFYAML.cpp:606
FileHeader Header
Definition: ELFYAML.h:203
static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value)
Definition: ELFYAML.cpp:425
llvm::yaml::Hex64 Entry
Definition: ELFYAML.h:74
static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value)
Definition: ELFYAML.cpp:743
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:127
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:57
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:96
static void groupSectionMapping(IO &IO, ELFYAML::Group &group)
Definition: ELFYAML.cpp:849
StringRef Name
Definition: ELFYAML.h:91
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:783
llvm::yaml::Hex8 ABIVersion
Definition: ELFYAML.h:70
Key
PAL metadata keys.
static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value)
Definition: ELFYAML.cpp:222
Optional< llvm::yaml::Hex64 > EntSize
Definition: ELFYAML.h:126
ELFYAML::ELF_RSS SpecSym
Definition: ELFYAML.cpp:949
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:713
static void bitset(IO &IO, ELFYAML::ELF_STO &Value)
Definition: ELFYAML.cpp:587
std::vector< ProgramHeader > ProgramHeaders
Definition: ELFYAML.h:204
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section)
Definition: ELFYAML.cpp:822
static void enumeration(IO &IO, ELFYAML::ELF_PT &Value)
Definition: ELFYAML.cpp:41
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
llvm::yaml::Hex32 Flags2
Definition: ELFYAML.h:193
#define BCase(X)
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value)
Definition: ELFYAML.cpp:616
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:81
static void bitset(IO &IO, ELFYAML::ELF_EF &Value)
Definition: ELFYAML.cpp:272
ELF_ELFCLASS Class
Definition: ELFYAML.h:67
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:242
static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value)
Definition: ELFYAML.cpp:724
static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value)
Definition: ELFYAML.cpp:687
#define ECase(X)
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:947
static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value)
Definition: ELFYAML.cpp:673
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:232
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:322
MIPS_AFL_FLAGS1 Flags1
Definition: ELFYAML.h:192
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:72
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:133
static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section)
Definition: ELFYAML.cpp:833
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value)
Definition: ELFYAML.cpp:663
ELF_ELFOSABI OSABI
Definition: ELFYAML.h:69
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