LLVM API Documentation

ELFYAML.cpp
Go to the documentation of this file.
00001 //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines classes for handling the YAML representation of ELF.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Object/ELFYAML.h"
00015 #include "llvm/Support/Casting.h"
00016 
00017 namespace llvm {
00018 
00019 ELFYAML::Section::~Section() {}
00020 
00021 namespace yaml {
00022 
00023 void
00024 ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(IO &IO,
00025                                                       ELFYAML::ELF_ET &Value) {
00026 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00027   ECase(ET_NONE)
00028   ECase(ET_REL)
00029   ECase(ET_EXEC)
00030   ECase(ET_DYN)
00031   ECase(ET_CORE)
00032 #undef ECase
00033 }
00034 
00035 void
00036 ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(IO &IO,
00037                                                       ELFYAML::ELF_EM &Value) {
00038 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00039   ECase(EM_NONE)
00040   ECase(EM_M32)
00041   ECase(EM_SPARC)
00042   ECase(EM_386)
00043   ECase(EM_68K)
00044   ECase(EM_88K)
00045   ECase(EM_486)
00046   ECase(EM_860)
00047   ECase(EM_MIPS)
00048   ECase(EM_S370)
00049   ECase(EM_MIPS_RS3_LE)
00050   ECase(EM_PARISC)
00051   ECase(EM_VPP500)
00052   ECase(EM_SPARC32PLUS)
00053   ECase(EM_960)
00054   ECase(EM_PPC)
00055   ECase(EM_PPC64)
00056   ECase(EM_S390)
00057   ECase(EM_SPU)
00058   ECase(EM_V800)
00059   ECase(EM_FR20)
00060   ECase(EM_RH32)
00061   ECase(EM_RCE)
00062   ECase(EM_ARM)
00063   ECase(EM_ALPHA)
00064   ECase(EM_SH)
00065   ECase(EM_SPARCV9)
00066   ECase(EM_TRICORE)
00067   ECase(EM_ARC)
00068   ECase(EM_H8_300)
00069   ECase(EM_H8_300H)
00070   ECase(EM_H8S)
00071   ECase(EM_H8_500)
00072   ECase(EM_IA_64)
00073   ECase(EM_MIPS_X)
00074   ECase(EM_COLDFIRE)
00075   ECase(EM_68HC12)
00076   ECase(EM_MMA)
00077   ECase(EM_PCP)
00078   ECase(EM_NCPU)
00079   ECase(EM_NDR1)
00080   ECase(EM_STARCORE)
00081   ECase(EM_ME16)
00082   ECase(EM_ST100)
00083   ECase(EM_TINYJ)
00084   ECase(EM_X86_64)
00085   ECase(EM_PDSP)
00086   ECase(EM_PDP10)
00087   ECase(EM_PDP11)
00088   ECase(EM_FX66)
00089   ECase(EM_ST9PLUS)
00090   ECase(EM_ST7)
00091   ECase(EM_68HC16)
00092   ECase(EM_68HC11)
00093   ECase(EM_68HC08)
00094   ECase(EM_68HC05)
00095   ECase(EM_SVX)
00096   ECase(EM_ST19)
00097   ECase(EM_VAX)
00098   ECase(EM_CRIS)
00099   ECase(EM_JAVELIN)
00100   ECase(EM_FIREPATH)
00101   ECase(EM_ZSP)
00102   ECase(EM_MMIX)
00103   ECase(EM_HUANY)
00104   ECase(EM_PRISM)
00105   ECase(EM_AVR)
00106   ECase(EM_FR30)
00107   ECase(EM_D10V)
00108   ECase(EM_D30V)
00109   ECase(EM_V850)
00110   ECase(EM_M32R)
00111   ECase(EM_MN10300)
00112   ECase(EM_MN10200)
00113   ECase(EM_PJ)
00114   ECase(EM_OPENRISC)
00115   ECase(EM_ARC_COMPACT)
00116   ECase(EM_XTENSA)
00117   ECase(EM_VIDEOCORE)
00118   ECase(EM_TMM_GPP)
00119   ECase(EM_NS32K)
00120   ECase(EM_TPC)
00121   ECase(EM_SNP1K)
00122   ECase(EM_ST200)
00123   ECase(EM_IP2K)
00124   ECase(EM_MAX)
00125   ECase(EM_CR)
00126   ECase(EM_F2MC16)
00127   ECase(EM_MSP430)
00128   ECase(EM_BLACKFIN)
00129   ECase(EM_SE_C33)
00130   ECase(EM_SEP)
00131   ECase(EM_ARCA)
00132   ECase(EM_UNICORE)
00133   ECase(EM_EXCESS)
00134   ECase(EM_DXP)
00135   ECase(EM_ALTERA_NIOS2)
00136   ECase(EM_CRX)
00137   ECase(EM_XGATE)
00138   ECase(EM_C166)
00139   ECase(EM_M16C)
00140   ECase(EM_DSPIC30F)
00141   ECase(EM_CE)
00142   ECase(EM_M32C)
00143   ECase(EM_TSK3000)
00144   ECase(EM_RS08)
00145   ECase(EM_SHARC)
00146   ECase(EM_ECOG2)
00147   ECase(EM_SCORE7)
00148   ECase(EM_DSP24)
00149   ECase(EM_VIDEOCORE3)
00150   ECase(EM_LATTICEMICO32)
00151   ECase(EM_SE_C17)
00152   ECase(EM_TI_C6000)
00153   ECase(EM_TI_C2000)
00154   ECase(EM_TI_C5500)
00155   ECase(EM_MMDSP_PLUS)
00156   ECase(EM_CYPRESS_M8C)
00157   ECase(EM_R32C)
00158   ECase(EM_TRIMEDIA)
00159   ECase(EM_HEXAGON)
00160   ECase(EM_8051)
00161   ECase(EM_STXP7X)
00162   ECase(EM_NDS32)
00163   ECase(EM_ECOG1)
00164   ECase(EM_ECOG1X)
00165   ECase(EM_MAXQ30)
00166   ECase(EM_XIMO16)
00167   ECase(EM_MANIK)
00168   ECase(EM_CRAYNV2)
00169   ECase(EM_RX)
00170   ECase(EM_METAG)
00171   ECase(EM_MCST_ELBRUS)
00172   ECase(EM_ECOG16)
00173   ECase(EM_CR16)
00174   ECase(EM_ETPU)
00175   ECase(EM_SLE9X)
00176   ECase(EM_L10M)
00177   ECase(EM_K10M)
00178   ECase(EM_AARCH64)
00179   ECase(EM_AVR32)
00180   ECase(EM_STM8)
00181   ECase(EM_TILE64)
00182   ECase(EM_TILEPRO)
00183   ECase(EM_CUDA)
00184   ECase(EM_TILEGX)
00185   ECase(EM_CLOUDSHIELD)
00186   ECase(EM_COREA_1ST)
00187   ECase(EM_COREA_2ND)
00188   ECase(EM_ARC_COMPACT2)
00189   ECase(EM_OPEN8)
00190   ECase(EM_RL78)
00191   ECase(EM_VIDEOCORE5)
00192   ECase(EM_78KOR)
00193   ECase(EM_56800EX)
00194 #undef ECase
00195 }
00196 
00197 void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration(
00198     IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
00199 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00200   // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
00201   // here.
00202   ECase(ELFCLASS32)
00203   ECase(ELFCLASS64)
00204 #undef ECase
00205 }
00206 
00207 void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
00208     IO &IO, ELFYAML::ELF_ELFDATA &Value) {
00209 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00210   // Since the semantics of ELFDATANONE is "invalid", just don't accept it
00211   // here.
00212   ECase(ELFDATA2LSB)
00213   ECase(ELFDATA2MSB)
00214 #undef ECase
00215 }
00216 
00217 void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
00218     IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
00219 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00220   ECase(ELFOSABI_NONE)
00221   ECase(ELFOSABI_HPUX)
00222   ECase(ELFOSABI_NETBSD)
00223   ECase(ELFOSABI_GNU)
00224   ECase(ELFOSABI_GNU)
00225   ECase(ELFOSABI_HURD)
00226   ECase(ELFOSABI_SOLARIS)
00227   ECase(ELFOSABI_AIX)
00228   ECase(ELFOSABI_IRIX)
00229   ECase(ELFOSABI_FREEBSD)
00230   ECase(ELFOSABI_TRU64)
00231   ECase(ELFOSABI_MODESTO)
00232   ECase(ELFOSABI_OPENBSD)
00233   ECase(ELFOSABI_OPENVMS)
00234   ECase(ELFOSABI_NSK)
00235   ECase(ELFOSABI_AROS)
00236   ECase(ELFOSABI_FENIXOS)
00237   ECase(ELFOSABI_C6000_ELFABI)
00238   ECase(ELFOSABI_C6000_LINUX)
00239   ECase(ELFOSABI_ARM)
00240   ECase(ELFOSABI_STANDALONE)
00241 #undef ECase
00242 }
00243 
00244 void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
00245                                                  ELFYAML::ELF_EF &Value) {
00246   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
00247   assert(Object && "The IO context is not initialized");
00248 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
00249 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M);
00250   switch (Object->Header.Machine) {
00251   case ELF::EM_ARM:
00252     BCase(EF_ARM_SOFT_FLOAT)
00253     BCase(EF_ARM_VFP_FLOAT)
00254     BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK)
00255     BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK)
00256     BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK)
00257     BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK)
00258     BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK)
00259     BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK)
00260     break;
00261   case ELF::EM_MIPS:
00262     BCase(EF_MIPS_NOREORDER)
00263     BCase(EF_MIPS_PIC)
00264     BCase(EF_MIPS_CPIC)
00265     BCase(EF_MIPS_ABI2)
00266     BCase(EF_MIPS_32BITMODE)
00267     BCase(EF_MIPS_ABI_O32)
00268     BCase(EF_MIPS_MICROMIPS)
00269     BCase(EF_MIPS_ARCH_ASE_M16)
00270     BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH)
00271     BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH)
00272     BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH)
00273     BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH)
00274     BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH)
00275     BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH)
00276     BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH)
00277     BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH)
00278     BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH)
00279     BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH)
00280     BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH)
00281     break;
00282   case ELF::EM_HEXAGON:
00283     BCase(EF_HEXAGON_MACH_V2)
00284     BCase(EF_HEXAGON_MACH_V3)
00285     BCase(EF_HEXAGON_MACH_V4)
00286     BCase(EF_HEXAGON_MACH_V5)
00287     BCase(EF_HEXAGON_ISA_V2)
00288     BCase(EF_HEXAGON_ISA_V3)
00289     BCase(EF_HEXAGON_ISA_V4)
00290     BCase(EF_HEXAGON_ISA_V5)
00291     break;
00292   default:
00293     llvm_unreachable("Unsupported architecture");
00294   }
00295 #undef BCase
00296 #undef BCaseMask
00297 }
00298 
00299 void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
00300     IO &IO, ELFYAML::ELF_SHT &Value) {
00301   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
00302   assert(Object && "The IO context is not initialized");
00303 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00304   ECase(SHT_NULL)
00305   ECase(SHT_PROGBITS)
00306   // No SHT_SYMTAB. Use the top-level `Symbols` key instead.
00307   // FIXME: Issue a diagnostic with this information.
00308   ECase(SHT_STRTAB)
00309   ECase(SHT_RELA)
00310   ECase(SHT_HASH)
00311   ECase(SHT_DYNAMIC)
00312   ECase(SHT_NOTE)
00313   ECase(SHT_NOBITS)
00314   ECase(SHT_REL)
00315   ECase(SHT_SHLIB)
00316   ECase(SHT_DYNSYM)
00317   ECase(SHT_INIT_ARRAY)
00318   ECase(SHT_FINI_ARRAY)
00319   ECase(SHT_PREINIT_ARRAY)
00320   ECase(SHT_GROUP)
00321   ECase(SHT_SYMTAB_SHNDX)
00322   ECase(SHT_LOOS)
00323   ECase(SHT_GNU_ATTRIBUTES)
00324   ECase(SHT_GNU_HASH)
00325   ECase(SHT_GNU_verdef)
00326   ECase(SHT_GNU_verneed)
00327   ECase(SHT_GNU_versym)
00328   ECase(SHT_HIOS)
00329   ECase(SHT_LOPROC)
00330   switch (Object->Header.Machine) {
00331   case ELF::EM_ARM:
00332     ECase(SHT_ARM_EXIDX)
00333     ECase(SHT_ARM_PREEMPTMAP)
00334     ECase(SHT_ARM_ATTRIBUTES)
00335     ECase(SHT_ARM_DEBUGOVERLAY)
00336     ECase(SHT_ARM_OVERLAYSECTION)
00337     break;
00338   case ELF::EM_HEXAGON:
00339     ECase(SHT_HEX_ORDERED)
00340     break;
00341   case ELF::EM_X86_64:
00342     ECase(SHT_X86_64_UNWIND)
00343     break;
00344   case ELF::EM_MIPS:
00345     ECase(SHT_MIPS_REGINFO)
00346     ECase(SHT_MIPS_OPTIONS)
00347     ECase(SHT_MIPS_ABIFLAGS)
00348     break;
00349   default:
00350     // Nothing to do.
00351     break;
00352   }
00353 #undef ECase
00354 }
00355 
00356 void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
00357                                                   ELFYAML::ELF_SHF &Value) {
00358 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
00359   BCase(SHF_WRITE)
00360   BCase(SHF_ALLOC)
00361   BCase(SHF_EXCLUDE)
00362   BCase(SHF_EXECINSTR)
00363   BCase(SHF_MERGE)
00364   BCase(SHF_STRINGS)
00365   BCase(SHF_INFO_LINK)
00366   BCase(SHF_LINK_ORDER)
00367   BCase(SHF_OS_NONCONFORMING)
00368   BCase(SHF_GROUP)
00369   BCase(SHF_TLS)
00370 #undef BCase
00371 }
00372 
00373 void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
00374     IO &IO, ELFYAML::ELF_STT &Value) {
00375 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00376   ECase(STT_NOTYPE)
00377   ECase(STT_OBJECT)
00378   ECase(STT_FUNC)
00379   ECase(STT_SECTION)
00380   ECase(STT_FILE)
00381   ECase(STT_COMMON)
00382   ECase(STT_TLS)
00383   ECase(STT_GNU_IFUNC)
00384 #undef ECase
00385 }
00386 
00387 void ScalarEnumerationTraits<ELFYAML::ELF_STV>::enumeration(
00388     IO &IO, ELFYAML::ELF_STV &Value) {
00389 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00390   ECase(STV_DEFAULT)
00391   ECase(STV_INTERNAL)
00392   ECase(STV_HIDDEN)
00393   ECase(STV_PROTECTED)
00394 #undef ECase
00395 }
00396 
00397 void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
00398     IO &IO, ELFYAML::ELF_REL &Value) {
00399   const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
00400   assert(Object && "The IO context is not initialized");
00401 #define ECase(X) IO.enumCase(Value, #X, ELF::X);
00402   switch (Object->Header.Machine) {
00403   case ELF::EM_X86_64:
00404     ECase(R_X86_64_NONE)
00405     ECase(R_X86_64_64)
00406     ECase(R_X86_64_PC32)
00407     ECase(R_X86_64_GOT32)
00408     ECase(R_X86_64_PLT32)
00409     ECase(R_X86_64_COPY)
00410     ECase(R_X86_64_GLOB_DAT)
00411     ECase(R_X86_64_JUMP_SLOT)
00412     ECase(R_X86_64_RELATIVE)
00413     ECase(R_X86_64_GOTPCREL)
00414     ECase(R_X86_64_32)
00415     ECase(R_X86_64_32S)
00416     ECase(R_X86_64_16)
00417     ECase(R_X86_64_PC16)
00418     ECase(R_X86_64_8)
00419     ECase(R_X86_64_PC8)
00420     ECase(R_X86_64_DTPMOD64)
00421     ECase(R_X86_64_DTPOFF64)
00422     ECase(R_X86_64_TPOFF64)
00423     ECase(R_X86_64_TLSGD)
00424     ECase(R_X86_64_TLSLD)
00425     ECase(R_X86_64_DTPOFF32)
00426     ECase(R_X86_64_GOTTPOFF)
00427     ECase(R_X86_64_TPOFF32)
00428     ECase(R_X86_64_PC64)
00429     ECase(R_X86_64_GOTOFF64)
00430     ECase(R_X86_64_GOTPC32)
00431     ECase(R_X86_64_GOT64)
00432     ECase(R_X86_64_GOTPCREL64)
00433     ECase(R_X86_64_GOTPC64)
00434     ECase(R_X86_64_GOTPLT64)
00435     ECase(R_X86_64_PLTOFF64)
00436     ECase(R_X86_64_SIZE32)
00437     ECase(R_X86_64_SIZE64)
00438     ECase(R_X86_64_GOTPC32_TLSDESC)
00439     ECase(R_X86_64_TLSDESC_CALL)
00440     ECase(R_X86_64_TLSDESC)
00441     ECase(R_X86_64_IRELATIVE)
00442     break;
00443   case ELF::EM_MIPS:
00444     ECase(R_MIPS_NONE)
00445     ECase(R_MIPS_16)
00446     ECase(R_MIPS_32)
00447     ECase(R_MIPS_REL32)
00448     ECase(R_MIPS_26)
00449     ECase(R_MIPS_HI16)
00450     ECase(R_MIPS_LO16)
00451     ECase(R_MIPS_GPREL16)
00452     ECase(R_MIPS_LITERAL)
00453     ECase(R_MIPS_GOT16)
00454     ECase(R_MIPS_PC16)
00455     ECase(R_MIPS_CALL16)
00456     ECase(R_MIPS_GPREL32)
00457     ECase(R_MIPS_UNUSED1)
00458     ECase(R_MIPS_UNUSED2)
00459     ECase(R_MIPS_SHIFT5)
00460     ECase(R_MIPS_SHIFT6)
00461     ECase(R_MIPS_64)
00462     ECase(R_MIPS_GOT_DISP)
00463     ECase(R_MIPS_GOT_PAGE)
00464     ECase(R_MIPS_GOT_OFST)
00465     ECase(R_MIPS_GOT_HI16)
00466     ECase(R_MIPS_GOT_LO16)
00467     ECase(R_MIPS_SUB)
00468     ECase(R_MIPS_INSERT_A)
00469     ECase(R_MIPS_INSERT_B)
00470     ECase(R_MIPS_DELETE)
00471     ECase(R_MIPS_HIGHER)
00472     ECase(R_MIPS_HIGHEST)
00473     ECase(R_MIPS_CALL_HI16)
00474     ECase(R_MIPS_CALL_LO16)
00475     ECase(R_MIPS_SCN_DISP)
00476     ECase(R_MIPS_REL16)
00477     ECase(R_MIPS_ADD_IMMEDIATE)
00478     ECase(R_MIPS_PJUMP)
00479     ECase(R_MIPS_RELGOT)
00480     ECase(R_MIPS_JALR)
00481     ECase(R_MIPS_TLS_DTPMOD32)
00482     ECase(R_MIPS_TLS_DTPREL32)
00483     ECase(R_MIPS_TLS_DTPMOD64)
00484     ECase(R_MIPS_TLS_DTPREL64)
00485     ECase(R_MIPS_TLS_GD)
00486     ECase(R_MIPS_TLS_LDM)
00487     ECase(R_MIPS_TLS_DTPREL_HI16)
00488     ECase(R_MIPS_TLS_DTPREL_LO16)
00489     ECase(R_MIPS_TLS_GOTTPREL)
00490     ECase(R_MIPS_TLS_TPREL32)
00491     ECase(R_MIPS_TLS_TPREL64)
00492     ECase(R_MIPS_TLS_TPREL_HI16)
00493     ECase(R_MIPS_TLS_TPREL_LO16)
00494     ECase(R_MIPS_GLOB_DAT)
00495     ECase(R_MIPS_PC21_S2)
00496     ECase(R_MIPS_PC26_S2)
00497     ECase(R_MIPS_PC18_S3)
00498     ECase(R_MIPS_PC19_S2)
00499     ECase(R_MIPS_PCHI16)
00500     ECase(R_MIPS_PCLO16)
00501     ECase(R_MIPS16_GOT16)
00502     ECase(R_MIPS16_HI16)
00503     ECase(R_MIPS16_LO16)
00504     ECase(R_MIPS_COPY)
00505     ECase(R_MIPS_JUMP_SLOT)
00506     ECase(R_MICROMIPS_26_S1)
00507     ECase(R_MICROMIPS_HI16)
00508     ECase(R_MICROMIPS_LO16)
00509     ECase(R_MICROMIPS_GOT16)
00510     ECase(R_MICROMIPS_PC16_S1)
00511     ECase(R_MICROMIPS_CALL16)
00512     ECase(R_MICROMIPS_GOT_DISP)
00513     ECase(R_MICROMIPS_GOT_PAGE)
00514     ECase(R_MICROMIPS_GOT_OFST)
00515     ECase(R_MICROMIPS_TLS_GD)
00516     ECase(R_MICROMIPS_TLS_LDM)
00517     ECase(R_MICROMIPS_TLS_DTPREL_HI16)
00518     ECase(R_MICROMIPS_TLS_DTPREL_LO16)
00519     ECase(R_MICROMIPS_TLS_TPREL_HI16)
00520     ECase(R_MICROMIPS_TLS_TPREL_LO16)
00521     ECase(R_MIPS_NUM)
00522     ECase(R_MIPS_PC32)
00523     break;
00524   case ELF::EM_HEXAGON:
00525     ECase(R_HEX_NONE)
00526     ECase(R_HEX_B22_PCREL)
00527     ECase(R_HEX_B15_PCREL)
00528     ECase(R_HEX_B7_PCREL)
00529     ECase(R_HEX_LO16)
00530     ECase(R_HEX_HI16)
00531     ECase(R_HEX_32)
00532     ECase(R_HEX_16)
00533     ECase(R_HEX_8)
00534     ECase(R_HEX_GPREL16_0)
00535     ECase(R_HEX_GPREL16_1)
00536     ECase(R_HEX_GPREL16_2)
00537     ECase(R_HEX_GPREL16_3)
00538     ECase(R_HEX_HL16)
00539     ECase(R_HEX_B13_PCREL)
00540     ECase(R_HEX_B9_PCREL)
00541     ECase(R_HEX_B32_PCREL_X)
00542     ECase(R_HEX_32_6_X)
00543     ECase(R_HEX_B22_PCREL_X)
00544     ECase(R_HEX_B15_PCREL_X)
00545     ECase(R_HEX_B13_PCREL_X)
00546     ECase(R_HEX_B9_PCREL_X)
00547     ECase(R_HEX_B7_PCREL_X)
00548     ECase(R_HEX_16_X)
00549     ECase(R_HEX_12_X)
00550     ECase(R_HEX_11_X)
00551     ECase(R_HEX_10_X)
00552     ECase(R_HEX_9_X)
00553     ECase(R_HEX_8_X)
00554     ECase(R_HEX_7_X)
00555     ECase(R_HEX_6_X)
00556     ECase(R_HEX_32_PCREL)
00557     ECase(R_HEX_COPY)
00558     ECase(R_HEX_GLOB_DAT)
00559     ECase(R_HEX_JMP_SLOT)
00560     ECase(R_HEX_RELATIVE)
00561     ECase(R_HEX_PLT_B22_PCREL)
00562     ECase(R_HEX_GOTREL_LO16)
00563     ECase(R_HEX_GOTREL_HI16)
00564     ECase(R_HEX_GOTREL_32)
00565     ECase(R_HEX_GOT_LO16)
00566     ECase(R_HEX_GOT_HI16)
00567     ECase(R_HEX_GOT_32)
00568     ECase(R_HEX_GOT_16)
00569     ECase(R_HEX_DTPMOD_32)
00570     ECase(R_HEX_DTPREL_LO16)
00571     ECase(R_HEX_DTPREL_HI16)
00572     ECase(R_HEX_DTPREL_32)
00573     ECase(R_HEX_DTPREL_16)
00574     ECase(R_HEX_GD_PLT_B22_PCREL)
00575     ECase(R_HEX_GD_GOT_LO16)
00576     ECase(R_HEX_GD_GOT_HI16)
00577     ECase(R_HEX_GD_GOT_32)
00578     ECase(R_HEX_GD_GOT_16)
00579     ECase(R_HEX_IE_LO16)
00580     ECase(R_HEX_IE_HI16)
00581     ECase(R_HEX_IE_32)
00582     ECase(R_HEX_IE_GOT_LO16)
00583     ECase(R_HEX_IE_GOT_HI16)
00584     ECase(R_HEX_IE_GOT_32)
00585     ECase(R_HEX_IE_GOT_16)
00586     ECase(R_HEX_TPREL_LO16)
00587     ECase(R_HEX_TPREL_HI16)
00588     ECase(R_HEX_TPREL_32)
00589     ECase(R_HEX_TPREL_16)
00590     ECase(R_HEX_6_PCREL_X)
00591     ECase(R_HEX_GOTREL_32_6_X)
00592     ECase(R_HEX_GOTREL_16_X)
00593     ECase(R_HEX_GOTREL_11_X)
00594     ECase(R_HEX_GOT_32_6_X)
00595     ECase(R_HEX_GOT_16_X)
00596     ECase(R_HEX_GOT_11_X)
00597     ECase(R_HEX_DTPREL_32_6_X)
00598     ECase(R_HEX_DTPREL_16_X)
00599     ECase(R_HEX_DTPREL_11_X)
00600     ECase(R_HEX_GD_GOT_32_6_X)
00601     ECase(R_HEX_GD_GOT_16_X)
00602     ECase(R_HEX_GD_GOT_11_X)
00603     ECase(R_HEX_IE_32_6_X)
00604     ECase(R_HEX_IE_16_X)
00605     ECase(R_HEX_IE_GOT_32_6_X)
00606     ECase(R_HEX_IE_GOT_16_X)
00607     ECase(R_HEX_IE_GOT_11_X)
00608     ECase(R_HEX_TPREL_32_6_X)
00609     ECase(R_HEX_TPREL_16_X)
00610     ECase(R_HEX_TPREL_11_X)
00611     break;
00612   case ELF::EM_386:
00613     ECase(R_386_NONE)
00614     ECase(R_386_32)
00615     ECase(R_386_PC32)
00616     ECase(R_386_GOT32)
00617     ECase(R_386_PLT32)
00618     ECase(R_386_COPY)
00619     ECase(R_386_GLOB_DAT)
00620     ECase(R_386_JUMP_SLOT)
00621     ECase(R_386_RELATIVE)
00622     ECase(R_386_GOTOFF)
00623     ECase(R_386_GOTPC)
00624     ECase(R_386_32PLT)
00625     ECase(R_386_TLS_TPOFF)
00626     ECase(R_386_TLS_IE)
00627     ECase(R_386_TLS_GOTIE)
00628     ECase(R_386_TLS_LE)
00629     ECase(R_386_TLS_GD)
00630     ECase(R_386_TLS_LDM)
00631     ECase(R_386_16)
00632     ECase(R_386_PC16)
00633     ECase(R_386_8)
00634     ECase(R_386_PC8)
00635     ECase(R_386_TLS_GD_32)
00636     ECase(R_386_TLS_GD_PUSH)
00637     ECase(R_386_TLS_GD_CALL)
00638     ECase(R_386_TLS_GD_POP)
00639     ECase(R_386_TLS_LDM_32)
00640     ECase(R_386_TLS_LDM_PUSH)
00641     ECase(R_386_TLS_LDM_CALL)
00642     ECase(R_386_TLS_LDM_POP)
00643     ECase(R_386_TLS_LDO_32)
00644     ECase(R_386_TLS_IE_32)
00645     ECase(R_386_TLS_LE_32)
00646     ECase(R_386_TLS_DTPMOD32)
00647     ECase(R_386_TLS_DTPOFF32)
00648     ECase(R_386_TLS_TPOFF32)
00649     ECase(R_386_TLS_GOTDESC)
00650     ECase(R_386_TLS_DESC_CALL)
00651     ECase(R_386_TLS_DESC)
00652     ECase(R_386_IRELATIVE)
00653     ECase(R_386_NUM)
00654     break;
00655   default:
00656     llvm_unreachable("Unsupported architecture");
00657   }
00658 #undef ECase
00659 }
00660 
00661 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
00662                                                  ELFYAML::FileHeader &FileHdr) {
00663   IO.mapRequired("Class", FileHdr.Class);
00664   IO.mapRequired("Data", FileHdr.Data);
00665   IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
00666   IO.mapRequired("Type", FileHdr.Type);
00667   IO.mapRequired("Machine", FileHdr.Machine);
00668   IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
00669   IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
00670 }
00671 
00672 void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
00673   IO.mapOptional("Name", Symbol.Name, StringRef());
00674   IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
00675   IO.mapOptional("Section", Symbol.Section, StringRef());
00676   IO.mapOptional("Value", Symbol.Value, Hex64(0));
00677   IO.mapOptional("Size", Symbol.Size, Hex64(0));
00678   IO.mapOptional("Visibility", Symbol.Visibility, ELFYAML::ELF_STV(0));
00679 }
00680 
00681 void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
00682     IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
00683   IO.mapOptional("Local", Symbols.Local);
00684   IO.mapOptional("Global", Symbols.Global);
00685   IO.mapOptional("Weak", Symbols.Weak);
00686 }
00687 
00688 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
00689   IO.mapOptional("Name", Section.Name, StringRef());
00690   IO.mapRequired("Type", Section.Type);
00691   IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
00692   IO.mapOptional("Address", Section.Address, Hex64(0));
00693   IO.mapOptional("Link", Section.Link, StringRef());
00694   IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
00695 }
00696 
00697 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
00698   commonSectionMapping(IO, Section);
00699   IO.mapOptional("Content", Section.Content);
00700   IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
00701 }
00702 
00703 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
00704   commonSectionMapping(IO, Section);
00705   IO.mapOptional("Info", Section.Info, StringRef());
00706   IO.mapOptional("Relocations", Section.Relocations);
00707 }
00708 
00709 void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping(
00710     IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
00711   ELFYAML::ELF_SHT sectionType;
00712   if (IO.outputting())
00713     sectionType = Section->Type;
00714   else
00715     IO.mapRequired("Type", sectionType);
00716 
00717   switch (sectionType) {
00718   case ELF::SHT_REL:
00719   case ELF::SHT_RELA:
00720     if (!IO.outputting())
00721       Section.reset(new ELFYAML::RelocationSection());
00722     sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
00723     break;
00724   default:
00725     if (!IO.outputting())
00726       Section.reset(new ELFYAML::RawContentSection());
00727     sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
00728   }
00729 }
00730 
00731 StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate(
00732     IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
00733   const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
00734   if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
00735     return StringRef();
00736   return "Section size must be greater or equal to the content size";
00737 }
00738 
00739 void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
00740                                                  ELFYAML::Relocation &Rel) {
00741   IO.mapRequired("Offset", Rel.Offset);
00742   IO.mapRequired("Symbol", Rel.Symbol);
00743   IO.mapRequired("Type", Rel.Type);
00744   IO.mapOptional("Addend", Rel.Addend);
00745 }
00746 
00747 void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
00748   assert(!IO.getContext() && "The IO context is initialized already");
00749   IO.setContext(&Object);
00750   IO.mapRequired("FileHeader", Object.Header);
00751   IO.mapOptional("Sections", Object.Sections);
00752   IO.mapOptional("Symbols", Object.Symbols);
00753   IO.setContext(nullptr);
00754 }
00755 
00756 } // end namespace yaml
00757 } // end namespace llvm