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

Generated by: LCOV version 1.13