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

Generated by: LCOV version 1.13