1 //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines classes for handling the YAML representation of ELF. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/ObjectYAML/ELFYAML.h" 14 #include "llvm/ADT/MapVector.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 "llvm/Support/WithColor.h" 22 #include <cassert> 23 #include <cstdint> 24 25 namespace llvm { 26 27 ELFYAML::Chunk::~Chunk() = default; 28 29 namespace yaml { 30 31 void ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration( 32 IO &IO, ELFYAML::ELF_ET &Value) { 33 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 34 ECase(ET_NONE); 35 ECase(ET_REL); 36 ECase(ET_EXEC); 37 ECase(ET_DYN); 38 ECase(ET_CORE); 39 #undef ECase 40 IO.enumFallback<Hex16>(Value); 41 } 42 43 void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration( 44 IO &IO, ELFYAML::ELF_PT &Value) { 45 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 46 ECase(PT_NULL); 47 ECase(PT_LOAD); 48 ECase(PT_DYNAMIC); 49 ECase(PT_INTERP); 50 ECase(PT_NOTE); 51 ECase(PT_SHLIB); 52 ECase(PT_PHDR); 53 ECase(PT_TLS); 54 ECase(PT_GNU_EH_FRAME); 55 ECase(PT_GNU_STACK); 56 ECase(PT_GNU_RELRO); 57 ECase(PT_GNU_PROPERTY); 58 #undef ECase 59 IO.enumFallback<Hex32>(Value); 60 } 61 62 void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration( 63 IO &IO, ELFYAML::ELF_EM &Value) { 64 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 65 ECase(EM_NONE); 66 ECase(EM_M32); 67 ECase(EM_SPARC); 68 ECase(EM_386); 69 ECase(EM_68K); 70 ECase(EM_88K); 71 ECase(EM_IAMCU); 72 ECase(EM_860); 73 ECase(EM_MIPS); 74 ECase(EM_S370); 75 ECase(EM_MIPS_RS3_LE); 76 ECase(EM_PARISC); 77 ECase(EM_VPP500); 78 ECase(EM_SPARC32PLUS); 79 ECase(EM_960); 80 ECase(EM_PPC); 81 ECase(EM_PPC64); 82 ECase(EM_S390); 83 ECase(EM_SPU); 84 ECase(EM_V800); 85 ECase(EM_FR20); 86 ECase(EM_RH32); 87 ECase(EM_RCE); 88 ECase(EM_ARM); 89 ECase(EM_ALPHA); 90 ECase(EM_SH); 91 ECase(EM_SPARCV9); 92 ECase(EM_TRICORE); 93 ECase(EM_ARC); 94 ECase(EM_H8_300); 95 ECase(EM_H8_300H); 96 ECase(EM_H8S); 97 ECase(EM_H8_500); 98 ECase(EM_IA_64); 99 ECase(EM_MIPS_X); 100 ECase(EM_COLDFIRE); 101 ECase(EM_68HC12); 102 ECase(EM_MMA); 103 ECase(EM_PCP); 104 ECase(EM_NCPU); 105 ECase(EM_NDR1); 106 ECase(EM_STARCORE); 107 ECase(EM_ME16); 108 ECase(EM_ST100); 109 ECase(EM_TINYJ); 110 ECase(EM_X86_64); 111 ECase(EM_PDSP); 112 ECase(EM_PDP10); 113 ECase(EM_PDP11); 114 ECase(EM_FX66); 115 ECase(EM_ST9PLUS); 116 ECase(EM_ST7); 117 ECase(EM_68HC16); 118 ECase(EM_68HC11); 119 ECase(EM_68HC08); 120 ECase(EM_68HC05); 121 ECase(EM_SVX); 122 ECase(EM_ST19); 123 ECase(EM_VAX); 124 ECase(EM_CRIS); 125 ECase(EM_JAVELIN); 126 ECase(EM_FIREPATH); 127 ECase(EM_ZSP); 128 ECase(EM_MMIX); 129 ECase(EM_HUANY); 130 ECase(EM_PRISM); 131 ECase(EM_AVR); 132 ECase(EM_FR30); 133 ECase(EM_D10V); 134 ECase(EM_D30V); 135 ECase(EM_V850); 136 ECase(EM_M32R); 137 ECase(EM_MN10300); 138 ECase(EM_MN10200); 139 ECase(EM_PJ); 140 ECase(EM_OPENRISC); 141 ECase(EM_ARC_COMPACT); 142 ECase(EM_XTENSA); 143 ECase(EM_VIDEOCORE); 144 ECase(EM_TMM_GPP); 145 ECase(EM_NS32K); 146 ECase(EM_TPC); 147 ECase(EM_SNP1K); 148 ECase(EM_ST200); 149 ECase(EM_IP2K); 150 ECase(EM_MAX); 151 ECase(EM_CR); 152 ECase(EM_F2MC16); 153 ECase(EM_MSP430); 154 ECase(EM_BLACKFIN); 155 ECase(EM_SE_C33); 156 ECase(EM_SEP); 157 ECase(EM_ARCA); 158 ECase(EM_UNICORE); 159 ECase(EM_EXCESS); 160 ECase(EM_DXP); 161 ECase(EM_ALTERA_NIOS2); 162 ECase(EM_CRX); 163 ECase(EM_XGATE); 164 ECase(EM_C166); 165 ECase(EM_M16C); 166 ECase(EM_DSPIC30F); 167 ECase(EM_CE); 168 ECase(EM_M32C); 169 ECase(EM_TSK3000); 170 ECase(EM_RS08); 171 ECase(EM_SHARC); 172 ECase(EM_ECOG2); 173 ECase(EM_SCORE7); 174 ECase(EM_DSP24); 175 ECase(EM_VIDEOCORE3); 176 ECase(EM_LATTICEMICO32); 177 ECase(EM_SE_C17); 178 ECase(EM_TI_C6000); 179 ECase(EM_TI_C2000); 180 ECase(EM_TI_C5500); 181 ECase(EM_MMDSP_PLUS); 182 ECase(EM_CYPRESS_M8C); 183 ECase(EM_R32C); 184 ECase(EM_TRIMEDIA); 185 ECase(EM_HEXAGON); 186 ECase(EM_8051); 187 ECase(EM_STXP7X); 188 ECase(EM_NDS32); 189 ECase(EM_ECOG1); 190 ECase(EM_ECOG1X); 191 ECase(EM_MAXQ30); 192 ECase(EM_XIMO16); 193 ECase(EM_MANIK); 194 ECase(EM_CRAYNV2); 195 ECase(EM_RX); 196 ECase(EM_METAG); 197 ECase(EM_MCST_ELBRUS); 198 ECase(EM_ECOG16); 199 ECase(EM_CR16); 200 ECase(EM_ETPU); 201 ECase(EM_SLE9X); 202 ECase(EM_L10M); 203 ECase(EM_K10M); 204 ECase(EM_AARCH64); 205 ECase(EM_AVR32); 206 ECase(EM_STM8); 207 ECase(EM_TILE64); 208 ECase(EM_TILEPRO); 209 ECase(EM_CUDA); 210 ECase(EM_TILEGX); 211 ECase(EM_CLOUDSHIELD); 212 ECase(EM_COREA_1ST); 213 ECase(EM_COREA_2ND); 214 ECase(EM_ARC_COMPACT2); 215 ECase(EM_OPEN8); 216 ECase(EM_RL78); 217 ECase(EM_VIDEOCORE5); 218 ECase(EM_78KOR); 219 ECase(EM_56800EX); 220 ECase(EM_AMDGPU); 221 ECase(EM_RISCV); 222 ECase(EM_LANAI); 223 ECase(EM_BPF); 224 #undef ECase 225 IO.enumFallback<Hex16>(Value); 226 } 227 228 void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration( 229 IO &IO, ELFYAML::ELF_ELFCLASS &Value) { 230 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 231 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it 232 // here. 233 ECase(ELFCLASS32); 234 ECase(ELFCLASS64); 235 #undef ECase 236 } 237 238 void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration( 239 IO &IO, ELFYAML::ELF_ELFDATA &Value) { 240 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 241 // ELFDATANONE is an invalid data encoding, but we accept it because 242 // we want to be able to produce invalid binaries for the tests. 243 ECase(ELFDATANONE); 244 ECase(ELFDATA2LSB); 245 ECase(ELFDATA2MSB); 246 #undef ECase 247 } 248 249 void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration( 250 IO &IO, ELFYAML::ELF_ELFOSABI &Value) { 251 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 252 ECase(ELFOSABI_NONE); 253 ECase(ELFOSABI_HPUX); 254 ECase(ELFOSABI_NETBSD); 255 ECase(ELFOSABI_GNU); 256 ECase(ELFOSABI_LINUX); 257 ECase(ELFOSABI_HURD); 258 ECase(ELFOSABI_SOLARIS); 259 ECase(ELFOSABI_AIX); 260 ECase(ELFOSABI_IRIX); 261 ECase(ELFOSABI_FREEBSD); 262 ECase(ELFOSABI_TRU64); 263 ECase(ELFOSABI_MODESTO); 264 ECase(ELFOSABI_OPENBSD); 265 ECase(ELFOSABI_OPENVMS); 266 ECase(ELFOSABI_NSK); 267 ECase(ELFOSABI_AROS); 268 ECase(ELFOSABI_FENIXOS); 269 ECase(ELFOSABI_CLOUDABI); 270 ECase(ELFOSABI_AMDGPU_HSA); 271 ECase(ELFOSABI_AMDGPU_PAL); 272 ECase(ELFOSABI_AMDGPU_MESA3D); 273 ECase(ELFOSABI_ARM); 274 ECase(ELFOSABI_C6000_ELFABI); 275 ECase(ELFOSABI_C6000_LINUX); 276 ECase(ELFOSABI_STANDALONE); 277 #undef ECase 278 IO.enumFallback<Hex8>(Value); 279 } 280 281 void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO, 282 ELFYAML::ELF_EF &Value) { 283 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 284 assert(Object && "The IO context is not initialized"); 285 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 286 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M) 287 switch (Object->Header.Machine) { 288 case ELF::EM_ARM: 289 BCase(EF_ARM_SOFT_FLOAT); 290 BCase(EF_ARM_VFP_FLOAT); 291 BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK); 292 BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK); 293 BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK); 294 BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK); 295 BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK); 296 BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK); 297 break; 298 case ELF::EM_MIPS: 299 BCase(EF_MIPS_NOREORDER); 300 BCase(EF_MIPS_PIC); 301 BCase(EF_MIPS_CPIC); 302 BCase(EF_MIPS_ABI2); 303 BCase(EF_MIPS_32BITMODE); 304 BCase(EF_MIPS_FP64); 305 BCase(EF_MIPS_NAN2008); 306 BCase(EF_MIPS_MICROMIPS); 307 BCase(EF_MIPS_ARCH_ASE_M16); 308 BCase(EF_MIPS_ARCH_ASE_MDMX); 309 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI); 310 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI); 311 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI); 312 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI); 313 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH); 314 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH); 315 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH); 316 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH); 317 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH); 318 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH); 319 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH); 320 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH); 321 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH); 322 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH); 323 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH); 324 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH); 325 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH); 326 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH); 327 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH); 328 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH); 329 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH); 330 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH); 331 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH); 332 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH); 333 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH); 334 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH); 335 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH); 336 BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH); 337 BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH); 338 BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH); 339 BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH); 340 BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH); 341 BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH); 342 break; 343 case ELF::EM_HEXAGON: 344 BCase(EF_HEXAGON_MACH_V2); 345 BCase(EF_HEXAGON_MACH_V3); 346 BCase(EF_HEXAGON_MACH_V4); 347 BCase(EF_HEXAGON_MACH_V5); 348 BCase(EF_HEXAGON_MACH_V55); 349 BCase(EF_HEXAGON_MACH_V60); 350 BCase(EF_HEXAGON_MACH_V62); 351 BCase(EF_HEXAGON_MACH_V65); 352 BCase(EF_HEXAGON_ISA_V2); 353 BCase(EF_HEXAGON_ISA_V3); 354 BCase(EF_HEXAGON_ISA_V4); 355 BCase(EF_HEXAGON_ISA_V5); 356 BCase(EF_HEXAGON_ISA_V55); 357 BCase(EF_HEXAGON_ISA_V60); 358 BCase(EF_HEXAGON_ISA_V62); 359 BCase(EF_HEXAGON_ISA_V65); 360 break; 361 case ELF::EM_AVR: 362 BCase(EF_AVR_ARCH_AVR1); 363 BCase(EF_AVR_ARCH_AVR2); 364 BCase(EF_AVR_ARCH_AVR25); 365 BCase(EF_AVR_ARCH_AVR3); 366 BCase(EF_AVR_ARCH_AVR31); 367 BCase(EF_AVR_ARCH_AVR35); 368 BCase(EF_AVR_ARCH_AVR4); 369 BCase(EF_AVR_ARCH_AVR51); 370 BCase(EF_AVR_ARCH_AVR6); 371 BCase(EF_AVR_ARCH_AVRTINY); 372 BCase(EF_AVR_ARCH_XMEGA1); 373 BCase(EF_AVR_ARCH_XMEGA2); 374 BCase(EF_AVR_ARCH_XMEGA3); 375 BCase(EF_AVR_ARCH_XMEGA4); 376 BCase(EF_AVR_ARCH_XMEGA5); 377 BCase(EF_AVR_ARCH_XMEGA6); 378 BCase(EF_AVR_ARCH_XMEGA7); 379 break; 380 case ELF::EM_RISCV: 381 BCase(EF_RISCV_RVC); 382 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT, EF_RISCV_FLOAT_ABI); 383 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE, EF_RISCV_FLOAT_ABI); 384 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_FLOAT_ABI); 385 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD, EF_RISCV_FLOAT_ABI); 386 BCase(EF_RISCV_RVE); 387 break; 388 case ELF::EM_AMDGPU: 389 BCaseMask(EF_AMDGPU_MACH_NONE, EF_AMDGPU_MACH); 390 BCaseMask(EF_AMDGPU_MACH_R600_R600, EF_AMDGPU_MACH); 391 BCaseMask(EF_AMDGPU_MACH_R600_R630, EF_AMDGPU_MACH); 392 BCaseMask(EF_AMDGPU_MACH_R600_RS880, EF_AMDGPU_MACH); 393 BCaseMask(EF_AMDGPU_MACH_R600_RV670, EF_AMDGPU_MACH); 394 BCaseMask(EF_AMDGPU_MACH_R600_RV710, EF_AMDGPU_MACH); 395 BCaseMask(EF_AMDGPU_MACH_R600_RV730, EF_AMDGPU_MACH); 396 BCaseMask(EF_AMDGPU_MACH_R600_RV770, EF_AMDGPU_MACH); 397 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR, EF_AMDGPU_MACH); 398 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS, EF_AMDGPU_MACH); 399 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER, EF_AMDGPU_MACH); 400 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD, EF_AMDGPU_MACH); 401 BCaseMask(EF_AMDGPU_MACH_R600_SUMO, EF_AMDGPU_MACH); 402 BCaseMask(EF_AMDGPU_MACH_R600_BARTS, EF_AMDGPU_MACH); 403 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS, EF_AMDGPU_MACH); 404 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN, EF_AMDGPU_MACH); 405 BCaseMask(EF_AMDGPU_MACH_R600_TURKS, EF_AMDGPU_MACH); 406 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600, EF_AMDGPU_MACH); 407 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601, EF_AMDGPU_MACH); 408 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700, EF_AMDGPU_MACH); 409 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701, EF_AMDGPU_MACH); 410 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702, EF_AMDGPU_MACH); 411 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703, EF_AMDGPU_MACH); 412 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704, EF_AMDGPU_MACH); 413 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801, EF_AMDGPU_MACH); 414 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802, EF_AMDGPU_MACH); 415 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803, EF_AMDGPU_MACH); 416 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810, EF_AMDGPU_MACH); 417 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900, EF_AMDGPU_MACH); 418 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902, EF_AMDGPU_MACH); 419 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904, EF_AMDGPU_MACH); 420 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906, EF_AMDGPU_MACH); 421 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908, EF_AMDGPU_MACH); 422 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909, EF_AMDGPU_MACH); 423 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010, EF_AMDGPU_MACH); 424 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011, EF_AMDGPU_MACH); 425 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012, EF_AMDGPU_MACH); 426 BCase(EF_AMDGPU_XNACK); 427 BCase(EF_AMDGPU_SRAM_ECC); 428 break; 429 case ELF::EM_X86_64: 430 break; 431 default: 432 llvm_unreachable("Unsupported architecture"); 433 } 434 #undef BCase 435 #undef BCaseMask 436 } 437 438 void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration( 439 IO &IO, ELFYAML::ELF_SHT &Value) { 440 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 441 assert(Object && "The IO context is not initialized"); 442 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 443 ECase(SHT_NULL); 444 ECase(SHT_PROGBITS); 445 ECase(SHT_SYMTAB); 446 // FIXME: Issue a diagnostic with this information. 447 ECase(SHT_STRTAB); 448 ECase(SHT_RELA); 449 ECase(SHT_HASH); 450 ECase(SHT_DYNAMIC); 451 ECase(SHT_NOTE); 452 ECase(SHT_NOBITS); 453 ECase(SHT_REL); 454 ECase(SHT_SHLIB); 455 ECase(SHT_DYNSYM); 456 ECase(SHT_INIT_ARRAY); 457 ECase(SHT_FINI_ARRAY); 458 ECase(SHT_PREINIT_ARRAY); 459 ECase(SHT_GROUP); 460 ECase(SHT_SYMTAB_SHNDX); 461 ECase(SHT_RELR); 462 ECase(SHT_ANDROID_REL); 463 ECase(SHT_ANDROID_RELA); 464 ECase(SHT_ANDROID_RELR); 465 ECase(SHT_LLVM_ODRTAB); 466 ECase(SHT_LLVM_LINKER_OPTIONS); 467 ECase(SHT_LLVM_CALL_GRAPH_PROFILE); 468 ECase(SHT_LLVM_ADDRSIG); 469 ECase(SHT_LLVM_DEPENDENT_LIBRARIES); 470 ECase(SHT_LLVM_SYMPART); 471 ECase(SHT_LLVM_PART_EHDR); 472 ECase(SHT_LLVM_PART_PHDR); 473 ECase(SHT_GNU_ATTRIBUTES); 474 ECase(SHT_GNU_HASH); 475 ECase(SHT_GNU_verdef); 476 ECase(SHT_GNU_verneed); 477 ECase(SHT_GNU_versym); 478 switch (Object->Header.Machine) { 479 case ELF::EM_ARM: 480 ECase(SHT_ARM_EXIDX); 481 ECase(SHT_ARM_PREEMPTMAP); 482 ECase(SHT_ARM_ATTRIBUTES); 483 ECase(SHT_ARM_DEBUGOVERLAY); 484 ECase(SHT_ARM_OVERLAYSECTION); 485 break; 486 case ELF::EM_HEXAGON: 487 ECase(SHT_HEX_ORDERED); 488 break; 489 case ELF::EM_X86_64: 490 ECase(SHT_X86_64_UNWIND); 491 break; 492 case ELF::EM_MIPS: 493 ECase(SHT_MIPS_REGINFO); 494 ECase(SHT_MIPS_OPTIONS); 495 ECase(SHT_MIPS_DWARF); 496 ECase(SHT_MIPS_ABIFLAGS); 497 break; 498 default: 499 // Nothing to do. 500 break; 501 } 502 #undef ECase 503 IO.enumFallback<Hex32>(Value); 504 } 505 506 void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO, 507 ELFYAML::ELF_PF &Value) { 508 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 509 BCase(PF_X); 510 BCase(PF_W); 511 BCase(PF_R); 512 } 513 514 void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO, 515 ELFYAML::ELF_SHF &Value) { 516 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 517 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 518 BCase(SHF_WRITE); 519 BCase(SHF_ALLOC); 520 BCase(SHF_EXCLUDE); 521 BCase(SHF_EXECINSTR); 522 BCase(SHF_MERGE); 523 BCase(SHF_STRINGS); 524 BCase(SHF_INFO_LINK); 525 BCase(SHF_LINK_ORDER); 526 BCase(SHF_OS_NONCONFORMING); 527 BCase(SHF_GROUP); 528 BCase(SHF_TLS); 529 BCase(SHF_COMPRESSED); 530 switch (Object->Header.Machine) { 531 case ELF::EM_ARM: 532 BCase(SHF_ARM_PURECODE); 533 break; 534 case ELF::EM_HEXAGON: 535 BCase(SHF_HEX_GPREL); 536 break; 537 case ELF::EM_MIPS: 538 BCase(SHF_MIPS_NODUPES); 539 BCase(SHF_MIPS_NAMES); 540 BCase(SHF_MIPS_LOCAL); 541 BCase(SHF_MIPS_NOSTRIP); 542 BCase(SHF_MIPS_GPREL); 543 BCase(SHF_MIPS_MERGE); 544 BCase(SHF_MIPS_ADDR); 545 BCase(SHF_MIPS_STRING); 546 break; 547 case ELF::EM_X86_64: 548 BCase(SHF_X86_64_LARGE); 549 break; 550 default: 551 // Nothing to do. 552 break; 553 } 554 #undef BCase 555 } 556 557 void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration( 558 IO &IO, ELFYAML::ELF_SHN &Value) { 559 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 560 ECase(SHN_UNDEF); 561 ECase(SHN_LORESERVE); 562 ECase(SHN_LOPROC); 563 ECase(SHN_HIPROC); 564 ECase(SHN_LOOS); 565 ECase(SHN_HIOS); 566 ECase(SHN_ABS); 567 ECase(SHN_COMMON); 568 ECase(SHN_XINDEX); 569 ECase(SHN_HIRESERVE); 570 ECase(SHN_AMDGPU_LDS); 571 ECase(SHN_HEXAGON_SCOMMON); 572 ECase(SHN_HEXAGON_SCOMMON_1); 573 ECase(SHN_HEXAGON_SCOMMON_2); 574 ECase(SHN_HEXAGON_SCOMMON_4); 575 ECase(SHN_HEXAGON_SCOMMON_8); 576 #undef ECase 577 IO.enumFallback<Hex16>(Value); 578 } 579 580 void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration( 581 IO &IO, ELFYAML::ELF_STB &Value) { 582 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 583 ECase(STB_LOCAL); 584 ECase(STB_GLOBAL); 585 ECase(STB_WEAK); 586 ECase(STB_GNU_UNIQUE); 587 #undef ECase 588 IO.enumFallback<Hex8>(Value); 589 } 590 591 void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration( 592 IO &IO, ELFYAML::ELF_STT &Value) { 593 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 594 ECase(STT_NOTYPE); 595 ECase(STT_OBJECT); 596 ECase(STT_FUNC); 597 ECase(STT_SECTION); 598 ECase(STT_FILE); 599 ECase(STT_COMMON); 600 ECase(STT_TLS); 601 ECase(STT_GNU_IFUNC); 602 #undef ECase 603 IO.enumFallback<Hex8>(Value); 604 } 605 606 607 void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration( 608 IO &IO, ELFYAML::ELF_RSS &Value) { 609 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 610 ECase(RSS_UNDEF); 611 ECase(RSS_GP); 612 ECase(RSS_GP0); 613 ECase(RSS_LOC); 614 #undef ECase 615 } 616 617 void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration( 618 IO &IO, ELFYAML::ELF_REL &Value) { 619 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 620 assert(Object && "The IO context is not initialized"); 621 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X); 622 switch (Object->Header.Machine) { 623 case ELF::EM_X86_64: 624 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def" 625 break; 626 case ELF::EM_MIPS: 627 #include "llvm/BinaryFormat/ELFRelocs/Mips.def" 628 break; 629 case ELF::EM_HEXAGON: 630 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def" 631 break; 632 case ELF::EM_386: 633 case ELF::EM_IAMCU: 634 #include "llvm/BinaryFormat/ELFRelocs/i386.def" 635 break; 636 case ELF::EM_AARCH64: 637 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def" 638 break; 639 case ELF::EM_ARM: 640 #include "llvm/BinaryFormat/ELFRelocs/ARM.def" 641 break; 642 case ELF::EM_ARC: 643 #include "llvm/BinaryFormat/ELFRelocs/ARC.def" 644 break; 645 case ELF::EM_RISCV: 646 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def" 647 break; 648 case ELF::EM_LANAI: 649 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def" 650 break; 651 case ELF::EM_AMDGPU: 652 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def" 653 break; 654 case ELF::EM_BPF: 655 #include "llvm/BinaryFormat/ELFRelocs/BPF.def" 656 break; 657 case ELF::EM_PPC64: 658 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def" 659 break; 660 default: 661 // Nothing to do. 662 break; 663 } 664 #undef ELF_RELOC 665 IO.enumFallback<Hex32>(Value); 666 } 667 668 void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration( 669 IO &IO, ELFYAML::ELF_DYNTAG &Value) { 670 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 671 assert(Object && "The IO context is not initialized"); 672 673 // Disable architecture specific tags by default. We might enable them below. 674 #define AARCH64_DYNAMIC_TAG(name, value) 675 #define MIPS_DYNAMIC_TAG(name, value) 676 #define HEXAGON_DYNAMIC_TAG(name, value) 677 #define PPC_DYNAMIC_TAG(name, value) 678 #define PPC64_DYNAMIC_TAG(name, value) 679 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc. 680 #define DYNAMIC_TAG_MARKER(name, value) 681 682 #define STRINGIFY(X) (#X) 683 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X); 684 switch (Object->Header.Machine) { 685 case ELF::EM_AARCH64: 686 #undef AARCH64_DYNAMIC_TAG 687 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 688 #include "llvm/BinaryFormat/DynamicTags.def" 689 #undef AARCH64_DYNAMIC_TAG 690 #define AARCH64_DYNAMIC_TAG(name, value) 691 break; 692 case ELF::EM_MIPS: 693 #undef MIPS_DYNAMIC_TAG 694 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 695 #include "llvm/BinaryFormat/DynamicTags.def" 696 #undef MIPS_DYNAMIC_TAG 697 #define MIPS_DYNAMIC_TAG(name, value) 698 break; 699 case ELF::EM_HEXAGON: 700 #undef HEXAGON_DYNAMIC_TAG 701 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 702 #include "llvm/BinaryFormat/DynamicTags.def" 703 #undef HEXAGON_DYNAMIC_TAG 704 #define HEXAGON_DYNAMIC_TAG(name, value) 705 break; 706 case ELF::EM_PPC: 707 #undef PPC_DYNAMIC_TAG 708 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 709 #include "llvm/BinaryFormat/DynamicTags.def" 710 #undef PPC_DYNAMIC_TAG 711 #define PPC_DYNAMIC_TAG(name, value) 712 break; 713 case ELF::EM_PPC64: 714 #undef PPC64_DYNAMIC_TAG 715 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 716 #include "llvm/BinaryFormat/DynamicTags.def" 717 #undef PPC64_DYNAMIC_TAG 718 #define PPC64_DYNAMIC_TAG(name, value) 719 break; 720 default: 721 #include "llvm/BinaryFormat/DynamicTags.def" 722 break; 723 } 724 #undef AARCH64_DYNAMIC_TAG 725 #undef MIPS_DYNAMIC_TAG 726 #undef HEXAGON_DYNAMIC_TAG 727 #undef PPC_DYNAMIC_TAG 728 #undef PPC64_DYNAMIC_TAG 729 #undef DYNAMIC_TAG_MARKER 730 #undef STRINGIFY 731 #undef DYNAMIC_TAG 732 733 IO.enumFallback<Hex64>(Value); 734 } 735 736 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration( 737 IO &IO, ELFYAML::MIPS_AFL_REG &Value) { 738 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X) 739 ECase(REG_NONE); 740 ECase(REG_32); 741 ECase(REG_64); 742 ECase(REG_128); 743 #undef ECase 744 } 745 746 void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration( 747 IO &IO, ELFYAML::MIPS_ABI_FP &Value) { 748 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X) 749 ECase(FP_ANY); 750 ECase(FP_DOUBLE); 751 ECase(FP_SINGLE); 752 ECase(FP_SOFT); 753 ECase(FP_OLD_64); 754 ECase(FP_XX); 755 ECase(FP_64); 756 ECase(FP_64A); 757 #undef ECase 758 } 759 760 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration( 761 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) { 762 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X) 763 ECase(EXT_NONE); 764 ECase(EXT_XLR); 765 ECase(EXT_OCTEON2); 766 ECase(EXT_OCTEONP); 767 ECase(EXT_LOONGSON_3A); 768 ECase(EXT_OCTEON); 769 ECase(EXT_5900); 770 ECase(EXT_4650); 771 ECase(EXT_4010); 772 ECase(EXT_4100); 773 ECase(EXT_3900); 774 ECase(EXT_10000); 775 ECase(EXT_SB1); 776 ECase(EXT_4111); 777 ECase(EXT_4120); 778 ECase(EXT_5400); 779 ECase(EXT_5500); 780 ECase(EXT_LOONGSON_2E); 781 ECase(EXT_LOONGSON_2F); 782 ECase(EXT_OCTEON3); 783 #undef ECase 784 } 785 786 void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration( 787 IO &IO, ELFYAML::MIPS_ISA &Value) { 788 IO.enumCase(Value, "MIPS1", 1); 789 IO.enumCase(Value, "MIPS2", 2); 790 IO.enumCase(Value, "MIPS3", 3); 791 IO.enumCase(Value, "MIPS4", 4); 792 IO.enumCase(Value, "MIPS5", 5); 793 IO.enumCase(Value, "MIPS32", 32); 794 IO.enumCase(Value, "MIPS64", 64); 795 } 796 797 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset( 798 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) { 799 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X) 800 BCase(DSP); 801 BCase(DSPR2); 802 BCase(EVA); 803 BCase(MCU); 804 BCase(MDMX); 805 BCase(MIPS3D); 806 BCase(MT); 807 BCase(SMARTMIPS); 808 BCase(VIRT); 809 BCase(MSA); 810 BCase(MIPS16); 811 BCase(MICROMIPS); 812 BCase(XPA); 813 #undef BCase 814 } 815 816 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset( 817 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) { 818 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X) 819 BCase(ODDSPREG); 820 #undef BCase 821 } 822 823 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO, 824 ELFYAML::FileHeader &FileHdr) { 825 IO.mapRequired("Class", FileHdr.Class); 826 IO.mapRequired("Data", FileHdr.Data); 827 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0)); 828 IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0)); 829 IO.mapRequired("Type", FileHdr.Type); 830 IO.mapRequired("Machine", FileHdr.Machine); 831 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0)); 832 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0)); 833 834 IO.mapOptional("SHEntSize", FileHdr.SHEntSize); 835 IO.mapOptional("SHOff", FileHdr.SHOff); 836 IO.mapOptional("SHNum", FileHdr.SHNum); 837 IO.mapOptional("SHStrNdx", FileHdr.SHStrNdx); 838 } 839 840 void MappingTraits<ELFYAML::ProgramHeader>::mapping( 841 IO &IO, ELFYAML::ProgramHeader &Phdr) { 842 IO.mapRequired("Type", Phdr.Type); 843 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0)); 844 IO.mapOptional("Sections", Phdr.Sections); 845 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0)); 846 IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0)); 847 IO.mapOptional("Align", Phdr.Align); 848 IO.mapOptional("FileSize", Phdr.FileSize); 849 IO.mapOptional("MemSize", Phdr.MemSize); 850 IO.mapOptional("Offset", Phdr.Offset); 851 } 852 853 LLVM_YAML_STRONG_TYPEDEF(StringRef, StOtherPiece) 854 855 template <> struct ScalarTraits<StOtherPiece> { 856 static void output(const StOtherPiece &Val, void *, raw_ostream &Out) { 857 Out << Val; 858 } 859 static StringRef input(StringRef Scalar, void *, StOtherPiece &Val) { 860 Val = Scalar; 861 return {}; 862 } 863 static QuotingType mustQuote(StringRef) { return QuotingType::None; } 864 }; 865 template <> struct SequenceElementTraits<StOtherPiece> { 866 static const bool flow = true; 867 }; 868 869 template <> struct ScalarTraits<ELFYAML::YAMLFlowString> { 870 static void output(const ELFYAML::YAMLFlowString &Val, void *, 871 raw_ostream &Out) { 872 Out << Val; 873 } 874 static StringRef input(StringRef Scalar, void *, 875 ELFYAML::YAMLFlowString &Val) { 876 Val = Scalar; 877 return {}; 878 } 879 static QuotingType mustQuote(StringRef S) { 880 return ScalarTraits<StringRef>::mustQuote(S); 881 } 882 }; 883 template <> struct SequenceElementTraits<ELFYAML::YAMLFlowString> { 884 static const bool flow = true; 885 }; 886 887 namespace { 888 889 struct NormalizedOther { 890 NormalizedOther(IO &IO) : YamlIO(IO) {} 891 NormalizedOther(IO &IO, Optional<uint8_t> Original) : YamlIO(IO) { 892 assert(Original && "This constructor is only used for outputting YAML and " 893 "assumes a non-empty Original"); 894 std::vector<StOtherPiece> Ret; 895 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext()); 896 for (std::pair<StringRef, uint8_t> &P : 897 getFlags(Object->Header.Machine).takeVector()) { 898 uint8_t FlagValue = P.second; 899 if ((*Original & FlagValue) != FlagValue) 900 continue; 901 *Original &= ~FlagValue; 902 Ret.push_back({P.first}); 903 } 904 905 if (*Original != 0) { 906 UnknownFlagsHolder = std::to_string(*Original); 907 Ret.push_back({UnknownFlagsHolder}); 908 } 909 910 if (!Ret.empty()) 911 Other = std::move(Ret); 912 } 913 914 uint8_t toValue(StringRef Name) { 915 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext()); 916 MapVector<StringRef, uint8_t> Flags = getFlags(Object->Header.Machine); 917 918 auto It = Flags.find(Name); 919 if (It != Flags.end()) 920 return It->second; 921 922 uint8_t Val; 923 if (to_integer(Name, Val)) 924 return Val; 925 926 YamlIO.setError("an unknown value is used for symbol's 'Other' field: " + 927 Name); 928 return 0; 929 } 930 931 Optional<uint8_t> denormalize(IO &) { 932 if (!Other) 933 return None; 934 uint8_t Ret = 0; 935 for (StOtherPiece &Val : *Other) 936 Ret |= toValue(Val); 937 return Ret; 938 } 939 940 // st_other field is used to encode symbol visibility and platform-dependent 941 // flags and values. This method returns a name to value map that is used for 942 // parsing and encoding this field. 943 MapVector<StringRef, uint8_t> getFlags(unsigned EMachine) { 944 MapVector<StringRef, uint8_t> Map; 945 // STV_* values are just enumeration values. We add them in a reversed order 946 // because when we convert the st_other to named constants when printing 947 // YAML we want to use a maximum number of bits on each step: 948 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but 949 // not as STV_HIDDEN (2) + STV_INTERNAL (1). 950 Map["STV_PROTECTED"] = ELF::STV_PROTECTED; 951 Map["STV_HIDDEN"] = ELF::STV_HIDDEN; 952 Map["STV_INTERNAL"] = ELF::STV_INTERNAL; 953 // STV_DEFAULT is used to represent the default visibility and has a value 954 // 0. We want to be able to read it from YAML documents, but there is no 955 // reason to print it. 956 if (!YamlIO.outputting()) 957 Map["STV_DEFAULT"] = ELF::STV_DEFAULT; 958 959 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags, 960 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and 961 // consumed first when we print the output, because we do not want to print 962 // any other flags that have the same bits instead. 963 if (EMachine == ELF::EM_MIPS) { 964 Map["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16; 965 Map["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS; 966 Map["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC; 967 Map["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT; 968 Map["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL; 969 } 970 return Map; 971 } 972 973 IO &YamlIO; 974 Optional<std::vector<StOtherPiece>> Other; 975 std::string UnknownFlagsHolder; 976 }; 977 978 } // end anonymous namespace 979 980 void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) { 981 IO.mapOptional("Name", Symbol.Name, StringRef()); 982 IO.mapOptional("NameIndex", Symbol.NameIndex); 983 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0)); 984 IO.mapOptional("Section", Symbol.Section, StringRef()); 985 IO.mapOptional("Index", Symbol.Index); 986 IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0)); 987 IO.mapOptional("Value", Symbol.Value, Hex64(0)); 988 IO.mapOptional("Size", Symbol.Size, Hex64(0)); 989 990 // Symbol's Other field is a bit special. It is usually a field that 991 // represents st_other and holds the symbol visibility. However, on some 992 // platforms, it can contain bit fields and regular values, or even sometimes a 993 // crazy mix of them (see comments for NormalizedOther). Because of this, we 994 // need special handling. 995 MappingNormalization<NormalizedOther, Optional<uint8_t>> Keys(IO, 996 Symbol.Other); 997 IO.mapOptional("Other", Keys->Other); 998 } 999 1000 StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO, 1001 ELFYAML::Symbol &Symbol) { 1002 if (Symbol.Index && Symbol.Section.data()) 1003 return "Index and Section cannot both be specified for Symbol"; 1004 if (Symbol.NameIndex && !Symbol.Name.empty()) 1005 return "Name and NameIndex cannot both be specified for Symbol"; 1006 return StringRef(); 1007 } 1008 1009 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) { 1010 IO.mapOptional("Name", Section.Name, StringRef()); 1011 IO.mapRequired("Type", Section.Type); 1012 IO.mapOptional("Flags", Section.Flags); 1013 IO.mapOptional("Address", Section.Address, Hex64(0)); 1014 IO.mapOptional("Link", Section.Link, StringRef()); 1015 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); 1016 IO.mapOptional("EntSize", Section.EntSize); 1017 1018 // obj2yaml does not dump these fields. They are expected to be empty when we 1019 // are producing YAML, because yaml2obj sets appropriate values for them 1020 // automatically when they are not explicitly defined. 1021 assert(!IO.outputting() || 1022 (!Section.ShOffset.hasValue() && !Section.ShSize.hasValue() && 1023 !Section.ShName.hasValue() && !Section.ShFlags.hasValue())); 1024 IO.mapOptional("ShName", Section.ShName); 1025 IO.mapOptional("ShOffset", Section.ShOffset); 1026 IO.mapOptional("ShSize", Section.ShSize); 1027 IO.mapOptional("ShFlags", Section.ShFlags); 1028 } 1029 1030 static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) { 1031 commonSectionMapping(IO, Section); 1032 IO.mapOptional("Entries", Section.Entries); 1033 IO.mapOptional("Content", Section.Content); 1034 } 1035 1036 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { 1037 commonSectionMapping(IO, Section); 1038 IO.mapOptional("Content", Section.Content); 1039 IO.mapOptional("Size", Section.Size); 1040 IO.mapOptional("Info", Section.Info); 1041 } 1042 1043 static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) { 1044 commonSectionMapping(IO, Section); 1045 IO.mapOptional("Content", Section.Content); 1046 IO.mapOptional("Size", Section.Size); 1047 IO.mapOptional("Entries", Section.Entries); 1048 } 1049 1050 static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) { 1051 commonSectionMapping(IO, Section); 1052 IO.mapOptional("Content", Section.Content); 1053 IO.mapOptional("Bucket", Section.Bucket); 1054 IO.mapOptional("Chain", Section.Chain); 1055 IO.mapOptional("Size", Section.Size); 1056 } 1057 1058 static void sectionMapping(IO &IO, ELFYAML::NoteSection &Section) { 1059 commonSectionMapping(IO, Section); 1060 IO.mapOptional("Content", Section.Content); 1061 IO.mapOptional("Size", Section.Size); 1062 IO.mapOptional("Notes", Section.Notes); 1063 } 1064 1065 1066 static void sectionMapping(IO &IO, ELFYAML::GnuHashSection &Section) { 1067 commonSectionMapping(IO, Section); 1068 IO.mapOptional("Content", Section.Content); 1069 IO.mapOptional("Header", Section.Header); 1070 IO.mapOptional("BloomFilter", Section.BloomFilter); 1071 IO.mapOptional("HashBuckets", Section.HashBuckets); 1072 IO.mapOptional("HashValues", Section.HashValues); 1073 } 1074 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) { 1075 commonSectionMapping(IO, Section); 1076 IO.mapOptional("Size", Section.Size, Hex64(0)); 1077 } 1078 1079 static void sectionMapping(IO &IO, ELFYAML::VerdefSection &Section) { 1080 commonSectionMapping(IO, Section); 1081 IO.mapRequired("Info", Section.Info); 1082 IO.mapOptional("Entries", Section.Entries); 1083 IO.mapOptional("Content", Section.Content); 1084 } 1085 1086 static void sectionMapping(IO &IO, ELFYAML::SymverSection &Section) { 1087 commonSectionMapping(IO, Section); 1088 IO.mapRequired("Entries", Section.Entries); 1089 } 1090 1091 static void sectionMapping(IO &IO, ELFYAML::VerneedSection &Section) { 1092 commonSectionMapping(IO, Section); 1093 IO.mapRequired("Info", Section.Info); 1094 IO.mapOptional("Dependencies", Section.VerneedV); 1095 IO.mapOptional("Content", Section.Content); 1096 } 1097 1098 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) { 1099 commonSectionMapping(IO, Section); 1100 IO.mapOptional("Info", Section.RelocatableSec, StringRef()); 1101 IO.mapOptional("Relocations", Section.Relocations); 1102 } 1103 1104 static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) { 1105 commonSectionMapping(IO, Section); 1106 IO.mapOptional("Entries", Section.Entries); 1107 IO.mapOptional("Content", Section.Content); 1108 } 1109 1110 static void groupSectionMapping(IO &IO, ELFYAML::Group &Group) { 1111 commonSectionMapping(IO, Group); 1112 IO.mapOptional("Info", Group.Signature); 1113 IO.mapRequired("Members", Group.Members); 1114 } 1115 1116 static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) { 1117 commonSectionMapping(IO, Section); 1118 IO.mapRequired("Entries", Section.Entries); 1119 } 1120 1121 static void sectionMapping(IO &IO, ELFYAML::AddrsigSection &Section) { 1122 commonSectionMapping(IO, Section); 1123 IO.mapOptional("Content", Section.Content); 1124 IO.mapOptional("Size", Section.Size); 1125 IO.mapOptional("Symbols", Section.Symbols); 1126 } 1127 1128 static void fillMapping(IO &IO, ELFYAML::Fill &Fill) { 1129 IO.mapOptional("Name", Fill.Name, StringRef()); 1130 IO.mapOptional("Pattern", Fill.Pattern); 1131 IO.mapRequired("Size", Fill.Size); 1132 } 1133 1134 static void sectionMapping(IO &IO, ELFYAML::LinkerOptionsSection &Section) { 1135 commonSectionMapping(IO, Section); 1136 IO.mapOptional("Options", Section.Options); 1137 IO.mapOptional("Content", Section.Content); 1138 } 1139 1140 static void sectionMapping(IO &IO, 1141 ELFYAML::DependentLibrariesSection &Section) { 1142 commonSectionMapping(IO, Section); 1143 IO.mapOptional("Libraries", Section.Libs); 1144 IO.mapOptional("Content", Section.Content); 1145 } 1146 1147 void MappingTraits<ELFYAML::SectionOrType>::mapping( 1148 IO &IO, ELFYAML::SectionOrType §ionOrType) { 1149 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType); 1150 } 1151 1152 void MappingTraits<ELFYAML::SectionName>::mapping( 1153 IO &IO, ELFYAML::SectionName §ionName) { 1154 IO.mapRequired("Section", sectionName.Section); 1155 } 1156 1157 static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) { 1158 commonSectionMapping(IO, Section); 1159 IO.mapOptional("Version", Section.Version, Hex16(0)); 1160 IO.mapRequired("ISA", Section.ISALevel); 1161 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0)); 1162 IO.mapOptional("ISAExtension", Section.ISAExtension, 1163 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE)); 1164 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0)); 1165 IO.mapOptional("FpABI", Section.FpABI, 1166 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY)); 1167 IO.mapOptional("GPRSize", Section.GPRSize, 1168 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1169 IO.mapOptional("CPR1Size", Section.CPR1Size, 1170 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1171 IO.mapOptional("CPR2Size", Section.CPR2Size, 1172 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1173 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0)); 1174 IO.mapOptional("Flags2", Section.Flags2, Hex32(0)); 1175 } 1176 1177 void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping( 1178 IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) { 1179 ELFYAML::ELF_SHT Type; 1180 if (IO.outputting()) { 1181 Type = cast<ELFYAML::Section>(Section.get())->Type; 1182 } else { 1183 // When the Type string does not have a "SHT_" prefix, we know it is not a 1184 // description of a regular ELF output section. Currently, we have one 1185 // special type named "Fill". See comments for Fill. 1186 StringRef StrType; 1187 IO.mapRequired("Type", StrType); 1188 if (StrType == "Fill") { 1189 Section.reset(new ELFYAML::Fill()); 1190 fillMapping(IO, *cast<ELFYAML::Fill>(Section.get())); 1191 return; 1192 } 1193 1194 IO.mapRequired("Type", Type); 1195 } 1196 1197 switch (Type) { 1198 case ELF::SHT_DYNAMIC: 1199 if (!IO.outputting()) 1200 Section.reset(new ELFYAML::DynamicSection()); 1201 sectionMapping(IO, *cast<ELFYAML::DynamicSection>(Section.get())); 1202 break; 1203 case ELF::SHT_REL: 1204 case ELF::SHT_RELA: 1205 if (!IO.outputting()) 1206 Section.reset(new ELFYAML::RelocationSection()); 1207 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get())); 1208 break; 1209 case ELF::SHT_RELR: 1210 if (!IO.outputting()) 1211 Section.reset(new ELFYAML::RelrSection()); 1212 sectionMapping(IO, *cast<ELFYAML::RelrSection>(Section.get())); 1213 break; 1214 case ELF::SHT_GROUP: 1215 if (!IO.outputting()) 1216 Section.reset(new ELFYAML::Group()); 1217 groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get())); 1218 break; 1219 case ELF::SHT_NOBITS: 1220 if (!IO.outputting()) 1221 Section.reset(new ELFYAML::NoBitsSection()); 1222 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get())); 1223 break; 1224 case ELF::SHT_HASH: 1225 if (!IO.outputting()) 1226 Section.reset(new ELFYAML::HashSection()); 1227 sectionMapping(IO, *cast<ELFYAML::HashSection>(Section.get())); 1228 break; 1229 case ELF::SHT_NOTE: 1230 if (!IO.outputting()) 1231 Section.reset(new ELFYAML::NoteSection()); 1232 sectionMapping(IO, *cast<ELFYAML::NoteSection>(Section.get())); 1233 break; 1234 case ELF::SHT_GNU_HASH: 1235 if (!IO.outputting()) 1236 Section.reset(new ELFYAML::GnuHashSection()); 1237 sectionMapping(IO, *cast<ELFYAML::GnuHashSection>(Section.get())); 1238 break; 1239 case ELF::SHT_MIPS_ABIFLAGS: 1240 if (!IO.outputting()) 1241 Section.reset(new ELFYAML::MipsABIFlags()); 1242 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get())); 1243 break; 1244 case ELF::SHT_GNU_verdef: 1245 if (!IO.outputting()) 1246 Section.reset(new ELFYAML::VerdefSection()); 1247 sectionMapping(IO, *cast<ELFYAML::VerdefSection>(Section.get())); 1248 break; 1249 case ELF::SHT_GNU_versym: 1250 if (!IO.outputting()) 1251 Section.reset(new ELFYAML::SymverSection()); 1252 sectionMapping(IO, *cast<ELFYAML::SymverSection>(Section.get())); 1253 break; 1254 case ELF::SHT_GNU_verneed: 1255 if (!IO.outputting()) 1256 Section.reset(new ELFYAML::VerneedSection()); 1257 sectionMapping(IO, *cast<ELFYAML::VerneedSection>(Section.get())); 1258 break; 1259 case ELF::SHT_SYMTAB_SHNDX: 1260 if (!IO.outputting()) 1261 Section.reset(new ELFYAML::SymtabShndxSection()); 1262 sectionMapping(IO, *cast<ELFYAML::SymtabShndxSection>(Section.get())); 1263 break; 1264 case ELF::SHT_LLVM_ADDRSIG: 1265 if (!IO.outputting()) 1266 Section.reset(new ELFYAML::AddrsigSection()); 1267 sectionMapping(IO, *cast<ELFYAML::AddrsigSection>(Section.get())); 1268 break; 1269 case ELF::SHT_LLVM_LINKER_OPTIONS: 1270 if (!IO.outputting()) 1271 Section.reset(new ELFYAML::LinkerOptionsSection()); 1272 sectionMapping(IO, *cast<ELFYAML::LinkerOptionsSection>(Section.get())); 1273 break; 1274 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES: 1275 if (!IO.outputting()) 1276 Section.reset(new ELFYAML::DependentLibrariesSection()); 1277 sectionMapping(IO, 1278 *cast<ELFYAML::DependentLibrariesSection>(Section.get())); 1279 break; 1280 default: 1281 if (!IO.outputting()) { 1282 StringRef Name; 1283 IO.mapOptional("Name", Name, StringRef()); 1284 Name = ELFYAML::dropUniqueSuffix(Name); 1285 1286 if (ELFYAML::StackSizesSection::nameMatches(Name)) 1287 Section = std::make_unique<ELFYAML::StackSizesSection>(); 1288 else 1289 Section = std::make_unique<ELFYAML::RawContentSection>(); 1290 } 1291 1292 if (auto S = dyn_cast<ELFYAML::RawContentSection>(Section.get())) 1293 sectionMapping(IO, *S); 1294 else 1295 sectionMapping(IO, *cast<ELFYAML::StackSizesSection>(Section.get())); 1296 } 1297 } 1298 1299 StringRef MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate( 1300 IO &io, std::unique_ptr<ELFYAML::Chunk> &C) { 1301 if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) { 1302 if (RawSection->Size && RawSection->Content && 1303 (uint64_t)(*RawSection->Size) < RawSection->Content->binary_size()) 1304 return "Section size must be greater than or equal to the content size"; 1305 if (RawSection->Flags && RawSection->ShFlags) 1306 return "ShFlags and Flags cannot be used together"; 1307 return {}; 1308 } 1309 1310 if (const auto *SS = dyn_cast<ELFYAML::StackSizesSection>(C.get())) { 1311 if (!SS->Entries && !SS->Content && !SS->Size) 1312 return ".stack_sizes: one of Content, Entries and Size must be specified"; 1313 1314 if (SS->Size && SS->Content && 1315 (uint64_t)(*SS->Size) < SS->Content->binary_size()) 1316 return ".stack_sizes: Size must be greater than or equal to the content " 1317 "size"; 1318 1319 // We accept Content, Size or both together when there are no Entries. 1320 if (!SS->Entries) 1321 return {}; 1322 1323 if (SS->Size) 1324 return ".stack_sizes: Size and Entries cannot be used together"; 1325 if (SS->Content) 1326 return ".stack_sizes: Content and Entries cannot be used together"; 1327 return {}; 1328 } 1329 1330 if (const auto *HS = dyn_cast<ELFYAML::HashSection>(C.get())) { 1331 if (!HS->Content && !HS->Bucket && !HS->Chain && !HS->Size) 1332 return "one of \"Content\", \"Size\", \"Bucket\" or \"Chain\" must be " 1333 "specified"; 1334 1335 if (HS->Content || HS->Size) { 1336 if (HS->Size && HS->Content && 1337 (uint64_t)*HS->Size < HS->Content->binary_size()) 1338 return "\"Size\" must be greater than or equal to the content " 1339 "size"; 1340 1341 if (HS->Bucket) 1342 return "\"Bucket\" cannot be used with \"Content\" or \"Size\""; 1343 if (HS->Chain) 1344 return "\"Chain\" cannot be used with \"Content\" or \"Size\""; 1345 return {}; 1346 } 1347 1348 if ((HS->Bucket && !HS->Chain) || (!HS->Bucket && HS->Chain)) 1349 return "\"Bucket\" and \"Chain\" must be used together"; 1350 return {}; 1351 } 1352 1353 if (const auto *Sec = dyn_cast<ELFYAML::AddrsigSection>(C.get())) { 1354 if (!Sec->Symbols && !Sec->Content && !Sec->Size) 1355 return "one of \"Content\", \"Size\" or \"Symbols\" must be specified"; 1356 1357 if (Sec->Content || Sec->Size) { 1358 if (Sec->Size && Sec->Content && 1359 (uint64_t)*Sec->Size < Sec->Content->binary_size()) 1360 return "\"Size\" must be greater than or equal to the content " 1361 "size"; 1362 1363 if (Sec->Symbols) 1364 return "\"Symbols\" cannot be used with \"Content\" or \"Size\""; 1365 return {}; 1366 } 1367 1368 if (!Sec->Symbols) 1369 return {}; 1370 1371 for (const ELFYAML::AddrsigSymbol &AS : *Sec->Symbols) 1372 if (AS.Index && AS.Name) 1373 return "\"Index\" and \"Name\" cannot be used together when defining a " 1374 "symbol"; 1375 return {}; 1376 } 1377 1378 if (const auto *NS = dyn_cast<ELFYAML::NoteSection>(C.get())) { 1379 if (!NS->Content && !NS->Size && !NS->Notes) 1380 return "one of \"Content\", \"Size\" or \"Notes\" must be " 1381 "specified"; 1382 1383 if (!NS->Content && !NS->Size) 1384 return {}; 1385 1386 if (NS->Size && NS->Content && 1387 (uint64_t)*NS->Size < NS->Content->binary_size()) 1388 return "\"Size\" must be greater than or equal to the content " 1389 "size"; 1390 1391 if (NS->Notes) 1392 return "\"Notes\" cannot be used with \"Content\" or \"Size\""; 1393 return {}; 1394 } 1395 1396 if (const auto *Sec = dyn_cast<ELFYAML::GnuHashSection>(C.get())) { 1397 if (!Sec->Content && !Sec->Header && !Sec->BloomFilter && 1398 !Sec->HashBuckets && !Sec->HashValues) 1399 return "either \"Content\" or \"Header\", \"BloomFilter\", " 1400 "\"HashBuckets\" and \"HashBuckets\" must be specified"; 1401 1402 if (Sec->Header || Sec->BloomFilter || Sec->HashBuckets || 1403 Sec->HashValues) { 1404 if (!Sec->Header || !Sec->BloomFilter || !Sec->HashBuckets || 1405 !Sec->HashValues) 1406 return "\"Header\", \"BloomFilter\", " 1407 "\"HashBuckets\" and \"HashValues\" must be used together"; 1408 if (Sec->Content) 1409 return "\"Header\", \"BloomFilter\", " 1410 "\"HashBuckets\" and \"HashValues\" can't be used together with " 1411 "\"Content\""; 1412 return {}; 1413 } 1414 1415 // Only Content is specified. 1416 return {}; 1417 } 1418 1419 if (const auto *Sec = dyn_cast<ELFYAML::LinkerOptionsSection>(C.get())) { 1420 if (Sec->Options && Sec->Content) 1421 return "\"Options\" and \"Content\" can't be used together"; 1422 return {}; 1423 } 1424 1425 if (const auto *Sec = dyn_cast<ELFYAML::DependentLibrariesSection>(C.get())) { 1426 if (Sec->Libs && Sec->Content) 1427 return "SHT_LLVM_DEPENDENT_LIBRARIES: \"Libraries\" and \"Content\" " 1428 "can't " 1429 "be used together"; 1430 return {}; 1431 } 1432 1433 if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) { 1434 if (!F->Pattern) 1435 return {}; 1436 if (F->Pattern->binary_size() != 0 && !F->Size) 1437 return "\"Size\" can't be 0 when \"Pattern\" is not empty"; 1438 return {}; 1439 } 1440 1441 if (const auto *VD = dyn_cast<ELFYAML::VerdefSection>(C.get())) { 1442 if (VD->Entries && VD->Content) 1443 return "SHT_GNU_verdef: \"Entries\" and \"Content\" can't be used " 1444 "together"; 1445 return {}; 1446 } 1447 1448 if (const auto *VD = dyn_cast<ELFYAML::VerneedSection>(C.get())) { 1449 if (VD->VerneedV && VD->Content) 1450 return "SHT_GNU_verneed: \"Dependencies\" and \"Content\" can't be used " 1451 "together"; 1452 return {}; 1453 } 1454 1455 if (const auto *RS = dyn_cast<ELFYAML::RelrSection>(C.get())) { 1456 if (RS->Entries && RS->Content) 1457 return "\"Entries\" and \"Content\" can't be used together"; 1458 return {}; 1459 } 1460 1461 return {}; 1462 } 1463 1464 namespace { 1465 1466 struct NormalizedMips64RelType { 1467 NormalizedMips64RelType(IO &) 1468 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1469 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1470 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1471 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {} 1472 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original) 1473 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF), 1474 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {} 1475 1476 ELFYAML::ELF_REL denormalize(IO &) { 1477 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24; 1478 return Res; 1479 } 1480 1481 ELFYAML::ELF_REL Type; 1482 ELFYAML::ELF_REL Type2; 1483 ELFYAML::ELF_REL Type3; 1484 ELFYAML::ELF_RSS SpecSym; 1485 }; 1486 1487 } // end anonymous namespace 1488 1489 void MappingTraits<ELFYAML::StackSizeEntry>::mapping( 1490 IO &IO, ELFYAML::StackSizeEntry &E) { 1491 assert(IO.getContext() && "The IO context is not initialized"); 1492 IO.mapOptional("Address", E.Address, Hex64(0)); 1493 IO.mapRequired("Size", E.Size); 1494 } 1495 1496 void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO, 1497 ELFYAML::GnuHashHeader &E) { 1498 assert(IO.getContext() && "The IO context is not initialized"); 1499 IO.mapOptional("NBuckets", E.NBuckets); 1500 IO.mapRequired("SymNdx", E.SymNdx); 1501 IO.mapOptional("MaskWords", E.MaskWords); 1502 IO.mapRequired("Shift2", E.Shift2); 1503 } 1504 1505 void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO, 1506 ELFYAML::DynamicEntry &Rel) { 1507 assert(IO.getContext() && "The IO context is not initialized"); 1508 1509 IO.mapRequired("Tag", Rel.Tag); 1510 IO.mapRequired("Value", Rel.Val); 1511 } 1512 1513 void MappingTraits<ELFYAML::NoteEntry>::mapping(IO &IO, ELFYAML::NoteEntry &N) { 1514 assert(IO.getContext() && "The IO context is not initialized"); 1515 1516 IO.mapOptional("Name", N.Name); 1517 IO.mapOptional("Desc", N.Desc); 1518 IO.mapRequired("Type", N.Type); 1519 } 1520 1521 void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO, 1522 ELFYAML::VerdefEntry &E) { 1523 assert(IO.getContext() && "The IO context is not initialized"); 1524 1525 IO.mapRequired("Version", E.Version); 1526 IO.mapRequired("Flags", E.Flags); 1527 IO.mapRequired("VersionNdx", E.VersionNdx); 1528 IO.mapRequired("Hash", E.Hash); 1529 IO.mapRequired("Names", E.VerNames); 1530 } 1531 1532 void MappingTraits<ELFYAML::VerneedEntry>::mapping(IO &IO, 1533 ELFYAML::VerneedEntry &E) { 1534 assert(IO.getContext() && "The IO context is not initialized"); 1535 1536 IO.mapRequired("Version", E.Version); 1537 IO.mapRequired("File", E.File); 1538 IO.mapRequired("Entries", E.AuxV); 1539 } 1540 1541 void MappingTraits<ELFYAML::VernauxEntry>::mapping(IO &IO, 1542 ELFYAML::VernauxEntry &E) { 1543 assert(IO.getContext() && "The IO context is not initialized"); 1544 1545 IO.mapRequired("Name", E.Name); 1546 IO.mapRequired("Hash", E.Hash); 1547 IO.mapRequired("Flags", E.Flags); 1548 IO.mapRequired("Other", E.Other); 1549 } 1550 1551 void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO, 1552 ELFYAML::Relocation &Rel) { 1553 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 1554 assert(Object && "The IO context is not initialized"); 1555 1556 IO.mapRequired("Offset", Rel.Offset); 1557 IO.mapOptional("Symbol", Rel.Symbol); 1558 1559 if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) && 1560 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) { 1561 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key( 1562 IO, Rel.Type); 1563 IO.mapRequired("Type", Key->Type); 1564 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); 1565 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); 1566 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF)); 1567 } else 1568 IO.mapRequired("Type", Rel.Type); 1569 1570 IO.mapOptional("Addend", Rel.Addend, (int64_t)0); 1571 } 1572 1573 void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) { 1574 assert(!IO.getContext() && "The IO context is initialized already"); 1575 IO.setContext(&Object); 1576 IO.mapTag("!ELF", true); 1577 IO.mapRequired("FileHeader", Object.Header); 1578 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders); 1579 IO.mapOptional("Sections", Object.Chunks); 1580 IO.mapOptional("Symbols", Object.Symbols); 1581 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols); 1582 IO.setContext(nullptr); 1583 } 1584 1585 void MappingTraits<ELFYAML::AddrsigSymbol>::mapping(IO &IO, ELFYAML::AddrsigSymbol &Sym) { 1586 assert(IO.getContext() && "The IO context is not initialized"); 1587 IO.mapOptional("Name", Sym.Name); 1588 IO.mapOptional("Index", Sym.Index); 1589 } 1590 1591 void MappingTraits<ELFYAML::LinkerOption>::mapping(IO &IO, 1592 ELFYAML::LinkerOption &Opt) { 1593 assert(IO.getContext() && "The IO context is not initialized"); 1594 IO.mapRequired("Name", Opt.Key); 1595 IO.mapRequired("Value", Opt.Value); 1596 } 1597 1598 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) 1599 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) 1600 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT) 1601 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE) 1602 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1) 1603 1604 } // end namespace yaml 1605 1606 } // end namespace llvm 1607