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/APInt.h" 15 #include "llvm/ADT/MapVector.h" 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/BinaryFormat/ELF.h" 18 #include "llvm/Support/ARMEHABI.h" 19 #include "llvm/Support/Casting.h" 20 #include "llvm/Support/ErrorHandling.h" 21 #include "llvm/Support/MipsABIFlags.h" 22 #include "llvm/Support/YAMLTraits.h" 23 #include "llvm/Support/WithColor.h" 24 #include <cassert> 25 #include <cstdint> 26 27 namespace llvm { 28 29 ELFYAML::Chunk::~Chunk() = default; 30 31 namespace ELFYAML { 32 ELF_ELFOSABI Object::getOSAbi() const { return Header.OSABI; } 33 34 unsigned Object::getMachine() const { 35 if (Header.Machine) 36 return *Header.Machine; 37 return llvm::ELF::EM_NONE; 38 } 39 40 constexpr StringRef SectionHeaderTable::TypeStr; 41 } // namespace ELFYAML 42 43 namespace yaml { 44 45 void ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration( 46 IO &IO, ELFYAML::ELF_ET &Value) { 47 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 48 ECase(ET_NONE); 49 ECase(ET_REL); 50 ECase(ET_EXEC); 51 ECase(ET_DYN); 52 ECase(ET_CORE); 53 #undef ECase 54 IO.enumFallback<Hex16>(Value); 55 } 56 57 void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration( 58 IO &IO, ELFYAML::ELF_PT &Value) { 59 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 60 ECase(PT_NULL); 61 ECase(PT_LOAD); 62 ECase(PT_DYNAMIC); 63 ECase(PT_INTERP); 64 ECase(PT_NOTE); 65 ECase(PT_SHLIB); 66 ECase(PT_PHDR); 67 ECase(PT_TLS); 68 ECase(PT_GNU_EH_FRAME); 69 ECase(PT_GNU_STACK); 70 ECase(PT_GNU_RELRO); 71 ECase(PT_GNU_PROPERTY); 72 #undef ECase 73 IO.enumFallback<Hex32>(Value); 74 } 75 76 void ScalarEnumerationTraits<ELFYAML::ELF_NT>::enumeration( 77 IO &IO, ELFYAML::ELF_NT &Value) { 78 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 79 // Generic note types. 80 ECase(NT_VERSION); 81 ECase(NT_ARCH); 82 ECase(NT_GNU_BUILD_ATTRIBUTE_OPEN); 83 ECase(NT_GNU_BUILD_ATTRIBUTE_FUNC); 84 // Core note types. 85 ECase(NT_PRSTATUS); 86 ECase(NT_FPREGSET); 87 ECase(NT_PRPSINFO); 88 ECase(NT_TASKSTRUCT); 89 ECase(NT_AUXV); 90 ECase(NT_PSTATUS); 91 ECase(NT_FPREGS); 92 ECase(NT_PSINFO); 93 ECase(NT_LWPSTATUS); 94 ECase(NT_LWPSINFO); 95 ECase(NT_WIN32PSTATUS); 96 ECase(NT_PPC_VMX); 97 ECase(NT_PPC_VSX); 98 ECase(NT_PPC_TAR); 99 ECase(NT_PPC_PPR); 100 ECase(NT_PPC_DSCR); 101 ECase(NT_PPC_EBB); 102 ECase(NT_PPC_PMU); 103 ECase(NT_PPC_TM_CGPR); 104 ECase(NT_PPC_TM_CFPR); 105 ECase(NT_PPC_TM_CVMX); 106 ECase(NT_PPC_TM_CVSX); 107 ECase(NT_PPC_TM_SPR); 108 ECase(NT_PPC_TM_CTAR); 109 ECase(NT_PPC_TM_CPPR); 110 ECase(NT_PPC_TM_CDSCR); 111 ECase(NT_386_TLS); 112 ECase(NT_386_IOPERM); 113 ECase(NT_X86_XSTATE); 114 ECase(NT_S390_HIGH_GPRS); 115 ECase(NT_S390_TIMER); 116 ECase(NT_S390_TODCMP); 117 ECase(NT_S390_TODPREG); 118 ECase(NT_S390_CTRS); 119 ECase(NT_S390_PREFIX); 120 ECase(NT_S390_LAST_BREAK); 121 ECase(NT_S390_SYSTEM_CALL); 122 ECase(NT_S390_TDB); 123 ECase(NT_S390_VXRS_LOW); 124 ECase(NT_S390_VXRS_HIGH); 125 ECase(NT_S390_GS_CB); 126 ECase(NT_S390_GS_BC); 127 ECase(NT_ARM_VFP); 128 ECase(NT_ARM_TLS); 129 ECase(NT_ARM_HW_BREAK); 130 ECase(NT_ARM_HW_WATCH); 131 ECase(NT_ARM_SVE); 132 ECase(NT_ARM_PAC_MASK); 133 ECase(NT_FILE); 134 ECase(NT_PRXFPREG); 135 ECase(NT_SIGINFO); 136 // LLVM-specific notes. 137 ECase(NT_LLVM_HWASAN_GLOBALS); 138 // GNU note types 139 ECase(NT_GNU_ABI_TAG); 140 ECase(NT_GNU_HWCAP); 141 ECase(NT_GNU_BUILD_ID); 142 ECase(NT_GNU_GOLD_VERSION); 143 ECase(NT_GNU_PROPERTY_TYPE_0); 144 // FreeBSD note types. 145 ECase(NT_FREEBSD_ABI_TAG); 146 ECase(NT_FREEBSD_NOINIT_TAG); 147 ECase(NT_FREEBSD_ARCH_TAG); 148 ECase(NT_FREEBSD_FEATURE_CTL); 149 // FreeBSD core note types. 150 ECase(NT_FREEBSD_THRMISC); 151 ECase(NT_FREEBSD_PROCSTAT_PROC); 152 ECase(NT_FREEBSD_PROCSTAT_FILES); 153 ECase(NT_FREEBSD_PROCSTAT_VMMAP); 154 ECase(NT_FREEBSD_PROCSTAT_GROUPS); 155 ECase(NT_FREEBSD_PROCSTAT_UMASK); 156 ECase(NT_FREEBSD_PROCSTAT_RLIMIT); 157 ECase(NT_FREEBSD_PROCSTAT_OSREL); 158 ECase(NT_FREEBSD_PROCSTAT_PSSTRINGS); 159 ECase(NT_FREEBSD_PROCSTAT_AUXV); 160 // NetBSD core note types. 161 ECase(NT_NETBSDCORE_PROCINFO); 162 ECase(NT_NETBSDCORE_AUXV); 163 ECase(NT_NETBSDCORE_LWPSTATUS); 164 // OpenBSD core note types. 165 ECase(NT_OPENBSD_PROCINFO); 166 ECase(NT_OPENBSD_AUXV); 167 ECase(NT_OPENBSD_REGS); 168 ECase(NT_OPENBSD_FPREGS); 169 ECase(NT_OPENBSD_XFPREGS); 170 ECase(NT_OPENBSD_WCOOKIE); 171 // AMD specific notes. (Code Object V2) 172 ECase(NT_AMD_HSA_CODE_OBJECT_VERSION); 173 ECase(NT_AMD_HSA_HSAIL); 174 ECase(NT_AMD_HSA_ISA_VERSION); 175 ECase(NT_AMD_HSA_METADATA); 176 ECase(NT_AMD_HSA_ISA_NAME); 177 ECase(NT_AMD_PAL_METADATA); 178 // AMDGPU specific notes. (Code Object V3) 179 ECase(NT_AMDGPU_METADATA); 180 // Android specific notes. 181 ECase(NT_ANDROID_TYPE_IDENT); 182 ECase(NT_ANDROID_TYPE_KUSER); 183 ECase(NT_ANDROID_TYPE_MEMTAG); 184 #undef ECase 185 IO.enumFallback<Hex32>(Value); 186 } 187 188 void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration( 189 IO &IO, ELFYAML::ELF_EM &Value) { 190 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 191 ECase(EM_NONE); 192 ECase(EM_M32); 193 ECase(EM_SPARC); 194 ECase(EM_386); 195 ECase(EM_68K); 196 ECase(EM_88K); 197 ECase(EM_IAMCU); 198 ECase(EM_860); 199 ECase(EM_MIPS); 200 ECase(EM_S370); 201 ECase(EM_MIPS_RS3_LE); 202 ECase(EM_PARISC); 203 ECase(EM_VPP500); 204 ECase(EM_SPARC32PLUS); 205 ECase(EM_960); 206 ECase(EM_PPC); 207 ECase(EM_PPC64); 208 ECase(EM_S390); 209 ECase(EM_SPU); 210 ECase(EM_V800); 211 ECase(EM_FR20); 212 ECase(EM_RH32); 213 ECase(EM_RCE); 214 ECase(EM_ARM); 215 ECase(EM_ALPHA); 216 ECase(EM_SH); 217 ECase(EM_SPARCV9); 218 ECase(EM_TRICORE); 219 ECase(EM_ARC); 220 ECase(EM_H8_300); 221 ECase(EM_H8_300H); 222 ECase(EM_H8S); 223 ECase(EM_H8_500); 224 ECase(EM_IA_64); 225 ECase(EM_MIPS_X); 226 ECase(EM_COLDFIRE); 227 ECase(EM_68HC12); 228 ECase(EM_MMA); 229 ECase(EM_PCP); 230 ECase(EM_NCPU); 231 ECase(EM_NDR1); 232 ECase(EM_STARCORE); 233 ECase(EM_ME16); 234 ECase(EM_ST100); 235 ECase(EM_TINYJ); 236 ECase(EM_X86_64); 237 ECase(EM_PDSP); 238 ECase(EM_PDP10); 239 ECase(EM_PDP11); 240 ECase(EM_FX66); 241 ECase(EM_ST9PLUS); 242 ECase(EM_ST7); 243 ECase(EM_68HC16); 244 ECase(EM_68HC11); 245 ECase(EM_68HC08); 246 ECase(EM_68HC05); 247 ECase(EM_SVX); 248 ECase(EM_ST19); 249 ECase(EM_VAX); 250 ECase(EM_CRIS); 251 ECase(EM_JAVELIN); 252 ECase(EM_FIREPATH); 253 ECase(EM_ZSP); 254 ECase(EM_MMIX); 255 ECase(EM_HUANY); 256 ECase(EM_PRISM); 257 ECase(EM_AVR); 258 ECase(EM_FR30); 259 ECase(EM_D10V); 260 ECase(EM_D30V); 261 ECase(EM_V850); 262 ECase(EM_M32R); 263 ECase(EM_MN10300); 264 ECase(EM_MN10200); 265 ECase(EM_PJ); 266 ECase(EM_OPENRISC); 267 ECase(EM_ARC_COMPACT); 268 ECase(EM_XTENSA); 269 ECase(EM_VIDEOCORE); 270 ECase(EM_TMM_GPP); 271 ECase(EM_NS32K); 272 ECase(EM_TPC); 273 ECase(EM_SNP1K); 274 ECase(EM_ST200); 275 ECase(EM_IP2K); 276 ECase(EM_MAX); 277 ECase(EM_CR); 278 ECase(EM_F2MC16); 279 ECase(EM_MSP430); 280 ECase(EM_BLACKFIN); 281 ECase(EM_SE_C33); 282 ECase(EM_SEP); 283 ECase(EM_ARCA); 284 ECase(EM_UNICORE); 285 ECase(EM_EXCESS); 286 ECase(EM_DXP); 287 ECase(EM_ALTERA_NIOS2); 288 ECase(EM_CRX); 289 ECase(EM_XGATE); 290 ECase(EM_C166); 291 ECase(EM_M16C); 292 ECase(EM_DSPIC30F); 293 ECase(EM_CE); 294 ECase(EM_M32C); 295 ECase(EM_TSK3000); 296 ECase(EM_RS08); 297 ECase(EM_SHARC); 298 ECase(EM_ECOG2); 299 ECase(EM_SCORE7); 300 ECase(EM_DSP24); 301 ECase(EM_VIDEOCORE3); 302 ECase(EM_LATTICEMICO32); 303 ECase(EM_SE_C17); 304 ECase(EM_TI_C6000); 305 ECase(EM_TI_C2000); 306 ECase(EM_TI_C5500); 307 ECase(EM_MMDSP_PLUS); 308 ECase(EM_CYPRESS_M8C); 309 ECase(EM_R32C); 310 ECase(EM_TRIMEDIA); 311 ECase(EM_HEXAGON); 312 ECase(EM_8051); 313 ECase(EM_STXP7X); 314 ECase(EM_NDS32); 315 ECase(EM_ECOG1); 316 ECase(EM_ECOG1X); 317 ECase(EM_MAXQ30); 318 ECase(EM_XIMO16); 319 ECase(EM_MANIK); 320 ECase(EM_CRAYNV2); 321 ECase(EM_RX); 322 ECase(EM_METAG); 323 ECase(EM_MCST_ELBRUS); 324 ECase(EM_ECOG16); 325 ECase(EM_CR16); 326 ECase(EM_ETPU); 327 ECase(EM_SLE9X); 328 ECase(EM_L10M); 329 ECase(EM_K10M); 330 ECase(EM_AARCH64); 331 ECase(EM_AVR32); 332 ECase(EM_STM8); 333 ECase(EM_TILE64); 334 ECase(EM_TILEPRO); 335 ECase(EM_MICROBLAZE); 336 ECase(EM_CUDA); 337 ECase(EM_TILEGX); 338 ECase(EM_CLOUDSHIELD); 339 ECase(EM_COREA_1ST); 340 ECase(EM_COREA_2ND); 341 ECase(EM_ARC_COMPACT2); 342 ECase(EM_OPEN8); 343 ECase(EM_RL78); 344 ECase(EM_VIDEOCORE5); 345 ECase(EM_78KOR); 346 ECase(EM_56800EX); 347 ECase(EM_AMDGPU); 348 ECase(EM_RISCV); 349 ECase(EM_LANAI); 350 ECase(EM_BPF); 351 ECase(EM_VE); 352 ECase(EM_CSKY); 353 ECase(EM_LOONGARCH); 354 #undef ECase 355 IO.enumFallback<Hex16>(Value); 356 } 357 358 void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration( 359 IO &IO, ELFYAML::ELF_ELFCLASS &Value) { 360 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 361 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it 362 // here. 363 ECase(ELFCLASS32); 364 ECase(ELFCLASS64); 365 #undef ECase 366 } 367 368 void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration( 369 IO &IO, ELFYAML::ELF_ELFDATA &Value) { 370 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 371 // ELFDATANONE is an invalid data encoding, but we accept it because 372 // we want to be able to produce invalid binaries for the tests. 373 ECase(ELFDATANONE); 374 ECase(ELFDATA2LSB); 375 ECase(ELFDATA2MSB); 376 #undef ECase 377 } 378 379 void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration( 380 IO &IO, ELFYAML::ELF_ELFOSABI &Value) { 381 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 382 ECase(ELFOSABI_NONE); 383 ECase(ELFOSABI_HPUX); 384 ECase(ELFOSABI_NETBSD); 385 ECase(ELFOSABI_GNU); 386 ECase(ELFOSABI_LINUX); 387 ECase(ELFOSABI_HURD); 388 ECase(ELFOSABI_SOLARIS); 389 ECase(ELFOSABI_AIX); 390 ECase(ELFOSABI_IRIX); 391 ECase(ELFOSABI_FREEBSD); 392 ECase(ELFOSABI_TRU64); 393 ECase(ELFOSABI_MODESTO); 394 ECase(ELFOSABI_OPENBSD); 395 ECase(ELFOSABI_OPENVMS); 396 ECase(ELFOSABI_NSK); 397 ECase(ELFOSABI_AROS); 398 ECase(ELFOSABI_FENIXOS); 399 ECase(ELFOSABI_CLOUDABI); 400 ECase(ELFOSABI_AMDGPU_HSA); 401 ECase(ELFOSABI_AMDGPU_PAL); 402 ECase(ELFOSABI_AMDGPU_MESA3D); 403 ECase(ELFOSABI_ARM); 404 ECase(ELFOSABI_C6000_ELFABI); 405 ECase(ELFOSABI_C6000_LINUX); 406 ECase(ELFOSABI_STANDALONE); 407 #undef ECase 408 IO.enumFallback<Hex8>(Value); 409 } 410 411 void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO, 412 ELFYAML::ELF_EF &Value) { 413 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 414 assert(Object && "The IO context is not initialized"); 415 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 416 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M) 417 switch (Object->getMachine()) { 418 case ELF::EM_ARM: 419 BCase(EF_ARM_SOFT_FLOAT); 420 BCase(EF_ARM_VFP_FLOAT); 421 BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK); 422 BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK); 423 BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK); 424 BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK); 425 BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK); 426 BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK); 427 break; 428 case ELF::EM_MIPS: 429 BCase(EF_MIPS_NOREORDER); 430 BCase(EF_MIPS_PIC); 431 BCase(EF_MIPS_CPIC); 432 BCase(EF_MIPS_ABI2); 433 BCase(EF_MIPS_32BITMODE); 434 BCase(EF_MIPS_FP64); 435 BCase(EF_MIPS_NAN2008); 436 BCase(EF_MIPS_MICROMIPS); 437 BCase(EF_MIPS_ARCH_ASE_M16); 438 BCase(EF_MIPS_ARCH_ASE_MDMX); 439 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI); 440 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI); 441 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI); 442 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI); 443 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH); 444 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH); 445 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH); 446 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH); 447 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH); 448 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH); 449 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH); 450 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH); 451 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH); 452 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH); 453 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH); 454 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH); 455 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH); 456 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH); 457 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH); 458 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH); 459 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH); 460 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH); 461 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH); 462 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH); 463 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH); 464 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH); 465 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH); 466 BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH); 467 BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH); 468 BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH); 469 BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH); 470 BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH); 471 BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH); 472 break; 473 case ELF::EM_HEXAGON: 474 BCaseMask(EF_HEXAGON_MACH_V2, EF_HEXAGON_MACH); 475 BCaseMask(EF_HEXAGON_MACH_V3, EF_HEXAGON_MACH); 476 BCaseMask(EF_HEXAGON_MACH_V4, EF_HEXAGON_MACH); 477 BCaseMask(EF_HEXAGON_MACH_V5, EF_HEXAGON_MACH); 478 BCaseMask(EF_HEXAGON_MACH_V55, EF_HEXAGON_MACH); 479 BCaseMask(EF_HEXAGON_MACH_V60, EF_HEXAGON_MACH); 480 BCaseMask(EF_HEXAGON_MACH_V62, EF_HEXAGON_MACH); 481 BCaseMask(EF_HEXAGON_MACH_V65, EF_HEXAGON_MACH); 482 BCaseMask(EF_HEXAGON_MACH_V66, EF_HEXAGON_MACH); 483 BCaseMask(EF_HEXAGON_MACH_V67, EF_HEXAGON_MACH); 484 BCaseMask(EF_HEXAGON_MACH_V67T, EF_HEXAGON_MACH); 485 BCaseMask(EF_HEXAGON_MACH_V68, EF_HEXAGON_MACH); 486 BCaseMask(EF_HEXAGON_MACH_V69, EF_HEXAGON_MACH); 487 BCaseMask(EF_HEXAGON_ISA_V2, EF_HEXAGON_ISA); 488 BCaseMask(EF_HEXAGON_ISA_V3, EF_HEXAGON_ISA); 489 BCaseMask(EF_HEXAGON_ISA_V4, EF_HEXAGON_ISA); 490 BCaseMask(EF_HEXAGON_ISA_V5, EF_HEXAGON_ISA); 491 BCaseMask(EF_HEXAGON_ISA_V55, EF_HEXAGON_ISA); 492 BCaseMask(EF_HEXAGON_ISA_V60, EF_HEXAGON_ISA); 493 BCaseMask(EF_HEXAGON_ISA_V62, EF_HEXAGON_ISA); 494 BCaseMask(EF_HEXAGON_ISA_V65, EF_HEXAGON_ISA); 495 BCaseMask(EF_HEXAGON_ISA_V66, EF_HEXAGON_ISA); 496 BCaseMask(EF_HEXAGON_ISA_V67, EF_HEXAGON_ISA); 497 BCaseMask(EF_HEXAGON_ISA_V68, EF_HEXAGON_ISA); 498 BCaseMask(EF_HEXAGON_ISA_V69, EF_HEXAGON_ISA); 499 break; 500 case ELF::EM_AVR: 501 BCaseMask(EF_AVR_ARCH_AVR1, EF_AVR_ARCH_MASK); 502 BCaseMask(EF_AVR_ARCH_AVR2, EF_AVR_ARCH_MASK); 503 BCaseMask(EF_AVR_ARCH_AVR25, EF_AVR_ARCH_MASK); 504 BCaseMask(EF_AVR_ARCH_AVR3, EF_AVR_ARCH_MASK); 505 BCaseMask(EF_AVR_ARCH_AVR31, EF_AVR_ARCH_MASK); 506 BCaseMask(EF_AVR_ARCH_AVR35, EF_AVR_ARCH_MASK); 507 BCaseMask(EF_AVR_ARCH_AVR4, EF_AVR_ARCH_MASK); 508 BCaseMask(EF_AVR_ARCH_AVR5, EF_AVR_ARCH_MASK); 509 BCaseMask(EF_AVR_ARCH_AVR51, EF_AVR_ARCH_MASK); 510 BCaseMask(EF_AVR_ARCH_AVR6, EF_AVR_ARCH_MASK); 511 BCaseMask(EF_AVR_ARCH_AVRTINY, EF_AVR_ARCH_MASK); 512 BCaseMask(EF_AVR_ARCH_XMEGA1, EF_AVR_ARCH_MASK); 513 BCaseMask(EF_AVR_ARCH_XMEGA2, EF_AVR_ARCH_MASK); 514 BCaseMask(EF_AVR_ARCH_XMEGA3, EF_AVR_ARCH_MASK); 515 BCaseMask(EF_AVR_ARCH_XMEGA4, EF_AVR_ARCH_MASK); 516 BCaseMask(EF_AVR_ARCH_XMEGA5, EF_AVR_ARCH_MASK); 517 BCaseMask(EF_AVR_ARCH_XMEGA6, EF_AVR_ARCH_MASK); 518 BCaseMask(EF_AVR_ARCH_XMEGA7, EF_AVR_ARCH_MASK); 519 BCase(EF_AVR_LINKRELAX_PREPARED); 520 break; 521 case ELF::EM_RISCV: 522 BCase(EF_RISCV_RVC); 523 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT, EF_RISCV_FLOAT_ABI); 524 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE, EF_RISCV_FLOAT_ABI); 525 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_FLOAT_ABI); 526 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD, EF_RISCV_FLOAT_ABI); 527 BCase(EF_RISCV_RVE); 528 BCase(EF_RISCV_TSO); 529 break; 530 case ELF::EM_AMDGPU: 531 BCaseMask(EF_AMDGPU_MACH_NONE, EF_AMDGPU_MACH); 532 BCaseMask(EF_AMDGPU_MACH_R600_R600, EF_AMDGPU_MACH); 533 BCaseMask(EF_AMDGPU_MACH_R600_R630, EF_AMDGPU_MACH); 534 BCaseMask(EF_AMDGPU_MACH_R600_RS880, EF_AMDGPU_MACH); 535 BCaseMask(EF_AMDGPU_MACH_R600_RV670, EF_AMDGPU_MACH); 536 BCaseMask(EF_AMDGPU_MACH_R600_RV710, EF_AMDGPU_MACH); 537 BCaseMask(EF_AMDGPU_MACH_R600_RV730, EF_AMDGPU_MACH); 538 BCaseMask(EF_AMDGPU_MACH_R600_RV770, EF_AMDGPU_MACH); 539 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR, EF_AMDGPU_MACH); 540 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS, EF_AMDGPU_MACH); 541 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER, EF_AMDGPU_MACH); 542 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD, EF_AMDGPU_MACH); 543 BCaseMask(EF_AMDGPU_MACH_R600_SUMO, EF_AMDGPU_MACH); 544 BCaseMask(EF_AMDGPU_MACH_R600_BARTS, EF_AMDGPU_MACH); 545 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS, EF_AMDGPU_MACH); 546 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN, EF_AMDGPU_MACH); 547 BCaseMask(EF_AMDGPU_MACH_R600_TURKS, EF_AMDGPU_MACH); 548 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600, EF_AMDGPU_MACH); 549 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601, EF_AMDGPU_MACH); 550 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX602, EF_AMDGPU_MACH); 551 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700, EF_AMDGPU_MACH); 552 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701, EF_AMDGPU_MACH); 553 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702, EF_AMDGPU_MACH); 554 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703, EF_AMDGPU_MACH); 555 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704, EF_AMDGPU_MACH); 556 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX705, EF_AMDGPU_MACH); 557 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801, EF_AMDGPU_MACH); 558 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802, EF_AMDGPU_MACH); 559 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803, EF_AMDGPU_MACH); 560 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX805, EF_AMDGPU_MACH); 561 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810, EF_AMDGPU_MACH); 562 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900, EF_AMDGPU_MACH); 563 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902, EF_AMDGPU_MACH); 564 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904, EF_AMDGPU_MACH); 565 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906, EF_AMDGPU_MACH); 566 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908, EF_AMDGPU_MACH); 567 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909, EF_AMDGPU_MACH); 568 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90A, EF_AMDGPU_MACH); 569 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90C, EF_AMDGPU_MACH); 570 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX940, EF_AMDGPU_MACH); 571 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010, EF_AMDGPU_MACH); 572 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011, EF_AMDGPU_MACH); 573 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012, EF_AMDGPU_MACH); 574 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1013, EF_AMDGPU_MACH); 575 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1030, EF_AMDGPU_MACH); 576 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1031, EF_AMDGPU_MACH); 577 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1032, EF_AMDGPU_MACH); 578 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1033, EF_AMDGPU_MACH); 579 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1034, EF_AMDGPU_MACH); 580 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1035, EF_AMDGPU_MACH); 581 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1036, EF_AMDGPU_MACH); 582 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1100, EF_AMDGPU_MACH); 583 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1101, EF_AMDGPU_MACH); 584 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1102, EF_AMDGPU_MACH); 585 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1103, EF_AMDGPU_MACH); 586 switch (Object->Header.ABIVersion) { 587 default: 588 // ELFOSABI_AMDGPU_PAL, ELFOSABI_AMDGPU_MESA3D support *_V3 flags. 589 LLVM_FALLTHROUGH; 590 case ELF::ELFABIVERSION_AMDGPU_HSA_V3: 591 BCase(EF_AMDGPU_FEATURE_XNACK_V3); 592 BCase(EF_AMDGPU_FEATURE_SRAMECC_V3); 593 break; 594 case ELF::ELFABIVERSION_AMDGPU_HSA_V4: 595 case ELF::ELFABIVERSION_AMDGPU_HSA_V5: 596 BCaseMask(EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4, 597 EF_AMDGPU_FEATURE_XNACK_V4); 598 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ANY_V4, 599 EF_AMDGPU_FEATURE_XNACK_V4); 600 BCaseMask(EF_AMDGPU_FEATURE_XNACK_OFF_V4, 601 EF_AMDGPU_FEATURE_XNACK_V4); 602 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ON_V4, 603 EF_AMDGPU_FEATURE_XNACK_V4); 604 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4, 605 EF_AMDGPU_FEATURE_SRAMECC_V4); 606 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ANY_V4, 607 EF_AMDGPU_FEATURE_SRAMECC_V4); 608 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_OFF_V4, 609 EF_AMDGPU_FEATURE_SRAMECC_V4); 610 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ON_V4, 611 EF_AMDGPU_FEATURE_SRAMECC_V4); 612 break; 613 } 614 break; 615 default: 616 break; 617 } 618 #undef BCase 619 #undef BCaseMask 620 } 621 622 void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration( 623 IO &IO, ELFYAML::ELF_SHT &Value) { 624 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 625 assert(Object && "The IO context is not initialized"); 626 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 627 ECase(SHT_NULL); 628 ECase(SHT_PROGBITS); 629 ECase(SHT_SYMTAB); 630 // FIXME: Issue a diagnostic with this information. 631 ECase(SHT_STRTAB); 632 ECase(SHT_RELA); 633 ECase(SHT_HASH); 634 ECase(SHT_DYNAMIC); 635 ECase(SHT_NOTE); 636 ECase(SHT_NOBITS); 637 ECase(SHT_REL); 638 ECase(SHT_SHLIB); 639 ECase(SHT_DYNSYM); 640 ECase(SHT_INIT_ARRAY); 641 ECase(SHT_FINI_ARRAY); 642 ECase(SHT_PREINIT_ARRAY); 643 ECase(SHT_GROUP); 644 ECase(SHT_SYMTAB_SHNDX); 645 ECase(SHT_RELR); 646 ECase(SHT_ANDROID_REL); 647 ECase(SHT_ANDROID_RELA); 648 ECase(SHT_ANDROID_RELR); 649 ECase(SHT_LLVM_ODRTAB); 650 ECase(SHT_LLVM_LINKER_OPTIONS); 651 ECase(SHT_LLVM_CALL_GRAPH_PROFILE); 652 ECase(SHT_LLVM_ADDRSIG); 653 ECase(SHT_LLVM_DEPENDENT_LIBRARIES); 654 ECase(SHT_LLVM_SYMPART); 655 ECase(SHT_LLVM_PART_EHDR); 656 ECase(SHT_LLVM_PART_PHDR); 657 ECase(SHT_LLVM_BB_ADDR_MAP_V0); 658 ECase(SHT_LLVM_BB_ADDR_MAP); 659 ECase(SHT_LLVM_OFFLOADING); 660 ECase(SHT_GNU_ATTRIBUTES); 661 ECase(SHT_GNU_HASH); 662 ECase(SHT_GNU_verdef); 663 ECase(SHT_GNU_verneed); 664 ECase(SHT_GNU_versym); 665 switch (Object->getMachine()) { 666 case ELF::EM_ARM: 667 ECase(SHT_ARM_EXIDX); 668 ECase(SHT_ARM_PREEMPTMAP); 669 ECase(SHT_ARM_ATTRIBUTES); 670 ECase(SHT_ARM_DEBUGOVERLAY); 671 ECase(SHT_ARM_OVERLAYSECTION); 672 break; 673 case ELF::EM_HEXAGON: 674 ECase(SHT_HEX_ORDERED); 675 break; 676 case ELF::EM_X86_64: 677 ECase(SHT_X86_64_UNWIND); 678 break; 679 case ELF::EM_MIPS: 680 ECase(SHT_MIPS_REGINFO); 681 ECase(SHT_MIPS_OPTIONS); 682 ECase(SHT_MIPS_DWARF); 683 ECase(SHT_MIPS_ABIFLAGS); 684 break; 685 case ELF::EM_RISCV: 686 ECase(SHT_RISCV_ATTRIBUTES); 687 break; 688 case ELF::EM_MSP430: 689 ECase(SHT_MSP430_ATTRIBUTES); 690 break; 691 default: 692 // Nothing to do. 693 break; 694 } 695 #undef ECase 696 IO.enumFallback<Hex32>(Value); 697 } 698 699 void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO, 700 ELFYAML::ELF_PF &Value) { 701 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 702 BCase(PF_X); 703 BCase(PF_W); 704 BCase(PF_R); 705 } 706 707 void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO, 708 ELFYAML::ELF_SHF &Value) { 709 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 710 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 711 BCase(SHF_WRITE); 712 BCase(SHF_ALLOC); 713 BCase(SHF_EXCLUDE); 714 BCase(SHF_EXECINSTR); 715 BCase(SHF_MERGE); 716 BCase(SHF_STRINGS); 717 BCase(SHF_INFO_LINK); 718 BCase(SHF_LINK_ORDER); 719 BCase(SHF_OS_NONCONFORMING); 720 BCase(SHF_GROUP); 721 BCase(SHF_TLS); 722 BCase(SHF_COMPRESSED); 723 switch (Object->getOSAbi()) { 724 case ELF::ELFOSABI_SOLARIS: 725 BCase(SHF_SUNW_NODISCARD); 726 break; 727 default: 728 BCase(SHF_GNU_RETAIN); 729 break; 730 } 731 switch (Object->getMachine()) { 732 case ELF::EM_ARM: 733 BCase(SHF_ARM_PURECODE); 734 break; 735 case ELF::EM_HEXAGON: 736 BCase(SHF_HEX_GPREL); 737 break; 738 case ELF::EM_MIPS: 739 BCase(SHF_MIPS_NODUPES); 740 BCase(SHF_MIPS_NAMES); 741 BCase(SHF_MIPS_LOCAL); 742 BCase(SHF_MIPS_NOSTRIP); 743 BCase(SHF_MIPS_GPREL); 744 BCase(SHF_MIPS_MERGE); 745 BCase(SHF_MIPS_ADDR); 746 BCase(SHF_MIPS_STRING); 747 break; 748 case ELF::EM_X86_64: 749 BCase(SHF_X86_64_LARGE); 750 break; 751 default: 752 // Nothing to do. 753 break; 754 } 755 #undef BCase 756 } 757 758 void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration( 759 IO &IO, ELFYAML::ELF_SHN &Value) { 760 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 761 assert(Object && "The IO context is not initialized"); 762 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 763 ECase(SHN_UNDEF); 764 ECase(SHN_LORESERVE); 765 ECase(SHN_LOPROC); 766 ECase(SHN_HIPROC); 767 ECase(SHN_LOOS); 768 ECase(SHN_HIOS); 769 ECase(SHN_ABS); 770 ECase(SHN_COMMON); 771 ECase(SHN_XINDEX); 772 ECase(SHN_HIRESERVE); 773 ECase(SHN_AMDGPU_LDS); 774 775 if (!IO.outputting() || Object->getMachine() == ELF::EM_MIPS) { 776 ECase(SHN_MIPS_ACOMMON); 777 ECase(SHN_MIPS_TEXT); 778 ECase(SHN_MIPS_DATA); 779 ECase(SHN_MIPS_SCOMMON); 780 ECase(SHN_MIPS_SUNDEFINED); 781 } 782 783 ECase(SHN_HEXAGON_SCOMMON); 784 ECase(SHN_HEXAGON_SCOMMON_1); 785 ECase(SHN_HEXAGON_SCOMMON_2); 786 ECase(SHN_HEXAGON_SCOMMON_4); 787 ECase(SHN_HEXAGON_SCOMMON_8); 788 #undef ECase 789 IO.enumFallback<Hex16>(Value); 790 } 791 792 void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration( 793 IO &IO, ELFYAML::ELF_STB &Value) { 794 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 795 ECase(STB_LOCAL); 796 ECase(STB_GLOBAL); 797 ECase(STB_WEAK); 798 ECase(STB_GNU_UNIQUE); 799 #undef ECase 800 IO.enumFallback<Hex8>(Value); 801 } 802 803 void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration( 804 IO &IO, ELFYAML::ELF_STT &Value) { 805 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 806 ECase(STT_NOTYPE); 807 ECase(STT_OBJECT); 808 ECase(STT_FUNC); 809 ECase(STT_SECTION); 810 ECase(STT_FILE); 811 ECase(STT_COMMON); 812 ECase(STT_TLS); 813 ECase(STT_GNU_IFUNC); 814 #undef ECase 815 IO.enumFallback<Hex8>(Value); 816 } 817 818 819 void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration( 820 IO &IO, ELFYAML::ELF_RSS &Value) { 821 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 822 ECase(RSS_UNDEF); 823 ECase(RSS_GP); 824 ECase(RSS_GP0); 825 ECase(RSS_LOC); 826 #undef ECase 827 } 828 829 void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration( 830 IO &IO, ELFYAML::ELF_REL &Value) { 831 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 832 assert(Object && "The IO context is not initialized"); 833 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X); 834 switch (Object->getMachine()) { 835 case ELF::EM_X86_64: 836 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def" 837 break; 838 case ELF::EM_MIPS: 839 #include "llvm/BinaryFormat/ELFRelocs/Mips.def" 840 break; 841 case ELF::EM_HEXAGON: 842 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def" 843 break; 844 case ELF::EM_386: 845 case ELF::EM_IAMCU: 846 #include "llvm/BinaryFormat/ELFRelocs/i386.def" 847 break; 848 case ELF::EM_AARCH64: 849 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def" 850 break; 851 case ELF::EM_ARM: 852 #include "llvm/BinaryFormat/ELFRelocs/ARM.def" 853 break; 854 case ELF::EM_ARC: 855 #include "llvm/BinaryFormat/ELFRelocs/ARC.def" 856 break; 857 case ELF::EM_RISCV: 858 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def" 859 break; 860 case ELF::EM_LANAI: 861 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def" 862 break; 863 case ELF::EM_AMDGPU: 864 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def" 865 break; 866 case ELF::EM_BPF: 867 #include "llvm/BinaryFormat/ELFRelocs/BPF.def" 868 break; 869 case ELF::EM_VE: 870 #include "llvm/BinaryFormat/ELFRelocs/VE.def" 871 break; 872 case ELF::EM_CSKY: 873 #include "llvm/BinaryFormat/ELFRelocs/CSKY.def" 874 break; 875 case ELF::EM_PPC: 876 #include "llvm/BinaryFormat/ELFRelocs/PowerPC.def" 877 break; 878 case ELF::EM_PPC64: 879 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def" 880 break; 881 case ELF::EM_68K: 882 #include "llvm/BinaryFormat/ELFRelocs/M68k.def" 883 break; 884 case ELF::EM_LOONGARCH: 885 #include "llvm/BinaryFormat/ELFRelocs/LoongArch.def" 886 break; 887 default: 888 // Nothing to do. 889 break; 890 } 891 #undef ELF_RELOC 892 IO.enumFallback<Hex32>(Value); 893 } 894 895 void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration( 896 IO &IO, ELFYAML::ELF_DYNTAG &Value) { 897 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 898 assert(Object && "The IO context is not initialized"); 899 900 // Disable architecture specific tags by default. We might enable them below. 901 #define AARCH64_DYNAMIC_TAG(name, value) 902 #define MIPS_DYNAMIC_TAG(name, value) 903 #define HEXAGON_DYNAMIC_TAG(name, value) 904 #define PPC_DYNAMIC_TAG(name, value) 905 #define PPC64_DYNAMIC_TAG(name, value) 906 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc. 907 #define DYNAMIC_TAG_MARKER(name, value) 908 909 #define STRINGIFY(X) (#X) 910 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X); 911 switch (Object->getMachine()) { 912 case ELF::EM_AARCH64: 913 #undef AARCH64_DYNAMIC_TAG 914 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 915 #include "llvm/BinaryFormat/DynamicTags.def" 916 #undef AARCH64_DYNAMIC_TAG 917 #define AARCH64_DYNAMIC_TAG(name, value) 918 break; 919 case ELF::EM_MIPS: 920 #undef MIPS_DYNAMIC_TAG 921 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 922 #include "llvm/BinaryFormat/DynamicTags.def" 923 #undef MIPS_DYNAMIC_TAG 924 #define MIPS_DYNAMIC_TAG(name, value) 925 break; 926 case ELF::EM_HEXAGON: 927 #undef HEXAGON_DYNAMIC_TAG 928 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 929 #include "llvm/BinaryFormat/DynamicTags.def" 930 #undef HEXAGON_DYNAMIC_TAG 931 #define HEXAGON_DYNAMIC_TAG(name, value) 932 break; 933 case ELF::EM_PPC: 934 #undef PPC_DYNAMIC_TAG 935 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 936 #include "llvm/BinaryFormat/DynamicTags.def" 937 #undef PPC_DYNAMIC_TAG 938 #define PPC_DYNAMIC_TAG(name, value) 939 break; 940 case ELF::EM_PPC64: 941 #undef PPC64_DYNAMIC_TAG 942 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 943 #include "llvm/BinaryFormat/DynamicTags.def" 944 #undef PPC64_DYNAMIC_TAG 945 #define PPC64_DYNAMIC_TAG(name, value) 946 break; 947 case ELF::EM_RISCV: 948 #undef RISCV_DYNAMIC_TAG 949 #define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 950 #include "llvm/BinaryFormat/DynamicTags.def" 951 #undef RISCV_DYNAMIC_TAG 952 #define RISCV_DYNAMIC_TAG(name, value) 953 break; 954 default: 955 #include "llvm/BinaryFormat/DynamicTags.def" 956 break; 957 } 958 #undef AARCH64_DYNAMIC_TAG 959 #undef MIPS_DYNAMIC_TAG 960 #undef HEXAGON_DYNAMIC_TAG 961 #undef PPC_DYNAMIC_TAG 962 #undef PPC64_DYNAMIC_TAG 963 #undef DYNAMIC_TAG_MARKER 964 #undef STRINGIFY 965 #undef DYNAMIC_TAG 966 967 IO.enumFallback<Hex64>(Value); 968 } 969 970 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration( 971 IO &IO, ELFYAML::MIPS_AFL_REG &Value) { 972 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X) 973 ECase(REG_NONE); 974 ECase(REG_32); 975 ECase(REG_64); 976 ECase(REG_128); 977 #undef ECase 978 } 979 980 void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration( 981 IO &IO, ELFYAML::MIPS_ABI_FP &Value) { 982 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X) 983 ECase(FP_ANY); 984 ECase(FP_DOUBLE); 985 ECase(FP_SINGLE); 986 ECase(FP_SOFT); 987 ECase(FP_OLD_64); 988 ECase(FP_XX); 989 ECase(FP_64); 990 ECase(FP_64A); 991 #undef ECase 992 } 993 994 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration( 995 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) { 996 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X) 997 ECase(EXT_NONE); 998 ECase(EXT_XLR); 999 ECase(EXT_OCTEON2); 1000 ECase(EXT_OCTEONP); 1001 ECase(EXT_LOONGSON_3A); 1002 ECase(EXT_OCTEON); 1003 ECase(EXT_5900); 1004 ECase(EXT_4650); 1005 ECase(EXT_4010); 1006 ECase(EXT_4100); 1007 ECase(EXT_3900); 1008 ECase(EXT_10000); 1009 ECase(EXT_SB1); 1010 ECase(EXT_4111); 1011 ECase(EXT_4120); 1012 ECase(EXT_5400); 1013 ECase(EXT_5500); 1014 ECase(EXT_LOONGSON_2E); 1015 ECase(EXT_LOONGSON_2F); 1016 ECase(EXT_OCTEON3); 1017 #undef ECase 1018 } 1019 1020 void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration( 1021 IO &IO, ELFYAML::MIPS_ISA &Value) { 1022 IO.enumCase(Value, "MIPS1", 1); 1023 IO.enumCase(Value, "MIPS2", 2); 1024 IO.enumCase(Value, "MIPS3", 3); 1025 IO.enumCase(Value, "MIPS4", 4); 1026 IO.enumCase(Value, "MIPS5", 5); 1027 IO.enumCase(Value, "MIPS32", 32); 1028 IO.enumCase(Value, "MIPS64", 64); 1029 IO.enumFallback<Hex32>(Value); 1030 } 1031 1032 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset( 1033 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) { 1034 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X) 1035 BCase(DSP); 1036 BCase(DSPR2); 1037 BCase(EVA); 1038 BCase(MCU); 1039 BCase(MDMX); 1040 BCase(MIPS3D); 1041 BCase(MT); 1042 BCase(SMARTMIPS); 1043 BCase(VIRT); 1044 BCase(MSA); 1045 BCase(MIPS16); 1046 BCase(MICROMIPS); 1047 BCase(XPA); 1048 BCase(CRC); 1049 BCase(GINV); 1050 #undef BCase 1051 } 1052 1053 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset( 1054 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) { 1055 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X) 1056 BCase(ODDSPREG); 1057 #undef BCase 1058 } 1059 1060 void MappingTraits<ELFYAML::SectionHeader>::mapping( 1061 IO &IO, ELFYAML::SectionHeader &SHdr) { 1062 IO.mapRequired("Name", SHdr.Name); 1063 } 1064 1065 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO, 1066 ELFYAML::FileHeader &FileHdr) { 1067 IO.mapRequired("Class", FileHdr.Class); 1068 IO.mapRequired("Data", FileHdr.Data); 1069 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0)); 1070 IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0)); 1071 IO.mapRequired("Type", FileHdr.Type); 1072 IO.mapOptional("Machine", FileHdr.Machine); 1073 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0)); 1074 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0)); 1075 IO.mapOptional("SectionHeaderStringTable", FileHdr.SectionHeaderStringTable); 1076 1077 // obj2yaml does not dump these fields. 1078 assert(!IO.outputting() || 1079 (!FileHdr.EPhOff && !FileHdr.EPhEntSize && !FileHdr.EPhNum)); 1080 IO.mapOptional("EPhOff", FileHdr.EPhOff); 1081 IO.mapOptional("EPhEntSize", FileHdr.EPhEntSize); 1082 IO.mapOptional("EPhNum", FileHdr.EPhNum); 1083 IO.mapOptional("EShEntSize", FileHdr.EShEntSize); 1084 IO.mapOptional("EShOff", FileHdr.EShOff); 1085 IO.mapOptional("EShNum", FileHdr.EShNum); 1086 IO.mapOptional("EShStrNdx", FileHdr.EShStrNdx); 1087 } 1088 1089 void MappingTraits<ELFYAML::ProgramHeader>::mapping( 1090 IO &IO, ELFYAML::ProgramHeader &Phdr) { 1091 IO.mapRequired("Type", Phdr.Type); 1092 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0)); 1093 IO.mapOptional("FirstSec", Phdr.FirstSec); 1094 IO.mapOptional("LastSec", Phdr.LastSec); 1095 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0)); 1096 IO.mapOptional("PAddr", Phdr.PAddr, Phdr.VAddr); 1097 IO.mapOptional("Align", Phdr.Align); 1098 IO.mapOptional("FileSize", Phdr.FileSize); 1099 IO.mapOptional("MemSize", Phdr.MemSize); 1100 IO.mapOptional("Offset", Phdr.Offset); 1101 } 1102 1103 std::string MappingTraits<ELFYAML::ProgramHeader>::validate( 1104 IO &IO, ELFYAML::ProgramHeader &FileHdr) { 1105 if (!FileHdr.FirstSec && FileHdr.LastSec) 1106 return "the \"LastSec\" key can't be used without the \"FirstSec\" key"; 1107 if (FileHdr.FirstSec && !FileHdr.LastSec) 1108 return "the \"FirstSec\" key can't be used without the \"LastSec\" key"; 1109 return ""; 1110 } 1111 1112 LLVM_YAML_STRONG_TYPEDEF(StringRef, StOtherPiece) 1113 1114 template <> struct ScalarTraits<StOtherPiece> { 1115 static void output(const StOtherPiece &Val, void *, raw_ostream &Out) { 1116 Out << Val; 1117 } 1118 static StringRef input(StringRef Scalar, void *, StOtherPiece &Val) { 1119 Val = Scalar; 1120 return {}; 1121 } 1122 static QuotingType mustQuote(StringRef) { return QuotingType::None; } 1123 }; 1124 template <> struct SequenceElementTraits<StOtherPiece> { 1125 static const bool flow = true; 1126 }; 1127 1128 template <> struct ScalarTraits<ELFYAML::YAMLFlowString> { 1129 static void output(const ELFYAML::YAMLFlowString &Val, void *, 1130 raw_ostream &Out) { 1131 Out << Val; 1132 } 1133 static StringRef input(StringRef Scalar, void *, 1134 ELFYAML::YAMLFlowString &Val) { 1135 Val = Scalar; 1136 return {}; 1137 } 1138 static QuotingType mustQuote(StringRef S) { 1139 return ScalarTraits<StringRef>::mustQuote(S); 1140 } 1141 }; 1142 template <> struct SequenceElementTraits<ELFYAML::YAMLFlowString> { 1143 static const bool flow = true; 1144 }; 1145 1146 namespace { 1147 1148 struct NormalizedOther { 1149 NormalizedOther(IO &IO) : YamlIO(IO) {} 1150 NormalizedOther(IO &IO, Optional<uint8_t> Original) : YamlIO(IO) { 1151 assert(Original && "This constructor is only used for outputting YAML and " 1152 "assumes a non-empty Original"); 1153 std::vector<StOtherPiece> Ret; 1154 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext()); 1155 for (std::pair<StringRef, uint8_t> &P : 1156 getFlags(Object->getMachine()).takeVector()) { 1157 uint8_t FlagValue = P.second; 1158 if ((*Original & FlagValue) != FlagValue) 1159 continue; 1160 *Original &= ~FlagValue; 1161 Ret.push_back({P.first}); 1162 } 1163 1164 if (*Original != 0) { 1165 UnknownFlagsHolder = std::to_string(*Original); 1166 Ret.push_back({UnknownFlagsHolder}); 1167 } 1168 1169 if (!Ret.empty()) 1170 Other = std::move(Ret); 1171 } 1172 1173 uint8_t toValue(StringRef Name) { 1174 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext()); 1175 MapVector<StringRef, uint8_t> Flags = getFlags(Object->getMachine()); 1176 1177 auto It = Flags.find(Name); 1178 if (It != Flags.end()) 1179 return It->second; 1180 1181 uint8_t Val; 1182 if (to_integer(Name, Val)) 1183 return Val; 1184 1185 YamlIO.setError("an unknown value is used for symbol's 'Other' field: " + 1186 Name); 1187 return 0; 1188 } 1189 1190 Optional<uint8_t> denormalize(IO &) { 1191 if (!Other) 1192 return None; 1193 uint8_t Ret = 0; 1194 for (StOtherPiece &Val : *Other) 1195 Ret |= toValue(Val); 1196 return Ret; 1197 } 1198 1199 // st_other field is used to encode symbol visibility and platform-dependent 1200 // flags and values. This method returns a name to value map that is used for 1201 // parsing and encoding this field. 1202 MapVector<StringRef, uint8_t> getFlags(unsigned EMachine) { 1203 MapVector<StringRef, uint8_t> Map; 1204 // STV_* values are just enumeration values. We add them in a reversed order 1205 // because when we convert the st_other to named constants when printing 1206 // YAML we want to use a maximum number of bits on each step: 1207 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but 1208 // not as STV_HIDDEN (2) + STV_INTERNAL (1). 1209 Map["STV_PROTECTED"] = ELF::STV_PROTECTED; 1210 Map["STV_HIDDEN"] = ELF::STV_HIDDEN; 1211 Map["STV_INTERNAL"] = ELF::STV_INTERNAL; 1212 // STV_DEFAULT is used to represent the default visibility and has a value 1213 // 0. We want to be able to read it from YAML documents, but there is no 1214 // reason to print it. 1215 if (!YamlIO.outputting()) 1216 Map["STV_DEFAULT"] = ELF::STV_DEFAULT; 1217 1218 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags, 1219 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and 1220 // consumed first when we print the output, because we do not want to print 1221 // any other flags that have the same bits instead. 1222 if (EMachine == ELF::EM_MIPS) { 1223 Map["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16; 1224 Map["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS; 1225 Map["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC; 1226 Map["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT; 1227 Map["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL; 1228 } 1229 1230 if (EMachine == ELF::EM_AARCH64) 1231 Map["STO_AARCH64_VARIANT_PCS"] = ELF::STO_AARCH64_VARIANT_PCS; 1232 if (EMachine == ELF::EM_RISCV) 1233 Map["STO_RISCV_VARIANT_CC"] = ELF::STO_RISCV_VARIANT_CC; 1234 return Map; 1235 } 1236 1237 IO &YamlIO; 1238 Optional<std::vector<StOtherPiece>> Other; 1239 std::string UnknownFlagsHolder; 1240 }; 1241 1242 } // end anonymous namespace 1243 1244 void ScalarTraits<ELFYAML::YAMLIntUInt>::output(const ELFYAML::YAMLIntUInt &Val, 1245 void *Ctx, raw_ostream &Out) { 1246 Out << Val; 1247 } 1248 1249 StringRef ScalarTraits<ELFYAML::YAMLIntUInt>::input(StringRef Scalar, void *Ctx, 1250 ELFYAML::YAMLIntUInt &Val) { 1251 const bool Is64 = static_cast<ELFYAML::Object *>(Ctx)->Header.Class == 1252 ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64); 1253 StringRef ErrMsg = "invalid number"; 1254 // We do not accept negative hex numbers because their meaning is ambiguous. 1255 // For example, would -0xfffffffff mean 1 or INT32_MIN? 1256 if (Scalar.empty() || Scalar.startswith("-0x")) 1257 return ErrMsg; 1258 1259 if (Scalar.startswith("-")) { 1260 const int64_t MinVal = Is64 ? INT64_MIN : INT32_MIN; 1261 long long Int; 1262 if (getAsSignedInteger(Scalar, /*Radix=*/0, Int) || (Int < MinVal)) 1263 return ErrMsg; 1264 Val = Int; 1265 return ""; 1266 } 1267 1268 const uint64_t MaxVal = Is64 ? UINT64_MAX : UINT32_MAX; 1269 unsigned long long UInt; 1270 if (getAsUnsignedInteger(Scalar, /*Radix=*/0, UInt) || (UInt > MaxVal)) 1271 return ErrMsg; 1272 Val = UInt; 1273 return ""; 1274 } 1275 1276 void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) { 1277 IO.mapOptional("Name", Symbol.Name, StringRef()); 1278 IO.mapOptional("StName", Symbol.StName); 1279 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0)); 1280 IO.mapOptional("Section", Symbol.Section); 1281 IO.mapOptional("Index", Symbol.Index); 1282 IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0)); 1283 IO.mapOptional("Value", Symbol.Value); 1284 IO.mapOptional("Size", Symbol.Size); 1285 1286 // Symbol's Other field is a bit special. It is usually a field that 1287 // represents st_other and holds the symbol visibility. However, on some 1288 // platforms, it can contain bit fields and regular values, or even sometimes a 1289 // crazy mix of them (see comments for NormalizedOther). Because of this, we 1290 // need special handling. 1291 MappingNormalization<NormalizedOther, Optional<uint8_t>> Keys(IO, 1292 Symbol.Other); 1293 IO.mapOptional("Other", Keys->Other); 1294 } 1295 1296 std::string MappingTraits<ELFYAML::Symbol>::validate(IO &IO, 1297 ELFYAML::Symbol &Symbol) { 1298 if (Symbol.Index && Symbol.Section) 1299 return "Index and Section cannot both be specified for Symbol"; 1300 return ""; 1301 } 1302 1303 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) { 1304 IO.mapOptional("Name", Section.Name, StringRef()); 1305 IO.mapRequired("Type", Section.Type); 1306 IO.mapOptional("Flags", Section.Flags); 1307 IO.mapOptional("Address", Section.Address); 1308 IO.mapOptional("Link", Section.Link); 1309 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); 1310 IO.mapOptional("EntSize", Section.EntSize); 1311 IO.mapOptional("Offset", Section.Offset); 1312 1313 IO.mapOptional("Content", Section.Content); 1314 IO.mapOptional("Size", Section.Size); 1315 1316 // obj2yaml does not dump these fields. They are expected to be empty when we 1317 // are producing YAML, because yaml2obj sets appropriate values for them 1318 // automatically when they are not explicitly defined. 1319 assert(!IO.outputting() || 1320 (!Section.ShOffset && !Section.ShSize && !Section.ShName && 1321 !Section.ShFlags && !Section.ShType && !Section.ShAddrAlign)); 1322 IO.mapOptional("ShAddrAlign", Section.ShAddrAlign); 1323 IO.mapOptional("ShName", Section.ShName); 1324 IO.mapOptional("ShOffset", Section.ShOffset); 1325 IO.mapOptional("ShSize", Section.ShSize); 1326 IO.mapOptional("ShFlags", Section.ShFlags); 1327 IO.mapOptional("ShType", Section.ShType); 1328 } 1329 1330 static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) { 1331 commonSectionMapping(IO, Section); 1332 IO.mapOptional("Entries", Section.Entries); 1333 } 1334 1335 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { 1336 commonSectionMapping(IO, Section); 1337 1338 // We also support reading a content as array of bytes using the ContentArray 1339 // key. obj2yaml never prints this field. 1340 assert(!IO.outputting() || !Section.ContentBuf); 1341 IO.mapOptional("ContentArray", Section.ContentBuf); 1342 if (Section.ContentBuf) { 1343 if (Section.Content) 1344 IO.setError("Content and ContentArray can't be used together"); 1345 Section.Content = yaml::BinaryRef(*Section.ContentBuf); 1346 } 1347 1348 IO.mapOptional("Info", Section.Info); 1349 } 1350 1351 static void sectionMapping(IO &IO, ELFYAML::BBAddrMapSection &Section) { 1352 commonSectionMapping(IO, Section); 1353 IO.mapOptional("Content", Section.Content); 1354 IO.mapOptional("Entries", Section.Entries); 1355 } 1356 1357 static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) { 1358 commonSectionMapping(IO, Section); 1359 IO.mapOptional("Entries", Section.Entries); 1360 } 1361 1362 static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) { 1363 commonSectionMapping(IO, Section); 1364 IO.mapOptional("Bucket", Section.Bucket); 1365 IO.mapOptional("Chain", Section.Chain); 1366 1367 // obj2yaml does not dump these fields. They can be used to override nchain 1368 // and nbucket values for creating broken sections. 1369 assert(!IO.outputting() || (!Section.NBucket && !Section.NChain)); 1370 IO.mapOptional("NChain", Section.NChain); 1371 IO.mapOptional("NBucket", Section.NBucket); 1372 } 1373 1374 static void sectionMapping(IO &IO, ELFYAML::NoteSection &Section) { 1375 commonSectionMapping(IO, Section); 1376 IO.mapOptional("Notes", Section.Notes); 1377 } 1378 1379 1380 static void sectionMapping(IO &IO, ELFYAML::GnuHashSection &Section) { 1381 commonSectionMapping(IO, Section); 1382 IO.mapOptional("Header", Section.Header); 1383 IO.mapOptional("BloomFilter", Section.BloomFilter); 1384 IO.mapOptional("HashBuckets", Section.HashBuckets); 1385 IO.mapOptional("HashValues", Section.HashValues); 1386 } 1387 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) { 1388 commonSectionMapping(IO, Section); 1389 } 1390 1391 static void sectionMapping(IO &IO, ELFYAML::VerdefSection &Section) { 1392 commonSectionMapping(IO, Section); 1393 IO.mapOptional("Info", Section.Info); 1394 IO.mapOptional("Entries", Section.Entries); 1395 } 1396 1397 static void sectionMapping(IO &IO, ELFYAML::SymverSection &Section) { 1398 commonSectionMapping(IO, Section); 1399 IO.mapOptional("Entries", Section.Entries); 1400 } 1401 1402 static void sectionMapping(IO &IO, ELFYAML::VerneedSection &Section) { 1403 commonSectionMapping(IO, Section); 1404 IO.mapOptional("Info", Section.Info); 1405 IO.mapOptional("Dependencies", Section.VerneedV); 1406 } 1407 1408 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) { 1409 commonSectionMapping(IO, Section); 1410 IO.mapOptional("Info", Section.RelocatableSec, StringRef()); 1411 IO.mapOptional("Relocations", Section.Relocations); 1412 } 1413 1414 static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) { 1415 commonSectionMapping(IO, Section); 1416 IO.mapOptional("Entries", Section.Entries); 1417 } 1418 1419 static void groupSectionMapping(IO &IO, ELFYAML::GroupSection &Group) { 1420 commonSectionMapping(IO, Group); 1421 IO.mapOptional("Info", Group.Signature); 1422 IO.mapOptional("Members", Group.Members); 1423 } 1424 1425 static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) { 1426 commonSectionMapping(IO, Section); 1427 IO.mapOptional("Entries", Section.Entries); 1428 } 1429 1430 static void sectionMapping(IO &IO, ELFYAML::AddrsigSection &Section) { 1431 commonSectionMapping(IO, Section); 1432 IO.mapOptional("Symbols", Section.Symbols); 1433 } 1434 1435 static void fillMapping(IO &IO, ELFYAML::Fill &Fill) { 1436 IO.mapOptional("Name", Fill.Name, StringRef()); 1437 IO.mapOptional("Pattern", Fill.Pattern); 1438 IO.mapOptional("Offset", Fill.Offset); 1439 IO.mapRequired("Size", Fill.Size); 1440 } 1441 1442 static void sectionHeaderTableMapping(IO &IO, 1443 ELFYAML::SectionHeaderTable &SHT) { 1444 IO.mapOptional("Offset", SHT.Offset); 1445 IO.mapOptional("Sections", SHT.Sections); 1446 IO.mapOptional("Excluded", SHT.Excluded); 1447 IO.mapOptional("NoHeaders", SHT.NoHeaders); 1448 } 1449 1450 static void sectionMapping(IO &IO, ELFYAML::LinkerOptionsSection &Section) { 1451 commonSectionMapping(IO, Section); 1452 IO.mapOptional("Options", Section.Options); 1453 } 1454 1455 static void sectionMapping(IO &IO, 1456 ELFYAML::DependentLibrariesSection &Section) { 1457 commonSectionMapping(IO, Section); 1458 IO.mapOptional("Libraries", Section.Libs); 1459 } 1460 1461 static void sectionMapping(IO &IO, ELFYAML::CallGraphProfileSection &Section) { 1462 commonSectionMapping(IO, Section); 1463 IO.mapOptional("Entries", Section.Entries); 1464 } 1465 1466 void MappingTraits<ELFYAML::SectionOrType>::mapping( 1467 IO &IO, ELFYAML::SectionOrType §ionOrType) { 1468 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType); 1469 } 1470 1471 static void sectionMapping(IO &IO, ELFYAML::ARMIndexTableSection &Section) { 1472 commonSectionMapping(IO, Section); 1473 IO.mapOptional("Entries", Section.Entries); 1474 } 1475 1476 static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) { 1477 commonSectionMapping(IO, Section); 1478 IO.mapOptional("Version", Section.Version, Hex16(0)); 1479 IO.mapRequired("ISA", Section.ISALevel); 1480 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0)); 1481 IO.mapOptional("ISAExtension", Section.ISAExtension, 1482 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE)); 1483 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0)); 1484 IO.mapOptional("FpABI", Section.FpABI, 1485 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY)); 1486 IO.mapOptional("GPRSize", Section.GPRSize, 1487 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1488 IO.mapOptional("CPR1Size", Section.CPR1Size, 1489 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1490 IO.mapOptional("CPR2Size", Section.CPR2Size, 1491 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1492 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0)); 1493 IO.mapOptional("Flags2", Section.Flags2, Hex32(0)); 1494 } 1495 1496 static StringRef getStringValue(IO &IO, const char *Key) { 1497 StringRef Val; 1498 IO.mapRequired(Key, Val); 1499 return Val; 1500 } 1501 1502 static void setStringValue(IO &IO, const char *Key, StringRef Val) { 1503 IO.mapRequired(Key, Val); 1504 } 1505 1506 static bool isInteger(StringRef Val) { 1507 APInt Tmp; 1508 return !Val.getAsInteger(0, Tmp); 1509 } 1510 1511 void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping( 1512 IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) { 1513 ELFYAML::ELF_SHT Type; 1514 StringRef TypeStr; 1515 if (IO.outputting()) { 1516 if (auto *S = dyn_cast<ELFYAML::Section>(Section.get())) 1517 Type = S->Type; 1518 else if (auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(Section.get())) 1519 TypeStr = SHT->TypeStr; 1520 } else { 1521 // When the Type string does not have a "SHT_" prefix, we know it is not a 1522 // description of a regular ELF output section. 1523 TypeStr = getStringValue(IO, "Type"); 1524 if (TypeStr.startswith("SHT_") || isInteger(TypeStr)) 1525 IO.mapRequired("Type", Type); 1526 } 1527 1528 if (TypeStr == "Fill") { 1529 assert(!IO.outputting()); // We don't dump fills currently. 1530 Section.reset(new ELFYAML::Fill()); 1531 fillMapping(IO, *cast<ELFYAML::Fill>(Section.get())); 1532 return; 1533 } 1534 1535 if (TypeStr == ELFYAML::SectionHeaderTable::TypeStr) { 1536 if (IO.outputting()) 1537 setStringValue(IO, "Type", TypeStr); 1538 else 1539 Section.reset(new ELFYAML::SectionHeaderTable(/*IsImplicit=*/false)); 1540 1541 sectionHeaderTableMapping( 1542 IO, *cast<ELFYAML::SectionHeaderTable>(Section.get())); 1543 return; 1544 } 1545 1546 const auto &Obj = *static_cast<ELFYAML::Object *>(IO.getContext()); 1547 if (Obj.getMachine() == ELF::EM_MIPS && Type == ELF::SHT_MIPS_ABIFLAGS) { 1548 if (!IO.outputting()) 1549 Section.reset(new ELFYAML::MipsABIFlags()); 1550 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get())); 1551 return; 1552 } 1553 1554 if (Obj.getMachine() == ELF::EM_ARM && Type == ELF::SHT_ARM_EXIDX) { 1555 if (!IO.outputting()) 1556 Section.reset(new ELFYAML::ARMIndexTableSection()); 1557 sectionMapping(IO, *cast<ELFYAML::ARMIndexTableSection>(Section.get())); 1558 return; 1559 } 1560 1561 switch (Type) { 1562 case ELF::SHT_DYNAMIC: 1563 if (!IO.outputting()) 1564 Section.reset(new ELFYAML::DynamicSection()); 1565 sectionMapping(IO, *cast<ELFYAML::DynamicSection>(Section.get())); 1566 break; 1567 case ELF::SHT_REL: 1568 case ELF::SHT_RELA: 1569 if (!IO.outputting()) 1570 Section.reset(new ELFYAML::RelocationSection()); 1571 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get())); 1572 break; 1573 case ELF::SHT_RELR: 1574 if (!IO.outputting()) 1575 Section.reset(new ELFYAML::RelrSection()); 1576 sectionMapping(IO, *cast<ELFYAML::RelrSection>(Section.get())); 1577 break; 1578 case ELF::SHT_GROUP: 1579 if (!IO.outputting()) 1580 Section.reset(new ELFYAML::GroupSection()); 1581 groupSectionMapping(IO, *cast<ELFYAML::GroupSection>(Section.get())); 1582 break; 1583 case ELF::SHT_NOBITS: 1584 if (!IO.outputting()) 1585 Section.reset(new ELFYAML::NoBitsSection()); 1586 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get())); 1587 break; 1588 case ELF::SHT_HASH: 1589 if (!IO.outputting()) 1590 Section.reset(new ELFYAML::HashSection()); 1591 sectionMapping(IO, *cast<ELFYAML::HashSection>(Section.get())); 1592 break; 1593 case ELF::SHT_NOTE: 1594 if (!IO.outputting()) 1595 Section.reset(new ELFYAML::NoteSection()); 1596 sectionMapping(IO, *cast<ELFYAML::NoteSection>(Section.get())); 1597 break; 1598 case ELF::SHT_GNU_HASH: 1599 if (!IO.outputting()) 1600 Section.reset(new ELFYAML::GnuHashSection()); 1601 sectionMapping(IO, *cast<ELFYAML::GnuHashSection>(Section.get())); 1602 break; 1603 case ELF::SHT_GNU_verdef: 1604 if (!IO.outputting()) 1605 Section.reset(new ELFYAML::VerdefSection()); 1606 sectionMapping(IO, *cast<ELFYAML::VerdefSection>(Section.get())); 1607 break; 1608 case ELF::SHT_GNU_versym: 1609 if (!IO.outputting()) 1610 Section.reset(new ELFYAML::SymverSection()); 1611 sectionMapping(IO, *cast<ELFYAML::SymverSection>(Section.get())); 1612 break; 1613 case ELF::SHT_GNU_verneed: 1614 if (!IO.outputting()) 1615 Section.reset(new ELFYAML::VerneedSection()); 1616 sectionMapping(IO, *cast<ELFYAML::VerneedSection>(Section.get())); 1617 break; 1618 case ELF::SHT_SYMTAB_SHNDX: 1619 if (!IO.outputting()) 1620 Section.reset(new ELFYAML::SymtabShndxSection()); 1621 sectionMapping(IO, *cast<ELFYAML::SymtabShndxSection>(Section.get())); 1622 break; 1623 case ELF::SHT_LLVM_ADDRSIG: 1624 if (!IO.outputting()) 1625 Section.reset(new ELFYAML::AddrsigSection()); 1626 sectionMapping(IO, *cast<ELFYAML::AddrsigSection>(Section.get())); 1627 break; 1628 case ELF::SHT_LLVM_LINKER_OPTIONS: 1629 if (!IO.outputting()) 1630 Section.reset(new ELFYAML::LinkerOptionsSection()); 1631 sectionMapping(IO, *cast<ELFYAML::LinkerOptionsSection>(Section.get())); 1632 break; 1633 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES: 1634 if (!IO.outputting()) 1635 Section.reset(new ELFYAML::DependentLibrariesSection()); 1636 sectionMapping(IO, 1637 *cast<ELFYAML::DependentLibrariesSection>(Section.get())); 1638 break; 1639 case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: 1640 if (!IO.outputting()) 1641 Section.reset(new ELFYAML::CallGraphProfileSection()); 1642 sectionMapping(IO, *cast<ELFYAML::CallGraphProfileSection>(Section.get())); 1643 break; 1644 case ELF::SHT_LLVM_BB_ADDR_MAP_V0: 1645 case ELF::SHT_LLVM_BB_ADDR_MAP: 1646 if (!IO.outputting()) 1647 Section.reset(new ELFYAML::BBAddrMapSection()); 1648 sectionMapping(IO, *cast<ELFYAML::BBAddrMapSection>(Section.get())); 1649 break; 1650 default: 1651 if (!IO.outputting()) { 1652 StringRef Name; 1653 IO.mapOptional("Name", Name, StringRef()); 1654 Name = ELFYAML::dropUniqueSuffix(Name); 1655 1656 if (ELFYAML::StackSizesSection::nameMatches(Name)) 1657 Section = std::make_unique<ELFYAML::StackSizesSection>(); 1658 else 1659 Section = std::make_unique<ELFYAML::RawContentSection>(); 1660 } 1661 1662 if (auto S = dyn_cast<ELFYAML::RawContentSection>(Section.get())) 1663 sectionMapping(IO, *S); 1664 else 1665 sectionMapping(IO, *cast<ELFYAML::StackSizesSection>(Section.get())); 1666 } 1667 } 1668 1669 std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate( 1670 IO &io, std::unique_ptr<ELFYAML::Chunk> &C) { 1671 if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) { 1672 if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size) 1673 return "\"Size\" can't be 0 when \"Pattern\" is not empty"; 1674 return ""; 1675 } 1676 1677 if (const auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(C.get())) { 1678 if (SHT->NoHeaders && (SHT->Sections || SHT->Excluded || SHT->Offset)) 1679 return "NoHeaders can't be used together with Offset/Sections/Excluded"; 1680 return ""; 1681 } 1682 1683 const ELFYAML::Section &Sec = *cast<ELFYAML::Section>(C.get()); 1684 if (Sec.Size && Sec.Content && 1685 (uint64_t)(*Sec.Size) < Sec.Content->binary_size()) 1686 return "Section size must be greater than or equal to the content size"; 1687 1688 auto BuildErrPrefix = [](ArrayRef<std::pair<StringRef, bool>> EntV) { 1689 std::string Msg; 1690 for (size_t I = 0, E = EntV.size(); I != E; ++I) { 1691 StringRef Name = EntV[I].first; 1692 if (I == 0) { 1693 Msg = "\"" + Name.str() + "\""; 1694 continue; 1695 } 1696 if (I != EntV.size() - 1) 1697 Msg += ", \"" + Name.str() + "\""; 1698 else 1699 Msg += " and \"" + Name.str() + "\""; 1700 } 1701 return Msg; 1702 }; 1703 1704 std::vector<std::pair<StringRef, bool>> Entries = Sec.getEntries(); 1705 const size_t NumUsedEntries = llvm::count_if( 1706 Entries, [](const std::pair<StringRef, bool> &P) { return P.second; }); 1707 1708 if ((Sec.Size || Sec.Content) && NumUsedEntries > 0) 1709 return BuildErrPrefix(Entries) + 1710 " cannot be used with \"Content\" or \"Size\""; 1711 1712 if (NumUsedEntries > 0 && Entries.size() != NumUsedEntries) 1713 return BuildErrPrefix(Entries) + " must be used together"; 1714 1715 if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) { 1716 if (RawSection->Flags && RawSection->ShFlags) 1717 return "ShFlags and Flags cannot be used together"; 1718 return ""; 1719 } 1720 1721 if (const auto *NB = dyn_cast<ELFYAML::NoBitsSection>(C.get())) { 1722 if (NB->Content) 1723 return "SHT_NOBITS section cannot have \"Content\""; 1724 return ""; 1725 } 1726 1727 if (const auto *MF = dyn_cast<ELFYAML::MipsABIFlags>(C.get())) { 1728 if (MF->Content) 1729 return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS " 1730 "sections"; 1731 if (MF->Size) 1732 return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections"; 1733 return ""; 1734 } 1735 1736 return ""; 1737 } 1738 1739 namespace { 1740 1741 struct NormalizedMips64RelType { 1742 NormalizedMips64RelType(IO &) 1743 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1744 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1745 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1746 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {} 1747 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original) 1748 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF), 1749 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {} 1750 1751 ELFYAML::ELF_REL denormalize(IO &) { 1752 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24; 1753 return Res; 1754 } 1755 1756 ELFYAML::ELF_REL Type; 1757 ELFYAML::ELF_REL Type2; 1758 ELFYAML::ELF_REL Type3; 1759 ELFYAML::ELF_RSS SpecSym; 1760 }; 1761 1762 } // end anonymous namespace 1763 1764 void MappingTraits<ELFYAML::StackSizeEntry>::mapping( 1765 IO &IO, ELFYAML::StackSizeEntry &E) { 1766 assert(IO.getContext() && "The IO context is not initialized"); 1767 IO.mapOptional("Address", E.Address, Hex64(0)); 1768 IO.mapRequired("Size", E.Size); 1769 } 1770 1771 void MappingTraits<ELFYAML::BBAddrMapEntry>::mapping( 1772 IO &IO, ELFYAML::BBAddrMapEntry &E) { 1773 assert(IO.getContext() && "The IO context is not initialized"); 1774 IO.mapRequired("Version", E.Version); 1775 IO.mapOptional("Feature", E.Feature, Hex8(0)); 1776 IO.mapOptional("Address", E.Address, Hex64(0)); 1777 IO.mapOptional("NumBlocks", E.NumBlocks); 1778 IO.mapOptional("BBEntries", E.BBEntries); 1779 } 1780 1781 void MappingTraits<ELFYAML::BBAddrMapEntry::BBEntry>::mapping( 1782 IO &IO, ELFYAML::BBAddrMapEntry::BBEntry &E) { 1783 assert(IO.getContext() && "The IO context is not initialized"); 1784 IO.mapRequired("AddressOffset", E.AddressOffset); 1785 IO.mapRequired("Size", E.Size); 1786 IO.mapRequired("Metadata", E.Metadata); 1787 } 1788 1789 void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO, 1790 ELFYAML::GnuHashHeader &E) { 1791 assert(IO.getContext() && "The IO context is not initialized"); 1792 IO.mapOptional("NBuckets", E.NBuckets); 1793 IO.mapRequired("SymNdx", E.SymNdx); 1794 IO.mapOptional("MaskWords", E.MaskWords); 1795 IO.mapRequired("Shift2", E.Shift2); 1796 } 1797 1798 void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO, 1799 ELFYAML::DynamicEntry &Rel) { 1800 assert(IO.getContext() && "The IO context is not initialized"); 1801 1802 IO.mapRequired("Tag", Rel.Tag); 1803 IO.mapRequired("Value", Rel.Val); 1804 } 1805 1806 void MappingTraits<ELFYAML::NoteEntry>::mapping(IO &IO, ELFYAML::NoteEntry &N) { 1807 assert(IO.getContext() && "The IO context is not initialized"); 1808 1809 IO.mapOptional("Name", N.Name); 1810 IO.mapOptional("Desc", N.Desc); 1811 IO.mapRequired("Type", N.Type); 1812 } 1813 1814 void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO, 1815 ELFYAML::VerdefEntry &E) { 1816 assert(IO.getContext() && "The IO context is not initialized"); 1817 1818 IO.mapOptional("Version", E.Version); 1819 IO.mapOptional("Flags", E.Flags); 1820 IO.mapOptional("VersionNdx", E.VersionNdx); 1821 IO.mapOptional("Hash", E.Hash); 1822 IO.mapRequired("Names", E.VerNames); 1823 } 1824 1825 void MappingTraits<ELFYAML::VerneedEntry>::mapping(IO &IO, 1826 ELFYAML::VerneedEntry &E) { 1827 assert(IO.getContext() && "The IO context is not initialized"); 1828 1829 IO.mapRequired("Version", E.Version); 1830 IO.mapRequired("File", E.File); 1831 IO.mapRequired("Entries", E.AuxV); 1832 } 1833 1834 void MappingTraits<ELFYAML::VernauxEntry>::mapping(IO &IO, 1835 ELFYAML::VernauxEntry &E) { 1836 assert(IO.getContext() && "The IO context is not initialized"); 1837 1838 IO.mapRequired("Name", E.Name); 1839 IO.mapRequired("Hash", E.Hash); 1840 IO.mapRequired("Flags", E.Flags); 1841 IO.mapRequired("Other", E.Other); 1842 } 1843 1844 void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO, 1845 ELFYAML::Relocation &Rel) { 1846 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 1847 assert(Object && "The IO context is not initialized"); 1848 1849 IO.mapOptional("Offset", Rel.Offset, (Hex64)0); 1850 IO.mapOptional("Symbol", Rel.Symbol); 1851 1852 if (Object->getMachine() == ELFYAML::ELF_EM(ELF::EM_MIPS) && 1853 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) { 1854 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key( 1855 IO, Rel.Type); 1856 IO.mapRequired("Type", Key->Type); 1857 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); 1858 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); 1859 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF)); 1860 } else 1861 IO.mapRequired("Type", Rel.Type); 1862 1863 IO.mapOptional("Addend", Rel.Addend, (ELFYAML::YAMLIntUInt)0); 1864 } 1865 1866 void MappingTraits<ELFYAML::ARMIndexTableEntry>::mapping( 1867 IO &IO, ELFYAML::ARMIndexTableEntry &E) { 1868 assert(IO.getContext() && "The IO context is not initialized"); 1869 IO.mapRequired("Offset", E.Offset); 1870 1871 StringRef CantUnwind = "EXIDX_CANTUNWIND"; 1872 if (IO.outputting() && (uint32_t)E.Value == ARM::EHABI::EXIDX_CANTUNWIND) 1873 IO.mapRequired("Value", CantUnwind); 1874 else if (!IO.outputting() && getStringValue(IO, "Value") == CantUnwind) 1875 E.Value = ARM::EHABI::EXIDX_CANTUNWIND; 1876 else 1877 IO.mapRequired("Value", E.Value); 1878 } 1879 1880 void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) { 1881 assert(!IO.getContext() && "The IO context is initialized already"); 1882 IO.setContext(&Object); 1883 IO.mapTag("!ELF", true); 1884 IO.mapRequired("FileHeader", Object.Header); 1885 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders); 1886 IO.mapOptional("Sections", Object.Chunks); 1887 IO.mapOptional("Symbols", Object.Symbols); 1888 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols); 1889 IO.mapOptional("DWARF", Object.DWARF); 1890 if (Object.DWARF) { 1891 Object.DWARF->IsLittleEndian = 1892 Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB); 1893 Object.DWARF->Is64BitAddrSize = 1894 Object.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64); 1895 } 1896 IO.setContext(nullptr); 1897 } 1898 1899 void MappingTraits<ELFYAML::LinkerOption>::mapping(IO &IO, 1900 ELFYAML::LinkerOption &Opt) { 1901 assert(IO.getContext() && "The IO context is not initialized"); 1902 IO.mapRequired("Name", Opt.Key); 1903 IO.mapRequired("Value", Opt.Value); 1904 } 1905 1906 void MappingTraits<ELFYAML::CallGraphEntryWeight>::mapping( 1907 IO &IO, ELFYAML::CallGraphEntryWeight &E) { 1908 assert(IO.getContext() && "The IO context is not initialized"); 1909 IO.mapRequired("Weight", E.Weight); 1910 } 1911 1912 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) 1913 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) 1914 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT) 1915 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE) 1916 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1) 1917 1918 } // end namespace yaml 1919 1920 } // end namespace llvm 1921