1 //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines classes for handling the YAML representation of ELF.
11 //===----------------------------------------------------------------------===//
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"
30 ELFYAML::Chunk::~Chunk() = default;
33 ELF_ELFOSABI
Object::getOSAbi() const { return Header
.OSABI
; }
35 unsigned Object::getMachine() const {
37 return *Header
.Machine
;
38 return llvm::ELF::EM_NONE
;
41 constexpr StringRef
SectionHeaderTable::TypeStr
;
42 } // namespace ELFYAML
46 void ScalarEnumerationTraits
<ELFYAML::ELF_ET
>::enumeration(
47 IO
&IO
, ELFYAML::ELF_ET
&Value
) {
48 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
55 IO
.enumFallback
<Hex16
>(Value
);
58 void ScalarEnumerationTraits
<ELFYAML::ELF_PT
>::enumeration(
59 IO
&IO
, ELFYAML::ELF_PT
&Value
) {
60 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
69 ECase(PT_GNU_EH_FRAME
);
72 ECase(PT_GNU_PROPERTY
);
74 IO
.enumFallback
<Hex32
>(Value
);
77 void ScalarEnumerationTraits
<ELFYAML::ELF_NT
>::enumeration(
78 IO
&IO
, ELFYAML::ELF_NT
&Value
) {
79 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
80 // Generic note types.
83 ECase(NT_GNU_BUILD_ATTRIBUTE_OPEN
);
84 ECase(NT_GNU_BUILD_ATTRIBUTE_FUNC
);
96 ECase(NT_WIN32PSTATUS
);
104 ECase(NT_PPC_TM_CGPR
);
105 ECase(NT_PPC_TM_CFPR
);
106 ECase(NT_PPC_TM_CVMX
);
107 ECase(NT_PPC_TM_CVSX
);
108 ECase(NT_PPC_TM_SPR
);
109 ECase(NT_PPC_TM_CTAR
);
110 ECase(NT_PPC_TM_CPPR
);
111 ECase(NT_PPC_TM_CDSCR
);
113 ECase(NT_386_IOPERM
);
114 ECase(NT_X86_XSTATE
);
115 ECase(NT_S390_HIGH_GPRS
);
116 ECase(NT_S390_TIMER
);
117 ECase(NT_S390_TODCMP
);
118 ECase(NT_S390_TODPREG
);
120 ECase(NT_S390_PREFIX
);
121 ECase(NT_S390_LAST_BREAK
);
122 ECase(NT_S390_SYSTEM_CALL
);
124 ECase(NT_S390_VXRS_LOW
);
125 ECase(NT_S390_VXRS_HIGH
);
126 ECase(NT_S390_GS_CB
);
127 ECase(NT_S390_GS_BC
);
130 ECase(NT_ARM_HW_BREAK
);
131 ECase(NT_ARM_HW_WATCH
);
133 ECase(NT_ARM_PAC_MASK
);
134 ECase(NT_ARM_TAGGED_ADDR_CTRL
);
142 // LLVM-specific notes.
143 ECase(NT_LLVM_HWASAN_GLOBALS
);
145 ECase(NT_GNU_ABI_TAG
);
147 ECase(NT_GNU_BUILD_ID
);
148 ECase(NT_GNU_GOLD_VERSION
);
149 ECase(NT_GNU_PROPERTY_TYPE_0
);
150 // FreeBSD note types.
151 ECase(NT_FREEBSD_ABI_TAG
);
152 ECase(NT_FREEBSD_NOINIT_TAG
);
153 ECase(NT_FREEBSD_ARCH_TAG
);
154 ECase(NT_FREEBSD_FEATURE_CTL
);
155 // FreeBSD core note types.
156 ECase(NT_FREEBSD_THRMISC
);
157 ECase(NT_FREEBSD_PROCSTAT_PROC
);
158 ECase(NT_FREEBSD_PROCSTAT_FILES
);
159 ECase(NT_FREEBSD_PROCSTAT_VMMAP
);
160 ECase(NT_FREEBSD_PROCSTAT_GROUPS
);
161 ECase(NT_FREEBSD_PROCSTAT_UMASK
);
162 ECase(NT_FREEBSD_PROCSTAT_RLIMIT
);
163 ECase(NT_FREEBSD_PROCSTAT_OSREL
);
164 ECase(NT_FREEBSD_PROCSTAT_PSSTRINGS
);
165 ECase(NT_FREEBSD_PROCSTAT_AUXV
);
166 // NetBSD core note types.
167 ECase(NT_NETBSDCORE_PROCINFO
);
168 ECase(NT_NETBSDCORE_AUXV
);
169 ECase(NT_NETBSDCORE_LWPSTATUS
);
170 // OpenBSD core note types.
171 ECase(NT_OPENBSD_PROCINFO
);
172 ECase(NT_OPENBSD_AUXV
);
173 ECase(NT_OPENBSD_REGS
);
174 ECase(NT_OPENBSD_FPREGS
);
175 ECase(NT_OPENBSD_XFPREGS
);
176 ECase(NT_OPENBSD_WCOOKIE
);
177 // AMD specific notes. (Code Object V2)
178 ECase(NT_AMD_HSA_CODE_OBJECT_VERSION
);
179 ECase(NT_AMD_HSA_HSAIL
);
180 ECase(NT_AMD_HSA_ISA_VERSION
);
181 ECase(NT_AMD_HSA_METADATA
);
182 ECase(NT_AMD_HSA_ISA_NAME
);
183 ECase(NT_AMD_PAL_METADATA
);
184 // AMDGPU specific notes. (Code Object V3)
185 ECase(NT_AMDGPU_METADATA
);
186 // Android specific notes.
187 ECase(NT_ANDROID_TYPE_IDENT
);
188 ECase(NT_ANDROID_TYPE_KUSER
);
189 ECase(NT_ANDROID_TYPE_MEMTAG
);
191 IO
.enumFallback
<Hex32
>(Value
);
194 void ScalarEnumerationTraits
<ELFYAML::ELF_EM
>::enumeration(
195 IO
&IO
, ELFYAML::ELF_EM
&Value
) {
196 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
207 ECase(EM_MIPS_RS3_LE
);
210 ECase(EM_SPARC32PLUS
);
273 ECase(EM_ARC_COMPACT
);
293 ECase(EM_ALTERA_NIOS2
);
307 ECase(EM_VIDEOCORE3
);
308 ECase(EM_LATTICEMICO32
);
313 ECase(EM_MMDSP_PLUS
);
314 ECase(EM_CYPRESS_M8C
);
329 ECase(EM_MCST_ELBRUS
);
341 ECase(EM_MICROBLAZE
);
344 ECase(EM_CLOUDSHIELD
);
347 ECase(EM_ARC_COMPACT2
);
350 ECase(EM_VIDEOCORE5
);
361 IO
.enumFallback
<Hex16
>(Value
);
364 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFCLASS
>::enumeration(
365 IO
&IO
, ELFYAML::ELF_ELFCLASS
&Value
) {
366 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
367 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
374 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFDATA
>::enumeration(
375 IO
&IO
, ELFYAML::ELF_ELFDATA
&Value
) {
376 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
377 // ELFDATANONE is an invalid data encoding, but we accept it because
378 // we want to be able to produce invalid binaries for the tests.
385 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFOSABI
>::enumeration(
386 IO
&IO
, ELFYAML::ELF_ELFOSABI
&Value
) {
387 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
388 ECase(ELFOSABI_NONE
);
389 ECase(ELFOSABI_HPUX
);
390 ECase(ELFOSABI_NETBSD
);
392 ECase(ELFOSABI_LINUX
);
393 ECase(ELFOSABI_HURD
);
394 ECase(ELFOSABI_SOLARIS
);
396 ECase(ELFOSABI_IRIX
);
397 ECase(ELFOSABI_FREEBSD
);
398 ECase(ELFOSABI_TRU64
);
399 ECase(ELFOSABI_MODESTO
);
400 ECase(ELFOSABI_OPENBSD
);
401 ECase(ELFOSABI_OPENVMS
);
403 ECase(ELFOSABI_AROS
);
404 ECase(ELFOSABI_FENIXOS
);
405 ECase(ELFOSABI_CLOUDABI
);
406 ECase(ELFOSABI_AMDGPU_HSA
);
407 ECase(ELFOSABI_AMDGPU_PAL
);
408 ECase(ELFOSABI_AMDGPU_MESA3D
);
410 ECase(ELFOSABI_ARM_FDPIC
);
411 ECase(ELFOSABI_C6000_ELFABI
);
412 ECase(ELFOSABI_C6000_LINUX
);
413 ECase(ELFOSABI_STANDALONE
);
415 IO
.enumFallback
<Hex8
>(Value
);
418 void ScalarBitSetTraits
<ELFYAML::ELF_EF
>::bitset(IO
&IO
,
419 ELFYAML::ELF_EF
&Value
) {
420 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
421 assert(Object
&& "The IO context is not initialized");
422 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
423 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
424 switch (Object
->getMachine()) {
426 BCase(EF_ARM_SOFT_FLOAT
);
427 BCase(EF_ARM_VFP_FLOAT
);
428 BCaseMask(EF_ARM_EABI_UNKNOWN
, EF_ARM_EABIMASK
);
429 BCaseMask(EF_ARM_EABI_VER1
, EF_ARM_EABIMASK
);
430 BCaseMask(EF_ARM_EABI_VER2
, EF_ARM_EABIMASK
);
431 BCaseMask(EF_ARM_EABI_VER3
, EF_ARM_EABIMASK
);
432 BCaseMask(EF_ARM_EABI_VER4
, EF_ARM_EABIMASK
);
433 BCaseMask(EF_ARM_EABI_VER5
, EF_ARM_EABIMASK
);
434 BCaseMask(EF_ARM_BE8
, EF_ARM_BE8
);
437 BCase(EF_MIPS_NOREORDER
);
441 BCase(EF_MIPS_32BITMODE
);
443 BCase(EF_MIPS_NAN2008
);
444 BCase(EF_MIPS_MICROMIPS
);
445 BCase(EF_MIPS_ARCH_ASE_M16
);
446 BCase(EF_MIPS_ARCH_ASE_MDMX
);
447 BCaseMask(EF_MIPS_ABI_O32
, EF_MIPS_ABI
);
448 BCaseMask(EF_MIPS_ABI_O64
, EF_MIPS_ABI
);
449 BCaseMask(EF_MIPS_ABI_EABI32
, EF_MIPS_ABI
);
450 BCaseMask(EF_MIPS_ABI_EABI64
, EF_MIPS_ABI
);
451 BCaseMask(EF_MIPS_MACH_3900
, EF_MIPS_MACH
);
452 BCaseMask(EF_MIPS_MACH_4010
, EF_MIPS_MACH
);
453 BCaseMask(EF_MIPS_MACH_4100
, EF_MIPS_MACH
);
454 BCaseMask(EF_MIPS_MACH_4650
, EF_MIPS_MACH
);
455 BCaseMask(EF_MIPS_MACH_4120
, EF_MIPS_MACH
);
456 BCaseMask(EF_MIPS_MACH_4111
, EF_MIPS_MACH
);
457 BCaseMask(EF_MIPS_MACH_SB1
, EF_MIPS_MACH
);
458 BCaseMask(EF_MIPS_MACH_OCTEON
, EF_MIPS_MACH
);
459 BCaseMask(EF_MIPS_MACH_XLR
, EF_MIPS_MACH
);
460 BCaseMask(EF_MIPS_MACH_OCTEON2
, EF_MIPS_MACH
);
461 BCaseMask(EF_MIPS_MACH_OCTEON3
, EF_MIPS_MACH
);
462 BCaseMask(EF_MIPS_MACH_5400
, EF_MIPS_MACH
);
463 BCaseMask(EF_MIPS_MACH_5900
, EF_MIPS_MACH
);
464 BCaseMask(EF_MIPS_MACH_5500
, EF_MIPS_MACH
);
465 BCaseMask(EF_MIPS_MACH_9000
, EF_MIPS_MACH
);
466 BCaseMask(EF_MIPS_MACH_LS2E
, EF_MIPS_MACH
);
467 BCaseMask(EF_MIPS_MACH_LS2F
, EF_MIPS_MACH
);
468 BCaseMask(EF_MIPS_MACH_LS3A
, EF_MIPS_MACH
);
469 BCaseMask(EF_MIPS_ARCH_1
, EF_MIPS_ARCH
);
470 BCaseMask(EF_MIPS_ARCH_2
, EF_MIPS_ARCH
);
471 BCaseMask(EF_MIPS_ARCH_3
, EF_MIPS_ARCH
);
472 BCaseMask(EF_MIPS_ARCH_4
, EF_MIPS_ARCH
);
473 BCaseMask(EF_MIPS_ARCH_5
, EF_MIPS_ARCH
);
474 BCaseMask(EF_MIPS_ARCH_32
, EF_MIPS_ARCH
);
475 BCaseMask(EF_MIPS_ARCH_64
, EF_MIPS_ARCH
);
476 BCaseMask(EF_MIPS_ARCH_32R2
, EF_MIPS_ARCH
);
477 BCaseMask(EF_MIPS_ARCH_64R2
, EF_MIPS_ARCH
);
478 BCaseMask(EF_MIPS_ARCH_32R6
, EF_MIPS_ARCH
);
479 BCaseMask(EF_MIPS_ARCH_64R6
, EF_MIPS_ARCH
);
481 case ELF::EM_HEXAGON
:
482 BCaseMask(EF_HEXAGON_MACH_V2
, EF_HEXAGON_MACH
);
483 BCaseMask(EF_HEXAGON_MACH_V3
, EF_HEXAGON_MACH
);
484 BCaseMask(EF_HEXAGON_MACH_V4
, EF_HEXAGON_MACH
);
485 BCaseMask(EF_HEXAGON_MACH_V5
, EF_HEXAGON_MACH
);
486 BCaseMask(EF_HEXAGON_MACH_V55
, EF_HEXAGON_MACH
);
487 BCaseMask(EF_HEXAGON_MACH_V60
, EF_HEXAGON_MACH
);
488 BCaseMask(EF_HEXAGON_MACH_V62
, EF_HEXAGON_MACH
);
489 BCaseMask(EF_HEXAGON_MACH_V65
, EF_HEXAGON_MACH
);
490 BCaseMask(EF_HEXAGON_MACH_V66
, EF_HEXAGON_MACH
);
491 BCaseMask(EF_HEXAGON_MACH_V67
, EF_HEXAGON_MACH
);
492 BCaseMask(EF_HEXAGON_MACH_V67T
, EF_HEXAGON_MACH
);
493 BCaseMask(EF_HEXAGON_MACH_V68
, EF_HEXAGON_MACH
);
494 BCaseMask(EF_HEXAGON_MACH_V69
, EF_HEXAGON_MACH
);
495 BCaseMask(EF_HEXAGON_MACH_V71
, EF_HEXAGON_MACH
);
496 BCaseMask(EF_HEXAGON_MACH_V71T
, EF_HEXAGON_MACH
);
497 BCaseMask(EF_HEXAGON_MACH_V73
, EF_HEXAGON_MACH
);
498 BCaseMask(EF_HEXAGON_ISA_V2
, EF_HEXAGON_ISA
);
499 BCaseMask(EF_HEXAGON_ISA_V3
, EF_HEXAGON_ISA
);
500 BCaseMask(EF_HEXAGON_ISA_V4
, EF_HEXAGON_ISA
);
501 BCaseMask(EF_HEXAGON_ISA_V5
, EF_HEXAGON_ISA
);
502 BCaseMask(EF_HEXAGON_ISA_V55
, EF_HEXAGON_ISA
);
503 BCaseMask(EF_HEXAGON_ISA_V60
, EF_HEXAGON_ISA
);
504 BCaseMask(EF_HEXAGON_ISA_V62
, EF_HEXAGON_ISA
);
505 BCaseMask(EF_HEXAGON_ISA_V65
, EF_HEXAGON_ISA
);
506 BCaseMask(EF_HEXAGON_ISA_V66
, EF_HEXAGON_ISA
);
507 BCaseMask(EF_HEXAGON_ISA_V67
, EF_HEXAGON_ISA
);
508 BCaseMask(EF_HEXAGON_ISA_V68
, EF_HEXAGON_ISA
);
509 BCaseMask(EF_HEXAGON_ISA_V69
, EF_HEXAGON_ISA
);
510 BCaseMask(EF_HEXAGON_ISA_V71
, EF_HEXAGON_ISA
);
511 BCaseMask(EF_HEXAGON_ISA_V73
, EF_HEXAGON_ISA
);
514 BCaseMask(EF_AVR_ARCH_AVR1
, EF_AVR_ARCH_MASK
);
515 BCaseMask(EF_AVR_ARCH_AVR2
, EF_AVR_ARCH_MASK
);
516 BCaseMask(EF_AVR_ARCH_AVR25
, EF_AVR_ARCH_MASK
);
517 BCaseMask(EF_AVR_ARCH_AVR3
, EF_AVR_ARCH_MASK
);
518 BCaseMask(EF_AVR_ARCH_AVR31
, EF_AVR_ARCH_MASK
);
519 BCaseMask(EF_AVR_ARCH_AVR35
, EF_AVR_ARCH_MASK
);
520 BCaseMask(EF_AVR_ARCH_AVR4
, EF_AVR_ARCH_MASK
);
521 BCaseMask(EF_AVR_ARCH_AVR5
, EF_AVR_ARCH_MASK
);
522 BCaseMask(EF_AVR_ARCH_AVR51
, EF_AVR_ARCH_MASK
);
523 BCaseMask(EF_AVR_ARCH_AVR6
, EF_AVR_ARCH_MASK
);
524 BCaseMask(EF_AVR_ARCH_AVRTINY
, EF_AVR_ARCH_MASK
);
525 BCaseMask(EF_AVR_ARCH_XMEGA1
, EF_AVR_ARCH_MASK
);
526 BCaseMask(EF_AVR_ARCH_XMEGA2
, EF_AVR_ARCH_MASK
);
527 BCaseMask(EF_AVR_ARCH_XMEGA3
, EF_AVR_ARCH_MASK
);
528 BCaseMask(EF_AVR_ARCH_XMEGA4
, EF_AVR_ARCH_MASK
);
529 BCaseMask(EF_AVR_ARCH_XMEGA5
, EF_AVR_ARCH_MASK
);
530 BCaseMask(EF_AVR_ARCH_XMEGA6
, EF_AVR_ARCH_MASK
);
531 BCaseMask(EF_AVR_ARCH_XMEGA7
, EF_AVR_ARCH_MASK
);
532 BCase(EF_AVR_LINKRELAX_PREPARED
);
534 case ELF::EM_LOONGARCH
:
535 BCaseMask(EF_LOONGARCH_ABI_SOFT_FLOAT
, EF_LOONGARCH_ABI_MODIFIER_MASK
);
536 BCaseMask(EF_LOONGARCH_ABI_SINGLE_FLOAT
, EF_LOONGARCH_ABI_MODIFIER_MASK
);
537 BCaseMask(EF_LOONGARCH_ABI_DOUBLE_FLOAT
, EF_LOONGARCH_ABI_MODIFIER_MASK
);
538 BCaseMask(EF_LOONGARCH_OBJABI_V0
, EF_LOONGARCH_OBJABI_MASK
);
539 BCaseMask(EF_LOONGARCH_OBJABI_V1
, EF_LOONGARCH_OBJABI_MASK
);
543 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT
, EF_RISCV_FLOAT_ABI
);
544 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE
, EF_RISCV_FLOAT_ABI
);
545 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE
, EF_RISCV_FLOAT_ABI
);
546 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD
, EF_RISCV_FLOAT_ABI
);
550 case ELF::EM_SPARC32PLUS
:
551 BCase(EF_SPARC_32PLUS
);
552 BCase(EF_SPARC_SUN_US1
);
553 BCase(EF_SPARC_SUN_US3
);
554 BCase(EF_SPARC_HAL_R1
);
556 case ELF::EM_SPARCV9
:
557 BCase(EF_SPARC_SUN_US1
);
558 BCase(EF_SPARC_SUN_US3
);
559 BCase(EF_SPARC_HAL_R1
);
560 BCaseMask(EF_SPARCV9_RMO
, EF_SPARCV9_MM
);
561 BCaseMask(EF_SPARCV9_PSO
, EF_SPARCV9_MM
);
562 BCaseMask(EF_SPARCV9_TSO
, EF_SPARCV9_MM
);
565 BCase(EF_XTENSA_XT_INSN
);
566 BCaseMask(EF_XTENSA_MACH_NONE
, EF_XTENSA_MACH
);
567 BCase(EF_XTENSA_XT_LIT
);
570 BCaseMask(EF_AMDGPU_MACH_NONE
, EF_AMDGPU_MACH
);
571 BCaseMask(EF_AMDGPU_MACH_R600_R600
, EF_AMDGPU_MACH
);
572 BCaseMask(EF_AMDGPU_MACH_R600_R630
, EF_AMDGPU_MACH
);
573 BCaseMask(EF_AMDGPU_MACH_R600_RS880
, EF_AMDGPU_MACH
);
574 BCaseMask(EF_AMDGPU_MACH_R600_RV670
, EF_AMDGPU_MACH
);
575 BCaseMask(EF_AMDGPU_MACH_R600_RV710
, EF_AMDGPU_MACH
);
576 BCaseMask(EF_AMDGPU_MACH_R600_RV730
, EF_AMDGPU_MACH
);
577 BCaseMask(EF_AMDGPU_MACH_R600_RV770
, EF_AMDGPU_MACH
);
578 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR
, EF_AMDGPU_MACH
);
579 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS
, EF_AMDGPU_MACH
);
580 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER
, EF_AMDGPU_MACH
);
581 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD
, EF_AMDGPU_MACH
);
582 BCaseMask(EF_AMDGPU_MACH_R600_SUMO
, EF_AMDGPU_MACH
);
583 BCaseMask(EF_AMDGPU_MACH_R600_BARTS
, EF_AMDGPU_MACH
);
584 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS
, EF_AMDGPU_MACH
);
585 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN
, EF_AMDGPU_MACH
);
586 BCaseMask(EF_AMDGPU_MACH_R600_TURKS
, EF_AMDGPU_MACH
);
587 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600
, EF_AMDGPU_MACH
);
588 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601
, EF_AMDGPU_MACH
);
589 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX602
, EF_AMDGPU_MACH
);
590 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700
, EF_AMDGPU_MACH
);
591 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701
, EF_AMDGPU_MACH
);
592 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702
, EF_AMDGPU_MACH
);
593 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703
, EF_AMDGPU_MACH
);
594 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704
, EF_AMDGPU_MACH
);
595 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX705
, EF_AMDGPU_MACH
);
596 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801
, EF_AMDGPU_MACH
);
597 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802
, EF_AMDGPU_MACH
);
598 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803
, EF_AMDGPU_MACH
);
599 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX805
, EF_AMDGPU_MACH
);
600 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810
, EF_AMDGPU_MACH
);
601 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900
, EF_AMDGPU_MACH
);
602 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902
, EF_AMDGPU_MACH
);
603 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904
, EF_AMDGPU_MACH
);
604 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906
, EF_AMDGPU_MACH
);
605 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908
, EF_AMDGPU_MACH
);
606 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909
, EF_AMDGPU_MACH
);
607 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90A
, EF_AMDGPU_MACH
);
608 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90C
, EF_AMDGPU_MACH
);
609 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX940
, EF_AMDGPU_MACH
);
610 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX941
, EF_AMDGPU_MACH
);
611 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX942
, EF_AMDGPU_MACH
);
612 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX950
, EF_AMDGPU_MACH
);
613 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010
, EF_AMDGPU_MACH
);
614 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011
, EF_AMDGPU_MACH
);
615 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012
, EF_AMDGPU_MACH
);
616 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1013
, EF_AMDGPU_MACH
);
617 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1030
, EF_AMDGPU_MACH
);
618 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1031
, EF_AMDGPU_MACH
);
619 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1032
, EF_AMDGPU_MACH
);
620 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1033
, EF_AMDGPU_MACH
);
621 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1034
, EF_AMDGPU_MACH
);
622 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1035
, EF_AMDGPU_MACH
);
623 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1036
, EF_AMDGPU_MACH
);
624 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1100
, EF_AMDGPU_MACH
);
625 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1101
, EF_AMDGPU_MACH
);
626 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1102
, EF_AMDGPU_MACH
);
627 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1103
, EF_AMDGPU_MACH
);
628 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1150
, EF_AMDGPU_MACH
);
629 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1151
, EF_AMDGPU_MACH
);
630 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1152
, EF_AMDGPU_MACH
);
631 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1153
, EF_AMDGPU_MACH
);
632 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1200
, EF_AMDGPU_MACH
);
633 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1201
, EF_AMDGPU_MACH
);
634 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX9_GENERIC
, EF_AMDGPU_MACH
);
635 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX9_4_GENERIC
, EF_AMDGPU_MACH
);
636 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX10_1_GENERIC
, EF_AMDGPU_MACH
);
637 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX10_3_GENERIC
, EF_AMDGPU_MACH
);
638 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX11_GENERIC
, EF_AMDGPU_MACH
);
639 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX12_GENERIC
, EF_AMDGPU_MACH
);
640 switch (Object
->Header
.ABIVersion
) {
642 // ELFOSABI_AMDGPU_PAL, ELFOSABI_AMDGPU_MESA3D support *_V3 flags.
644 case ELF::ELFABIVERSION_AMDGPU_HSA_V3
:
645 BCase(EF_AMDGPU_FEATURE_XNACK_V3
);
646 BCase(EF_AMDGPU_FEATURE_SRAMECC_V3
);
648 case ELF::ELFABIVERSION_AMDGPU_HSA_V6
:
649 for (unsigned K
= ELF::EF_AMDGPU_GENERIC_VERSION_MIN
;
650 K
<= ELF::EF_AMDGPU_GENERIC_VERSION_MAX
; ++K
) {
651 std::string Key
= "EF_AMDGPU_GENERIC_VERSION_V" + std::to_string(K
);
652 IO
.maskedBitSetCase(Value
, Key
.c_str(),
653 K
<< ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET
,
654 ELF::EF_AMDGPU_GENERIC_VERSION
);
657 case ELF::ELFABIVERSION_AMDGPU_HSA_V4
:
658 case ELF::ELFABIVERSION_AMDGPU_HSA_V5
:
659 BCaseMask(EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
,
660 EF_AMDGPU_FEATURE_XNACK_V4
);
661 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ANY_V4
,
662 EF_AMDGPU_FEATURE_XNACK_V4
);
663 BCaseMask(EF_AMDGPU_FEATURE_XNACK_OFF_V4
,
664 EF_AMDGPU_FEATURE_XNACK_V4
);
665 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ON_V4
,
666 EF_AMDGPU_FEATURE_XNACK_V4
);
667 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
,
668 EF_AMDGPU_FEATURE_SRAMECC_V4
);
669 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
,
670 EF_AMDGPU_FEATURE_SRAMECC_V4
);
671 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
,
672 EF_AMDGPU_FEATURE_SRAMECC_V4
);
673 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ON_V4
,
674 EF_AMDGPU_FEATURE_SRAMECC_V4
);
685 void ScalarEnumerationTraits
<ELFYAML::ELF_SHT
>::enumeration(
686 IO
&IO
, ELFYAML::ELF_SHT
&Value
) {
687 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
688 assert(Object
&& "The IO context is not initialized");
689 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
693 // FIXME: Issue a diagnostic with this information.
703 ECase(SHT_INIT_ARRAY
);
704 ECase(SHT_FINI_ARRAY
);
705 ECase(SHT_PREINIT_ARRAY
);
707 ECase(SHT_SYMTAB_SHNDX
);
710 ECase(SHT_ANDROID_REL
);
711 ECase(SHT_ANDROID_RELA
);
712 ECase(SHT_ANDROID_RELR
);
713 ECase(SHT_LLVM_ODRTAB
);
714 ECase(SHT_LLVM_LINKER_OPTIONS
);
715 ECase(SHT_LLVM_CALL_GRAPH_PROFILE
);
716 ECase(SHT_LLVM_ADDRSIG
);
717 ECase(SHT_LLVM_DEPENDENT_LIBRARIES
);
718 ECase(SHT_LLVM_SYMPART
);
719 ECase(SHT_LLVM_PART_EHDR
);
720 ECase(SHT_LLVM_PART_PHDR
);
721 ECase(SHT_LLVM_BB_ADDR_MAP_V0
);
722 ECase(SHT_LLVM_BB_ADDR_MAP
);
723 ECase(SHT_LLVM_OFFLOADING
);
725 ECase(SHT_GNU_ATTRIBUTES
);
727 ECase(SHT_GNU_verdef
);
728 ECase(SHT_GNU_verneed
);
729 ECase(SHT_GNU_versym
);
730 switch (Object
->getMachine()) {
732 ECase(SHT_ARM_EXIDX
);
733 ECase(SHT_ARM_PREEMPTMAP
);
734 ECase(SHT_ARM_ATTRIBUTES
);
735 ECase(SHT_ARM_DEBUGOVERLAY
);
736 ECase(SHT_ARM_OVERLAYSECTION
);
738 case ELF::EM_HEXAGON
:
739 ECase(SHT_HEX_ORDERED
);
740 ECase(SHT_HEXAGON_ATTRIBUTES
);
743 ECase(SHT_X86_64_UNWIND
);
746 ECase(SHT_MIPS_REGINFO
);
747 ECase(SHT_MIPS_OPTIONS
);
748 ECase(SHT_MIPS_DWARF
);
749 ECase(SHT_MIPS_ABIFLAGS
);
752 ECase(SHT_RISCV_ATTRIBUTES
);
755 ECase(SHT_MSP430_ATTRIBUTES
);
757 case ELF::EM_AARCH64
:
758 ECase(SHT_AARCH64_AUTH_RELR
);
759 ECase(SHT_AARCH64_MEMTAG_GLOBALS_STATIC
);
760 ECase(SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC
);
767 IO
.enumFallback
<Hex32
>(Value
);
770 void ScalarBitSetTraits
<ELFYAML::ELF_PF
>::bitset(IO
&IO
,
771 ELFYAML::ELF_PF
&Value
) {
772 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
778 void ScalarBitSetTraits
<ELFYAML::ELF_SHF
>::bitset(IO
&IO
,
779 ELFYAML::ELF_SHF
&Value
) {
780 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
781 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
785 BCase(SHF_EXECINSTR
);
788 BCase(SHF_INFO_LINK
);
789 BCase(SHF_LINK_ORDER
);
790 BCase(SHF_OS_NONCONFORMING
);
793 BCase(SHF_COMPRESSED
);
794 switch (Object
->getOSAbi()) {
795 case ELF::ELFOSABI_SOLARIS
:
796 BCase(SHF_SUNW_NODISCARD
);
799 BCase(SHF_GNU_RETAIN
);
802 switch (Object
->getMachine()) {
804 BCase(SHF_ARM_PURECODE
);
806 case ELF::EM_HEXAGON
:
807 BCase(SHF_HEX_GPREL
);
810 BCase(SHF_MIPS_NODUPES
);
811 BCase(SHF_MIPS_NAMES
);
812 BCase(SHF_MIPS_LOCAL
);
813 BCase(SHF_MIPS_NOSTRIP
);
814 BCase(SHF_MIPS_GPREL
);
815 BCase(SHF_MIPS_MERGE
);
816 BCase(SHF_MIPS_ADDR
);
817 BCase(SHF_MIPS_STRING
);
820 BCase(SHF_X86_64_LARGE
);
829 void ScalarEnumerationTraits
<ELFYAML::ELF_SHN
>::enumeration(
830 IO
&IO
, ELFYAML::ELF_SHN
&Value
) {
831 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
832 assert(Object
&& "The IO context is not initialized");
833 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
835 ECase(SHN_LORESERVE
);
843 ECase(SHN_HIRESERVE
);
844 ECase(SHN_AMDGPU_LDS
);
846 if (!IO
.outputting() || Object
->getMachine() == ELF::EM_MIPS
) {
847 ECase(SHN_MIPS_ACOMMON
);
848 ECase(SHN_MIPS_TEXT
);
849 ECase(SHN_MIPS_DATA
);
850 ECase(SHN_MIPS_SCOMMON
);
851 ECase(SHN_MIPS_SUNDEFINED
);
854 ECase(SHN_HEXAGON_SCOMMON
);
855 ECase(SHN_HEXAGON_SCOMMON_1
);
856 ECase(SHN_HEXAGON_SCOMMON_2
);
857 ECase(SHN_HEXAGON_SCOMMON_4
);
858 ECase(SHN_HEXAGON_SCOMMON_8
);
860 IO
.enumFallback
<Hex16
>(Value
);
863 void ScalarEnumerationTraits
<ELFYAML::ELF_STB
>::enumeration(
864 IO
&IO
, ELFYAML::ELF_STB
&Value
) {
865 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
869 ECase(STB_GNU_UNIQUE
);
871 IO
.enumFallback
<Hex8
>(Value
);
874 void ScalarEnumerationTraits
<ELFYAML::ELF_STT
>::enumeration(
875 IO
&IO
, ELFYAML::ELF_STT
&Value
) {
876 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
884 ECase(STT_GNU_IFUNC
);
886 IO
.enumFallback
<Hex8
>(Value
);
890 void ScalarEnumerationTraits
<ELFYAML::ELF_RSS
>::enumeration(
891 IO
&IO
, ELFYAML::ELF_RSS
&Value
) {
892 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
900 void ScalarEnumerationTraits
<ELFYAML::ELF_REL
>::enumeration(
901 IO
&IO
, ELFYAML::ELF_REL
&Value
) {
902 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
903 assert(Object
&& "The IO context is not initialized");
904 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
905 switch (Object
->getMachine()) {
907 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
910 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
912 case ELF::EM_HEXAGON
:
913 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
917 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
919 case ELF::EM_AARCH64
:
920 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
923 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
926 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
929 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
932 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
935 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
938 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
941 #include "llvm/BinaryFormat/ELFRelocs/VE.def"
944 #include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
947 #include "llvm/BinaryFormat/ELFRelocs/PowerPC.def"
950 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
953 #include "llvm/BinaryFormat/ELFRelocs/M68k.def"
955 case ELF::EM_LOONGARCH
:
956 #include "llvm/BinaryFormat/ELFRelocs/LoongArch.def"
959 #include "llvm/BinaryFormat/ELFRelocs/Xtensa.def"
966 IO
.enumFallback
<Hex32
>(Value
);
969 void ScalarEnumerationTraits
<ELFYAML::ELF_DYNTAG
>::enumeration(
970 IO
&IO
, ELFYAML::ELF_DYNTAG
&Value
) {
971 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
972 assert(Object
&& "The IO context is not initialized");
974 // Disable architecture specific tags by default. We might enable them below.
975 #define AARCH64_DYNAMIC_TAG(name, value)
976 #define MIPS_DYNAMIC_TAG(name, value)
977 #define HEXAGON_DYNAMIC_TAG(name, value)
978 #define PPC_DYNAMIC_TAG(name, value)
979 #define PPC64_DYNAMIC_TAG(name, value)
980 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
981 #define DYNAMIC_TAG_MARKER(name, value)
983 #define STRINGIFY(X) (#X)
984 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
985 switch (Object
->getMachine()) {
986 case ELF::EM_AARCH64
:
987 #undef AARCH64_DYNAMIC_TAG
988 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
989 #include "llvm/BinaryFormat/DynamicTags.def"
990 #undef AARCH64_DYNAMIC_TAG
991 #define AARCH64_DYNAMIC_TAG(name, value)
994 #undef MIPS_DYNAMIC_TAG
995 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
996 #include "llvm/BinaryFormat/DynamicTags.def"
997 #undef MIPS_DYNAMIC_TAG
998 #define MIPS_DYNAMIC_TAG(name, value)
1000 case ELF::EM_HEXAGON
:
1001 #undef HEXAGON_DYNAMIC_TAG
1002 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1003 #include "llvm/BinaryFormat/DynamicTags.def"
1004 #undef HEXAGON_DYNAMIC_TAG
1005 #define HEXAGON_DYNAMIC_TAG(name, value)
1008 #undef PPC_DYNAMIC_TAG
1009 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1010 #include "llvm/BinaryFormat/DynamicTags.def"
1011 #undef PPC_DYNAMIC_TAG
1012 #define PPC_DYNAMIC_TAG(name, value)
1015 #undef PPC64_DYNAMIC_TAG
1016 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1017 #include "llvm/BinaryFormat/DynamicTags.def"
1018 #undef PPC64_DYNAMIC_TAG
1019 #define PPC64_DYNAMIC_TAG(name, value)
1022 #undef RISCV_DYNAMIC_TAG
1023 #define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1024 #include "llvm/BinaryFormat/DynamicTags.def"
1025 #undef RISCV_DYNAMIC_TAG
1026 #define RISCV_DYNAMIC_TAG(name, value)
1029 #include "llvm/BinaryFormat/DynamicTags.def"
1032 #undef AARCH64_DYNAMIC_TAG
1033 #undef MIPS_DYNAMIC_TAG
1034 #undef HEXAGON_DYNAMIC_TAG
1035 #undef PPC_DYNAMIC_TAG
1036 #undef PPC64_DYNAMIC_TAG
1037 #undef DYNAMIC_TAG_MARKER
1041 IO
.enumFallback
<Hex64
>(Value
);
1044 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_REG
>::enumeration(
1045 IO
&IO
, ELFYAML::MIPS_AFL_REG
&Value
) {
1046 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1054 void ScalarEnumerationTraits
<ELFYAML::MIPS_ABI_FP
>::enumeration(
1055 IO
&IO
, ELFYAML::MIPS_ABI_FP
&Value
) {
1056 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
1068 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_EXT
>::enumeration(
1069 IO
&IO
, ELFYAML::MIPS_AFL_EXT
&Value
) {
1070 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1075 ECase(EXT_LOONGSON_3A
);
1088 ECase(EXT_LOONGSON_2E
);
1089 ECase(EXT_LOONGSON_2F
);
1094 void ScalarEnumerationTraits
<ELFYAML::MIPS_ISA
>::enumeration(
1095 IO
&IO
, ELFYAML::MIPS_ISA
&Value
) {
1096 IO
.enumCase(Value
, "MIPS1", 1);
1097 IO
.enumCase(Value
, "MIPS2", 2);
1098 IO
.enumCase(Value
, "MIPS3", 3);
1099 IO
.enumCase(Value
, "MIPS4", 4);
1100 IO
.enumCase(Value
, "MIPS5", 5);
1101 IO
.enumCase(Value
, "MIPS32", 32);
1102 IO
.enumCase(Value
, "MIPS64", 64);
1103 IO
.enumFallback
<Hex32
>(Value
);
1106 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_ASE
>::bitset(
1107 IO
&IO
, ELFYAML::MIPS_AFL_ASE
&Value
) {
1108 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
1127 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_FLAGS1
>::bitset(
1128 IO
&IO
, ELFYAML::MIPS_AFL_FLAGS1
&Value
) {
1129 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
1134 void MappingTraits
<ELFYAML::SectionHeader
>::mapping(
1135 IO
&IO
, ELFYAML::SectionHeader
&SHdr
) {
1136 IO
.mapRequired("Name", SHdr
.Name
);
1139 void MappingTraits
<ELFYAML::FileHeader
>::mapping(IO
&IO
,
1140 ELFYAML::FileHeader
&FileHdr
) {
1141 IO
.mapRequired("Class", FileHdr
.Class
);
1142 IO
.mapRequired("Data", FileHdr
.Data
);
1143 IO
.mapOptional("OSABI", FileHdr
.OSABI
, ELFYAML::ELF_ELFOSABI(0));
1144 IO
.mapOptional("ABIVersion", FileHdr
.ABIVersion
, Hex8(0));
1145 IO
.mapRequired("Type", FileHdr
.Type
);
1146 IO
.mapOptional("Machine", FileHdr
.Machine
);
1147 IO
.mapOptional("Flags", FileHdr
.Flags
, ELFYAML::ELF_EF(0));
1148 IO
.mapOptional("Entry", FileHdr
.Entry
, Hex64(0));
1149 IO
.mapOptional("SectionHeaderStringTable", FileHdr
.SectionHeaderStringTable
);
1151 // obj2yaml does not dump these fields.
1152 assert(!IO
.outputting() ||
1153 (!FileHdr
.EPhOff
&& !FileHdr
.EPhEntSize
&& !FileHdr
.EPhNum
));
1154 IO
.mapOptional("EPhOff", FileHdr
.EPhOff
);
1155 IO
.mapOptional("EPhEntSize", FileHdr
.EPhEntSize
);
1156 IO
.mapOptional("EPhNum", FileHdr
.EPhNum
);
1157 IO
.mapOptional("EShEntSize", FileHdr
.EShEntSize
);
1158 IO
.mapOptional("EShOff", FileHdr
.EShOff
);
1159 IO
.mapOptional("EShNum", FileHdr
.EShNum
);
1160 IO
.mapOptional("EShStrNdx", FileHdr
.EShStrNdx
);
1163 void MappingTraits
<ELFYAML::ProgramHeader
>::mapping(
1164 IO
&IO
, ELFYAML::ProgramHeader
&Phdr
) {
1165 IO
.mapRequired("Type", Phdr
.Type
);
1166 IO
.mapOptional("Flags", Phdr
.Flags
, ELFYAML::ELF_PF(0));
1167 IO
.mapOptional("FirstSec", Phdr
.FirstSec
);
1168 IO
.mapOptional("LastSec", Phdr
.LastSec
);
1169 IO
.mapOptional("VAddr", Phdr
.VAddr
, Hex64(0));
1170 IO
.mapOptional("PAddr", Phdr
.PAddr
, Phdr
.VAddr
);
1171 IO
.mapOptional("Align", Phdr
.Align
);
1172 IO
.mapOptional("FileSize", Phdr
.FileSize
);
1173 IO
.mapOptional("MemSize", Phdr
.MemSize
);
1174 IO
.mapOptional("Offset", Phdr
.Offset
);
1177 std::string MappingTraits
<ELFYAML::ProgramHeader
>::validate(
1178 IO
&IO
, ELFYAML::ProgramHeader
&FileHdr
) {
1179 if (!FileHdr
.FirstSec
&& FileHdr
.LastSec
)
1180 return "the \"LastSec\" key can't be used without the \"FirstSec\" key";
1181 if (FileHdr
.FirstSec
&& !FileHdr
.LastSec
)
1182 return "the \"FirstSec\" key can't be used without the \"LastSec\" key";
1186 LLVM_YAML_STRONG_TYPEDEF(StringRef
, StOtherPiece
)
1188 template <> struct ScalarTraits
<StOtherPiece
> {
1189 static void output(const StOtherPiece
&Val
, void *, raw_ostream
&Out
) {
1192 static StringRef
input(StringRef Scalar
, void *, StOtherPiece
&Val
) {
1196 static QuotingType
mustQuote(StringRef
) { return QuotingType::None
; }
1198 template <> struct SequenceElementTraits
<StOtherPiece
> {
1199 static const bool flow
= true;
1202 template <> struct ScalarTraits
<ELFYAML::YAMLFlowString
> {
1203 static void output(const ELFYAML::YAMLFlowString
&Val
, void *,
1207 static StringRef
input(StringRef Scalar
, void *,
1208 ELFYAML::YAMLFlowString
&Val
) {
1212 static QuotingType
mustQuote(StringRef S
) {
1213 return ScalarTraits
<StringRef
>::mustQuote(S
);
1216 template <> struct SequenceElementTraits
<ELFYAML::YAMLFlowString
> {
1217 static const bool flow
= true;
1222 struct NormalizedOther
{
1223 NormalizedOther(IO
&IO
) : YamlIO(IO
) {}
1224 NormalizedOther(IO
&IO
, std::optional
<uint8_t> Original
) : YamlIO(IO
) {
1225 assert(Original
&& "This constructor is only used for outputting YAML and "
1226 "assumes a non-empty Original");
1227 std::vector
<StOtherPiece
> Ret
;
1228 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
1229 for (std::pair
<StringRef
, uint8_t> &P
:
1230 getFlags(Object
->getMachine()).takeVector()) {
1231 uint8_t FlagValue
= P
.second
;
1232 if ((*Original
& FlagValue
) != FlagValue
)
1234 *Original
&= ~FlagValue
;
1235 Ret
.push_back({P
.first
});
1238 if (*Original
!= 0) {
1239 UnknownFlagsHolder
= std::to_string(*Original
);
1240 Ret
.push_back({UnknownFlagsHolder
});
1244 Other
= std::move(Ret
);
1247 uint8_t toValue(StringRef Name
) {
1248 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
1249 MapVector
<StringRef
, uint8_t> Flags
= getFlags(Object
->getMachine());
1251 auto It
= Flags
.find(Name
);
1252 if (It
!= Flags
.end())
1256 if (to_integer(Name
, Val
))
1259 YamlIO
.setError("an unknown value is used for symbol's 'Other' field: " +
1264 std::optional
<uint8_t> denormalize(IO
&) {
1266 return std::nullopt
;
1268 for (StOtherPiece
&Val
: *Other
)
1269 Ret
|= toValue(Val
);
1273 // st_other field is used to encode symbol visibility and platform-dependent
1274 // flags and values. This method returns a name to value map that is used for
1275 // parsing and encoding this field.
1276 MapVector
<StringRef
, uint8_t> getFlags(unsigned EMachine
) {
1277 MapVector
<StringRef
, uint8_t> Map
;
1278 // STV_* values are just enumeration values. We add them in a reversed order
1279 // because when we convert the st_other to named constants when printing
1280 // YAML we want to use a maximum number of bits on each step:
1281 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
1282 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
1283 Map
["STV_PROTECTED"] = ELF::STV_PROTECTED
;
1284 Map
["STV_HIDDEN"] = ELF::STV_HIDDEN
;
1285 Map
["STV_INTERNAL"] = ELF::STV_INTERNAL
;
1286 // STV_DEFAULT is used to represent the default visibility and has a value
1287 // 0. We want to be able to read it from YAML documents, but there is no
1288 // reason to print it.
1289 if (!YamlIO
.outputting())
1290 Map
["STV_DEFAULT"] = ELF::STV_DEFAULT
;
1292 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
1293 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
1294 // consumed first when we print the output, because we do not want to print
1295 // any other flags that have the same bits instead.
1296 if (EMachine
== ELF::EM_MIPS
) {
1297 Map
["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16
;
1298 Map
["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS
;
1299 Map
["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC
;
1300 Map
["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT
;
1301 Map
["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL
;
1304 if (EMachine
== ELF::EM_AARCH64
)
1305 Map
["STO_AARCH64_VARIANT_PCS"] = ELF::STO_AARCH64_VARIANT_PCS
;
1306 if (EMachine
== ELF::EM_RISCV
)
1307 Map
["STO_RISCV_VARIANT_CC"] = ELF::STO_RISCV_VARIANT_CC
;
1312 std::optional
<std::vector
<StOtherPiece
>> Other
;
1313 std::string UnknownFlagsHolder
;
1316 } // end anonymous namespace
1318 void ScalarTraits
<ELFYAML::YAMLIntUInt
>::output(const ELFYAML::YAMLIntUInt
&Val
,
1319 void *Ctx
, raw_ostream
&Out
) {
1323 StringRef ScalarTraits
<ELFYAML::YAMLIntUInt
>::input(StringRef Scalar
, void *Ctx
,
1324 ELFYAML::YAMLIntUInt
&Val
) {
1325 const bool Is64
= static_cast<ELFYAML::Object
*>(Ctx
)->Header
.Class
==
1326 ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
);
1327 StringRef ErrMsg
= "invalid number";
1328 // We do not accept negative hex numbers because their meaning is ambiguous.
1329 // For example, would -0xfffffffff mean 1 or INT32_MIN?
1330 if (Scalar
.empty() || Scalar
.starts_with("-0x"))
1333 if (Scalar
.starts_with("-")) {
1334 const int64_t MinVal
= Is64
? INT64_MIN
: INT32_MIN
;
1336 if (getAsSignedInteger(Scalar
, /*Radix=*/0, Int
) || (Int
< MinVal
))
1342 const uint64_t MaxVal
= Is64
? UINT64_MAX
: UINT32_MAX
;
1343 unsigned long long UInt
;
1344 if (getAsUnsignedInteger(Scalar
, /*Radix=*/0, UInt
) || (UInt
> MaxVal
))
1350 void MappingTraits
<ELFYAML::Symbol
>::mapping(IO
&IO
, ELFYAML::Symbol
&Symbol
) {
1351 IO
.mapOptional("Name", Symbol
.Name
, StringRef());
1352 IO
.mapOptional("StName", Symbol
.StName
);
1353 IO
.mapOptional("Type", Symbol
.Type
, ELFYAML::ELF_STT(0));
1354 IO
.mapOptional("Section", Symbol
.Section
);
1355 IO
.mapOptional("Index", Symbol
.Index
);
1356 IO
.mapOptional("Binding", Symbol
.Binding
, ELFYAML::ELF_STB(0));
1357 IO
.mapOptional("Value", Symbol
.Value
);
1358 IO
.mapOptional("Size", Symbol
.Size
);
1360 // Symbol's Other field is a bit special. It is usually a field that
1361 // represents st_other and holds the symbol visibility. However, on some
1362 // platforms, it can contain bit fields and regular values, or even sometimes
1363 // a crazy mix of them (see comments for NormalizedOther). Because of this, we
1364 // need special handling.
1365 MappingNormalization
<NormalizedOther
, std::optional
<uint8_t>> Keys(
1367 IO
.mapOptional("Other", Keys
->Other
);
1370 std::string MappingTraits
<ELFYAML::Symbol
>::validate(IO
&IO
,
1371 ELFYAML::Symbol
&Symbol
) {
1372 if (Symbol
.Index
&& Symbol
.Section
)
1373 return "Index and Section cannot both be specified for Symbol";
1377 static void commonSectionMapping(IO
&IO
, ELFYAML::Section
&Section
) {
1378 IO
.mapOptional("Name", Section
.Name
, StringRef());
1379 IO
.mapRequired("Type", Section
.Type
);
1380 IO
.mapOptional("Flags", Section
.Flags
);
1381 IO
.mapOptional("Address", Section
.Address
);
1382 IO
.mapOptional("Link", Section
.Link
);
1383 IO
.mapOptional("AddressAlign", Section
.AddressAlign
, Hex64(0));
1384 IO
.mapOptional("EntSize", Section
.EntSize
);
1385 IO
.mapOptional("Offset", Section
.Offset
);
1387 IO
.mapOptional("Content", Section
.Content
);
1388 IO
.mapOptional("Size", Section
.Size
);
1390 // obj2yaml does not dump these fields. They are expected to be empty when we
1391 // are producing YAML, because yaml2obj sets appropriate values for them
1392 // automatically when they are not explicitly defined.
1393 assert(!IO
.outputting() ||
1394 (!Section
.ShOffset
&& !Section
.ShSize
&& !Section
.ShName
&&
1395 !Section
.ShFlags
&& !Section
.ShType
&& !Section
.ShAddrAlign
));
1396 IO
.mapOptional("ShAddrAlign", Section
.ShAddrAlign
);
1397 IO
.mapOptional("ShName", Section
.ShName
);
1398 IO
.mapOptional("ShOffset", Section
.ShOffset
);
1399 IO
.mapOptional("ShSize", Section
.ShSize
);
1400 IO
.mapOptional("ShFlags", Section
.ShFlags
);
1401 IO
.mapOptional("ShType", Section
.ShType
);
1404 static void sectionMapping(IO
&IO
, ELFYAML::DynamicSection
&Section
) {
1405 commonSectionMapping(IO
, Section
);
1406 IO
.mapOptional("Entries", Section
.Entries
);
1409 static void sectionMapping(IO
&IO
, ELFYAML::RawContentSection
&Section
) {
1410 commonSectionMapping(IO
, Section
);
1412 // We also support reading a content as array of bytes using the ContentArray
1413 // key. obj2yaml never prints this field.
1414 assert(!IO
.outputting() || !Section
.ContentBuf
);
1415 IO
.mapOptional("ContentArray", Section
.ContentBuf
);
1416 if (Section
.ContentBuf
) {
1417 if (Section
.Content
)
1418 IO
.setError("Content and ContentArray can't be used together");
1419 Section
.Content
= yaml::BinaryRef(*Section
.ContentBuf
);
1422 IO
.mapOptional("Info", Section
.Info
);
1425 static void sectionMapping(IO
&IO
, ELFYAML::BBAddrMapSection
&Section
) {
1426 commonSectionMapping(IO
, Section
);
1427 IO
.mapOptional("Content", Section
.Content
);
1428 IO
.mapOptional("Entries", Section
.Entries
);
1429 IO
.mapOptional("PGOAnalyses", Section
.PGOAnalyses
);
1432 static void sectionMapping(IO
&IO
, ELFYAML::StackSizesSection
&Section
) {
1433 commonSectionMapping(IO
, Section
);
1434 IO
.mapOptional("Entries", Section
.Entries
);
1437 static void sectionMapping(IO
&IO
, ELFYAML::HashSection
&Section
) {
1438 commonSectionMapping(IO
, Section
);
1439 IO
.mapOptional("Bucket", Section
.Bucket
);
1440 IO
.mapOptional("Chain", Section
.Chain
);
1442 // obj2yaml does not dump these fields. They can be used to override nchain
1443 // and nbucket values for creating broken sections.
1444 assert(!IO
.outputting() || (!Section
.NBucket
&& !Section
.NChain
));
1445 IO
.mapOptional("NChain", Section
.NChain
);
1446 IO
.mapOptional("NBucket", Section
.NBucket
);
1449 static void sectionMapping(IO
&IO
, ELFYAML::NoteSection
&Section
) {
1450 commonSectionMapping(IO
, Section
);
1451 IO
.mapOptional("Notes", Section
.Notes
);
1455 static void sectionMapping(IO
&IO
, ELFYAML::GnuHashSection
&Section
) {
1456 commonSectionMapping(IO
, Section
);
1457 IO
.mapOptional("Header", Section
.Header
);
1458 IO
.mapOptional("BloomFilter", Section
.BloomFilter
);
1459 IO
.mapOptional("HashBuckets", Section
.HashBuckets
);
1460 IO
.mapOptional("HashValues", Section
.HashValues
);
1462 static void sectionMapping(IO
&IO
, ELFYAML::NoBitsSection
&Section
) {
1463 commonSectionMapping(IO
, Section
);
1466 static void sectionMapping(IO
&IO
, ELFYAML::VerdefSection
&Section
) {
1467 commonSectionMapping(IO
, Section
);
1468 IO
.mapOptional("Info", Section
.Info
);
1469 IO
.mapOptional("Entries", Section
.Entries
);
1472 static void sectionMapping(IO
&IO
, ELFYAML::SymverSection
&Section
) {
1473 commonSectionMapping(IO
, Section
);
1474 IO
.mapOptional("Entries", Section
.Entries
);
1477 static void sectionMapping(IO
&IO
, ELFYAML::VerneedSection
&Section
) {
1478 commonSectionMapping(IO
, Section
);
1479 IO
.mapOptional("Info", Section
.Info
);
1480 IO
.mapOptional("Dependencies", Section
.VerneedV
);
1483 static void sectionMapping(IO
&IO
, ELFYAML::RelocationSection
&Section
) {
1484 commonSectionMapping(IO
, Section
);
1485 IO
.mapOptional("Info", Section
.RelocatableSec
, StringRef());
1486 IO
.mapOptional("Relocations", Section
.Relocations
);
1489 static void sectionMapping(IO
&IO
, ELFYAML::RelrSection
&Section
) {
1490 commonSectionMapping(IO
, Section
);
1491 IO
.mapOptional("Entries", Section
.Entries
);
1494 static void groupSectionMapping(IO
&IO
, ELFYAML::GroupSection
&Group
) {
1495 commonSectionMapping(IO
, Group
);
1496 IO
.mapOptional("Info", Group
.Signature
);
1497 IO
.mapOptional("Members", Group
.Members
);
1500 static void sectionMapping(IO
&IO
, ELFYAML::SymtabShndxSection
&Section
) {
1501 commonSectionMapping(IO
, Section
);
1502 IO
.mapOptional("Entries", Section
.Entries
);
1505 static void sectionMapping(IO
&IO
, ELFYAML::AddrsigSection
&Section
) {
1506 commonSectionMapping(IO
, Section
);
1507 IO
.mapOptional("Symbols", Section
.Symbols
);
1510 static void fillMapping(IO
&IO
, ELFYAML::Fill
&Fill
) {
1511 IO
.mapOptional("Name", Fill
.Name
, StringRef());
1512 IO
.mapOptional("Pattern", Fill
.Pattern
);
1513 IO
.mapOptional("Offset", Fill
.Offset
);
1514 IO
.mapRequired("Size", Fill
.Size
);
1517 static void sectionHeaderTableMapping(IO
&IO
,
1518 ELFYAML::SectionHeaderTable
&SHT
) {
1519 IO
.mapOptional("Offset", SHT
.Offset
);
1520 IO
.mapOptional("Sections", SHT
.Sections
);
1521 IO
.mapOptional("Excluded", SHT
.Excluded
);
1522 IO
.mapOptional("NoHeaders", SHT
.NoHeaders
);
1525 static void sectionMapping(IO
&IO
, ELFYAML::LinkerOptionsSection
&Section
) {
1526 commonSectionMapping(IO
, Section
);
1527 IO
.mapOptional("Options", Section
.Options
);
1530 static void sectionMapping(IO
&IO
,
1531 ELFYAML::DependentLibrariesSection
&Section
) {
1532 commonSectionMapping(IO
, Section
);
1533 IO
.mapOptional("Libraries", Section
.Libs
);
1536 static void sectionMapping(IO
&IO
, ELFYAML::CallGraphProfileSection
&Section
) {
1537 commonSectionMapping(IO
, Section
);
1538 IO
.mapOptional("Entries", Section
.Entries
);
1541 void MappingTraits
<ELFYAML::SectionOrType
>::mapping(
1542 IO
&IO
, ELFYAML::SectionOrType
§ionOrType
) {
1543 IO
.mapRequired("SectionOrType", sectionOrType
.sectionNameOrType
);
1546 static void sectionMapping(IO
&IO
, ELFYAML::ARMIndexTableSection
&Section
) {
1547 commonSectionMapping(IO
, Section
);
1548 IO
.mapOptional("Entries", Section
.Entries
);
1551 static void sectionMapping(IO
&IO
, ELFYAML::MipsABIFlags
&Section
) {
1552 commonSectionMapping(IO
, Section
);
1553 IO
.mapOptional("Version", Section
.Version
, Hex16(0));
1554 IO
.mapRequired("ISA", Section
.ISALevel
);
1555 IO
.mapOptional("ISARevision", Section
.ISARevision
, Hex8(0));
1556 IO
.mapOptional("ISAExtension", Section
.ISAExtension
,
1557 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE
));
1558 IO
.mapOptional("ASEs", Section
.ASEs
, ELFYAML::MIPS_AFL_ASE(0));
1559 IO
.mapOptional("FpABI", Section
.FpABI
,
1560 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY
));
1561 IO
.mapOptional("GPRSize", Section
.GPRSize
,
1562 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1563 IO
.mapOptional("CPR1Size", Section
.CPR1Size
,
1564 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1565 IO
.mapOptional("CPR2Size", Section
.CPR2Size
,
1566 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1567 IO
.mapOptional("Flags1", Section
.Flags1
, ELFYAML::MIPS_AFL_FLAGS1(0));
1568 IO
.mapOptional("Flags2", Section
.Flags2
, Hex32(0));
1571 static StringRef
getStringValue(IO
&IO
, const char *Key
) {
1573 IO
.mapRequired(Key
, Val
);
1577 static void setStringValue(IO
&IO
, const char *Key
, StringRef Val
) {
1578 IO
.mapRequired(Key
, Val
);
1581 static bool isInteger(StringRef Val
) {
1583 return !Val
.getAsInteger(0, Tmp
);
1586 void MappingTraits
<std::unique_ptr
<ELFYAML::Chunk
>>::mapping(
1587 IO
&IO
, std::unique_ptr
<ELFYAML::Chunk
> &Section
) {
1588 ELFYAML::ELF_SHT Type
;
1590 if (IO
.outputting()) {
1591 if (auto *S
= dyn_cast
<ELFYAML::Section
>(Section
.get()))
1593 else if (auto *SHT
= dyn_cast
<ELFYAML::SectionHeaderTable
>(Section
.get()))
1594 TypeStr
= SHT
->TypeStr
;
1596 // When the Type string does not have a "SHT_" prefix, we know it is not a
1597 // description of a regular ELF output section.
1598 TypeStr
= getStringValue(IO
, "Type");
1599 if (TypeStr
.starts_with("SHT_") || isInteger(TypeStr
))
1600 IO
.mapRequired("Type", Type
);
1603 if (TypeStr
== "Fill") {
1604 assert(!IO
.outputting()); // We don't dump fills currently.
1605 Section
.reset(new ELFYAML::Fill());
1606 fillMapping(IO
, *cast
<ELFYAML::Fill
>(Section
.get()));
1610 if (TypeStr
== ELFYAML::SectionHeaderTable::TypeStr
) {
1611 if (IO
.outputting())
1612 setStringValue(IO
, "Type", TypeStr
);
1614 Section
.reset(new ELFYAML::SectionHeaderTable(/*IsImplicit=*/false));
1616 sectionHeaderTableMapping(
1617 IO
, *cast
<ELFYAML::SectionHeaderTable
>(Section
.get()));
1621 const auto &Obj
= *static_cast<ELFYAML::Object
*>(IO
.getContext());
1622 if (Obj
.getMachine() == ELF::EM_MIPS
&& Type
== ELF::SHT_MIPS_ABIFLAGS
) {
1623 if (!IO
.outputting())
1624 Section
.reset(new ELFYAML::MipsABIFlags());
1625 sectionMapping(IO
, *cast
<ELFYAML::MipsABIFlags
>(Section
.get()));
1629 if (Obj
.getMachine() == ELF::EM_ARM
&& Type
== ELF::SHT_ARM_EXIDX
) {
1630 if (!IO
.outputting())
1631 Section
.reset(new ELFYAML::ARMIndexTableSection());
1632 sectionMapping(IO
, *cast
<ELFYAML::ARMIndexTableSection
>(Section
.get()));
1637 case ELF::SHT_DYNAMIC
:
1638 if (!IO
.outputting())
1639 Section
.reset(new ELFYAML::DynamicSection());
1640 sectionMapping(IO
, *cast
<ELFYAML::DynamicSection
>(Section
.get()));
1645 if (!IO
.outputting())
1646 Section
.reset(new ELFYAML::RelocationSection());
1647 sectionMapping(IO
, *cast
<ELFYAML::RelocationSection
>(Section
.get()));
1650 if (!IO
.outputting())
1651 Section
.reset(new ELFYAML::RelrSection());
1652 sectionMapping(IO
, *cast
<ELFYAML::RelrSection
>(Section
.get()));
1654 case ELF::SHT_GROUP
:
1655 if (!IO
.outputting())
1656 Section
.reset(new ELFYAML::GroupSection());
1657 groupSectionMapping(IO
, *cast
<ELFYAML::GroupSection
>(Section
.get()));
1659 case ELF::SHT_NOBITS
:
1660 if (!IO
.outputting())
1661 Section
.reset(new ELFYAML::NoBitsSection());
1662 sectionMapping(IO
, *cast
<ELFYAML::NoBitsSection
>(Section
.get()));
1665 if (!IO
.outputting())
1666 Section
.reset(new ELFYAML::HashSection());
1667 sectionMapping(IO
, *cast
<ELFYAML::HashSection
>(Section
.get()));
1670 if (!IO
.outputting())
1671 Section
.reset(new ELFYAML::NoteSection());
1672 sectionMapping(IO
, *cast
<ELFYAML::NoteSection
>(Section
.get()));
1674 case ELF::SHT_GNU_HASH
:
1675 if (!IO
.outputting())
1676 Section
.reset(new ELFYAML::GnuHashSection());
1677 sectionMapping(IO
, *cast
<ELFYAML::GnuHashSection
>(Section
.get()));
1679 case ELF::SHT_GNU_verdef
:
1680 if (!IO
.outputting())
1681 Section
.reset(new ELFYAML::VerdefSection());
1682 sectionMapping(IO
, *cast
<ELFYAML::VerdefSection
>(Section
.get()));
1684 case ELF::SHT_GNU_versym
:
1685 if (!IO
.outputting())
1686 Section
.reset(new ELFYAML::SymverSection());
1687 sectionMapping(IO
, *cast
<ELFYAML::SymverSection
>(Section
.get()));
1689 case ELF::SHT_GNU_verneed
:
1690 if (!IO
.outputting())
1691 Section
.reset(new ELFYAML::VerneedSection());
1692 sectionMapping(IO
, *cast
<ELFYAML::VerneedSection
>(Section
.get()));
1694 case ELF::SHT_SYMTAB_SHNDX
:
1695 if (!IO
.outputting())
1696 Section
.reset(new ELFYAML::SymtabShndxSection());
1697 sectionMapping(IO
, *cast
<ELFYAML::SymtabShndxSection
>(Section
.get()));
1699 case ELF::SHT_LLVM_ADDRSIG
:
1700 if (!IO
.outputting())
1701 Section
.reset(new ELFYAML::AddrsigSection());
1702 sectionMapping(IO
, *cast
<ELFYAML::AddrsigSection
>(Section
.get()));
1704 case ELF::SHT_LLVM_LINKER_OPTIONS
:
1705 if (!IO
.outputting())
1706 Section
.reset(new ELFYAML::LinkerOptionsSection());
1707 sectionMapping(IO
, *cast
<ELFYAML::LinkerOptionsSection
>(Section
.get()));
1709 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES
:
1710 if (!IO
.outputting())
1711 Section
.reset(new ELFYAML::DependentLibrariesSection());
1713 *cast
<ELFYAML::DependentLibrariesSection
>(Section
.get()));
1715 case ELF::SHT_LLVM_CALL_GRAPH_PROFILE
:
1716 if (!IO
.outputting())
1717 Section
.reset(new ELFYAML::CallGraphProfileSection());
1718 sectionMapping(IO
, *cast
<ELFYAML::CallGraphProfileSection
>(Section
.get()));
1720 case ELF::SHT_LLVM_BB_ADDR_MAP
:
1721 if (!IO
.outputting())
1722 Section
.reset(new ELFYAML::BBAddrMapSection());
1723 sectionMapping(IO
, *cast
<ELFYAML::BBAddrMapSection
>(Section
.get()));
1726 if (!IO
.outputting()) {
1728 IO
.mapOptional("Name", Name
, StringRef());
1729 Name
= ELFYAML::dropUniqueSuffix(Name
);
1731 if (ELFYAML::StackSizesSection::nameMatches(Name
))
1732 Section
= std::make_unique
<ELFYAML::StackSizesSection
>();
1734 Section
= std::make_unique
<ELFYAML::RawContentSection
>();
1737 if (auto S
= dyn_cast
<ELFYAML::RawContentSection
>(Section
.get()))
1738 sectionMapping(IO
, *S
);
1740 sectionMapping(IO
, *cast
<ELFYAML::StackSizesSection
>(Section
.get()));
1744 std::string MappingTraits
<std::unique_ptr
<ELFYAML::Chunk
>>::validate(
1745 IO
&io
, std::unique_ptr
<ELFYAML::Chunk
> &C
) {
1746 if (const auto *F
= dyn_cast
<ELFYAML::Fill
>(C
.get())) {
1747 if (F
->Pattern
&& F
->Pattern
->binary_size() != 0 && !F
->Size
)
1748 return "\"Size\" can't be 0 when \"Pattern\" is not empty";
1752 if (const auto *SHT
= dyn_cast
<ELFYAML::SectionHeaderTable
>(C
.get())) {
1753 if (SHT
->NoHeaders
&& (SHT
->Sections
|| SHT
->Excluded
|| SHT
->Offset
))
1754 return "NoHeaders can't be used together with Offset/Sections/Excluded";
1758 const ELFYAML::Section
&Sec
= *cast
<ELFYAML::Section
>(C
.get());
1759 if (Sec
.Size
&& Sec
.Content
&&
1760 (uint64_t)(*Sec
.Size
) < Sec
.Content
->binary_size())
1761 return "Section size must be greater than or equal to the content size";
1763 auto BuildErrPrefix
= [](ArrayRef
<std::pair
<StringRef
, bool>> EntV
) {
1765 for (size_t I
= 0, E
= EntV
.size(); I
!= E
; ++I
) {
1766 StringRef Name
= EntV
[I
].first
;
1768 Msg
= "\"" + Name
.str() + "\"";
1771 if (I
!= EntV
.size() - 1)
1772 Msg
+= ", \"" + Name
.str() + "\"";
1774 Msg
+= " and \"" + Name
.str() + "\"";
1779 std::vector
<std::pair
<StringRef
, bool>> Entries
= Sec
.getEntries();
1780 const size_t NumUsedEntries
= llvm::count_if(
1781 Entries
, [](const std::pair
<StringRef
, bool> &P
) { return P
.second
; });
1783 if ((Sec
.Size
|| Sec
.Content
) && NumUsedEntries
> 0)
1784 return BuildErrPrefix(Entries
) +
1785 " cannot be used with \"Content\" or \"Size\"";
1787 if (NumUsedEntries
> 0 && Entries
.size() != NumUsedEntries
)
1788 return BuildErrPrefix(Entries
) + " must be used together";
1790 if (const auto *RawSection
= dyn_cast
<ELFYAML::RawContentSection
>(C
.get())) {
1791 if (RawSection
->Flags
&& RawSection
->ShFlags
)
1792 return "ShFlags and Flags cannot be used together";
1796 if (const auto *NB
= dyn_cast
<ELFYAML::NoBitsSection
>(C
.get())) {
1798 return "SHT_NOBITS section cannot have \"Content\"";
1802 if (const auto *MF
= dyn_cast
<ELFYAML::MipsABIFlags
>(C
.get())) {
1804 return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS "
1807 return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections";
1816 struct NormalizedMips64RelType
{
1817 NormalizedMips64RelType(IO
&)
1818 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1819 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1820 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1821 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF
)) {}
1822 NormalizedMips64RelType(IO
&, ELFYAML::ELF_REL Original
)
1823 : Type(Original
& 0xFF), Type2(Original
>> 8 & 0xFF),
1824 Type3(Original
>> 16 & 0xFF), SpecSym(Original
>> 24 & 0xFF) {}
1826 ELFYAML::ELF_REL
denormalize(IO
&) {
1827 ELFYAML::ELF_REL Res
= Type
| Type2
<< 8 | Type3
<< 16 | SpecSym
<< 24;
1831 ELFYAML::ELF_REL Type
;
1832 ELFYAML::ELF_REL Type2
;
1833 ELFYAML::ELF_REL Type3
;
1834 ELFYAML::ELF_RSS SpecSym
;
1837 } // end anonymous namespace
1839 void MappingTraits
<ELFYAML::StackSizeEntry
>::mapping(
1840 IO
&IO
, ELFYAML::StackSizeEntry
&E
) {
1841 assert(IO
.getContext() && "The IO context is not initialized");
1842 IO
.mapOptional("Address", E
.Address
, Hex64(0));
1843 IO
.mapRequired("Size", E
.Size
);
1846 void MappingTraits
<ELFYAML::BBAddrMapEntry
>::mapping(
1847 IO
&IO
, ELFYAML::BBAddrMapEntry
&E
) {
1848 assert(IO
.getContext() && "The IO context is not initialized");
1849 IO
.mapRequired("Version", E
.Version
);
1850 IO
.mapOptional("Feature", E
.Feature
, Hex8(0));
1851 IO
.mapOptional("NumBBRanges", E
.NumBBRanges
);
1852 IO
.mapOptional("BBRanges", E
.BBRanges
);
1855 void MappingTraits
<ELFYAML::BBAddrMapEntry::BBRangeEntry
>::mapping(
1856 IO
&IO
, ELFYAML::BBAddrMapEntry::BBRangeEntry
&E
) {
1857 IO
.mapOptional("BaseAddress", E
.BaseAddress
, Hex64(0));
1858 IO
.mapOptional("NumBlocks", E
.NumBlocks
);
1859 IO
.mapOptional("BBEntries", E
.BBEntries
);
1862 void MappingTraits
<ELFYAML::BBAddrMapEntry::BBEntry
>::mapping(
1863 IO
&IO
, ELFYAML::BBAddrMapEntry::BBEntry
&E
) {
1864 assert(IO
.getContext() && "The IO context is not initialized");
1865 IO
.mapOptional("ID", E
.ID
);
1866 IO
.mapRequired("AddressOffset", E
.AddressOffset
);
1867 IO
.mapRequired("Size", E
.Size
);
1868 IO
.mapRequired("Metadata", E
.Metadata
);
1871 void MappingTraits
<ELFYAML::PGOAnalysisMapEntry
>::mapping(
1872 IO
&IO
, ELFYAML::PGOAnalysisMapEntry
&E
) {
1873 assert(IO
.getContext() && "The IO context is not initialized");
1874 IO
.mapOptional("FuncEntryCount", E
.FuncEntryCount
);
1875 IO
.mapOptional("PGOBBEntries", E
.PGOBBEntries
);
1878 void MappingTraits
<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry
>::mapping(
1879 IO
&IO
, ELFYAML::PGOAnalysisMapEntry::PGOBBEntry
&E
) {
1880 assert(IO
.getContext() && "The IO context is not initialized");
1881 IO
.mapOptional("BBFreq", E
.BBFreq
);
1882 IO
.mapOptional("Successors", E
.Successors
);
1885 void MappingTraits
<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry
>::
1887 ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry
&E
) {
1888 assert(IO
.getContext() && "The IO context is not initialized");
1889 IO
.mapRequired("ID", E
.ID
);
1890 IO
.mapRequired("BrProb", E
.BrProb
);
1893 void MappingTraits
<ELFYAML::GnuHashHeader
>::mapping(IO
&IO
,
1894 ELFYAML::GnuHashHeader
&E
) {
1895 assert(IO
.getContext() && "The IO context is not initialized");
1896 IO
.mapOptional("NBuckets", E
.NBuckets
);
1897 IO
.mapRequired("SymNdx", E
.SymNdx
);
1898 IO
.mapOptional("MaskWords", E
.MaskWords
);
1899 IO
.mapRequired("Shift2", E
.Shift2
);
1902 void MappingTraits
<ELFYAML::DynamicEntry
>::mapping(IO
&IO
,
1903 ELFYAML::DynamicEntry
&Rel
) {
1904 assert(IO
.getContext() && "The IO context is not initialized");
1906 IO
.mapRequired("Tag", Rel
.Tag
);
1907 IO
.mapRequired("Value", Rel
.Val
);
1910 void MappingTraits
<ELFYAML::NoteEntry
>::mapping(IO
&IO
, ELFYAML::NoteEntry
&N
) {
1911 assert(IO
.getContext() && "The IO context is not initialized");
1913 IO
.mapOptional("Name", N
.Name
);
1914 IO
.mapOptional("Desc", N
.Desc
);
1915 IO
.mapRequired("Type", N
.Type
);
1918 void MappingTraits
<ELFYAML::VerdefEntry
>::mapping(IO
&IO
,
1919 ELFYAML::VerdefEntry
&E
) {
1920 assert(IO
.getContext() && "The IO context is not initialized");
1922 IO
.mapOptional("Version", E
.Version
);
1923 IO
.mapOptional("Flags", E
.Flags
);
1924 IO
.mapOptional("VersionNdx", E
.VersionNdx
);
1925 IO
.mapOptional("Hash", E
.Hash
);
1926 IO
.mapOptional("VDAux", E
.VDAux
);
1927 IO
.mapRequired("Names", E
.VerNames
);
1930 void MappingTraits
<ELFYAML::VerneedEntry
>::mapping(IO
&IO
,
1931 ELFYAML::VerneedEntry
&E
) {
1932 assert(IO
.getContext() && "The IO context is not initialized");
1934 IO
.mapRequired("Version", E
.Version
);
1935 IO
.mapRequired("File", E
.File
);
1936 IO
.mapRequired("Entries", E
.AuxV
);
1939 void MappingTraits
<ELFYAML::VernauxEntry
>::mapping(IO
&IO
,
1940 ELFYAML::VernauxEntry
&E
) {
1941 assert(IO
.getContext() && "The IO context is not initialized");
1943 IO
.mapRequired("Name", E
.Name
);
1944 IO
.mapRequired("Hash", E
.Hash
);
1945 IO
.mapRequired("Flags", E
.Flags
);
1946 IO
.mapRequired("Other", E
.Other
);
1949 void MappingTraits
<ELFYAML::Relocation
>::mapping(IO
&IO
,
1950 ELFYAML::Relocation
&Rel
) {
1951 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
1952 assert(Object
&& "The IO context is not initialized");
1954 IO
.mapOptional("Offset", Rel
.Offset
, (Hex64
)0);
1955 IO
.mapOptional("Symbol", Rel
.Symbol
);
1957 if (Object
->getMachine() == ELFYAML::ELF_EM(ELF::EM_MIPS
) &&
1958 Object
->Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
)) {
1959 MappingNormalization
<NormalizedMips64RelType
, ELFYAML::ELF_REL
> Key(
1961 IO
.mapRequired("Type", Key
->Type
);
1962 IO
.mapOptional("Type2", Key
->Type2
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1963 IO
.mapOptional("Type3", Key
->Type3
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1964 IO
.mapOptional("SpecSym", Key
->SpecSym
, ELFYAML::ELF_RSS(ELF::RSS_UNDEF
));
1966 IO
.mapRequired("Type", Rel
.Type
);
1968 IO
.mapOptional("Addend", Rel
.Addend
, (ELFYAML::YAMLIntUInt
)0);
1971 void MappingTraits
<ELFYAML::ARMIndexTableEntry
>::mapping(
1972 IO
&IO
, ELFYAML::ARMIndexTableEntry
&E
) {
1973 assert(IO
.getContext() && "The IO context is not initialized");
1974 IO
.mapRequired("Offset", E
.Offset
);
1976 StringRef CantUnwind
= "EXIDX_CANTUNWIND";
1977 if (IO
.outputting() && (uint32_t)E
.Value
== ARM::EHABI::EXIDX_CANTUNWIND
)
1978 IO
.mapRequired("Value", CantUnwind
);
1979 else if (!IO
.outputting() && getStringValue(IO
, "Value") == CantUnwind
)
1980 E
.Value
= ARM::EHABI::EXIDX_CANTUNWIND
;
1982 IO
.mapRequired("Value", E
.Value
);
1985 void MappingTraits
<ELFYAML::Object
>::mapping(IO
&IO
, ELFYAML::Object
&Object
) {
1986 assert(!IO
.getContext() && "The IO context is initialized already");
1987 IO
.setContext(&Object
);
1988 IO
.mapTag("!ELF", true);
1989 IO
.mapRequired("FileHeader", Object
.Header
);
1990 IO
.mapOptional("ProgramHeaders", Object
.ProgramHeaders
);
1991 IO
.mapOptional("Sections", Object
.Chunks
);
1992 IO
.mapOptional("Symbols", Object
.Symbols
);
1993 IO
.mapOptional("DynamicSymbols", Object
.DynamicSymbols
);
1994 IO
.mapOptional("DWARF", Object
.DWARF
);
1996 Object
.DWARF
->IsLittleEndian
=
1997 Object
.Header
.Data
== ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB
);
1998 Object
.DWARF
->Is64BitAddrSize
=
1999 Object
.Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
);
2001 IO
.setContext(nullptr);
2004 void MappingTraits
<ELFYAML::LinkerOption
>::mapping(IO
&IO
,
2005 ELFYAML::LinkerOption
&Opt
) {
2006 assert(IO
.getContext() && "The IO context is not initialized");
2007 IO
.mapRequired("Name", Opt
.Key
);
2008 IO
.mapRequired("Value", Opt
.Value
);
2011 void MappingTraits
<ELFYAML::CallGraphEntryWeight
>::mapping(
2012 IO
&IO
, ELFYAML::CallGraphEntryWeight
&E
) {
2013 assert(IO
.getContext() && "The IO context is not initialized");
2014 IO
.mapRequired("Weight", E
.Weight
);
2017 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG
)
2018 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP
)
2019 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT
)
2020 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE
)
2021 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1
)
2023 } // end namespace yaml
2025 } // end namespace llvm