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_LOONGARCH: 522 BCaseMask(EF_LOONGARCH_BASE_ABI_ILP32S, EF_LOONGARCH_BASE_ABI_MASK); 523 BCaseMask(EF_LOONGARCH_BASE_ABI_ILP32F, EF_LOONGARCH_BASE_ABI_MASK); 524 BCaseMask(EF_LOONGARCH_BASE_ABI_ILP32D, EF_LOONGARCH_BASE_ABI_MASK); 525 BCaseMask(EF_LOONGARCH_BASE_ABI_LP64S, EF_LOONGARCH_BASE_ABI_MASK); 526 BCaseMask(EF_LOONGARCH_BASE_ABI_LP64F, EF_LOONGARCH_BASE_ABI_MASK); 527 BCaseMask(EF_LOONGARCH_BASE_ABI_LP64D, EF_LOONGARCH_BASE_ABI_MASK); 528 break; 529 case ELF::EM_RISCV: 530 BCase(EF_RISCV_RVC); 531 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT, EF_RISCV_FLOAT_ABI); 532 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE, EF_RISCV_FLOAT_ABI); 533 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_FLOAT_ABI); 534 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD, EF_RISCV_FLOAT_ABI); 535 BCase(EF_RISCV_RVE); 536 BCase(EF_RISCV_TSO); 537 break; 538 case ELF::EM_AMDGPU: 539 BCaseMask(EF_AMDGPU_MACH_NONE, EF_AMDGPU_MACH); 540 BCaseMask(EF_AMDGPU_MACH_R600_R600, EF_AMDGPU_MACH); 541 BCaseMask(EF_AMDGPU_MACH_R600_R630, EF_AMDGPU_MACH); 542 BCaseMask(EF_AMDGPU_MACH_R600_RS880, EF_AMDGPU_MACH); 543 BCaseMask(EF_AMDGPU_MACH_R600_RV670, EF_AMDGPU_MACH); 544 BCaseMask(EF_AMDGPU_MACH_R600_RV710, EF_AMDGPU_MACH); 545 BCaseMask(EF_AMDGPU_MACH_R600_RV730, EF_AMDGPU_MACH); 546 BCaseMask(EF_AMDGPU_MACH_R600_RV770, EF_AMDGPU_MACH); 547 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR, EF_AMDGPU_MACH); 548 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS, EF_AMDGPU_MACH); 549 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER, EF_AMDGPU_MACH); 550 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD, EF_AMDGPU_MACH); 551 BCaseMask(EF_AMDGPU_MACH_R600_SUMO, EF_AMDGPU_MACH); 552 BCaseMask(EF_AMDGPU_MACH_R600_BARTS, EF_AMDGPU_MACH); 553 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS, EF_AMDGPU_MACH); 554 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN, EF_AMDGPU_MACH); 555 BCaseMask(EF_AMDGPU_MACH_R600_TURKS, EF_AMDGPU_MACH); 556 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600, EF_AMDGPU_MACH); 557 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601, EF_AMDGPU_MACH); 558 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX602, EF_AMDGPU_MACH); 559 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700, EF_AMDGPU_MACH); 560 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701, EF_AMDGPU_MACH); 561 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702, EF_AMDGPU_MACH); 562 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703, EF_AMDGPU_MACH); 563 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704, EF_AMDGPU_MACH); 564 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX705, EF_AMDGPU_MACH); 565 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801, EF_AMDGPU_MACH); 566 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802, EF_AMDGPU_MACH); 567 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803, EF_AMDGPU_MACH); 568 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX805, EF_AMDGPU_MACH); 569 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810, EF_AMDGPU_MACH); 570 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900, EF_AMDGPU_MACH); 571 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902, EF_AMDGPU_MACH); 572 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904, EF_AMDGPU_MACH); 573 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906, EF_AMDGPU_MACH); 574 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908, EF_AMDGPU_MACH); 575 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909, EF_AMDGPU_MACH); 576 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90A, EF_AMDGPU_MACH); 577 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90C, EF_AMDGPU_MACH); 578 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX940, EF_AMDGPU_MACH); 579 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010, EF_AMDGPU_MACH); 580 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011, EF_AMDGPU_MACH); 581 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012, EF_AMDGPU_MACH); 582 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1013, EF_AMDGPU_MACH); 583 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1030, EF_AMDGPU_MACH); 584 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1031, EF_AMDGPU_MACH); 585 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1032, EF_AMDGPU_MACH); 586 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1033, EF_AMDGPU_MACH); 587 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1034, EF_AMDGPU_MACH); 588 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1035, EF_AMDGPU_MACH); 589 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1036, EF_AMDGPU_MACH); 590 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1100, EF_AMDGPU_MACH); 591 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1101, EF_AMDGPU_MACH); 592 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1102, EF_AMDGPU_MACH); 593 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1103, EF_AMDGPU_MACH); 594 switch (Object->Header.ABIVersion) { 595 default: 596 // ELFOSABI_AMDGPU_PAL, ELFOSABI_AMDGPU_MESA3D support *_V3 flags. 597 LLVM_FALLTHROUGH; 598 case ELF::ELFABIVERSION_AMDGPU_HSA_V3: 599 BCase(EF_AMDGPU_FEATURE_XNACK_V3); 600 BCase(EF_AMDGPU_FEATURE_SRAMECC_V3); 601 break; 602 case ELF::ELFABIVERSION_AMDGPU_HSA_V4: 603 case ELF::ELFABIVERSION_AMDGPU_HSA_V5: 604 BCaseMask(EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4, 605 EF_AMDGPU_FEATURE_XNACK_V4); 606 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ANY_V4, 607 EF_AMDGPU_FEATURE_XNACK_V4); 608 BCaseMask(EF_AMDGPU_FEATURE_XNACK_OFF_V4, 609 EF_AMDGPU_FEATURE_XNACK_V4); 610 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ON_V4, 611 EF_AMDGPU_FEATURE_XNACK_V4); 612 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4, 613 EF_AMDGPU_FEATURE_SRAMECC_V4); 614 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ANY_V4, 615 EF_AMDGPU_FEATURE_SRAMECC_V4); 616 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_OFF_V4, 617 EF_AMDGPU_FEATURE_SRAMECC_V4); 618 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ON_V4, 619 EF_AMDGPU_FEATURE_SRAMECC_V4); 620 break; 621 } 622 break; 623 default: 624 break; 625 } 626 #undef BCase 627 #undef BCaseMask 628 } 629 630 void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration( 631 IO &IO, ELFYAML::ELF_SHT &Value) { 632 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 633 assert(Object && "The IO context is not initialized"); 634 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 635 ECase(SHT_NULL); 636 ECase(SHT_PROGBITS); 637 ECase(SHT_SYMTAB); 638 // FIXME: Issue a diagnostic with this information. 639 ECase(SHT_STRTAB); 640 ECase(SHT_RELA); 641 ECase(SHT_HASH); 642 ECase(SHT_DYNAMIC); 643 ECase(SHT_NOTE); 644 ECase(SHT_NOBITS); 645 ECase(SHT_REL); 646 ECase(SHT_SHLIB); 647 ECase(SHT_DYNSYM); 648 ECase(SHT_INIT_ARRAY); 649 ECase(SHT_FINI_ARRAY); 650 ECase(SHT_PREINIT_ARRAY); 651 ECase(SHT_GROUP); 652 ECase(SHT_SYMTAB_SHNDX); 653 ECase(SHT_RELR); 654 ECase(SHT_ANDROID_REL); 655 ECase(SHT_ANDROID_RELA); 656 ECase(SHT_ANDROID_RELR); 657 ECase(SHT_LLVM_ODRTAB); 658 ECase(SHT_LLVM_LINKER_OPTIONS); 659 ECase(SHT_LLVM_CALL_GRAPH_PROFILE); 660 ECase(SHT_LLVM_ADDRSIG); 661 ECase(SHT_LLVM_DEPENDENT_LIBRARIES); 662 ECase(SHT_LLVM_SYMPART); 663 ECase(SHT_LLVM_PART_EHDR); 664 ECase(SHT_LLVM_PART_PHDR); 665 ECase(SHT_LLVM_BB_ADDR_MAP_V0); 666 ECase(SHT_LLVM_BB_ADDR_MAP); 667 ECase(SHT_LLVM_OFFLOADING); 668 ECase(SHT_GNU_ATTRIBUTES); 669 ECase(SHT_GNU_HASH); 670 ECase(SHT_GNU_verdef); 671 ECase(SHT_GNU_verneed); 672 ECase(SHT_GNU_versym); 673 switch (Object->getMachine()) { 674 case ELF::EM_ARM: 675 ECase(SHT_ARM_EXIDX); 676 ECase(SHT_ARM_PREEMPTMAP); 677 ECase(SHT_ARM_ATTRIBUTES); 678 ECase(SHT_ARM_DEBUGOVERLAY); 679 ECase(SHT_ARM_OVERLAYSECTION); 680 break; 681 case ELF::EM_HEXAGON: 682 ECase(SHT_HEX_ORDERED); 683 break; 684 case ELF::EM_X86_64: 685 ECase(SHT_X86_64_UNWIND); 686 break; 687 case ELF::EM_MIPS: 688 ECase(SHT_MIPS_REGINFO); 689 ECase(SHT_MIPS_OPTIONS); 690 ECase(SHT_MIPS_DWARF); 691 ECase(SHT_MIPS_ABIFLAGS); 692 break; 693 case ELF::EM_RISCV: 694 ECase(SHT_RISCV_ATTRIBUTES); 695 break; 696 case ELF::EM_MSP430: 697 ECase(SHT_MSP430_ATTRIBUTES); 698 break; 699 default: 700 // Nothing to do. 701 break; 702 } 703 #undef ECase 704 IO.enumFallback<Hex32>(Value); 705 } 706 707 void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO, 708 ELFYAML::ELF_PF &Value) { 709 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 710 BCase(PF_X); 711 BCase(PF_W); 712 BCase(PF_R); 713 } 714 715 void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO, 716 ELFYAML::ELF_SHF &Value) { 717 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 718 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X) 719 BCase(SHF_WRITE); 720 BCase(SHF_ALLOC); 721 BCase(SHF_EXCLUDE); 722 BCase(SHF_EXECINSTR); 723 BCase(SHF_MERGE); 724 BCase(SHF_STRINGS); 725 BCase(SHF_INFO_LINK); 726 BCase(SHF_LINK_ORDER); 727 BCase(SHF_OS_NONCONFORMING); 728 BCase(SHF_GROUP); 729 BCase(SHF_TLS); 730 BCase(SHF_COMPRESSED); 731 switch (Object->getOSAbi()) { 732 case ELF::ELFOSABI_SOLARIS: 733 BCase(SHF_SUNW_NODISCARD); 734 break; 735 default: 736 BCase(SHF_GNU_RETAIN); 737 break; 738 } 739 switch (Object->getMachine()) { 740 case ELF::EM_ARM: 741 BCase(SHF_ARM_PURECODE); 742 break; 743 case ELF::EM_HEXAGON: 744 BCase(SHF_HEX_GPREL); 745 break; 746 case ELF::EM_MIPS: 747 BCase(SHF_MIPS_NODUPES); 748 BCase(SHF_MIPS_NAMES); 749 BCase(SHF_MIPS_LOCAL); 750 BCase(SHF_MIPS_NOSTRIP); 751 BCase(SHF_MIPS_GPREL); 752 BCase(SHF_MIPS_MERGE); 753 BCase(SHF_MIPS_ADDR); 754 BCase(SHF_MIPS_STRING); 755 break; 756 case ELF::EM_X86_64: 757 BCase(SHF_X86_64_LARGE); 758 break; 759 default: 760 // Nothing to do. 761 break; 762 } 763 #undef BCase 764 } 765 766 void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration( 767 IO &IO, ELFYAML::ELF_SHN &Value) { 768 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 769 assert(Object && "The IO context is not initialized"); 770 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 771 ECase(SHN_UNDEF); 772 ECase(SHN_LORESERVE); 773 ECase(SHN_LOPROC); 774 ECase(SHN_HIPROC); 775 ECase(SHN_LOOS); 776 ECase(SHN_HIOS); 777 ECase(SHN_ABS); 778 ECase(SHN_COMMON); 779 ECase(SHN_XINDEX); 780 ECase(SHN_HIRESERVE); 781 ECase(SHN_AMDGPU_LDS); 782 783 if (!IO.outputting() || Object->getMachine() == ELF::EM_MIPS) { 784 ECase(SHN_MIPS_ACOMMON); 785 ECase(SHN_MIPS_TEXT); 786 ECase(SHN_MIPS_DATA); 787 ECase(SHN_MIPS_SCOMMON); 788 ECase(SHN_MIPS_SUNDEFINED); 789 } 790 791 ECase(SHN_HEXAGON_SCOMMON); 792 ECase(SHN_HEXAGON_SCOMMON_1); 793 ECase(SHN_HEXAGON_SCOMMON_2); 794 ECase(SHN_HEXAGON_SCOMMON_4); 795 ECase(SHN_HEXAGON_SCOMMON_8); 796 #undef ECase 797 IO.enumFallback<Hex16>(Value); 798 } 799 800 void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration( 801 IO &IO, ELFYAML::ELF_STB &Value) { 802 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 803 ECase(STB_LOCAL); 804 ECase(STB_GLOBAL); 805 ECase(STB_WEAK); 806 ECase(STB_GNU_UNIQUE); 807 #undef ECase 808 IO.enumFallback<Hex8>(Value); 809 } 810 811 void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration( 812 IO &IO, ELFYAML::ELF_STT &Value) { 813 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 814 ECase(STT_NOTYPE); 815 ECase(STT_OBJECT); 816 ECase(STT_FUNC); 817 ECase(STT_SECTION); 818 ECase(STT_FILE); 819 ECase(STT_COMMON); 820 ECase(STT_TLS); 821 ECase(STT_GNU_IFUNC); 822 #undef ECase 823 IO.enumFallback<Hex8>(Value); 824 } 825 826 827 void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration( 828 IO &IO, ELFYAML::ELF_RSS &Value) { 829 #define ECase(X) IO.enumCase(Value, #X, ELF::X) 830 ECase(RSS_UNDEF); 831 ECase(RSS_GP); 832 ECase(RSS_GP0); 833 ECase(RSS_LOC); 834 #undef ECase 835 } 836 837 void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration( 838 IO &IO, ELFYAML::ELF_REL &Value) { 839 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 840 assert(Object && "The IO context is not initialized"); 841 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X); 842 switch (Object->getMachine()) { 843 case ELF::EM_X86_64: 844 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def" 845 break; 846 case ELF::EM_MIPS: 847 #include "llvm/BinaryFormat/ELFRelocs/Mips.def" 848 break; 849 case ELF::EM_HEXAGON: 850 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def" 851 break; 852 case ELF::EM_386: 853 case ELF::EM_IAMCU: 854 #include "llvm/BinaryFormat/ELFRelocs/i386.def" 855 break; 856 case ELF::EM_AARCH64: 857 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def" 858 break; 859 case ELF::EM_ARM: 860 #include "llvm/BinaryFormat/ELFRelocs/ARM.def" 861 break; 862 case ELF::EM_ARC: 863 #include "llvm/BinaryFormat/ELFRelocs/ARC.def" 864 break; 865 case ELF::EM_RISCV: 866 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def" 867 break; 868 case ELF::EM_LANAI: 869 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def" 870 break; 871 case ELF::EM_AMDGPU: 872 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def" 873 break; 874 case ELF::EM_BPF: 875 #include "llvm/BinaryFormat/ELFRelocs/BPF.def" 876 break; 877 case ELF::EM_VE: 878 #include "llvm/BinaryFormat/ELFRelocs/VE.def" 879 break; 880 case ELF::EM_CSKY: 881 #include "llvm/BinaryFormat/ELFRelocs/CSKY.def" 882 break; 883 case ELF::EM_PPC: 884 #include "llvm/BinaryFormat/ELFRelocs/PowerPC.def" 885 break; 886 case ELF::EM_PPC64: 887 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def" 888 break; 889 case ELF::EM_68K: 890 #include "llvm/BinaryFormat/ELFRelocs/M68k.def" 891 break; 892 case ELF::EM_LOONGARCH: 893 #include "llvm/BinaryFormat/ELFRelocs/LoongArch.def" 894 break; 895 default: 896 // Nothing to do. 897 break; 898 } 899 #undef ELF_RELOC 900 IO.enumFallback<Hex32>(Value); 901 } 902 903 void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration( 904 IO &IO, ELFYAML::ELF_DYNTAG &Value) { 905 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 906 assert(Object && "The IO context is not initialized"); 907 908 // Disable architecture specific tags by default. We might enable them below. 909 #define AARCH64_DYNAMIC_TAG(name, value) 910 #define MIPS_DYNAMIC_TAG(name, value) 911 #define HEXAGON_DYNAMIC_TAG(name, value) 912 #define PPC_DYNAMIC_TAG(name, value) 913 #define PPC64_DYNAMIC_TAG(name, value) 914 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc. 915 #define DYNAMIC_TAG_MARKER(name, value) 916 917 #define STRINGIFY(X) (#X) 918 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X); 919 switch (Object->getMachine()) { 920 case ELF::EM_AARCH64: 921 #undef AARCH64_DYNAMIC_TAG 922 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 923 #include "llvm/BinaryFormat/DynamicTags.def" 924 #undef AARCH64_DYNAMIC_TAG 925 #define AARCH64_DYNAMIC_TAG(name, value) 926 break; 927 case ELF::EM_MIPS: 928 #undef MIPS_DYNAMIC_TAG 929 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 930 #include "llvm/BinaryFormat/DynamicTags.def" 931 #undef MIPS_DYNAMIC_TAG 932 #define MIPS_DYNAMIC_TAG(name, value) 933 break; 934 case ELF::EM_HEXAGON: 935 #undef HEXAGON_DYNAMIC_TAG 936 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 937 #include "llvm/BinaryFormat/DynamicTags.def" 938 #undef HEXAGON_DYNAMIC_TAG 939 #define HEXAGON_DYNAMIC_TAG(name, value) 940 break; 941 case ELF::EM_PPC: 942 #undef PPC_DYNAMIC_TAG 943 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 944 #include "llvm/BinaryFormat/DynamicTags.def" 945 #undef PPC_DYNAMIC_TAG 946 #define PPC_DYNAMIC_TAG(name, value) 947 break; 948 case ELF::EM_PPC64: 949 #undef PPC64_DYNAMIC_TAG 950 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 951 #include "llvm/BinaryFormat/DynamicTags.def" 952 #undef PPC64_DYNAMIC_TAG 953 #define PPC64_DYNAMIC_TAG(name, value) 954 break; 955 case ELF::EM_RISCV: 956 #undef RISCV_DYNAMIC_TAG 957 #define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) 958 #include "llvm/BinaryFormat/DynamicTags.def" 959 #undef RISCV_DYNAMIC_TAG 960 #define RISCV_DYNAMIC_TAG(name, value) 961 break; 962 default: 963 #include "llvm/BinaryFormat/DynamicTags.def" 964 break; 965 } 966 #undef AARCH64_DYNAMIC_TAG 967 #undef MIPS_DYNAMIC_TAG 968 #undef HEXAGON_DYNAMIC_TAG 969 #undef PPC_DYNAMIC_TAG 970 #undef PPC64_DYNAMIC_TAG 971 #undef DYNAMIC_TAG_MARKER 972 #undef STRINGIFY 973 #undef DYNAMIC_TAG 974 975 IO.enumFallback<Hex64>(Value); 976 } 977 978 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration( 979 IO &IO, ELFYAML::MIPS_AFL_REG &Value) { 980 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X) 981 ECase(REG_NONE); 982 ECase(REG_32); 983 ECase(REG_64); 984 ECase(REG_128); 985 #undef ECase 986 } 987 988 void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration( 989 IO &IO, ELFYAML::MIPS_ABI_FP &Value) { 990 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X) 991 ECase(FP_ANY); 992 ECase(FP_DOUBLE); 993 ECase(FP_SINGLE); 994 ECase(FP_SOFT); 995 ECase(FP_OLD_64); 996 ECase(FP_XX); 997 ECase(FP_64); 998 ECase(FP_64A); 999 #undef ECase 1000 } 1001 1002 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration( 1003 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) { 1004 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X) 1005 ECase(EXT_NONE); 1006 ECase(EXT_XLR); 1007 ECase(EXT_OCTEON2); 1008 ECase(EXT_OCTEONP); 1009 ECase(EXT_LOONGSON_3A); 1010 ECase(EXT_OCTEON); 1011 ECase(EXT_5900); 1012 ECase(EXT_4650); 1013 ECase(EXT_4010); 1014 ECase(EXT_4100); 1015 ECase(EXT_3900); 1016 ECase(EXT_10000); 1017 ECase(EXT_SB1); 1018 ECase(EXT_4111); 1019 ECase(EXT_4120); 1020 ECase(EXT_5400); 1021 ECase(EXT_5500); 1022 ECase(EXT_LOONGSON_2E); 1023 ECase(EXT_LOONGSON_2F); 1024 ECase(EXT_OCTEON3); 1025 #undef ECase 1026 } 1027 1028 void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration( 1029 IO &IO, ELFYAML::MIPS_ISA &Value) { 1030 IO.enumCase(Value, "MIPS1", 1); 1031 IO.enumCase(Value, "MIPS2", 2); 1032 IO.enumCase(Value, "MIPS3", 3); 1033 IO.enumCase(Value, "MIPS4", 4); 1034 IO.enumCase(Value, "MIPS5", 5); 1035 IO.enumCase(Value, "MIPS32", 32); 1036 IO.enumCase(Value, "MIPS64", 64); 1037 IO.enumFallback<Hex32>(Value); 1038 } 1039 1040 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset( 1041 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) { 1042 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X) 1043 BCase(DSP); 1044 BCase(DSPR2); 1045 BCase(EVA); 1046 BCase(MCU); 1047 BCase(MDMX); 1048 BCase(MIPS3D); 1049 BCase(MT); 1050 BCase(SMARTMIPS); 1051 BCase(VIRT); 1052 BCase(MSA); 1053 BCase(MIPS16); 1054 BCase(MICROMIPS); 1055 BCase(XPA); 1056 BCase(CRC); 1057 BCase(GINV); 1058 #undef BCase 1059 } 1060 1061 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset( 1062 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) { 1063 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X) 1064 BCase(ODDSPREG); 1065 #undef BCase 1066 } 1067 1068 void MappingTraits<ELFYAML::SectionHeader>::mapping( 1069 IO &IO, ELFYAML::SectionHeader &SHdr) { 1070 IO.mapRequired("Name", SHdr.Name); 1071 } 1072 1073 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO, 1074 ELFYAML::FileHeader &FileHdr) { 1075 IO.mapRequired("Class", FileHdr.Class); 1076 IO.mapRequired("Data", FileHdr.Data); 1077 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0)); 1078 IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0)); 1079 IO.mapRequired("Type", FileHdr.Type); 1080 IO.mapOptional("Machine", FileHdr.Machine); 1081 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0)); 1082 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0)); 1083 IO.mapOptional("SectionHeaderStringTable", FileHdr.SectionHeaderStringTable); 1084 1085 // obj2yaml does not dump these fields. 1086 assert(!IO.outputting() || 1087 (!FileHdr.EPhOff && !FileHdr.EPhEntSize && !FileHdr.EPhNum)); 1088 IO.mapOptional("EPhOff", FileHdr.EPhOff); 1089 IO.mapOptional("EPhEntSize", FileHdr.EPhEntSize); 1090 IO.mapOptional("EPhNum", FileHdr.EPhNum); 1091 IO.mapOptional("EShEntSize", FileHdr.EShEntSize); 1092 IO.mapOptional("EShOff", FileHdr.EShOff); 1093 IO.mapOptional("EShNum", FileHdr.EShNum); 1094 IO.mapOptional("EShStrNdx", FileHdr.EShStrNdx); 1095 } 1096 1097 void MappingTraits<ELFYAML::ProgramHeader>::mapping( 1098 IO &IO, ELFYAML::ProgramHeader &Phdr) { 1099 IO.mapRequired("Type", Phdr.Type); 1100 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0)); 1101 IO.mapOptional("FirstSec", Phdr.FirstSec); 1102 IO.mapOptional("LastSec", Phdr.LastSec); 1103 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0)); 1104 IO.mapOptional("PAddr", Phdr.PAddr, Phdr.VAddr); 1105 IO.mapOptional("Align", Phdr.Align); 1106 IO.mapOptional("FileSize", Phdr.FileSize); 1107 IO.mapOptional("MemSize", Phdr.MemSize); 1108 IO.mapOptional("Offset", Phdr.Offset); 1109 } 1110 1111 std::string MappingTraits<ELFYAML::ProgramHeader>::validate( 1112 IO &IO, ELFYAML::ProgramHeader &FileHdr) { 1113 if (!FileHdr.FirstSec && FileHdr.LastSec) 1114 return "the \"LastSec\" key can't be used without the \"FirstSec\" key"; 1115 if (FileHdr.FirstSec && !FileHdr.LastSec) 1116 return "the \"FirstSec\" key can't be used without the \"LastSec\" key"; 1117 return ""; 1118 } 1119 1120 LLVM_YAML_STRONG_TYPEDEF(StringRef, StOtherPiece) 1121 1122 template <> struct ScalarTraits<StOtherPiece> { 1123 static void output(const StOtherPiece &Val, void *, raw_ostream &Out) { 1124 Out << Val; 1125 } 1126 static StringRef input(StringRef Scalar, void *, StOtherPiece &Val) { 1127 Val = Scalar; 1128 return {}; 1129 } 1130 static QuotingType mustQuote(StringRef) { return QuotingType::None; } 1131 }; 1132 template <> struct SequenceElementTraits<StOtherPiece> { 1133 static const bool flow = true; 1134 }; 1135 1136 template <> struct ScalarTraits<ELFYAML::YAMLFlowString> { 1137 static void output(const ELFYAML::YAMLFlowString &Val, void *, 1138 raw_ostream &Out) { 1139 Out << Val; 1140 } 1141 static StringRef input(StringRef Scalar, void *, 1142 ELFYAML::YAMLFlowString &Val) { 1143 Val = Scalar; 1144 return {}; 1145 } 1146 static QuotingType mustQuote(StringRef S) { 1147 return ScalarTraits<StringRef>::mustQuote(S); 1148 } 1149 }; 1150 template <> struct SequenceElementTraits<ELFYAML::YAMLFlowString> { 1151 static const bool flow = true; 1152 }; 1153 1154 namespace { 1155 1156 struct NormalizedOther { 1157 NormalizedOther(IO &IO) : YamlIO(IO) {} 1158 NormalizedOther(IO &IO, Optional<uint8_t> Original) : YamlIO(IO) { 1159 assert(Original && "This constructor is only used for outputting YAML and " 1160 "assumes a non-empty Original"); 1161 std::vector<StOtherPiece> Ret; 1162 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext()); 1163 for (std::pair<StringRef, uint8_t> &P : 1164 getFlags(Object->getMachine()).takeVector()) { 1165 uint8_t FlagValue = P.second; 1166 if ((*Original & FlagValue) != FlagValue) 1167 continue; 1168 *Original &= ~FlagValue; 1169 Ret.push_back({P.first}); 1170 } 1171 1172 if (*Original != 0) { 1173 UnknownFlagsHolder = std::to_string(*Original); 1174 Ret.push_back({UnknownFlagsHolder}); 1175 } 1176 1177 if (!Ret.empty()) 1178 Other = std::move(Ret); 1179 } 1180 1181 uint8_t toValue(StringRef Name) { 1182 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext()); 1183 MapVector<StringRef, uint8_t> Flags = getFlags(Object->getMachine()); 1184 1185 auto It = Flags.find(Name); 1186 if (It != Flags.end()) 1187 return It->second; 1188 1189 uint8_t Val; 1190 if (to_integer(Name, Val)) 1191 return Val; 1192 1193 YamlIO.setError("an unknown value is used for symbol's 'Other' field: " + 1194 Name); 1195 return 0; 1196 } 1197 1198 Optional<uint8_t> denormalize(IO &) { 1199 if (!Other) 1200 return None; 1201 uint8_t Ret = 0; 1202 for (StOtherPiece &Val : *Other) 1203 Ret |= toValue(Val); 1204 return Ret; 1205 } 1206 1207 // st_other field is used to encode symbol visibility and platform-dependent 1208 // flags and values. This method returns a name to value map that is used for 1209 // parsing and encoding this field. 1210 MapVector<StringRef, uint8_t> getFlags(unsigned EMachine) { 1211 MapVector<StringRef, uint8_t> Map; 1212 // STV_* values are just enumeration values. We add them in a reversed order 1213 // because when we convert the st_other to named constants when printing 1214 // YAML we want to use a maximum number of bits on each step: 1215 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but 1216 // not as STV_HIDDEN (2) + STV_INTERNAL (1). 1217 Map["STV_PROTECTED"] = ELF::STV_PROTECTED; 1218 Map["STV_HIDDEN"] = ELF::STV_HIDDEN; 1219 Map["STV_INTERNAL"] = ELF::STV_INTERNAL; 1220 // STV_DEFAULT is used to represent the default visibility and has a value 1221 // 0. We want to be able to read it from YAML documents, but there is no 1222 // reason to print it. 1223 if (!YamlIO.outputting()) 1224 Map["STV_DEFAULT"] = ELF::STV_DEFAULT; 1225 1226 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags, 1227 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and 1228 // consumed first when we print the output, because we do not want to print 1229 // any other flags that have the same bits instead. 1230 if (EMachine == ELF::EM_MIPS) { 1231 Map["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16; 1232 Map["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS; 1233 Map["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC; 1234 Map["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT; 1235 Map["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL; 1236 } 1237 1238 if (EMachine == ELF::EM_AARCH64) 1239 Map["STO_AARCH64_VARIANT_PCS"] = ELF::STO_AARCH64_VARIANT_PCS; 1240 if (EMachine == ELF::EM_RISCV) 1241 Map["STO_RISCV_VARIANT_CC"] = ELF::STO_RISCV_VARIANT_CC; 1242 return Map; 1243 } 1244 1245 IO &YamlIO; 1246 Optional<std::vector<StOtherPiece>> Other; 1247 std::string UnknownFlagsHolder; 1248 }; 1249 1250 } // end anonymous namespace 1251 1252 void ScalarTraits<ELFYAML::YAMLIntUInt>::output(const ELFYAML::YAMLIntUInt &Val, 1253 void *Ctx, raw_ostream &Out) { 1254 Out << Val; 1255 } 1256 1257 StringRef ScalarTraits<ELFYAML::YAMLIntUInt>::input(StringRef Scalar, void *Ctx, 1258 ELFYAML::YAMLIntUInt &Val) { 1259 const bool Is64 = static_cast<ELFYAML::Object *>(Ctx)->Header.Class == 1260 ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64); 1261 StringRef ErrMsg = "invalid number"; 1262 // We do not accept negative hex numbers because their meaning is ambiguous. 1263 // For example, would -0xfffffffff mean 1 or INT32_MIN? 1264 if (Scalar.empty() || Scalar.startswith("-0x")) 1265 return ErrMsg; 1266 1267 if (Scalar.startswith("-")) { 1268 const int64_t MinVal = Is64 ? INT64_MIN : INT32_MIN; 1269 long long Int; 1270 if (getAsSignedInteger(Scalar, /*Radix=*/0, Int) || (Int < MinVal)) 1271 return ErrMsg; 1272 Val = Int; 1273 return ""; 1274 } 1275 1276 const uint64_t MaxVal = Is64 ? UINT64_MAX : UINT32_MAX; 1277 unsigned long long UInt; 1278 if (getAsUnsignedInteger(Scalar, /*Radix=*/0, UInt) || (UInt > MaxVal)) 1279 return ErrMsg; 1280 Val = UInt; 1281 return ""; 1282 } 1283 1284 void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) { 1285 IO.mapOptional("Name", Symbol.Name, StringRef()); 1286 IO.mapOptional("StName", Symbol.StName); 1287 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0)); 1288 IO.mapOptional("Section", Symbol.Section); 1289 IO.mapOptional("Index", Symbol.Index); 1290 IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0)); 1291 IO.mapOptional("Value", Symbol.Value); 1292 IO.mapOptional("Size", Symbol.Size); 1293 1294 // Symbol's Other field is a bit special. It is usually a field that 1295 // represents st_other and holds the symbol visibility. However, on some 1296 // platforms, it can contain bit fields and regular values, or even sometimes a 1297 // crazy mix of them (see comments for NormalizedOther). Because of this, we 1298 // need special handling. 1299 MappingNormalization<NormalizedOther, Optional<uint8_t>> Keys(IO, 1300 Symbol.Other); 1301 IO.mapOptional("Other", Keys->Other); 1302 } 1303 1304 std::string MappingTraits<ELFYAML::Symbol>::validate(IO &IO, 1305 ELFYAML::Symbol &Symbol) { 1306 if (Symbol.Index && Symbol.Section) 1307 return "Index and Section cannot both be specified for Symbol"; 1308 return ""; 1309 } 1310 1311 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) { 1312 IO.mapOptional("Name", Section.Name, StringRef()); 1313 IO.mapRequired("Type", Section.Type); 1314 IO.mapOptional("Flags", Section.Flags); 1315 IO.mapOptional("Address", Section.Address); 1316 IO.mapOptional("Link", Section.Link); 1317 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); 1318 IO.mapOptional("EntSize", Section.EntSize); 1319 IO.mapOptional("Offset", Section.Offset); 1320 1321 IO.mapOptional("Content", Section.Content); 1322 IO.mapOptional("Size", Section.Size); 1323 1324 // obj2yaml does not dump these fields. They are expected to be empty when we 1325 // are producing YAML, because yaml2obj sets appropriate values for them 1326 // automatically when they are not explicitly defined. 1327 assert(!IO.outputting() || 1328 (!Section.ShOffset && !Section.ShSize && !Section.ShName && 1329 !Section.ShFlags && !Section.ShType && !Section.ShAddrAlign)); 1330 IO.mapOptional("ShAddrAlign", Section.ShAddrAlign); 1331 IO.mapOptional("ShName", Section.ShName); 1332 IO.mapOptional("ShOffset", Section.ShOffset); 1333 IO.mapOptional("ShSize", Section.ShSize); 1334 IO.mapOptional("ShFlags", Section.ShFlags); 1335 IO.mapOptional("ShType", Section.ShType); 1336 } 1337 1338 static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) { 1339 commonSectionMapping(IO, Section); 1340 IO.mapOptional("Entries", Section.Entries); 1341 } 1342 1343 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) { 1344 commonSectionMapping(IO, Section); 1345 1346 // We also support reading a content as array of bytes using the ContentArray 1347 // key. obj2yaml never prints this field. 1348 assert(!IO.outputting() || !Section.ContentBuf); 1349 IO.mapOptional("ContentArray", Section.ContentBuf); 1350 if (Section.ContentBuf) { 1351 if (Section.Content) 1352 IO.setError("Content and ContentArray can't be used together"); 1353 Section.Content = yaml::BinaryRef(*Section.ContentBuf); 1354 } 1355 1356 IO.mapOptional("Info", Section.Info); 1357 } 1358 1359 static void sectionMapping(IO &IO, ELFYAML::BBAddrMapSection &Section) { 1360 commonSectionMapping(IO, Section); 1361 IO.mapOptional("Content", Section.Content); 1362 IO.mapOptional("Entries", Section.Entries); 1363 } 1364 1365 static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) { 1366 commonSectionMapping(IO, Section); 1367 IO.mapOptional("Entries", Section.Entries); 1368 } 1369 1370 static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) { 1371 commonSectionMapping(IO, Section); 1372 IO.mapOptional("Bucket", Section.Bucket); 1373 IO.mapOptional("Chain", Section.Chain); 1374 1375 // obj2yaml does not dump these fields. They can be used to override nchain 1376 // and nbucket values for creating broken sections. 1377 assert(!IO.outputting() || (!Section.NBucket && !Section.NChain)); 1378 IO.mapOptional("NChain", Section.NChain); 1379 IO.mapOptional("NBucket", Section.NBucket); 1380 } 1381 1382 static void sectionMapping(IO &IO, ELFYAML::NoteSection &Section) { 1383 commonSectionMapping(IO, Section); 1384 IO.mapOptional("Notes", Section.Notes); 1385 } 1386 1387 1388 static void sectionMapping(IO &IO, ELFYAML::GnuHashSection &Section) { 1389 commonSectionMapping(IO, Section); 1390 IO.mapOptional("Header", Section.Header); 1391 IO.mapOptional("BloomFilter", Section.BloomFilter); 1392 IO.mapOptional("HashBuckets", Section.HashBuckets); 1393 IO.mapOptional("HashValues", Section.HashValues); 1394 } 1395 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) { 1396 commonSectionMapping(IO, Section); 1397 } 1398 1399 static void sectionMapping(IO &IO, ELFYAML::VerdefSection &Section) { 1400 commonSectionMapping(IO, Section); 1401 IO.mapOptional("Info", Section.Info); 1402 IO.mapOptional("Entries", Section.Entries); 1403 } 1404 1405 static void sectionMapping(IO &IO, ELFYAML::SymverSection &Section) { 1406 commonSectionMapping(IO, Section); 1407 IO.mapOptional("Entries", Section.Entries); 1408 } 1409 1410 static void sectionMapping(IO &IO, ELFYAML::VerneedSection &Section) { 1411 commonSectionMapping(IO, Section); 1412 IO.mapOptional("Info", Section.Info); 1413 IO.mapOptional("Dependencies", Section.VerneedV); 1414 } 1415 1416 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) { 1417 commonSectionMapping(IO, Section); 1418 IO.mapOptional("Info", Section.RelocatableSec, StringRef()); 1419 IO.mapOptional("Relocations", Section.Relocations); 1420 } 1421 1422 static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) { 1423 commonSectionMapping(IO, Section); 1424 IO.mapOptional("Entries", Section.Entries); 1425 } 1426 1427 static void groupSectionMapping(IO &IO, ELFYAML::GroupSection &Group) { 1428 commonSectionMapping(IO, Group); 1429 IO.mapOptional("Info", Group.Signature); 1430 IO.mapOptional("Members", Group.Members); 1431 } 1432 1433 static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) { 1434 commonSectionMapping(IO, Section); 1435 IO.mapOptional("Entries", Section.Entries); 1436 } 1437 1438 static void sectionMapping(IO &IO, ELFYAML::AddrsigSection &Section) { 1439 commonSectionMapping(IO, Section); 1440 IO.mapOptional("Symbols", Section.Symbols); 1441 } 1442 1443 static void fillMapping(IO &IO, ELFYAML::Fill &Fill) { 1444 IO.mapOptional("Name", Fill.Name, StringRef()); 1445 IO.mapOptional("Pattern", Fill.Pattern); 1446 IO.mapOptional("Offset", Fill.Offset); 1447 IO.mapRequired("Size", Fill.Size); 1448 } 1449 1450 static void sectionHeaderTableMapping(IO &IO, 1451 ELFYAML::SectionHeaderTable &SHT) { 1452 IO.mapOptional("Offset", SHT.Offset); 1453 IO.mapOptional("Sections", SHT.Sections); 1454 IO.mapOptional("Excluded", SHT.Excluded); 1455 IO.mapOptional("NoHeaders", SHT.NoHeaders); 1456 } 1457 1458 static void sectionMapping(IO &IO, ELFYAML::LinkerOptionsSection &Section) { 1459 commonSectionMapping(IO, Section); 1460 IO.mapOptional("Options", Section.Options); 1461 } 1462 1463 static void sectionMapping(IO &IO, 1464 ELFYAML::DependentLibrariesSection &Section) { 1465 commonSectionMapping(IO, Section); 1466 IO.mapOptional("Libraries", Section.Libs); 1467 } 1468 1469 static void sectionMapping(IO &IO, ELFYAML::CallGraphProfileSection &Section) { 1470 commonSectionMapping(IO, Section); 1471 IO.mapOptional("Entries", Section.Entries); 1472 } 1473 1474 void MappingTraits<ELFYAML::SectionOrType>::mapping( 1475 IO &IO, ELFYAML::SectionOrType §ionOrType) { 1476 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType); 1477 } 1478 1479 static void sectionMapping(IO &IO, ELFYAML::ARMIndexTableSection &Section) { 1480 commonSectionMapping(IO, Section); 1481 IO.mapOptional("Entries", Section.Entries); 1482 } 1483 1484 static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) { 1485 commonSectionMapping(IO, Section); 1486 IO.mapOptional("Version", Section.Version, Hex16(0)); 1487 IO.mapRequired("ISA", Section.ISALevel); 1488 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0)); 1489 IO.mapOptional("ISAExtension", Section.ISAExtension, 1490 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE)); 1491 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0)); 1492 IO.mapOptional("FpABI", Section.FpABI, 1493 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY)); 1494 IO.mapOptional("GPRSize", Section.GPRSize, 1495 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1496 IO.mapOptional("CPR1Size", Section.CPR1Size, 1497 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1498 IO.mapOptional("CPR2Size", Section.CPR2Size, 1499 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE)); 1500 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0)); 1501 IO.mapOptional("Flags2", Section.Flags2, Hex32(0)); 1502 } 1503 1504 static StringRef getStringValue(IO &IO, const char *Key) { 1505 StringRef Val; 1506 IO.mapRequired(Key, Val); 1507 return Val; 1508 } 1509 1510 static void setStringValue(IO &IO, const char *Key, StringRef Val) { 1511 IO.mapRequired(Key, Val); 1512 } 1513 1514 static bool isInteger(StringRef Val) { 1515 APInt Tmp; 1516 return !Val.getAsInteger(0, Tmp); 1517 } 1518 1519 void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping( 1520 IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) { 1521 ELFYAML::ELF_SHT Type; 1522 StringRef TypeStr; 1523 if (IO.outputting()) { 1524 if (auto *S = dyn_cast<ELFYAML::Section>(Section.get())) 1525 Type = S->Type; 1526 else if (auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(Section.get())) 1527 TypeStr = SHT->TypeStr; 1528 } else { 1529 // When the Type string does not have a "SHT_" prefix, we know it is not a 1530 // description of a regular ELF output section. 1531 TypeStr = getStringValue(IO, "Type"); 1532 if (TypeStr.startswith("SHT_") || isInteger(TypeStr)) 1533 IO.mapRequired("Type", Type); 1534 } 1535 1536 if (TypeStr == "Fill") { 1537 assert(!IO.outputting()); // We don't dump fills currently. 1538 Section.reset(new ELFYAML::Fill()); 1539 fillMapping(IO, *cast<ELFYAML::Fill>(Section.get())); 1540 return; 1541 } 1542 1543 if (TypeStr == ELFYAML::SectionHeaderTable::TypeStr) { 1544 if (IO.outputting()) 1545 setStringValue(IO, "Type", TypeStr); 1546 else 1547 Section.reset(new ELFYAML::SectionHeaderTable(/*IsImplicit=*/false)); 1548 1549 sectionHeaderTableMapping( 1550 IO, *cast<ELFYAML::SectionHeaderTable>(Section.get())); 1551 return; 1552 } 1553 1554 const auto &Obj = *static_cast<ELFYAML::Object *>(IO.getContext()); 1555 if (Obj.getMachine() == ELF::EM_MIPS && Type == ELF::SHT_MIPS_ABIFLAGS) { 1556 if (!IO.outputting()) 1557 Section.reset(new ELFYAML::MipsABIFlags()); 1558 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get())); 1559 return; 1560 } 1561 1562 if (Obj.getMachine() == ELF::EM_ARM && Type == ELF::SHT_ARM_EXIDX) { 1563 if (!IO.outputting()) 1564 Section.reset(new ELFYAML::ARMIndexTableSection()); 1565 sectionMapping(IO, *cast<ELFYAML::ARMIndexTableSection>(Section.get())); 1566 return; 1567 } 1568 1569 switch (Type) { 1570 case ELF::SHT_DYNAMIC: 1571 if (!IO.outputting()) 1572 Section.reset(new ELFYAML::DynamicSection()); 1573 sectionMapping(IO, *cast<ELFYAML::DynamicSection>(Section.get())); 1574 break; 1575 case ELF::SHT_REL: 1576 case ELF::SHT_RELA: 1577 if (!IO.outputting()) 1578 Section.reset(new ELFYAML::RelocationSection()); 1579 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get())); 1580 break; 1581 case ELF::SHT_RELR: 1582 if (!IO.outputting()) 1583 Section.reset(new ELFYAML::RelrSection()); 1584 sectionMapping(IO, *cast<ELFYAML::RelrSection>(Section.get())); 1585 break; 1586 case ELF::SHT_GROUP: 1587 if (!IO.outputting()) 1588 Section.reset(new ELFYAML::GroupSection()); 1589 groupSectionMapping(IO, *cast<ELFYAML::GroupSection>(Section.get())); 1590 break; 1591 case ELF::SHT_NOBITS: 1592 if (!IO.outputting()) 1593 Section.reset(new ELFYAML::NoBitsSection()); 1594 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get())); 1595 break; 1596 case ELF::SHT_HASH: 1597 if (!IO.outputting()) 1598 Section.reset(new ELFYAML::HashSection()); 1599 sectionMapping(IO, *cast<ELFYAML::HashSection>(Section.get())); 1600 break; 1601 case ELF::SHT_NOTE: 1602 if (!IO.outputting()) 1603 Section.reset(new ELFYAML::NoteSection()); 1604 sectionMapping(IO, *cast<ELFYAML::NoteSection>(Section.get())); 1605 break; 1606 case ELF::SHT_GNU_HASH: 1607 if (!IO.outputting()) 1608 Section.reset(new ELFYAML::GnuHashSection()); 1609 sectionMapping(IO, *cast<ELFYAML::GnuHashSection>(Section.get())); 1610 break; 1611 case ELF::SHT_GNU_verdef: 1612 if (!IO.outputting()) 1613 Section.reset(new ELFYAML::VerdefSection()); 1614 sectionMapping(IO, *cast<ELFYAML::VerdefSection>(Section.get())); 1615 break; 1616 case ELF::SHT_GNU_versym: 1617 if (!IO.outputting()) 1618 Section.reset(new ELFYAML::SymverSection()); 1619 sectionMapping(IO, *cast<ELFYAML::SymverSection>(Section.get())); 1620 break; 1621 case ELF::SHT_GNU_verneed: 1622 if (!IO.outputting()) 1623 Section.reset(new ELFYAML::VerneedSection()); 1624 sectionMapping(IO, *cast<ELFYAML::VerneedSection>(Section.get())); 1625 break; 1626 case ELF::SHT_SYMTAB_SHNDX: 1627 if (!IO.outputting()) 1628 Section.reset(new ELFYAML::SymtabShndxSection()); 1629 sectionMapping(IO, *cast<ELFYAML::SymtabShndxSection>(Section.get())); 1630 break; 1631 case ELF::SHT_LLVM_ADDRSIG: 1632 if (!IO.outputting()) 1633 Section.reset(new ELFYAML::AddrsigSection()); 1634 sectionMapping(IO, *cast<ELFYAML::AddrsigSection>(Section.get())); 1635 break; 1636 case ELF::SHT_LLVM_LINKER_OPTIONS: 1637 if (!IO.outputting()) 1638 Section.reset(new ELFYAML::LinkerOptionsSection()); 1639 sectionMapping(IO, *cast<ELFYAML::LinkerOptionsSection>(Section.get())); 1640 break; 1641 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES: 1642 if (!IO.outputting()) 1643 Section.reset(new ELFYAML::DependentLibrariesSection()); 1644 sectionMapping(IO, 1645 *cast<ELFYAML::DependentLibrariesSection>(Section.get())); 1646 break; 1647 case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: 1648 if (!IO.outputting()) 1649 Section.reset(new ELFYAML::CallGraphProfileSection()); 1650 sectionMapping(IO, *cast<ELFYAML::CallGraphProfileSection>(Section.get())); 1651 break; 1652 case ELF::SHT_LLVM_BB_ADDR_MAP_V0: 1653 case ELF::SHT_LLVM_BB_ADDR_MAP: 1654 if (!IO.outputting()) 1655 Section.reset(new ELFYAML::BBAddrMapSection()); 1656 sectionMapping(IO, *cast<ELFYAML::BBAddrMapSection>(Section.get())); 1657 break; 1658 default: 1659 if (!IO.outputting()) { 1660 StringRef Name; 1661 IO.mapOptional("Name", Name, StringRef()); 1662 Name = ELFYAML::dropUniqueSuffix(Name); 1663 1664 if (ELFYAML::StackSizesSection::nameMatches(Name)) 1665 Section = std::make_unique<ELFYAML::StackSizesSection>(); 1666 else 1667 Section = std::make_unique<ELFYAML::RawContentSection>(); 1668 } 1669 1670 if (auto S = dyn_cast<ELFYAML::RawContentSection>(Section.get())) 1671 sectionMapping(IO, *S); 1672 else 1673 sectionMapping(IO, *cast<ELFYAML::StackSizesSection>(Section.get())); 1674 } 1675 } 1676 1677 std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate( 1678 IO &io, std::unique_ptr<ELFYAML::Chunk> &C) { 1679 if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) { 1680 if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size) 1681 return "\"Size\" can't be 0 when \"Pattern\" is not empty"; 1682 return ""; 1683 } 1684 1685 if (const auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(C.get())) { 1686 if (SHT->NoHeaders && (SHT->Sections || SHT->Excluded || SHT->Offset)) 1687 return "NoHeaders can't be used together with Offset/Sections/Excluded"; 1688 return ""; 1689 } 1690 1691 const ELFYAML::Section &Sec = *cast<ELFYAML::Section>(C.get()); 1692 if (Sec.Size && Sec.Content && 1693 (uint64_t)(*Sec.Size) < Sec.Content->binary_size()) 1694 return "Section size must be greater than or equal to the content size"; 1695 1696 auto BuildErrPrefix = [](ArrayRef<std::pair<StringRef, bool>> EntV) { 1697 std::string Msg; 1698 for (size_t I = 0, E = EntV.size(); I != E; ++I) { 1699 StringRef Name = EntV[I].first; 1700 if (I == 0) { 1701 Msg = "\"" + Name.str() + "\""; 1702 continue; 1703 } 1704 if (I != EntV.size() - 1) 1705 Msg += ", \"" + Name.str() + "\""; 1706 else 1707 Msg += " and \"" + Name.str() + "\""; 1708 } 1709 return Msg; 1710 }; 1711 1712 std::vector<std::pair<StringRef, bool>> Entries = Sec.getEntries(); 1713 const size_t NumUsedEntries = llvm::count_if( 1714 Entries, [](const std::pair<StringRef, bool> &P) { return P.second; }); 1715 1716 if ((Sec.Size || Sec.Content) && NumUsedEntries > 0) 1717 return BuildErrPrefix(Entries) + 1718 " cannot be used with \"Content\" or \"Size\""; 1719 1720 if (NumUsedEntries > 0 && Entries.size() != NumUsedEntries) 1721 return BuildErrPrefix(Entries) + " must be used together"; 1722 1723 if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) { 1724 if (RawSection->Flags && RawSection->ShFlags) 1725 return "ShFlags and Flags cannot be used together"; 1726 return ""; 1727 } 1728 1729 if (const auto *NB = dyn_cast<ELFYAML::NoBitsSection>(C.get())) { 1730 if (NB->Content) 1731 return "SHT_NOBITS section cannot have \"Content\""; 1732 return ""; 1733 } 1734 1735 if (const auto *MF = dyn_cast<ELFYAML::MipsABIFlags>(C.get())) { 1736 if (MF->Content) 1737 return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS " 1738 "sections"; 1739 if (MF->Size) 1740 return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections"; 1741 return ""; 1742 } 1743 1744 return ""; 1745 } 1746 1747 namespace { 1748 1749 struct NormalizedMips64RelType { 1750 NormalizedMips64RelType(IO &) 1751 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1752 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1753 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)), 1754 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {} 1755 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original) 1756 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF), 1757 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {} 1758 1759 ELFYAML::ELF_REL denormalize(IO &) { 1760 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24; 1761 return Res; 1762 } 1763 1764 ELFYAML::ELF_REL Type; 1765 ELFYAML::ELF_REL Type2; 1766 ELFYAML::ELF_REL Type3; 1767 ELFYAML::ELF_RSS SpecSym; 1768 }; 1769 1770 } // end anonymous namespace 1771 1772 void MappingTraits<ELFYAML::StackSizeEntry>::mapping( 1773 IO &IO, ELFYAML::StackSizeEntry &E) { 1774 assert(IO.getContext() && "The IO context is not initialized"); 1775 IO.mapOptional("Address", E.Address, Hex64(0)); 1776 IO.mapRequired("Size", E.Size); 1777 } 1778 1779 void MappingTraits<ELFYAML::BBAddrMapEntry>::mapping( 1780 IO &IO, ELFYAML::BBAddrMapEntry &E) { 1781 assert(IO.getContext() && "The IO context is not initialized"); 1782 IO.mapRequired("Version", E.Version); 1783 IO.mapOptional("Feature", E.Feature, Hex8(0)); 1784 IO.mapOptional("Address", E.Address, Hex64(0)); 1785 IO.mapOptional("NumBlocks", E.NumBlocks); 1786 IO.mapOptional("BBEntries", E.BBEntries); 1787 } 1788 1789 void MappingTraits<ELFYAML::BBAddrMapEntry::BBEntry>::mapping( 1790 IO &IO, ELFYAML::BBAddrMapEntry::BBEntry &E) { 1791 assert(IO.getContext() && "The IO context is not initialized"); 1792 IO.mapRequired("AddressOffset", E.AddressOffset); 1793 IO.mapRequired("Size", E.Size); 1794 IO.mapRequired("Metadata", E.Metadata); 1795 } 1796 1797 void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO, 1798 ELFYAML::GnuHashHeader &E) { 1799 assert(IO.getContext() && "The IO context is not initialized"); 1800 IO.mapOptional("NBuckets", E.NBuckets); 1801 IO.mapRequired("SymNdx", E.SymNdx); 1802 IO.mapOptional("MaskWords", E.MaskWords); 1803 IO.mapRequired("Shift2", E.Shift2); 1804 } 1805 1806 void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO, 1807 ELFYAML::DynamicEntry &Rel) { 1808 assert(IO.getContext() && "The IO context is not initialized"); 1809 1810 IO.mapRequired("Tag", Rel.Tag); 1811 IO.mapRequired("Value", Rel.Val); 1812 } 1813 1814 void MappingTraits<ELFYAML::NoteEntry>::mapping(IO &IO, ELFYAML::NoteEntry &N) { 1815 assert(IO.getContext() && "The IO context is not initialized"); 1816 1817 IO.mapOptional("Name", N.Name); 1818 IO.mapOptional("Desc", N.Desc); 1819 IO.mapRequired("Type", N.Type); 1820 } 1821 1822 void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO, 1823 ELFYAML::VerdefEntry &E) { 1824 assert(IO.getContext() && "The IO context is not initialized"); 1825 1826 IO.mapOptional("Version", E.Version); 1827 IO.mapOptional("Flags", E.Flags); 1828 IO.mapOptional("VersionNdx", E.VersionNdx); 1829 IO.mapOptional("Hash", E.Hash); 1830 IO.mapRequired("Names", E.VerNames); 1831 } 1832 1833 void MappingTraits<ELFYAML::VerneedEntry>::mapping(IO &IO, 1834 ELFYAML::VerneedEntry &E) { 1835 assert(IO.getContext() && "The IO context is not initialized"); 1836 1837 IO.mapRequired("Version", E.Version); 1838 IO.mapRequired("File", E.File); 1839 IO.mapRequired("Entries", E.AuxV); 1840 } 1841 1842 void MappingTraits<ELFYAML::VernauxEntry>::mapping(IO &IO, 1843 ELFYAML::VernauxEntry &E) { 1844 assert(IO.getContext() && "The IO context is not initialized"); 1845 1846 IO.mapRequired("Name", E.Name); 1847 IO.mapRequired("Hash", E.Hash); 1848 IO.mapRequired("Flags", E.Flags); 1849 IO.mapRequired("Other", E.Other); 1850 } 1851 1852 void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO, 1853 ELFYAML::Relocation &Rel) { 1854 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext()); 1855 assert(Object && "The IO context is not initialized"); 1856 1857 IO.mapOptional("Offset", Rel.Offset, (Hex64)0); 1858 IO.mapOptional("Symbol", Rel.Symbol); 1859 1860 if (Object->getMachine() == ELFYAML::ELF_EM(ELF::EM_MIPS) && 1861 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) { 1862 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key( 1863 IO, Rel.Type); 1864 IO.mapRequired("Type", Key->Type); 1865 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); 1866 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE)); 1867 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF)); 1868 } else 1869 IO.mapRequired("Type", Rel.Type); 1870 1871 IO.mapOptional("Addend", Rel.Addend, (ELFYAML::YAMLIntUInt)0); 1872 } 1873 1874 void MappingTraits<ELFYAML::ARMIndexTableEntry>::mapping( 1875 IO &IO, ELFYAML::ARMIndexTableEntry &E) { 1876 assert(IO.getContext() && "The IO context is not initialized"); 1877 IO.mapRequired("Offset", E.Offset); 1878 1879 StringRef CantUnwind = "EXIDX_CANTUNWIND"; 1880 if (IO.outputting() && (uint32_t)E.Value == ARM::EHABI::EXIDX_CANTUNWIND) 1881 IO.mapRequired("Value", CantUnwind); 1882 else if (!IO.outputting() && getStringValue(IO, "Value") == CantUnwind) 1883 E.Value = ARM::EHABI::EXIDX_CANTUNWIND; 1884 else 1885 IO.mapRequired("Value", E.Value); 1886 } 1887 1888 void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) { 1889 assert(!IO.getContext() && "The IO context is initialized already"); 1890 IO.setContext(&Object); 1891 IO.mapTag("!ELF", true); 1892 IO.mapRequired("FileHeader", Object.Header); 1893 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders); 1894 IO.mapOptional("Sections", Object.Chunks); 1895 IO.mapOptional("Symbols", Object.Symbols); 1896 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols); 1897 IO.mapOptional("DWARF", Object.DWARF); 1898 if (Object.DWARF) { 1899 Object.DWARF->IsLittleEndian = 1900 Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB); 1901 Object.DWARF->Is64BitAddrSize = 1902 Object.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64); 1903 } 1904 IO.setContext(nullptr); 1905 } 1906 1907 void MappingTraits<ELFYAML::LinkerOption>::mapping(IO &IO, 1908 ELFYAML::LinkerOption &Opt) { 1909 assert(IO.getContext() && "The IO context is not initialized"); 1910 IO.mapRequired("Name", Opt.Key); 1911 IO.mapRequired("Value", Opt.Value); 1912 } 1913 1914 void MappingTraits<ELFYAML::CallGraphEntryWeight>::mapping( 1915 IO &IO, ELFYAML::CallGraphEntryWeight &E) { 1916 assert(IO.getContext() && "The IO context is not initialized"); 1917 IO.mapRequired("Weight", E.Weight); 1918 } 1919 1920 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) 1921 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) 1922 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT) 1923 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE) 1924 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1) 1925 1926 } // end namespace yaml 1927 1928 } // end namespace llvm 1929