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

Generated by: LCOV version 1.13