LCOV - code coverage report
Current view: top level - lib/ObjectYAML - ELFYAML.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 675 689 98.0 %
Date: 2017-09-14 15:23:50 Functions: 39 39 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      14             : #include "llvm/ObjectYAML/ELFYAML.h"
      15             : #include "llvm/ADT/StringRef.h"
      16             : #include "llvm/BinaryFormat/ELF.h"
      17             : #include "llvm/Support/Casting.h"
      18             : #include "llvm/Support/ErrorHandling.h"
      19             : #include "llvm/Support/MipsABIFlags.h"
      20             : #include "llvm/Support/YAMLTraits.h"
      21             : #include <cassert>
      22             : #include <cstdint>
      23             : 
      24             : namespace llvm {
      25             : 
      26             : ELFYAML::Section::~Section() = default;
      27             : 
      28             : namespace yaml {
      29             : 
      30         101 : void ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(
      31             :     IO &IO, ELFYAML::ELF_ET &Value) {
      32             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
      33         101 :   ECase(ET_NONE);
      34         101 :   ECase(ET_REL);
      35         101 :   ECase(ET_EXEC);
      36         101 :   ECase(ET_DYN);
      37         101 :   ECase(ET_CORE);
      38             : #undef ECase
      39         101 :   IO.enumFallback<Hex16>(Value);
      40         101 : }
      41             : 
      42           8 : void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration(
      43             :     IO &IO, ELFYAML::ELF_PT &Value) {
      44             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
      45           8 :   ECase(PT_NULL);
      46           8 :   ECase(PT_LOAD);
      47           8 :   ECase(PT_DYNAMIC);
      48           8 :   ECase(PT_INTERP);
      49           8 :   ECase(PT_NOTE);
      50           8 :   ECase(PT_SHLIB);
      51           8 :   ECase(PT_PHDR);
      52           8 :   ECase(PT_TLS);
      53             : #undef ECase
      54           8 :   IO.enumFallback<Hex32>(Value);
      55           8 : }
      56             : 
      57         101 : void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(
      58             :     IO &IO, ELFYAML::ELF_EM &Value) {
      59             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
      60         101 :   ECase(EM_NONE);
      61         101 :   ECase(EM_M32);
      62         101 :   ECase(EM_SPARC);
      63         101 :   ECase(EM_386);
      64         101 :   ECase(EM_68K);
      65         101 :   ECase(EM_88K);
      66         101 :   ECase(EM_IAMCU);
      67         101 :   ECase(EM_860);
      68         101 :   ECase(EM_MIPS);
      69         101 :   ECase(EM_S370);
      70         101 :   ECase(EM_MIPS_RS3_LE);
      71         101 :   ECase(EM_PARISC);
      72         101 :   ECase(EM_VPP500);
      73         101 :   ECase(EM_SPARC32PLUS);
      74         101 :   ECase(EM_960);
      75         101 :   ECase(EM_PPC);
      76         101 :   ECase(EM_PPC64);
      77         101 :   ECase(EM_S390);
      78         101 :   ECase(EM_SPU);
      79         101 :   ECase(EM_V800);
      80         101 :   ECase(EM_FR20);
      81         101 :   ECase(EM_RH32);
      82         101 :   ECase(EM_RCE);
      83         101 :   ECase(EM_ARM);
      84         101 :   ECase(EM_ALPHA);
      85         101 :   ECase(EM_SH);
      86         101 :   ECase(EM_SPARCV9);
      87         101 :   ECase(EM_TRICORE);
      88         101 :   ECase(EM_ARC);
      89         101 :   ECase(EM_H8_300);
      90         101 :   ECase(EM_H8_300H);
      91         101 :   ECase(EM_H8S);
      92         101 :   ECase(EM_H8_500);
      93         101 :   ECase(EM_IA_64);
      94         101 :   ECase(EM_MIPS_X);
      95         101 :   ECase(EM_COLDFIRE);
      96         101 :   ECase(EM_68HC12);
      97         101 :   ECase(EM_MMA);
      98         101 :   ECase(EM_PCP);
      99         101 :   ECase(EM_NCPU);
     100         101 :   ECase(EM_NDR1);
     101         101 :   ECase(EM_STARCORE);
     102         101 :   ECase(EM_ME16);
     103         101 :   ECase(EM_ST100);
     104         101 :   ECase(EM_TINYJ);
     105         101 :   ECase(EM_X86_64);
     106         101 :   ECase(EM_PDSP);
     107         101 :   ECase(EM_PDP10);
     108         101 :   ECase(EM_PDP11);
     109         101 :   ECase(EM_FX66);
     110         101 :   ECase(EM_ST9PLUS);
     111         101 :   ECase(EM_ST7);
     112         101 :   ECase(EM_68HC16);
     113         101 :   ECase(EM_68HC11);
     114         101 :   ECase(EM_68HC08);
     115         101 :   ECase(EM_68HC05);
     116         101 :   ECase(EM_SVX);
     117         101 :   ECase(EM_ST19);
     118         101 :   ECase(EM_VAX);
     119         101 :   ECase(EM_CRIS);
     120         101 :   ECase(EM_JAVELIN);
     121         101 :   ECase(EM_FIREPATH);
     122         101 :   ECase(EM_ZSP);
     123         101 :   ECase(EM_MMIX);
     124         101 :   ECase(EM_HUANY);
     125         101 :   ECase(EM_PRISM);
     126         101 :   ECase(EM_AVR);
     127         101 :   ECase(EM_FR30);
     128         101 :   ECase(EM_D10V);
     129         101 :   ECase(EM_D30V);
     130         101 :   ECase(EM_V850);
     131         101 :   ECase(EM_M32R);
     132         101 :   ECase(EM_MN10300);
     133         101 :   ECase(EM_MN10200);
     134         101 :   ECase(EM_PJ);
     135         101 :   ECase(EM_OPENRISC);
     136         101 :   ECase(EM_ARC_COMPACT);
     137         101 :   ECase(EM_XTENSA);
     138         101 :   ECase(EM_VIDEOCORE);
     139         101 :   ECase(EM_TMM_GPP);
     140         101 :   ECase(EM_NS32K);
     141         101 :   ECase(EM_TPC);
     142         101 :   ECase(EM_SNP1K);
     143         101 :   ECase(EM_ST200);
     144         101 :   ECase(EM_IP2K);
     145         101 :   ECase(EM_MAX);
     146         101 :   ECase(EM_CR);
     147         101 :   ECase(EM_F2MC16);
     148         101 :   ECase(EM_MSP430);
     149         101 :   ECase(EM_BLACKFIN);
     150         101 :   ECase(EM_SE_C33);
     151         101 :   ECase(EM_SEP);
     152         101 :   ECase(EM_ARCA);
     153         101 :   ECase(EM_UNICORE);
     154         101 :   ECase(EM_EXCESS);
     155         101 :   ECase(EM_DXP);
     156         101 :   ECase(EM_ALTERA_NIOS2);
     157         101 :   ECase(EM_CRX);
     158         101 :   ECase(EM_XGATE);
     159         101 :   ECase(EM_C166);
     160         101 :   ECase(EM_M16C);
     161         101 :   ECase(EM_DSPIC30F);
     162         101 :   ECase(EM_CE);
     163         101 :   ECase(EM_M32C);
     164         101 :   ECase(EM_TSK3000);
     165         101 :   ECase(EM_RS08);
     166         101 :   ECase(EM_SHARC);
     167         101 :   ECase(EM_ECOG2);
     168         101 :   ECase(EM_SCORE7);
     169         101 :   ECase(EM_DSP24);
     170         101 :   ECase(EM_VIDEOCORE3);
     171         101 :   ECase(EM_LATTICEMICO32);
     172         101 :   ECase(EM_SE_C17);
     173         101 :   ECase(EM_TI_C6000);
     174         101 :   ECase(EM_TI_C2000);
     175         101 :   ECase(EM_TI_C5500);
     176         101 :   ECase(EM_MMDSP_PLUS);
     177         101 :   ECase(EM_CYPRESS_M8C);
     178         101 :   ECase(EM_R32C);
     179         101 :   ECase(EM_TRIMEDIA);
     180         101 :   ECase(EM_HEXAGON);
     181         101 :   ECase(EM_8051);
     182         101 :   ECase(EM_STXP7X);
     183         101 :   ECase(EM_NDS32);
     184         101 :   ECase(EM_ECOG1);
     185         101 :   ECase(EM_ECOG1X);
     186         101 :   ECase(EM_MAXQ30);
     187         101 :   ECase(EM_XIMO16);
     188         101 :   ECase(EM_MANIK);
     189         101 :   ECase(EM_CRAYNV2);
     190         101 :   ECase(EM_RX);
     191         101 :   ECase(EM_METAG);
     192         101 :   ECase(EM_MCST_ELBRUS);
     193         101 :   ECase(EM_ECOG16);
     194         101 :   ECase(EM_CR16);
     195         101 :   ECase(EM_ETPU);
     196         101 :   ECase(EM_SLE9X);
     197         101 :   ECase(EM_L10M);
     198         101 :   ECase(EM_K10M);
     199         101 :   ECase(EM_AARCH64);
     200         101 :   ECase(EM_AVR32);
     201         101 :   ECase(EM_STM8);
     202         101 :   ECase(EM_TILE64);
     203         101 :   ECase(EM_TILEPRO);
     204         101 :   ECase(EM_CUDA);
     205         101 :   ECase(EM_TILEGX);
     206         101 :   ECase(EM_CLOUDSHIELD);
     207         101 :   ECase(EM_COREA_1ST);
     208         101 :   ECase(EM_COREA_2ND);
     209         101 :   ECase(EM_ARC_COMPACT2);
     210         101 :   ECase(EM_OPEN8);
     211         101 :   ECase(EM_RL78);
     212         101 :   ECase(EM_VIDEOCORE5);
     213         101 :   ECase(EM_78KOR);
     214         101 :   ECase(EM_56800EX);
     215         101 :   ECase(EM_AMDGPU);
     216         101 :   ECase(EM_RISCV);
     217         101 :   ECase(EM_LANAI);
     218         101 :   ECase(EM_BPF);
     219             : #undef ECase
     220         101 : }
     221             : 
     222         101 : void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration(
     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         101 :   ECase(ELFCLASS32);
     228         101 :   ECase(ELFCLASS64);
     229             : #undef ECase
     230         101 : }
     231             : 
     232         101 : void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
     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.
     237         101 :   ECase(ELFDATA2LSB);
     238         101 :   ECase(ELFDATA2MSB);
     239             : #undef ECase
     240         101 : }
     241             : 
     242          13 : void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
     243             :     IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
     244             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
     245          13 :   ECase(ELFOSABI_NONE);
     246          13 :   ECase(ELFOSABI_HPUX);
     247          13 :   ECase(ELFOSABI_NETBSD);
     248          13 :   ECase(ELFOSABI_GNU);
     249          13 :   ECase(ELFOSABI_GNU);
     250          13 :   ECase(ELFOSABI_HURD);
     251          13 :   ECase(ELFOSABI_SOLARIS);
     252          13 :   ECase(ELFOSABI_AIX);
     253          13 :   ECase(ELFOSABI_IRIX);
     254          13 :   ECase(ELFOSABI_FREEBSD);
     255          13 :   ECase(ELFOSABI_TRU64);
     256          13 :   ECase(ELFOSABI_MODESTO);
     257          13 :   ECase(ELFOSABI_OPENBSD);
     258          13 :   ECase(ELFOSABI_OPENVMS);
     259          13 :   ECase(ELFOSABI_NSK);
     260          13 :   ECase(ELFOSABI_AROS);
     261          13 :   ECase(ELFOSABI_FENIXOS);
     262          13 :   ECase(ELFOSABI_CLOUDABI);
     263          13 :   ECase(ELFOSABI_C6000_ELFABI);
     264          13 :   ECase(ELFOSABI_AMDGPU_HSA);
     265          13 :   ECase(ELFOSABI_C6000_LINUX);
     266          13 :   ECase(ELFOSABI_ARM);
     267          13 :   ECase(ELFOSABI_STANDALONE);
     268             : #undef ECase
     269          13 : }
     270             : 
     271          26 : void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
     272             :                                                  ELFYAML::ELF_EF &Value) {
     273          26 :   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
     274             :   assert(Object && "The IO context is not initialized");
     275             : #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
     276             : #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
     277          26 :   switch (Object->Header.Machine) {
     278           1 :   case ELF::EM_ARM:
     279           1 :     BCase(EF_ARM_SOFT_FLOAT);
     280           1 :     BCase(EF_ARM_VFP_FLOAT);
     281           1 :     BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK);
     282           1 :     BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK);
     283           1 :     BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK);
     284           1 :     BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK);
     285           1 :     BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK);
     286           1 :     BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK);
     287           1 :     break;
     288          22 :   case ELF::EM_MIPS:
     289          22 :     BCase(EF_MIPS_NOREORDER);
     290          22 :     BCase(EF_MIPS_PIC);
     291          22 :     BCase(EF_MIPS_CPIC);
     292          22 :     BCase(EF_MIPS_ABI2);
     293          22 :     BCase(EF_MIPS_32BITMODE);
     294          22 :     BCase(EF_MIPS_FP64);
     295          22 :     BCase(EF_MIPS_NAN2008);
     296          22 :     BCase(EF_MIPS_MICROMIPS);
     297          22 :     BCase(EF_MIPS_ARCH_ASE_M16);
     298          22 :     BCase(EF_MIPS_ARCH_ASE_MDMX);
     299          22 :     BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI);
     300          22 :     BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI);
     301          22 :     BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI);
     302          22 :     BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI);
     303          22 :     BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH);
     304          22 :     BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH);
     305          22 :     BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH);
     306          22 :     BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH);
     307          22 :     BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH);
     308          22 :     BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH);
     309          22 :     BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH);
     310          22 :     BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH);
     311          22 :     BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH);
     312          22 :     BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH);
     313          22 :     BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH);
     314          22 :     BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH);
     315          22 :     BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH);
     316          22 :     BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH);
     317          22 :     BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH);
     318          22 :     BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH);
     319          22 :     BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH);
     320          22 :     BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH);
     321          22 :     BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH);
     322          22 :     BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH);
     323          22 :     BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH);
     324          22 :     BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH);
     325          22 :     BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH);
     326          22 :     BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH);
     327          22 :     BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH);
     328          22 :     BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH);
     329          22 :     BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH);
     330          22 :     BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH);
     331          22 :     BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH);
     332          22 :     break;
     333           1 :   case ELF::EM_HEXAGON:
     334           1 :     BCase(EF_HEXAGON_MACH_V2);
     335           1 :     BCase(EF_HEXAGON_MACH_V3);
     336           1 :     BCase(EF_HEXAGON_MACH_V4);
     337           1 :     BCase(EF_HEXAGON_MACH_V5);
     338           1 :     BCase(EF_HEXAGON_ISA_V2);
     339           1 :     BCase(EF_HEXAGON_ISA_V3);
     340           1 :     BCase(EF_HEXAGON_ISA_V4);
     341           1 :     BCase(EF_HEXAGON_ISA_V5);
     342           1 :     break;
     343           1 :   case ELF::EM_AVR:
     344           1 :     BCase(EF_AVR_ARCH_AVR1);
     345           1 :     BCase(EF_AVR_ARCH_AVR2);
     346           1 :     BCase(EF_AVR_ARCH_AVR25);
     347           1 :     BCase(EF_AVR_ARCH_AVR3);
     348           1 :     BCase(EF_AVR_ARCH_AVR31);
     349           1 :     BCase(EF_AVR_ARCH_AVR35);
     350           1 :     BCase(EF_AVR_ARCH_AVR4);
     351           1 :     BCase(EF_AVR_ARCH_AVR51);
     352           1 :     BCase(EF_AVR_ARCH_AVR6);
     353           1 :     BCase(EF_AVR_ARCH_AVRTINY);
     354           1 :     BCase(EF_AVR_ARCH_XMEGA1);
     355           1 :     BCase(EF_AVR_ARCH_XMEGA2);
     356           1 :     BCase(EF_AVR_ARCH_XMEGA3);
     357           1 :     BCase(EF_AVR_ARCH_XMEGA4);
     358           1 :     BCase(EF_AVR_ARCH_XMEGA5);
     359           1 :     BCase(EF_AVR_ARCH_XMEGA6);
     360           1 :     BCase(EF_AVR_ARCH_XMEGA7);
     361           1 :     break;
     362             :   case ELF::EM_AMDGPU:
     363             :   case ELF::EM_X86_64:
     364             :     break;
     365           0 :   default:
     366           0 :     llvm_unreachable("Unsupported architecture");
     367             :   }
     368             : #undef BCase
     369             : #undef BCaseMask
     370          26 : }
     371             : 
     372         414 : void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
     373             :     IO &IO, ELFYAML::ELF_SHT &Value) {
     374         414 :   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
     375             :   assert(Object && "The IO context is not initialized");
     376             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
     377         414 :   ECase(SHT_NULL);
     378         414 :   ECase(SHT_PROGBITS);
     379             :   // No SHT_SYMTAB. Use the top-level `Symbols` key instead.
     380             :   // FIXME: Issue a diagnostic with this information.
     381         414 :   ECase(SHT_STRTAB);
     382         414 :   ECase(SHT_RELA);
     383         414 :   ECase(SHT_HASH);
     384         414 :   ECase(SHT_DYNAMIC);
     385         414 :   ECase(SHT_NOTE);
     386         414 :   ECase(SHT_NOBITS);
     387         414 :   ECase(SHT_REL);
     388         414 :   ECase(SHT_SHLIB);
     389         414 :   ECase(SHT_DYNSYM);
     390         414 :   ECase(SHT_INIT_ARRAY);
     391         414 :   ECase(SHT_FINI_ARRAY);
     392         414 :   ECase(SHT_PREINIT_ARRAY);
     393         414 :   ECase(SHT_GROUP);
     394         414 :   ECase(SHT_SYMTAB_SHNDX);
     395         414 :   ECase(SHT_LOOS);
     396         414 :   ECase(SHT_LLVM_ODRTAB);
     397         414 :   ECase(SHT_GNU_ATTRIBUTES);
     398         414 :   ECase(SHT_GNU_HASH);
     399         414 :   ECase(SHT_GNU_verdef);
     400         414 :   ECase(SHT_GNU_verneed);
     401         414 :   ECase(SHT_GNU_versym);
     402         414 :   ECase(SHT_HIOS);
     403         414 :   ECase(SHT_LOPROC);
     404         414 :   switch (Object->Header.Machine) {
     405          10 :   case ELF::EM_ARM:
     406          10 :     ECase(SHT_ARM_EXIDX);
     407          10 :     ECase(SHT_ARM_PREEMPTMAP);
     408          10 :     ECase(SHT_ARM_ATTRIBUTES);
     409          10 :     ECase(SHT_ARM_DEBUGOVERLAY);
     410          10 :     ECase(SHT_ARM_OVERLAYSECTION);
     411          10 :     break;
     412           2 :   case ELF::EM_HEXAGON:
     413           2 :     ECase(SHT_HEX_ORDERED);
     414           2 :     break;
     415         280 :   case ELF::EM_X86_64:
     416         280 :     ECase(SHT_X86_64_UNWIND);
     417         280 :     break;
     418          68 :   case ELF::EM_MIPS:
     419          68 :     ECase(SHT_MIPS_REGINFO);
     420          68 :     ECase(SHT_MIPS_OPTIONS);
     421          68 :     ECase(SHT_MIPS_ABIFLAGS);
     422          68 :     break;
     423             :   default:
     424             :     // Nothing to do.
     425             :     break;
     426             :   }
     427             : #undef ECase
     428         414 : }
     429             : 
     430           8 : void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO,
     431             :                                                  ELFYAML::ELF_PF &Value) {
     432             : #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
     433           8 :   BCase(PF_X);
     434           8 :   BCase(PF_W);
     435           8 :   BCase(PF_R);
     436           8 : }
     437             : 
     438         158 : void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
     439             :                                                   ELFYAML::ELF_SHF &Value) {
     440         158 :   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
     441             : #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
     442         158 :   BCase(SHF_WRITE);
     443         158 :   BCase(SHF_ALLOC);
     444         158 :   BCase(SHF_EXCLUDE);
     445         158 :   BCase(SHF_EXECINSTR);
     446         158 :   BCase(SHF_MERGE);
     447         158 :   BCase(SHF_STRINGS);
     448         158 :   BCase(SHF_INFO_LINK);
     449         158 :   BCase(SHF_LINK_ORDER);
     450         158 :   BCase(SHF_OS_NONCONFORMING);
     451         158 :   BCase(SHF_GROUP);
     452         158 :   BCase(SHF_TLS);
     453         158 :   switch (Object->Header.Machine) {
     454           4 :   case ELF::EM_ARM:
     455           4 :     BCase(SHF_ARM_PURECODE);
     456           4 :     break;
     457           1 :   case ELF::EM_HEXAGON:
     458           1 :     BCase(SHF_HEX_GPREL);
     459           1 :     break;
     460          36 :   case ELF::EM_MIPS:
     461          36 :     BCase(SHF_MIPS_NODUPES);
     462          36 :     BCase(SHF_MIPS_NAMES);
     463          36 :     BCase(SHF_MIPS_LOCAL);
     464          36 :     BCase(SHF_MIPS_NOSTRIP);
     465          36 :     BCase(SHF_MIPS_GPREL);
     466          36 :     BCase(SHF_MIPS_MERGE);
     467          36 :     BCase(SHF_MIPS_ADDR);
     468          36 :     BCase(SHF_MIPS_STRING);
     469          36 :     break;
     470         100 :   case ELF::EM_X86_64:
     471         100 :     BCase(SHF_X86_64_LARGE);
     472         100 :     break;
     473             :   default:
     474             :     // Nothing to do.
     475             :     break;
     476             :   }
     477             : #undef BCase
     478         158 : }
     479             : 
     480           9 : void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
     481             :     IO &IO, ELFYAML::ELF_SHN &Value) {
     482             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
     483           9 :   ECase(SHN_UNDEF);
     484           9 :   ECase(SHN_LORESERVE);
     485           9 :   ECase(SHN_LOPROC);
     486           9 :   ECase(SHN_HIPROC);
     487           9 :   ECase(SHN_LOOS);
     488           9 :   ECase(SHN_HIOS);
     489           9 :   ECase(SHN_ABS);
     490           9 :   ECase(SHN_COMMON);
     491           9 :   ECase(SHN_XINDEX);
     492           9 :   ECase(SHN_HIRESERVE);
     493           9 :   ECase(SHN_HEXAGON_SCOMMON);
     494           9 :   ECase(SHN_HEXAGON_SCOMMON_1);
     495           9 :   ECase(SHN_HEXAGON_SCOMMON_2);
     496           9 :   ECase(SHN_HEXAGON_SCOMMON_4);
     497           9 :   ECase(SHN_HEXAGON_SCOMMON_8);
     498             : #undef ECase
     499           9 :   IO.enumFallback<Hex32>(Value);
     500           9 : }
     501             : 
     502         170 : void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
     503             :     IO &IO, ELFYAML::ELF_STT &Value) {
     504             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
     505         170 :   ECase(STT_NOTYPE);
     506         170 :   ECase(STT_OBJECT);
     507         170 :   ECase(STT_FUNC);
     508         170 :   ECase(STT_SECTION);
     509         170 :   ECase(STT_FILE);
     510         170 :   ECase(STT_COMMON);
     511         170 :   ECase(STT_TLS);
     512         170 :   ECase(STT_GNU_IFUNC);
     513             : #undef ECase
     514         170 : }
     515             : 
     516          12 : void ScalarEnumerationTraits<ELFYAML::ELF_STV>::enumeration(
     517             :     IO &IO, ELFYAML::ELF_STV &Value) {
     518             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
     519          12 :   ECase(STV_DEFAULT);
     520          12 :   ECase(STV_INTERNAL);
     521          12 :   ECase(STV_HIDDEN);
     522          12 :   ECase(STV_PROTECTED);
     523             : #undef ECase
     524          12 : }
     525             : 
     526           3 : void ScalarBitSetTraits<ELFYAML::ELF_STO>::bitset(IO &IO,
     527             :                                                   ELFYAML::ELF_STO &Value) {
     528           3 :   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
     529             :   assert(Object && "The IO context is not initialized");
     530             : #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
     531           3 :   switch (Object->Header.Machine) {
     532           3 :   case ELF::EM_MIPS:
     533           3 :     BCase(STO_MIPS_OPTIONAL);
     534           3 :     BCase(STO_MIPS_PLT);
     535           3 :     BCase(STO_MIPS_PIC);
     536           3 :     BCase(STO_MIPS_MICROMIPS);
     537           3 :     break;
     538             :   default:
     539             :     break; // Nothing to do
     540             :   }
     541             : #undef BCase
     542             : #undef BCaseMask
     543           3 : }
     544             : 
     545           2 : void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration(
     546             :     IO &IO, ELFYAML::ELF_RSS &Value) {
     547             : #define ECase(X) IO.enumCase(Value, #X, ELF::X)
     548           2 :   ECase(RSS_UNDEF);
     549           2 :   ECase(RSS_GP);
     550           2 :   ECase(RSS_GP0);
     551           2 :   ECase(RSS_LOC);
     552             : #undef ECase
     553           2 : }
     554             : 
     555         131 : void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
     556             :     IO &IO, ELFYAML::ELF_REL &Value) {
     557         131 :   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
     558             :   assert(Object && "The IO context is not initialized");
     559             : #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
     560         131 :   switch (Object->Header.Machine) {
     561          59 :   case ELF::EM_X86_64:
     562             : #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
     563          59 :     break;
     564          36 :   case ELF::EM_MIPS:
     565             : #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
     566          36 :     break;
     567           0 :   case ELF::EM_HEXAGON:
     568             : #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
     569           0 :     break;
     570           9 :   case ELF::EM_386:
     571             :   case ELF::EM_IAMCU:
     572             : #include "llvm/BinaryFormat/ELFRelocs/i386.def"
     573           9 :     break;
     574           7 :   case ELF::EM_AARCH64:
     575             : #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
     576           7 :     break;
     577           1 :   case ELF::EM_ARM:
     578             : #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
     579           1 :     break;
     580           0 :   case ELF::EM_ARC:
     581             : #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
     582           0 :     break;
     583           0 :   case ELF::EM_RISCV:
     584             : #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
     585           0 :     break;
     586           7 :   case ELF::EM_LANAI:
     587             : #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
     588           7 :     break;
     589          12 :   case ELF::EM_AMDGPU:
     590             : #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
     591          12 :     break;
     592           0 :   case ELF::EM_BPF:
     593             : #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
     594           0 :     break;
     595           0 :   default:
     596           0 :     llvm_unreachable("Unsupported architecture");
     597             :   }
     598             : #undef ELF_RELOC
     599         131 :   IO.enumFallback<Hex32>(Value);
     600         131 : }
     601             : 
     602           7 : void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration(
     603             :     IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
     604             : #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
     605           7 :   ECase(REG_NONE);
     606           7 :   ECase(REG_32);
     607           7 :   ECase(REG_64);
     608           7 :   ECase(REG_128);
     609             : #undef ECase
     610           7 : }
     611             : 
     612           3 : void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration(
     613             :     IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
     614             : #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
     615           3 :   ECase(FP_ANY);
     616           3 :   ECase(FP_DOUBLE);
     617           3 :   ECase(FP_SINGLE);
     618           3 :   ECase(FP_SOFT);
     619           3 :   ECase(FP_OLD_64);
     620           3 :   ECase(FP_XX);
     621           3 :   ECase(FP_64);
     622           3 :   ECase(FP_64A);
     623             : #undef ECase
     624           3 : }
     625             : 
     626           2 : void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration(
     627             :     IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
     628             : #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
     629           2 :   ECase(EXT_NONE);
     630           2 :   ECase(EXT_XLR);
     631           2 :   ECase(EXT_OCTEON2);
     632           2 :   ECase(EXT_OCTEONP);
     633           2 :   ECase(EXT_LOONGSON_3A);
     634           2 :   ECase(EXT_OCTEON);
     635           2 :   ECase(EXT_5900);
     636           2 :   ECase(EXT_4650);
     637           2 :   ECase(EXT_4010);
     638           2 :   ECase(EXT_4100);
     639           2 :   ECase(EXT_3900);
     640           2 :   ECase(EXT_10000);
     641           2 :   ECase(EXT_SB1);
     642           2 :   ECase(EXT_4111);
     643           2 :   ECase(EXT_4120);
     644           2 :   ECase(EXT_5400);
     645           2 :   ECase(EXT_5500);
     646           2 :   ECase(EXT_LOONGSON_2E);
     647           2 :   ECase(EXT_LOONGSON_2F);
     648           2 :   ECase(EXT_OCTEON3);
     649             : #undef ECase
     650           2 : }
     651             : 
     652           3 : void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration(
     653             :     IO &IO, ELFYAML::MIPS_ISA &Value) {
     654           3 :   IO.enumCase(Value, "MIPS1", 1);
     655           3 :   IO.enumCase(Value, "MIPS2", 2);
     656           3 :   IO.enumCase(Value, "MIPS3", 3);
     657           3 :   IO.enumCase(Value, "MIPS4", 4);
     658           3 :   IO.enumCase(Value, "MIPS5", 5);
     659           3 :   IO.enumCase(Value, "MIPS32", 32);
     660           3 :   IO.enumCase(Value, "MIPS64", 64);
     661           3 : }
     662             : 
     663           2 : void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset(
     664             :     IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
     665             : #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
     666           2 :   BCase(DSP);
     667           2 :   BCase(DSPR2);
     668           2 :   BCase(EVA);
     669           2 :   BCase(MCU);
     670           2 :   BCase(MDMX);
     671           2 :   BCase(MIPS3D);
     672           2 :   BCase(MT);
     673           2 :   BCase(SMARTMIPS);
     674           2 :   BCase(VIRT);
     675           2 :   BCase(MSA);
     676           2 :   BCase(MIPS16);
     677           2 :   BCase(MICROMIPS);
     678           2 :   BCase(XPA);
     679             : #undef BCase
     680           2 : }
     681             : 
     682           3 : void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset(
     683             :     IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
     684             : #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
     685           3 :   BCase(ODDSPREG);
     686             : #undef BCase
     687           3 : }
     688             : 
     689         101 : void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
     690             :                                                  ELFYAML::FileHeader &FileHdr) {
     691         202 :   IO.mapRequired("Class", FileHdr.Class);
     692         202 :   IO.mapRequired("Data", FileHdr.Data);
     693         202 :   IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
     694         202 :   IO.mapRequired("Type", FileHdr.Type);
     695         202 :   IO.mapRequired("Machine", FileHdr.Machine);
     696         202 :   IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
     697         202 :   IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
     698         101 : }
     699             : 
     700           8 : void MappingTraits<ELFYAML::ProgramHeader>::mapping(
     701             :     IO &IO, ELFYAML::ProgramHeader &Phdr) {
     702          16 :   IO.mapRequired("Type", Phdr.Type);
     703          16 :   IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
     704          16 :   IO.mapOptional("Sections", Phdr.Sections);
     705          16 :   IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
     706          16 :   IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
     707           8 : }
     708             : 
     709             : namespace {
     710             : 
     711             : struct NormalizedOther {
     712             :   NormalizedOther(IO &)
     713         396 :       : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
     714             :   NormalizedOther(IO &, uint8_t Original)
     715         303 :       : Visibility(Original & 0x3), Other(Original & ~0x3) {}
     716             : 
     717         132 :   uint8_t denormalize(IO &) { return Visibility | Other; }
     718             : 
     719             :   ELFYAML::ELF_STV Visibility;
     720             :   ELFYAML::ELF_STO Other;
     721             : };
     722             : 
     723             : } // end anonymous namespace
     724             : 
     725         233 : void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
     726         466 :   IO.mapOptional("Name", Symbol.Name, StringRef());
     727         466 :   IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
     728         466 :   IO.mapOptional("Section", Symbol.Section, StringRef());
     729         466 :   IO.mapOptional("Index", Symbol.Index);
     730         466 :   IO.mapOptional("Value", Symbol.Value, Hex64(0));
     731         466 :   IO.mapOptional("Size", Symbol.Size, Hex64(0));
     732             : 
     733         699 :   MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
     734         466 :   IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
     735         466 :   IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
     736         233 : }
     737             : 
     738         233 : StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
     739             :                                                    ELFYAML::Symbol &Symbol) {
     740         242 :   if (Symbol.Index && Symbol.Section.data()) {
     741           1 :     return "Index and Section cannot both be specified for Symbol";
     742             :   }
     743         248 :   if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
     744           0 :     return "Large indexes are not supported";
     745             :   }
     746         256 :   if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
     747           0 :     return "Use a section name to define which section a symbol is defined in";
     748             :   }
     749         232 :   return StringRef();
     750             : }
     751             : 
     752          66 : void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
     753             :     IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
     754         132 :   IO.mapOptional("Local", Symbols.Local);
     755         132 :   IO.mapOptional("Global", Symbols.Global);
     756         132 :   IO.mapOptional("Weak", Symbols.Weak);
     757          66 : }
     758             : 
     759         244 : static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
     760         488 :   IO.mapOptional("Name", Section.Name, StringRef());
     761         488 :   IO.mapRequired("Type", Section.Type);
     762         488 :   IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
     763         488 :   IO.mapOptional("Address", Section.Address, Hex64(0));
     764         488 :   IO.mapOptional("Link", Section.Link, StringRef());
     765         488 :   IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
     766         488 :   IO.mapOptional("Info", Section.Info, StringRef());
     767         244 : }
     768             : 
     769         174 : static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
     770         174 :   commonSectionMapping(IO, Section);
     771         348 :   IO.mapOptional("Content", Section.Content);
     772         696 :   IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
     773         174 : }
     774             : 
     775           9 : static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
     776           9 :   commonSectionMapping(IO, Section);
     777          18 :   IO.mapOptional("Size", Section.Size, Hex64(0));
     778           9 : }
     779             : 
     780          51 : static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
     781          51 :   commonSectionMapping(IO, Section);
     782         102 :   IO.mapOptional("Relocations", Section.Relocations);
     783          51 : }
     784             : 
     785           7 : static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
     786           7 :   commonSectionMapping(IO, group);
     787          14 :   IO.mapRequired("Members", group.Members);
     788           7 : }
     789             : 
     790          16 : void MappingTraits<ELFYAML::SectionOrType>::mapping(
     791             :     IO &IO, ELFYAML::SectionOrType &sectionOrType) {
     792          32 :   IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
     793          16 : }
     794             : 
     795          11 : void MappingTraits<ELFYAML::SectionName>::mapping(
     796             :     IO &IO, ELFYAML::SectionName &sectionName) {
     797          22 :   IO.mapRequired("Section", sectionName.Section);
     798          11 : }
     799             : 
     800           3 : static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) {
     801           3 :   commonSectionMapping(IO, Section);
     802           6 :   IO.mapOptional("Version", Section.Version, Hex16(0));
     803           6 :   IO.mapRequired("ISA", Section.ISALevel);
     804           6 :   IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
     805           6 :   IO.mapOptional("ISAExtension", Section.ISAExtension,
     806           6 :                  ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
     807           6 :   IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
     808           6 :   IO.mapOptional("FpABI", Section.FpABI,
     809           6 :                  ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
     810           6 :   IO.mapOptional("GPRSize", Section.GPRSize,
     811           6 :                  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
     812           6 :   IO.mapOptional("CPR1Size", Section.CPR1Size,
     813           6 :                  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
     814           6 :   IO.mapOptional("CPR2Size", Section.CPR2Size,
     815           6 :                  ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
     816           6 :   IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
     817           6 :   IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
     818           3 : }
     819             : 
     820         244 : void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping(
     821             :     IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
     822             :   ELFYAML::ELF_SHT sectionType;
     823         244 :   if (IO.outputting())
     824          74 :     sectionType = Section->Type;
     825             :   else
     826             :     IO.mapRequired("Type", sectionType);
     827             : 
     828         244 :   switch (sectionType) {
     829          51 :   case ELF::SHT_REL:
     830             :   case ELF::SHT_RELA:
     831          51 :     if (!IO.outputting())
     832          80 :       Section.reset(new ELFYAML::RelocationSection());
     833         102 :     sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
     834          51 :     break;
     835           7 :   case ELF::SHT_GROUP:
     836           7 :     if (!IO.outputting())
     837           4 :       Section.reset(new ELFYAML::Group());
     838          14 :     groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
     839           7 :     break;
     840           9 :   case ELF::SHT_NOBITS:
     841           9 :     if (!IO.outputting())
     842          10 :       Section.reset(new ELFYAML::NoBitsSection());
     843          18 :     sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
     844           9 :     break;
     845           3 :   case ELF::SHT_MIPS_ABIFLAGS:
     846           3 :     if (!IO.outputting())
     847           2 :       Section.reset(new ELFYAML::MipsABIFlags());
     848           6 :     sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
     849           3 :     break;
     850         174 :   default:
     851         174 :     if (!IO.outputting())
     852         244 :       Section.reset(new ELFYAML::RawContentSection());
     853         348 :     sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
     854             :   }
     855         244 : }
     856             : 
     857         244 : StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate(
     858             :     IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
     859         418 :   const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
     860         348 :   if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
     861         243 :     return StringRef();
     862           1 :   return "Section size must be greater or equal to the content size";
     863             : }
     864             : 
     865             : namespace {
     866             : 
     867             : struct NormalizedMips64RelType {
     868             :   NormalizedMips64RelType(IO &)
     869           6 :       : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
     870             :         Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
     871             :         Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
     872          30 :         SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
     873             :   NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
     874          21 :       : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
     875          49 :         Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
     876             : 
     877             :   ELFYAML::ELF_REL denormalize(IO &) {
     878          12 :     ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
     879             :     return Res;
     880             :   }
     881             : 
     882             :   ELFYAML::ELF_REL Type;
     883             :   ELFYAML::ELF_REL Type2;
     884             :   ELFYAML::ELF_REL Type3;
     885             :   ELFYAML::ELF_RSS SpecSym;
     886             : };
     887             : 
     888             : } // end anonymous namespace
     889             : 
     890         121 : void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
     891             :                                                  ELFYAML::Relocation &Rel) {
     892         121 :   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
     893             :   assert(Object && "The IO context is not initialized");
     894             : 
     895         242 :   IO.mapRequired("Offset", Rel.Offset);
     896         242 :   IO.mapOptional("Symbol", Rel.Symbol);
     897             : 
     898         268 :   if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
     899          52 :       Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
     900             :     MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
     901          26 :         IO, Rel.Type);
     902          26 :     IO.mapRequired("Type", Key->Type);
     903          26 :     IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
     904          26 :     IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
     905          26 :     IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
     906             :   } else
     907         108 :     IO.mapRequired("Type", Rel.Type);
     908             : 
     909         242 :   IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
     910         121 : }
     911             : 
     912         101 : void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
     913             :   assert(!IO.getContext() && "The IO context is initialized already");
     914         101 :   IO.setContext(&Object);
     915         202 :   IO.mapTag("!ELF", true);
     916         202 :   IO.mapRequired("FileHeader", Object.Header);
     917         202 :   IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
     918         202 :   IO.mapOptional("Sections", Object.Sections);
     919         202 :   IO.mapOptional("Symbols", Object.Symbols);
     920         101 :   IO.setContext(nullptr);
     921         101 : }
     922             : 
     923             : LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
     924             : LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
     925             : LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
     926             : LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
     927             : LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
     928             : 
     929             : } // end namespace yaml
     930             : 
     931             : } // end namespace llvm

Generated by: LCOV version 1.13