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

Generated by: LCOV version 1.13