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  // No SHT_SYMTAB. Use the top-level `Symbols` key instead.
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);
414  ECase(SHT_HIOS);
415  ECase(SHT_LOPROC);
416  switch (Object->Header.Machine) {
417  case ELF::EM_ARM:
423  break;
424  case ELF::EM_HEXAGON:
426  break;
427  case ELF::EM_X86_64:
429  break;
430  case ELF::EM_MIPS:
434  break;
435  default:
436  // Nothing to do.
437  break;
438  }
439 #undef ECase
440 }
441 
443  ELFYAML::ELF_PF &Value) {
444 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
445  BCase(PF_X);
446  BCase(PF_W);
447  BCase(PF_R);
448 }
449 
451  ELFYAML::ELF_SHF &Value) {
452  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
453 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
454  BCase(SHF_WRITE);
455  BCase(SHF_ALLOC);
458  BCase(SHF_MERGE);
463  BCase(SHF_GROUP);
464  BCase(SHF_TLS);
466  switch (Object->Header.Machine) {
467  case ELF::EM_ARM:
469  break;
470  case ELF::EM_HEXAGON:
472  break;
473  case ELF::EM_MIPS:
482  break;
483  case ELF::EM_X86_64:
485  break;
486  default:
487  // Nothing to do.
488  break;
489  }
490 #undef BCase
491 }
492 
494  IO &IO, ELFYAML::ELF_SHN &Value) {
495 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
496  ECase(SHN_UNDEF);
498  ECase(SHN_LOPROC);
499  ECase(SHN_HIPROC);
500  ECase(SHN_LOOS);
501  ECase(SHN_HIOS);
502  ECase(SHN_ABS);
503  ECase(SHN_COMMON);
504  ECase(SHN_XINDEX);
511 #undef ECase
512  IO.enumFallback<Hex32>(Value);
513 }
514 
516  IO &IO, ELFYAML::ELF_STT &Value) {
517 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
518  ECase(STT_NOTYPE);
519  ECase(STT_OBJECT);
520  ECase(STT_FUNC);
522  ECase(STT_FILE);
523  ECase(STT_COMMON);
524  ECase(STT_TLS);
526 #undef ECase
527 }
528 
530  IO &IO, ELFYAML::ELF_STV &Value) {
531 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
534  ECase(STV_HIDDEN);
536 #undef ECase
537 }
538 
540  ELFYAML::ELF_STO &Value) {
541  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
542  assert(Object && "The IO context is not initialized");
543 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
544  switch (Object->Header.Machine) {
545  case ELF::EM_MIPS:
550  break;
551  default:
552  break; // Nothing to do
553  }
554 #undef BCase
555 #undef BCaseMask
556 }
557 
559  IO &IO, ELFYAML::ELF_RSS &Value) {
560 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
561  ECase(RSS_UNDEF);
562  ECase(RSS_GP);
563  ECase(RSS_GP0);
564  ECase(RSS_LOC);
565 #undef ECase
566 }
567 
569  IO &IO, ELFYAML::ELF_REL &Value) {
570  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
571  assert(Object && "The IO context is not initialized");
572 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
573  switch (Object->Header.Machine) {
574  case ELF::EM_X86_64:
575 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
576  break;
577  case ELF::EM_MIPS:
578 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
579  break;
580  case ELF::EM_HEXAGON:
581 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
582  break;
583  case ELF::EM_386:
584  case ELF::EM_IAMCU:
585 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
586  break;
587  case ELF::EM_AARCH64:
588 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
589  break;
590  case ELF::EM_ARM:
591 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
592  break;
593  case ELF::EM_ARC:
594 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
595  break;
596  case ELF::EM_RISCV:
597 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
598  break;
599  case ELF::EM_LANAI:
600 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
601  break;
602  case ELF::EM_AMDGPU:
603 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
604  break;
605  case ELF::EM_BPF:
606 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
607  break;
608  default:
609  llvm_unreachable("Unsupported architecture");
610  }
611 #undef ELF_RELOC
612  IO.enumFallback<Hex32>(Value);
613 }
614 
616  IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
617 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
618  ECase(REG_NONE);
619  ECase(REG_32);
620  ECase(REG_64);
621  ECase(REG_128);
622 #undef ECase
623 }
624 
626  IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
627 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
628  ECase(FP_ANY);
629  ECase(FP_DOUBLE);
630  ECase(FP_SINGLE);
631  ECase(FP_SOFT);
632  ECase(FP_OLD_64);
633  ECase(FP_XX);
634  ECase(FP_64);
635  ECase(FP_64A);
636 #undef ECase
637 }
638 
640  IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
641 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
642  ECase(EXT_NONE);
643  ECase(EXT_XLR);
644  ECase(EXT_OCTEON2);
645  ECase(EXT_OCTEONP);
646  ECase(EXT_LOONGSON_3A);
647  ECase(EXT_OCTEON);
648  ECase(EXT_5900);
649  ECase(EXT_4650);
650  ECase(EXT_4010);
651  ECase(EXT_4100);
652  ECase(EXT_3900);
653  ECase(EXT_10000);
654  ECase(EXT_SB1);
655  ECase(EXT_4111);
656  ECase(EXT_4120);
657  ECase(EXT_5400);
658  ECase(EXT_5500);
659  ECase(EXT_LOONGSON_2E);
660  ECase(EXT_LOONGSON_2F);
661  ECase(EXT_OCTEON3);
662 #undef ECase
663 }
664 
666  IO &IO, ELFYAML::MIPS_ISA &Value) {
667  IO.enumCase(Value, "MIPS1", 1);
668  IO.enumCase(Value, "MIPS2", 2);
669  IO.enumCase(Value, "MIPS3", 3);
670  IO.enumCase(Value, "MIPS4", 4);
671  IO.enumCase(Value, "MIPS5", 5);
672  IO.enumCase(Value, "MIPS32", 32);
673  IO.enumCase(Value, "MIPS64", 64);
674 }
675 
677  IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
678 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
679  BCase(DSP);
680  BCase(DSPR2);
681  BCase(EVA);
682  BCase(MCU);
683  BCase(MDMX);
684  BCase(MIPS3D);
685  BCase(MT);
686  BCase(SMARTMIPS);
687  BCase(VIRT);
688  BCase(MSA);
689  BCase(MIPS16);
690  BCase(MICROMIPS);
691  BCase(XPA);
692 #undef BCase
693 }
694 
696  IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
697 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
698  BCase(ODDSPREG);
699 #undef BCase
700 }
701 
703  ELFYAML::FileHeader &FileHdr) {
704  IO.mapRequired("Class", FileHdr.Class);
705  IO.mapRequired("Data", FileHdr.Data);
706  IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
707  IO.mapRequired("Type", FileHdr.Type);
708  IO.mapRequired("Machine", FileHdr.Machine);
709  IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
710  IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
711 }
712 
714  IO &IO, ELFYAML::ProgramHeader &Phdr) {
715  IO.mapRequired("Type", Phdr.Type);
716  IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
717  IO.mapOptional("Sections", Phdr.Sections);
718  IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
719  IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
720 }
721 
722 namespace {
723 
724 struct NormalizedOther {
725  NormalizedOther(IO &)
726  : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
727  NormalizedOther(IO &, uint8_t Original)
728  : Visibility(Original & 0x3), Other(Original & ~0x3) {}
729 
730  uint8_t denormalize(IO &) { return Visibility | Other; }
731 
732  ELFYAML::ELF_STV Visibility;
733  ELFYAML::ELF_STO Other;
734 };
735 
736 } // end anonymous namespace
737 
739  IO.mapOptional("Name", Symbol.Name, StringRef());
740  IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
741  IO.mapOptional("Section", Symbol.Section, StringRef());
742  IO.mapOptional("Index", Symbol.Index);
743  IO.mapOptional("Value", Symbol.Value, Hex64(0));
744  IO.mapOptional("Size", Symbol.Size, Hex64(0));
745 
747  IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
748  IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
749 }
750 
753  if (Symbol.Index && Symbol.Section.data()) {
754  return "Index and Section cannot both be specified for Symbol";
755  }
756  if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
757  return "Large indexes are not supported";
758  }
759  if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
760  return "Use a section name to define which section a symbol is defined in";
761  }
762  return StringRef();
763 }
764 
767  IO.mapOptional("Local", Symbols.Local);
768  IO.mapOptional("Global", Symbols.Global);
769  IO.mapOptional("Weak", Symbols.Weak);
770 }
771 
773  IO.mapOptional("Name", Section.Name, StringRef());
774  IO.mapRequired("Type", Section.Type);
775  IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
776  IO.mapOptional("Address", Section.Address, Hex64(0));
777  IO.mapOptional("Link", Section.Link, StringRef());
778  IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
779  IO.mapOptional("Info", Section.Info, StringRef());
780 }
781 
783  commonSectionMapping(IO, Section);
784  IO.mapOptional("Content", Section.Content);
785  IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
786 }
787 
789  commonSectionMapping(IO, Section);
790  IO.mapOptional("Size", Section.Size, Hex64(0));
791 }
792 
794  commonSectionMapping(IO, Section);
795  IO.mapOptional("Relocations", Section.Relocations);
796 }
797 
798 static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
799  commonSectionMapping(IO, group);
800  IO.mapRequired("Members", group.Members);
801 }
802 
804  IO &IO, ELFYAML::SectionOrType &sectionOrType) {
805  IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
806 }
807 
809  IO &IO, ELFYAML::SectionName &sectionName) {
810  IO.mapRequired("Section", sectionName.Section);
811 }
812 
814  commonSectionMapping(IO, Section);
815  IO.mapOptional("Version", Section.Version, Hex16(0));
816  IO.mapRequired("ISA", Section.ISALevel);
817  IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
818  IO.mapOptional("ISAExtension", Section.ISAExtension,
819  ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
820  IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
821  IO.mapOptional("FpABI", Section.FpABI,
822  ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
823  IO.mapOptional("GPRSize", Section.GPRSize,
824  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
825  IO.mapOptional("CPR1Size", Section.CPR1Size,
826  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
827  IO.mapOptional("CPR2Size", Section.CPR2Size,
828  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
829  IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
830  IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
831 }
832 
834  IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
835  ELFYAML::ELF_SHT sectionType;
836  if (IO.outputting())
837  sectionType = Section->Type;
838  else
839  IO.mapRequired("Type", sectionType);
840 
841  switch (sectionType) {
842  case ELF::SHT_REL:
843  case ELF::SHT_RELA:
844  if (!IO.outputting())
845  Section.reset(new ELFYAML::RelocationSection());
846  sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
847  break;
848  case ELF::SHT_GROUP:
849  if (!IO.outputting())
850  Section.reset(new ELFYAML::Group());
851  groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
852  break;
853  case ELF::SHT_NOBITS:
854  if (!IO.outputting())
855  Section.reset(new ELFYAML::NoBitsSection());
856  sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
857  break;
859  if (!IO.outputting())
860  Section.reset(new ELFYAML::MipsABIFlags());
861  sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
862  break;
863  default:
864  if (!IO.outputting())
865  Section.reset(new ELFYAML::RawContentSection());
866  sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
867  }
868 }
869 
871  IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
872  const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
873  if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
874  return StringRef();
875  return "Section size must be greater or equal to the content size";
876 }
877 
878 namespace {
879 
880 struct NormalizedMips64RelType {
881  NormalizedMips64RelType(IO &)
882  : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
883  Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
884  Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
885  SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
886  NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
887  : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
888  Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
889 
890  ELFYAML::ELF_REL denormalize(IO &) {
891  ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
892  return Res;
893  }
894 
895  ELFYAML::ELF_REL Type;
896  ELFYAML::ELF_REL Type2;
897  ELFYAML::ELF_REL Type3;
898  ELFYAML::ELF_RSS SpecSym;
899 };
900 
901 } // end anonymous namespace
902 
904  ELFYAML::Relocation &Rel) {
905  const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
906  assert(Object && "The IO context is not initialized");
907 
908  IO.mapRequired("Offset", Rel.Offset);
909  IO.mapOptional("Symbol", Rel.Symbol);
910 
911  if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
912  Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
914  IO, Rel.Type);
915  IO.mapRequired("Type", Key->Type);
916  IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
917  IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
918  IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
919  } else
920  IO.mapRequired("Type", Rel.Type);
921 
922  IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
923 }
924 
926  assert(!IO.getContext() && "The IO context is initialized already");
927  IO.setContext(&Object);
928  IO.mapTag("!ELF", true);
929  IO.mapRequired("FileHeader", Object.Header);
930  IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
931  IO.mapOptional("Sections", Object.Sections);
932  IO.mapOptional("Symbols", Object.Symbols);
933  IO.setContext(nullptr);
934 }
935 
936 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
937 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
938 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
939 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
940 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
941 
942 } // end namespace yaml
943 
944 } // 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< ELF_SHN > Index
Definition: ELFYAML.h:93
void * getContext()
Definition: YAMLTraits.cpp:43
llvm::yaml::Hex64 PAddr
Definition: ELFYAML.h:85
std::vector< SectionName > Sections
Definition: ELFYAML.h:86
llvm::yaml::Hex16 Version
Definition: ELFYAML.h:181
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:897
llvm::yaml::Hex64 Address
Definition: ELFYAML.h:121
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:732
FileHeader Header
Definition: ELFYAML.h:201
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:895
LocalGlobalWeakSymbols Symbols
Definition: ELFYAML.h:208
llvm::yaml::Hex64 AddressAlign
Definition: ELFYAML.h:124
std::vector< Symbol > Weak
Definition: ELFYAML.h:102
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:141
StringRef Section
Definition: ELFYAML.h:92
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:95
static void groupSectionMapping(IO &IO, ELFYAML::Group &group)
Definition: ELFYAML.cpp:798
void enumFallback(T &Val)
Definition: YAMLTraits.h:605
StringRef Name
Definition: ELFYAML.h:90
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:733
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:898
std::vector< Symbol > Global
Definition: ELFYAML.h:101
virtual bool mapTag(StringRef Tag, bool Default=false)=0
std::vector< ProgramHeader > ProgramHeaders
Definition: ELFYAML.h:202
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:772
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:191
#define BCase(X)
std::vector< std::unique_ptr< Section > > Sections
Definition: ELFYAML.h:203
std::vector< Symbol > Local
Definition: ELFYAML.h:100
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
llvm::yaml::Hex8 ISARevision
Definition: ELFYAML.h:183
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:153
llvm::yaml::Hex64 Offset
Definition: ELFYAML.h:163
void setContext(void *)
Definition: YAMLTraits.cpp:47
#define ECase(X)
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:896
MIPS_AFL_EXT ISAExtension
Definition: ELFYAML.h:188
llvm::yaml::Hex64 Value
Definition: ELFYAML.h:94
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:190
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:131
static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section)
Definition: ELFYAML.cpp:782
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:166
std::vector< Relocation > Relocations
Definition: ELFYAML.h:170