Home | History | Annotate | Download | only in Object
      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/Object/ELFYAML.h"
     15 #include "llvm/Support/Casting.h"
     16 
     17 namespace llvm {
     18 
     19 ELFYAML::Section::~Section() {}
     20 
     21 namespace yaml {
     22 
     23 void
     24 ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(IO &IO,
     25                                                       ELFYAML::ELF_ET &Value) {
     26 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
     27   ECase(ET_NONE)
     28   ECase(ET_REL)
     29   ECase(ET_EXEC)
     30   ECase(ET_DYN)
     31   ECase(ET_CORE)
     32 #undef ECase
     33 }
     34 
     35 void
     36 ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(IO &IO,
     37                                                       ELFYAML::ELF_EM &Value) {
     38 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
     39   ECase(EM_NONE)
     40   ECase(EM_M32)
     41   ECase(EM_SPARC)
     42   ECase(EM_386)
     43   ECase(EM_68K)
     44   ECase(EM_88K)
     45   ECase(EM_486)
     46   ECase(EM_860)
     47   ECase(EM_MIPS)
     48   ECase(EM_S370)
     49   ECase(EM_MIPS_RS3_LE)
     50   ECase(EM_PARISC)
     51   ECase(EM_VPP500)
     52   ECase(EM_SPARC32PLUS)
     53   ECase(EM_960)
     54   ECase(EM_PPC)
     55   ECase(EM_PPC64)
     56   ECase(EM_S390)
     57   ECase(EM_SPU)
     58   ECase(EM_V800)
     59   ECase(EM_FR20)
     60   ECase(EM_RH32)
     61   ECase(EM_RCE)
     62   ECase(EM_ARM)
     63   ECase(EM_ALPHA)
     64   ECase(EM_SH)
     65   ECase(EM_SPARCV9)
     66   ECase(EM_TRICORE)
     67   ECase(EM_ARC)
     68   ECase(EM_H8_300)
     69   ECase(EM_H8_300H)
     70   ECase(EM_H8S)
     71   ECase(EM_H8_500)
     72   ECase(EM_IA_64)
     73   ECase(EM_MIPS_X)
     74   ECase(EM_COLDFIRE)
     75   ECase(EM_68HC12)
     76   ECase(EM_MMA)
     77   ECase(EM_PCP)
     78   ECase(EM_NCPU)
     79   ECase(EM_NDR1)
     80   ECase(EM_STARCORE)
     81   ECase(EM_ME16)
     82   ECase(EM_ST100)
     83   ECase(EM_TINYJ)
     84   ECase(EM_X86_64)
     85   ECase(EM_PDSP)
     86   ECase(EM_PDP10)
     87   ECase(EM_PDP11)
     88   ECase(EM_FX66)
     89   ECase(EM_ST9PLUS)
     90   ECase(EM_ST7)
     91   ECase(EM_68HC16)
     92   ECase(EM_68HC11)
     93   ECase(EM_68HC08)
     94   ECase(EM_68HC05)
     95   ECase(EM_SVX)
     96   ECase(EM_ST19)
     97   ECase(EM_VAX)
     98   ECase(EM_CRIS)
     99   ECase(EM_JAVELIN)
    100   ECase(EM_FIREPATH)
    101   ECase(EM_ZSP)
    102   ECase(EM_MMIX)
    103   ECase(EM_HUANY)
    104   ECase(EM_PRISM)
    105   ECase(EM_AVR)
    106   ECase(EM_FR30)
    107   ECase(EM_D10V)
    108   ECase(EM_D30V)
    109   ECase(EM_V850)
    110   ECase(EM_M32R)
    111   ECase(EM_MN10300)
    112   ECase(EM_MN10200)
    113   ECase(EM_PJ)
    114   ECase(EM_OPENRISC)
    115   ECase(EM_ARC_COMPACT)
    116   ECase(EM_XTENSA)
    117   ECase(EM_VIDEOCORE)
    118   ECase(EM_TMM_GPP)
    119   ECase(EM_NS32K)
    120   ECase(EM_TPC)
    121   ECase(EM_SNP1K)
    122   ECase(EM_ST200)
    123   ECase(EM_IP2K)
    124   ECase(EM_MAX)
    125   ECase(EM_CR)
    126   ECase(EM_F2MC16)
    127   ECase(EM_MSP430)
    128   ECase(EM_BLACKFIN)
    129   ECase(EM_SE_C33)
    130   ECase(EM_SEP)
    131   ECase(EM_ARCA)
    132   ECase(EM_UNICORE)
    133   ECase(EM_EXCESS)
    134   ECase(EM_DXP)
    135   ECase(EM_ALTERA_NIOS2)
    136   ECase(EM_CRX)
    137   ECase(EM_XGATE)
    138   ECase(EM_C166)
    139   ECase(EM_M16C)
    140   ECase(EM_DSPIC30F)
    141   ECase(EM_CE)
    142   ECase(EM_M32C)
    143   ECase(EM_TSK3000)
    144   ECase(EM_RS08)
    145   ECase(EM_SHARC)
    146   ECase(EM_ECOG2)
    147   ECase(EM_SCORE7)
    148   ECase(EM_DSP24)
    149   ECase(EM_VIDEOCORE3)
    150   ECase(EM_LATTICEMICO32)
    151   ECase(EM_SE_C17)
    152   ECase(EM_TI_C6000)
    153   ECase(EM_TI_C2000)
    154   ECase(EM_TI_C5500)
    155   ECase(EM_MMDSP_PLUS)
    156   ECase(EM_CYPRESS_M8C)
    157   ECase(EM_R32C)
    158   ECase(EM_TRIMEDIA)
    159   ECase(EM_HEXAGON)
    160   ECase(EM_8051)
    161   ECase(EM_STXP7X)
    162   ECase(EM_NDS32)
    163   ECase(EM_ECOG1)
    164   ECase(EM_ECOG1X)
    165   ECase(EM_MAXQ30)
    166   ECase(EM_XIMO16)
    167   ECase(EM_MANIK)
    168   ECase(EM_CRAYNV2)
    169   ECase(EM_RX)
    170   ECase(EM_METAG)
    171   ECase(EM_MCST_ELBRUS)
    172   ECase(EM_ECOG16)
    173   ECase(EM_CR16)
    174   ECase(EM_ETPU)
    175   ECase(EM_SLE9X)
    176   ECase(EM_L10M)
    177   ECase(EM_K10M)
    178   ECase(EM_AARCH64)
    179   ECase(EM_AVR32)
    180   ECase(EM_STM8)
    181   ECase(EM_TILE64)
    182   ECase(EM_TILEPRO)
    183   ECase(EM_CUDA)
    184   ECase(EM_TILEGX)
    185   ECase(EM_CLOUDSHIELD)
    186   ECase(EM_COREA_1ST)
    187   ECase(EM_COREA_2ND)
    188   ECase(EM_ARC_COMPACT2)
    189   ECase(EM_OPEN8)
    190   ECase(EM_RL78)
    191   ECase(EM_VIDEOCORE5)
    192   ECase(EM_78KOR)
    193   ECase(EM_56800EX)
    194 #undef ECase
    195 }
    196 
    197 void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration(
    198     IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
    199 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
    200   // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
    201   // here.
    202   ECase(ELFCLASS32)
    203   ECase(ELFCLASS64)
    204 #undef ECase
    205 }
    206 
    207 void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
    208     IO &IO, ELFYAML::ELF_ELFDATA &Value) {
    209 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
    210   // Since the semantics of ELFDATANONE is "invalid", just don't accept it
    211   // here.
    212   ECase(ELFDATA2LSB)
    213   ECase(ELFDATA2MSB)
    214 #undef ECase
    215 }
    216 
    217 void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
    218     IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
    219 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
    220   ECase(ELFOSABI_NONE)
    221   ECase(ELFOSABI_HPUX)
    222   ECase(ELFOSABI_NETBSD)
    223   ECase(ELFOSABI_GNU)
    224   ECase(ELFOSABI_GNU)
    225   ECase(ELFOSABI_HURD)
    226   ECase(ELFOSABI_SOLARIS)
    227   ECase(ELFOSABI_AIX)
    228   ECase(ELFOSABI_IRIX)
    229   ECase(ELFOSABI_FREEBSD)
    230   ECase(ELFOSABI_TRU64)
    231   ECase(ELFOSABI_MODESTO)
    232   ECase(ELFOSABI_OPENBSD)
    233   ECase(ELFOSABI_OPENVMS)
    234   ECase(ELFOSABI_NSK)
    235   ECase(ELFOSABI_AROS)
    236   ECase(ELFOSABI_FENIXOS)
    237   ECase(ELFOSABI_C6000_ELFABI)
    238   ECase(ELFOSABI_C6000_LINUX)
    239   ECase(ELFOSABI_ARM)
    240   ECase(ELFOSABI_STANDALONE)
    241 #undef ECase
    242 }
    243 
    244 void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
    245                                                  ELFYAML::ELF_EF &Value) {
    246   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
    247   assert(Object && "The IO context is not initialized");
    248 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
    249 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M);
    250   switch (Object->Header.Machine) {
    251   case ELF::EM_ARM:
    252     BCase(EF_ARM_SOFT_FLOAT)
    253     BCase(EF_ARM_VFP_FLOAT)
    254     BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK)
    255     BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK)
    256     BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK)
    257     BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK)
    258     BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK)
    259     BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK)
    260     break;
    261   case ELF::EM_MIPS:
    262     BCase(EF_MIPS_NOREORDER)
    263     BCase(EF_MIPS_PIC)
    264     BCase(EF_MIPS_CPIC)
    265     BCase(EF_MIPS_ABI2)
    266     BCase(EF_MIPS_32BITMODE)
    267     BCase(EF_MIPS_ABI_O32)
    268     BCase(EF_MIPS_MICROMIPS)
    269     BCase(EF_MIPS_ARCH_ASE_M16)
    270     BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH)
    271     BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH)
    272     BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH)
    273     BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH)
    274     BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH)
    275     BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH)
    276     BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH)
    277     BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH)
    278     BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH)
    279     BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH)
    280     BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH)
    281     break;
    282   case ELF::EM_HEXAGON:
    283     BCase(EF_HEXAGON_MACH_V2)
    284     BCase(EF_HEXAGON_MACH_V3)
    285     BCase(EF_HEXAGON_MACH_V4)
    286     BCase(EF_HEXAGON_MACH_V5)
    287     BCase(EF_HEXAGON_ISA_V2)
    288     BCase(EF_HEXAGON_ISA_V3)
    289     BCase(EF_HEXAGON_ISA_V4)
    290     BCase(EF_HEXAGON_ISA_V5)
    291     break;
    292   default:
    293     llvm_unreachable("Unsupported architecture");
    294   }
    295 #undef BCase
    296 #undef BCaseMask
    297 }
    298 
    299 void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
    300     IO &IO, ELFYAML::ELF_SHT &Value) {
    301 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
    302   ECase(SHT_NULL)
    303   ECase(SHT_PROGBITS)
    304   // No SHT_SYMTAB. Use the top-level `Symbols` key instead.
    305   // FIXME: Issue a diagnostic with this information.
    306   ECase(SHT_STRTAB)
    307   ECase(SHT_RELA)
    308   ECase(SHT_HASH)
    309   ECase(SHT_DYNAMIC)
    310   ECase(SHT_NOTE)
    311   ECase(SHT_NOBITS)
    312   ECase(SHT_REL)
    313   ECase(SHT_SHLIB)
    314   ECase(SHT_DYNSYM)
    315   ECase(SHT_INIT_ARRAY)
    316   ECase(SHT_FINI_ARRAY)
    317   ECase(SHT_PREINIT_ARRAY)
    318   ECase(SHT_GROUP)
    319   ECase(SHT_SYMTAB_SHNDX)
    320   ECase(SHT_LOOS)
    321   ECase(SHT_GNU_ATTRIBUTES)
    322   ECase(SHT_GNU_HASH)
    323   ECase(SHT_GNU_verdef)
    324   ECase(SHT_GNU_verneed)
    325   ECase(SHT_GNU_versym)
    326   ECase(SHT_HIOS)
    327   ECase(SHT_LOPROC)
    328   ECase(SHT_ARM_EXIDX)
    329   ECase(SHT_ARM_PREEMPTMAP)
    330   ECase(SHT_ARM_ATTRIBUTES)
    331   ECase(SHT_ARM_DEBUGOVERLAY)
    332   ECase(SHT_ARM_OVERLAYSECTION)
    333   ECase(SHT_HEX_ORDERED)
    334   ECase(SHT_X86_64_UNWIND)
    335   ECase(SHT_MIPS_REGINFO)
    336   ECase(SHT_MIPS_OPTIONS)
    337 #undef ECase
    338 }
    339 
    340 void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
    341                                                   ELFYAML::ELF_SHF &Value) {
    342 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
    343   BCase(SHF_WRITE)
    344   BCase(SHF_ALLOC)
    345   BCase(SHF_EXCLUDE)
    346   BCase(SHF_EXECINSTR)
    347   BCase(SHF_MERGE)
    348   BCase(SHF_STRINGS)
    349   BCase(SHF_INFO_LINK)
    350   BCase(SHF_LINK_ORDER)
    351   BCase(SHF_OS_NONCONFORMING)
    352   BCase(SHF_GROUP)
    353   BCase(SHF_TLS)
    354 #undef BCase
    355 }
    356 
    357 void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
    358     IO &IO, ELFYAML::ELF_STT &Value) {
    359 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
    360   ECase(STT_NOTYPE)
    361   ECase(STT_OBJECT)
    362   ECase(STT_FUNC)
    363   ECase(STT_SECTION)
    364   ECase(STT_FILE)
    365   ECase(STT_COMMON)
    366   ECase(STT_TLS)
    367   ECase(STT_GNU_IFUNC)
    368 #undef ECase
    369 }
    370 
    371 void ScalarEnumerationTraits<ELFYAML::ELF_STV>::enumeration(
    372     IO &IO, ELFYAML::ELF_STV &Value) {
    373 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
    374   ECase(STV_DEFAULT)
    375   ECase(STV_INTERNAL)
    376   ECase(STV_HIDDEN)
    377   ECase(STV_PROTECTED)
    378 #undef ECase
    379 }
    380 
    381 void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
    382     IO &IO, ELFYAML::ELF_REL &Value) {
    383   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
    384   assert(Object && "The IO context is not initialized");
    385 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
    386   switch (Object->Header.Machine) {
    387   case ELF::EM_X86_64:
    388     ECase(R_X86_64_NONE)
    389     ECase(R_X86_64_64)
    390     ECase(R_X86_64_PC32)
    391     ECase(R_X86_64_GOT32)
    392     ECase(R_X86_64_PLT32)
    393     ECase(R_X86_64_COPY)
    394     ECase(R_X86_64_GLOB_DAT)
    395     ECase(R_X86_64_JUMP_SLOT)
    396     ECase(R_X86_64_RELATIVE)
    397     ECase(R_X86_64_GOTPCREL)
    398     ECase(R_X86_64_32)
    399     ECase(R_X86_64_32S)
    400     ECase(R_X86_64_16)
    401     ECase(R_X86_64_PC16)
    402     ECase(R_X86_64_8)
    403     ECase(R_X86_64_PC8)
    404     ECase(R_X86_64_DTPMOD64)
    405     ECase(R_X86_64_DTPOFF64)
    406     ECase(R_X86_64_TPOFF64)
    407     ECase(R_X86_64_TLSGD)
    408     ECase(R_X86_64_TLSLD)
    409     ECase(R_X86_64_DTPOFF32)
    410     ECase(R_X86_64_GOTTPOFF)
    411     ECase(R_X86_64_TPOFF32)
    412     ECase(R_X86_64_PC64)
    413     ECase(R_X86_64_GOTOFF64)
    414     ECase(R_X86_64_GOTPC32)
    415     ECase(R_X86_64_GOT64)
    416     ECase(R_X86_64_GOTPCREL64)
    417     ECase(R_X86_64_GOTPC64)
    418     ECase(R_X86_64_GOTPLT64)
    419     ECase(R_X86_64_PLTOFF64)
    420     ECase(R_X86_64_SIZE32)
    421     ECase(R_X86_64_SIZE64)
    422     ECase(R_X86_64_GOTPC32_TLSDESC)
    423     ECase(R_X86_64_TLSDESC_CALL)
    424     ECase(R_X86_64_TLSDESC)
    425     ECase(R_X86_64_IRELATIVE)
    426     break;
    427   case ELF::EM_MIPS:
    428     ECase(R_MIPS_NONE)
    429     ECase(R_MIPS_16)
    430     ECase(R_MIPS_32)
    431     ECase(R_MIPS_REL32)
    432     ECase(R_MIPS_26)
    433     ECase(R_MIPS_HI16)
    434     ECase(R_MIPS_LO16)
    435     ECase(R_MIPS_GPREL16)
    436     ECase(R_MIPS_LITERAL)
    437     ECase(R_MIPS_GOT16)
    438     ECase(R_MIPS_PC16)
    439     ECase(R_MIPS_CALL16)
    440     ECase(R_MIPS_GPREL32)
    441     ECase(R_MIPS_UNUSED1)
    442     ECase(R_MIPS_UNUSED2)
    443     ECase(R_MIPS_SHIFT5)
    444     ECase(R_MIPS_SHIFT6)
    445     ECase(R_MIPS_64)
    446     ECase(R_MIPS_GOT_DISP)
    447     ECase(R_MIPS_GOT_PAGE)
    448     ECase(R_MIPS_GOT_OFST)
    449     ECase(R_MIPS_GOT_HI16)
    450     ECase(R_MIPS_GOT_LO16)
    451     ECase(R_MIPS_SUB)
    452     ECase(R_MIPS_INSERT_A)
    453     ECase(R_MIPS_INSERT_B)
    454     ECase(R_MIPS_DELETE)
    455     ECase(R_MIPS_HIGHER)
    456     ECase(R_MIPS_HIGHEST)
    457     ECase(R_MIPS_CALL_HI16)
    458     ECase(R_MIPS_CALL_LO16)
    459     ECase(R_MIPS_SCN_DISP)
    460     ECase(R_MIPS_REL16)
    461     ECase(R_MIPS_ADD_IMMEDIATE)
    462     ECase(R_MIPS_PJUMP)
    463     ECase(R_MIPS_RELGOT)
    464     ECase(R_MIPS_JALR)
    465     ECase(R_MIPS_TLS_DTPMOD32)
    466     ECase(R_MIPS_TLS_DTPREL32)
    467     ECase(R_MIPS_TLS_DTPMOD64)
    468     ECase(R_MIPS_TLS_DTPREL64)
    469     ECase(R_MIPS_TLS_GD)
    470     ECase(R_MIPS_TLS_LDM)
    471     ECase(R_MIPS_TLS_DTPREL_HI16)
    472     ECase(R_MIPS_TLS_DTPREL_LO16)
    473     ECase(R_MIPS_TLS_GOTTPREL)
    474     ECase(R_MIPS_TLS_TPREL32)
    475     ECase(R_MIPS_TLS_TPREL64)
    476     ECase(R_MIPS_TLS_TPREL_HI16)
    477     ECase(R_MIPS_TLS_TPREL_LO16)
    478     ECase(R_MIPS_GLOB_DAT)
    479     ECase(R_MIPS_PC21_S2)
    480     ECase(R_MIPS_PC26_S2)
    481     ECase(R_MIPS_PC18_S3)
    482     ECase(R_MIPS_PC19_S2)
    483     ECase(R_MIPS_PCHI16)
    484     ECase(R_MIPS_PCLO16)
    485     ECase(R_MIPS16_GOT16)
    486     ECase(R_MIPS16_HI16)
    487     ECase(R_MIPS16_LO16)
    488     ECase(R_MIPS_COPY)
    489     ECase(R_MIPS_JUMP_SLOT)
    490     ECase(R_MICROMIPS_26_S1)
    491     ECase(R_MICROMIPS_HI16)
    492     ECase(R_MICROMIPS_LO16)
    493     ECase(R_MICROMIPS_GOT16)
    494     ECase(R_MICROMIPS_PC16_S1)
    495     ECase(R_MICROMIPS_CALL16)
    496     ECase(R_MICROMIPS_GOT_DISP)
    497     ECase(R_MICROMIPS_GOT_PAGE)
    498     ECase(R_MICROMIPS_GOT_OFST)
    499     ECase(R_MICROMIPS_TLS_GD)
    500     ECase(R_MICROMIPS_TLS_LDM)
    501     ECase(R_MICROMIPS_TLS_DTPREL_HI16)
    502     ECase(R_MICROMIPS_TLS_DTPREL_LO16)
    503     ECase(R_MICROMIPS_TLS_TPREL_HI16)
    504     ECase(R_MICROMIPS_TLS_TPREL_LO16)
    505     ECase(R_MIPS_NUM)
    506     ECase(R_MIPS_PC32)
    507     break;
    508   case ELF::EM_HEXAGON:
    509     ECase(R_HEX_NONE)
    510     ECase(R_HEX_B22_PCREL)
    511     ECase(R_HEX_B15_PCREL)
    512     ECase(R_HEX_B7_PCREL)
    513     ECase(R_HEX_LO16)
    514     ECase(R_HEX_HI16)
    515     ECase(R_HEX_32)
    516     ECase(R_HEX_16)
    517     ECase(R_HEX_8)
    518     ECase(R_HEX_GPREL16_0)
    519     ECase(R_HEX_GPREL16_1)
    520     ECase(R_HEX_GPREL16_2)
    521     ECase(R_HEX_GPREL16_3)
    522     ECase(R_HEX_HL16)
    523     ECase(R_HEX_B13_PCREL)
    524     ECase(R_HEX_B9_PCREL)
    525     ECase(R_HEX_B32_PCREL_X)
    526     ECase(R_HEX_32_6_X)
    527     ECase(R_HEX_B22_PCREL_X)
    528     ECase(R_HEX_B15_PCREL_X)
    529     ECase(R_HEX_B13_PCREL_X)
    530     ECase(R_HEX_B9_PCREL_X)
    531     ECase(R_HEX_B7_PCREL_X)
    532     ECase(R_HEX_16_X)
    533     ECase(R_HEX_12_X)
    534     ECase(R_HEX_11_X)
    535     ECase(R_HEX_10_X)
    536     ECase(R_HEX_9_X)
    537     ECase(R_HEX_8_X)
    538     ECase(R_HEX_7_X)
    539     ECase(R_HEX_6_X)
    540     ECase(R_HEX_32_PCREL)
    541     ECase(R_HEX_COPY)
    542     ECase(R_HEX_GLOB_DAT)
    543     ECase(R_HEX_JMP_SLOT)
    544     ECase(R_HEX_RELATIVE)
    545     ECase(R_HEX_PLT_B22_PCREL)
    546     ECase(R_HEX_GOTREL_LO16)
    547     ECase(R_HEX_GOTREL_HI16)
    548     ECase(R_HEX_GOTREL_32)
    549     ECase(R_HEX_GOT_LO16)
    550     ECase(R_HEX_GOT_HI16)
    551     ECase(R_HEX_GOT_32)
    552     ECase(R_HEX_GOT_16)
    553     ECase(R_HEX_DTPMOD_32)
    554     ECase(R_HEX_DTPREL_LO16)
    555     ECase(R_HEX_DTPREL_HI16)
    556     ECase(R_HEX_DTPREL_32)
    557     ECase(R_HEX_DTPREL_16)
    558     ECase(R_HEX_GD_PLT_B22_PCREL)
    559     ECase(R_HEX_GD_GOT_LO16)
    560     ECase(R_HEX_GD_GOT_HI16)
    561     ECase(R_HEX_GD_GOT_32)
    562     ECase(R_HEX_GD_GOT_16)
    563     ECase(R_HEX_IE_LO16)
    564     ECase(R_HEX_IE_HI16)
    565     ECase(R_HEX_IE_32)
    566     ECase(R_HEX_IE_GOT_LO16)
    567     ECase(R_HEX_IE_GOT_HI16)
    568     ECase(R_HEX_IE_GOT_32)
    569     ECase(R_HEX_IE_GOT_16)
    570     ECase(R_HEX_TPREL_LO16)
    571     ECase(R_HEX_TPREL_HI16)
    572     ECase(R_HEX_TPREL_32)
    573     ECase(R_HEX_TPREL_16)
    574     ECase(R_HEX_6_PCREL_X)
    575     ECase(R_HEX_GOTREL_32_6_X)
    576     ECase(R_HEX_GOTREL_16_X)
    577     ECase(R_HEX_GOTREL_11_X)
    578     ECase(R_HEX_GOT_32_6_X)
    579     ECase(R_HEX_GOT_16_X)
    580     ECase(R_HEX_GOT_11_X)
    581     ECase(R_HEX_DTPREL_32_6_X)
    582     ECase(R_HEX_DTPREL_16_X)
    583     ECase(R_HEX_DTPREL_11_X)
    584     ECase(R_HEX_GD_GOT_32_6_X)
    585     ECase(R_HEX_GD_GOT_16_X)
    586     ECase(R_HEX_GD_GOT_11_X)
    587     ECase(R_HEX_IE_32_6_X)
    588     ECase(R_HEX_IE_16_X)
    589     ECase(R_HEX_IE_GOT_32_6_X)
    590     ECase(R_HEX_IE_GOT_16_X)
    591     ECase(R_HEX_IE_GOT_11_X)
    592     ECase(R_HEX_TPREL_32_6_X)
    593     ECase(R_HEX_TPREL_16_X)
    594     ECase(R_HEX_TPREL_11_X)
    595     break;
    596   case ELF::EM_386:
    597     ECase(R_386_NONE)
    598     ECase(R_386_32)
    599     ECase(R_386_PC32)
    600     ECase(R_386_GOT32)
    601     ECase(R_386_PLT32)
    602     ECase(R_386_COPY)
    603     ECase(R_386_GLOB_DAT)
    604     ECase(R_386_JUMP_SLOT)
    605     ECase(R_386_RELATIVE)
    606     ECase(R_386_GOTOFF)
    607     ECase(R_386_GOTPC)
    608     ECase(R_386_32PLT)
    609     ECase(R_386_TLS_TPOFF)
    610     ECase(R_386_TLS_IE)
    611     ECase(R_386_TLS_GOTIE)
    612     ECase(R_386_TLS_LE)
    613     ECase(R_386_TLS_GD)
    614     ECase(R_386_TLS_LDM)
    615     ECase(R_386_16)
    616     ECase(R_386_PC16)
    617     ECase(R_386_8)
    618     ECase(R_386_PC8)
    619     ECase(R_386_TLS_GD_32)
    620     ECase(R_386_TLS_GD_PUSH)
    621     ECase(R_386_TLS_GD_CALL)
    622     ECase(R_386_TLS_GD_POP)
    623     ECase(R_386_TLS_LDM_32)
    624     ECase(R_386_TLS_LDM_PUSH)
    625     ECase(R_386_TLS_LDM_CALL)
    626     ECase(R_386_TLS_LDM_POP)
    627     ECase(R_386_TLS_LDO_32)
    628     ECase(R_386_TLS_IE_32)
    629     ECase(R_386_TLS_LE_32)
    630     ECase(R_386_TLS_DTPMOD32)
    631     ECase(R_386_TLS_DTPOFF32)
    632     ECase(R_386_TLS_TPOFF32)
    633     ECase(R_386_TLS_GOTDESC)
    634     ECase(R_386_TLS_DESC_CALL)
    635     ECase(R_386_TLS_DESC)
    636     ECase(R_386_IRELATIVE)
    637     ECase(R_386_NUM)
    638     break;
    639   default:
    640     llvm_unreachable("Unsupported architecture");
    641   }
    642 #undef ECase
    643 }
    644 
    645 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
    646                                                  ELFYAML::FileHeader &FileHdr) {
    647   IO.mapRequired("Class", FileHdr.Class);
    648   IO.mapRequired("Data", FileHdr.Data);
    649   IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
    650   IO.mapRequired("Type", FileHdr.Type);
    651   IO.mapRequired("Machine", FileHdr.Machine);
    652   IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
    653   IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
    654 }
    655 
    656 void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
    657   IO.mapOptional("Name", Symbol.Name, StringRef());
    658   IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
    659   IO.mapOptional("Section", Symbol.Section, StringRef());
    660   IO.mapOptional("Value", Symbol.Value, Hex64(0));
    661   IO.mapOptional("Size", Symbol.Size, Hex64(0));
    662   IO.mapOptional("Visibility", Symbol.Visibility, ELFYAML::ELF_STV(0));
    663 }
    664 
    665 void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
    666     IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
    667   IO.mapOptional("Local", Symbols.Local);
    668   IO.mapOptional("Global", Symbols.Global);
    669   IO.mapOptional("Weak", Symbols.Weak);
    670 }
    671 
    672 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
    673   IO.mapOptional("Name", Section.Name, StringRef());
    674   IO.mapRequired("Type", Section.Type);
    675   IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
    676   IO.mapOptional("Address", Section.Address, Hex64(0));
    677   IO.mapOptional("Link", Section.Link, StringRef());
    678   IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
    679 }
    680 
    681 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
    682   commonSectionMapping(IO, Section);
    683   IO.mapOptional("Content", Section.Content);
    684   IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
    685 }
    686 
    687 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
    688   commonSectionMapping(IO, Section);
    689   IO.mapOptional("Info", Section.Info, StringRef());
    690   IO.mapOptional("Relocations", Section.Relocations);
    691 }
    692 
    693 void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping(
    694     IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
    695   ELFYAML::ELF_SHT sectionType;
    696   if (IO.outputting())
    697     sectionType = Section->Type;
    698   else
    699     IO.mapRequired("Type", sectionType);
    700 
    701   switch (sectionType) {
    702   case ELF::SHT_REL:
    703   case ELF::SHT_RELA:
    704     if (!IO.outputting())
    705       Section.reset(new ELFYAML::RelocationSection());
    706     sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
    707     break;
    708   default:
    709     if (!IO.outputting())
    710       Section.reset(new ELFYAML::RawContentSection());
    711     sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
    712   }
    713 }
    714 
    715 StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate(
    716     IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
    717   const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
    718   if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
    719     return StringRef();
    720   return "Section size must be greater or equal to the content size";
    721 }
    722 
    723 void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
    724                                                  ELFYAML::Relocation &Rel) {
    725   IO.mapRequired("Offset", Rel.Offset);
    726   IO.mapRequired("Symbol", Rel.Symbol);
    727   IO.mapRequired("Type", Rel.Type);
    728   IO.mapOptional("Addend", Rel.Addend);
    729 }
    730 
    731 void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
    732   assert(!IO.getContext() && "The IO context is initialized already");
    733   IO.setContext(&Object);
    734   IO.mapRequired("FileHeader", Object.Header);
    735   IO.mapOptional("Sections", Object.Sections);
    736   IO.mapOptional("Symbols", Object.Symbols);
    737   IO.setContext(nullptr);
    738 }
    739 
    740 } // end namespace yaml
    741 } // end namespace llvm
    742