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 16namespace llvm { 17namespace yaml { 18 19void 20ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(IO &IO, 21 ELFYAML::ELF_ET &Value) { 22#define ECase(X) IO.enumCase(Value, #X, ELF::X); 23 ECase(ET_NONE) 24 ECase(ET_REL) 25 ECase(ET_EXEC) 26 ECase(ET_DYN) 27 ECase(ET_CORE) 28#undef ECase 29} 30 31void 32ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(IO &IO, 33 ELFYAML::ELF_EM &Value) { 34#define ECase(X) IO.enumCase(Value, #X, ELF::X); 35 ECase(EM_NONE) 36 ECase(EM_M32) 37 ECase(EM_SPARC) 38 ECase(EM_386) 39 ECase(EM_68K) 40 ECase(EM_88K) 41 ECase(EM_486) 42 ECase(EM_860) 43 ECase(EM_MIPS) 44 ECase(EM_S370) 45 ECase(EM_MIPS_RS3_LE) 46 ECase(EM_PARISC) 47 ECase(EM_VPP500) 48 ECase(EM_SPARC32PLUS) 49 ECase(EM_960) 50 ECase(EM_PPC) 51 ECase(EM_PPC64) 52 ECase(EM_S390) 53 ECase(EM_SPU) 54 ECase(EM_V800) 55 ECase(EM_FR20) 56 ECase(EM_RH32) 57 ECase(EM_RCE) 58 ECase(EM_ARM) 59 ECase(EM_ALPHA) 60 ECase(EM_SH) 61 ECase(EM_SPARCV9) 62 ECase(EM_TRICORE) 63 ECase(EM_ARC) 64 ECase(EM_H8_300) 65 ECase(EM_H8_300H) 66 ECase(EM_H8S) 67 ECase(EM_H8_500) 68 ECase(EM_IA_64) 69 ECase(EM_MIPS_X) 70 ECase(EM_COLDFIRE) 71 ECase(EM_68HC12) 72 ECase(EM_MMA) 73 ECase(EM_PCP) 74 ECase(EM_NCPU) 75 ECase(EM_NDR1) 76 ECase(EM_STARCORE) 77 ECase(EM_ME16) 78 ECase(EM_ST100) 79 ECase(EM_TINYJ) 80 ECase(EM_X86_64) 81 ECase(EM_PDSP) 82 ECase(EM_PDP10) 83 ECase(EM_PDP11) 84 ECase(EM_FX66) 85 ECase(EM_ST9PLUS) 86 ECase(EM_ST7) 87 ECase(EM_68HC16) 88 ECase(EM_68HC11) 89 ECase(EM_68HC08) 90 ECase(EM_68HC05) 91 ECase(EM_SVX) 92 ECase(EM_ST19) 93 ECase(EM_VAX) 94 ECase(EM_CRIS) 95 ECase(EM_JAVELIN) 96 ECase(EM_FIREPATH) 97 ECase(EM_ZSP) 98 ECase(EM_MMIX) 99 ECase(EM_HUANY) 100 ECase(EM_PRISM) 101 ECase(EM_AVR) 102 ECase(EM_FR30) 103 ECase(EM_D10V) 104 ECase(EM_D30V) 105 ECase(EM_V850) 106 ECase(EM_M32R) 107 ECase(EM_MN10300) 108 ECase(EM_MN10200) 109 ECase(EM_PJ) 110 ECase(EM_OPENRISC) 111 ECase(EM_ARC_COMPACT) 112 ECase(EM_XTENSA) 113 ECase(EM_VIDEOCORE) 114 ECase(EM_TMM_GPP) 115 ECase(EM_NS32K) 116 ECase(EM_TPC) 117 ECase(EM_SNP1K) 118 ECase(EM_ST200) 119 ECase(EM_IP2K) 120 ECase(EM_MAX) 121 ECase(EM_CR) 122 ECase(EM_F2MC16) 123 ECase(EM_MSP430) 124 ECase(EM_BLACKFIN) 125 ECase(EM_SE_C33) 126 ECase(EM_SEP) 127 ECase(EM_ARCA) 128 ECase(EM_UNICORE) 129 ECase(EM_EXCESS) 130 ECase(EM_DXP) 131 ECase(EM_ALTERA_NIOS2) 132 ECase(EM_CRX) 133 ECase(EM_XGATE) 134 ECase(EM_C166) 135 ECase(EM_M16C) 136 ECase(EM_DSPIC30F) 137 ECase(EM_CE) 138 ECase(EM_M32C) 139 ECase(EM_TSK3000) 140 ECase(EM_RS08) 141 ECase(EM_SHARC) 142 ECase(EM_ECOG2) 143 ECase(EM_SCORE7) 144 ECase(EM_DSP24) 145 ECase(EM_VIDEOCORE3) 146 ECase(EM_LATTICEMICO32) 147 ECase(EM_SE_C17) 148 ECase(EM_TI_C6000) 149 ECase(EM_TI_C2000) 150 ECase(EM_TI_C5500) 151 ECase(EM_MMDSP_PLUS) 152 ECase(EM_CYPRESS_M8C) 153 ECase(EM_R32C) 154 ECase(EM_TRIMEDIA) 155 ECase(EM_HEXAGON) 156 ECase(EM_8051) 157 ECase(EM_STXP7X) 158 ECase(EM_NDS32) 159 ECase(EM_ECOG1) 160 ECase(EM_ECOG1X) 161 ECase(EM_MAXQ30) 162 ECase(EM_XIMO16) 163 ECase(EM_MANIK) 164 ECase(EM_CRAYNV2) 165 ECase(EM_RX) 166 ECase(EM_METAG) 167 ECase(EM_MCST_ELBRUS) 168 ECase(EM_ECOG16) 169 ECase(EM_CR16) 170 ECase(EM_ETPU) 171 ECase(EM_SLE9X) 172 ECase(EM_L10M) 173 ECase(EM_K10M) 174 ECase(EM_AARCH64) 175 ECase(EM_AVR32) 176 ECase(EM_STM8) 177 ECase(EM_TILE64) 178 ECase(EM_TILEPRO) 179 ECase(EM_CUDA) 180 ECase(EM_TILEGX) 181 ECase(EM_CLOUDSHIELD) 182 ECase(EM_COREA_1ST) 183 ECase(EM_COREA_2ND) 184 ECase(EM_ARC_COMPACT2) 185 ECase(EM_OPEN8) 186 ECase(EM_RL78) 187 ECase(EM_VIDEOCORE5) 188 ECase(EM_78KOR) 189 ECase(EM_56800EX) 190#undef ECase 191} 192 193void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration( 194 IO &IO, ELFYAML::ELF_ELFCLASS &Value) { 195#define ECase(X) IO.enumCase(Value, #X, ELF::X); 196 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it 197 // here. 198 ECase(ELFCLASS32) 199 ECase(ELFCLASS64) 200#undef ECase 201} 202 203void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration( 204 IO &IO, ELFYAML::ELF_ELFDATA &Value) { 205#define ECase(X) IO.enumCase(Value, #X, ELF::X); 206 // Since the semantics of ELFDATANONE is "invalid", just don't accept it 207 // here. 208 ECase(ELFDATA2LSB) 209 ECase(ELFDATA2MSB) 210#undef ECase 211} 212 213void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration( 214 IO &IO, ELFYAML::ELF_ELFOSABI &Value) { 215#define ECase(X) IO.enumCase(Value, #X, ELF::X); 216 ECase(ELFOSABI_NONE) 217 ECase(ELFOSABI_HPUX) 218 ECase(ELFOSABI_NETBSD) 219 ECase(ELFOSABI_GNU) 220 ECase(ELFOSABI_GNU) 221 ECase(ELFOSABI_HURD) 222 ECase(ELFOSABI_SOLARIS) 223 ECase(ELFOSABI_AIX) 224 ECase(ELFOSABI_IRIX) 225 ECase(ELFOSABI_FREEBSD) 226 ECase(ELFOSABI_TRU64) 227 ECase(ELFOSABI_MODESTO) 228 ECase(ELFOSABI_OPENBSD) 229 ECase(ELFOSABI_OPENVMS) 230 ECase(ELFOSABI_NSK) 231 ECase(ELFOSABI_AROS) 232 ECase(ELFOSABI_FENIXOS) 233 ECase(ELFOSABI_C6000_ELFABI) 234 ECase(ELFOSABI_C6000_LINUX) 235 ECase(ELFOSABI_ARM) 236 ECase(ELFOSABI_STANDALONE) 237#undef ECase 238} 239 240void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration( 241 IO &IO, ELFYAML::ELF_SHT &Value) { 242#define ECase(X) IO.enumCase(Value, #X, ELF::X); 243 ECase(SHT_NULL) 244 ECase(SHT_PROGBITS) 245 // No SHT_SYMTAB. Use the top-level `Symbols` key instead. 246 // FIXME: Issue a diagnostic with this information. 247 ECase(SHT_STRTAB) 248 ECase(SHT_RELA) 249 ECase(SHT_HASH) 250 ECase(SHT_DYNAMIC) 251 ECase(SHT_NOTE) 252 ECase(SHT_NOBITS) 253 ECase(SHT_REL) 254 ECase(SHT_SHLIB) 255 ECase(SHT_DYNSYM) 256 ECase(SHT_INIT_ARRAY) 257 ECase(SHT_FINI_ARRAY) 258 ECase(SHT_PREINIT_ARRAY) 259 ECase(SHT_GROUP) 260 ECase(SHT_SYMTAB_SHNDX) 261#undef ECase 262} 263 264void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO, 265 ELFYAML::ELF_SHF &Value) { 266#define BCase(X) IO.bitSetCase(Value, #X, ELF::X); 267 BCase(SHF_WRITE) 268 BCase(SHF_ALLOC) 269 BCase(SHF_EXECINSTR) 270 BCase(SHF_MERGE) 271 BCase(SHF_STRINGS) 272 BCase(SHF_INFO_LINK) 273 BCase(SHF_LINK_ORDER) 274 BCase(SHF_OS_NONCONFORMING) 275 BCase(SHF_GROUP) 276 BCase(SHF_TLS) 277#undef BCase 278} 279 280void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration( 281 IO &IO, ELFYAML::ELF_STT &Value) { 282#define ECase(X) IO.enumCase(Value, #X, ELF::X); 283 ECase(STT_NOTYPE) 284 ECase(STT_OBJECT) 285 ECase(STT_FUNC) 286 ECase(STT_SECTION) 287 ECase(STT_FILE) 288 ECase(STT_COMMON) 289 ECase(STT_TLS) 290 ECase(STT_GNU_IFUNC) 291#undef ECase 292} 293 294void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO, 295 ELFYAML::FileHeader &FileHdr) { 296 IO.mapRequired("Class", FileHdr.Class); 297 IO.mapRequired("Data", FileHdr.Data); 298 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0)); 299 IO.mapRequired("Type", FileHdr.Type); 300 IO.mapRequired("Machine", FileHdr.Machine); 301 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0)); 302} 303 304void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) { 305 IO.mapOptional("Name", Symbol.Name, StringRef()); 306 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0)); 307 IO.mapOptional("Section", Symbol.Section, StringRef()); 308 IO.mapOptional("Value", Symbol.Value, Hex64(0)); 309 IO.mapOptional("Size", Symbol.Size, Hex64(0)); 310} 311 312void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping( 313 IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) { 314 IO.mapOptional("Local", Symbols.Local); 315 IO.mapOptional("Global", Symbols.Global); 316 IO.mapOptional("Weak", Symbols.Weak); 317} 318 319void MappingTraits<ELFYAML::Section>::mapping(IO &IO, 320 ELFYAML::Section &Section) { 321 IO.mapOptional("Name", Section.Name, StringRef()); 322 IO.mapRequired("Type", Section.Type); 323 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0)); 324 IO.mapOptional("Address", Section.Address, Hex64(0)); 325 IO.mapOptional("Content", Section.Content); 326 IO.mapOptional("Link", Section.Link); 327 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); 328} 329 330void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) { 331 IO.mapRequired("FileHeader", Object.Header); 332 IO.mapOptional("Sections", Object.Sections); 333 IO.mapOptional("Symbols", Object.Symbols); 334} 335 336} // end namespace yaml 337} // end namespace llvm 338