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
);
141 // LLVM-specific notes.
142 ECase(NT_LLVM_HWASAN_GLOBALS
);
144 ECase(NT_GNU_ABI_TAG
);
146 ECase(NT_GNU_BUILD_ID
);
147 ECase(NT_GNU_GOLD_VERSION
);
148 ECase(NT_GNU_PROPERTY_TYPE_0
);
149 // FreeBSD note types.
150 ECase(NT_FREEBSD_ABI_TAG
);
151 ECase(NT_FREEBSD_NOINIT_TAG
);
152 ECase(NT_FREEBSD_ARCH_TAG
);
153 ECase(NT_FREEBSD_FEATURE_CTL
);
154 // FreeBSD core note types.
155 ECase(NT_FREEBSD_THRMISC
);
156 ECase(NT_FREEBSD_PROCSTAT_PROC
);
157 ECase(NT_FREEBSD_PROCSTAT_FILES
);
158 ECase(NT_FREEBSD_PROCSTAT_VMMAP
);
159 ECase(NT_FREEBSD_PROCSTAT_GROUPS
);
160 ECase(NT_FREEBSD_PROCSTAT_UMASK
);
161 ECase(NT_FREEBSD_PROCSTAT_RLIMIT
);
162 ECase(NT_FREEBSD_PROCSTAT_OSREL
);
163 ECase(NT_FREEBSD_PROCSTAT_PSSTRINGS
);
164 ECase(NT_FREEBSD_PROCSTAT_AUXV
);
165 // NetBSD core note types.
166 ECase(NT_NETBSDCORE_PROCINFO
);
167 ECase(NT_NETBSDCORE_AUXV
);
168 ECase(NT_NETBSDCORE_LWPSTATUS
);
169 // OpenBSD core note types.
170 ECase(NT_OPENBSD_PROCINFO
);
171 ECase(NT_OPENBSD_AUXV
);
172 ECase(NT_OPENBSD_REGS
);
173 ECase(NT_OPENBSD_FPREGS
);
174 ECase(NT_OPENBSD_XFPREGS
);
175 ECase(NT_OPENBSD_WCOOKIE
);
176 // AMD specific notes. (Code Object V2)
177 ECase(NT_AMD_HSA_CODE_OBJECT_VERSION
);
178 ECase(NT_AMD_HSA_HSAIL
);
179 ECase(NT_AMD_HSA_ISA_VERSION
);
180 ECase(NT_AMD_HSA_METADATA
);
181 ECase(NT_AMD_HSA_ISA_NAME
);
182 ECase(NT_AMD_PAL_METADATA
);
183 // AMDGPU specific notes. (Code Object V3)
184 ECase(NT_AMDGPU_METADATA
);
185 // Android specific notes.
186 ECase(NT_ANDROID_TYPE_IDENT
);
187 ECase(NT_ANDROID_TYPE_KUSER
);
188 ECase(NT_ANDROID_TYPE_MEMTAG
);
190 IO
.enumFallback
<Hex32
>(Value
);
193 void ScalarEnumerationTraits
<ELFYAML::ELF_EM
>::enumeration(
194 IO
&IO
, ELFYAML::ELF_EM
&Value
) {
195 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
206 ECase(EM_MIPS_RS3_LE
);
209 ECase(EM_SPARC32PLUS
);
272 ECase(EM_ARC_COMPACT
);
292 ECase(EM_ALTERA_NIOS2
);
306 ECase(EM_VIDEOCORE3
);
307 ECase(EM_LATTICEMICO32
);
312 ECase(EM_MMDSP_PLUS
);
313 ECase(EM_CYPRESS_M8C
);
328 ECase(EM_MCST_ELBRUS
);
340 ECase(EM_MICROBLAZE
);
343 ECase(EM_CLOUDSHIELD
);
346 ECase(EM_ARC_COMPACT2
);
349 ECase(EM_VIDEOCORE5
);
360 IO
.enumFallback
<Hex16
>(Value
);
363 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFCLASS
>::enumeration(
364 IO
&IO
, ELFYAML::ELF_ELFCLASS
&Value
) {
365 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
366 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
373 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFDATA
>::enumeration(
374 IO
&IO
, ELFYAML::ELF_ELFDATA
&Value
) {
375 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
376 // ELFDATANONE is an invalid data encoding, but we accept it because
377 // we want to be able to produce invalid binaries for the tests.
384 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFOSABI
>::enumeration(
385 IO
&IO
, ELFYAML::ELF_ELFOSABI
&Value
) {
386 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
387 ECase(ELFOSABI_NONE
);
388 ECase(ELFOSABI_HPUX
);
389 ECase(ELFOSABI_NETBSD
);
391 ECase(ELFOSABI_LINUX
);
392 ECase(ELFOSABI_HURD
);
393 ECase(ELFOSABI_SOLARIS
);
395 ECase(ELFOSABI_IRIX
);
396 ECase(ELFOSABI_FREEBSD
);
397 ECase(ELFOSABI_TRU64
);
398 ECase(ELFOSABI_MODESTO
);
399 ECase(ELFOSABI_OPENBSD
);
400 ECase(ELFOSABI_OPENVMS
);
402 ECase(ELFOSABI_AROS
);
403 ECase(ELFOSABI_FENIXOS
);
404 ECase(ELFOSABI_CLOUDABI
);
405 ECase(ELFOSABI_AMDGPU_HSA
);
406 ECase(ELFOSABI_AMDGPU_PAL
);
407 ECase(ELFOSABI_AMDGPU_MESA3D
);
409 ECase(ELFOSABI_C6000_ELFABI
);
410 ECase(ELFOSABI_C6000_LINUX
);
411 ECase(ELFOSABI_STANDALONE
);
413 IO
.enumFallback
<Hex8
>(Value
);
416 void ScalarBitSetTraits
<ELFYAML::ELF_EF
>::bitset(IO
&IO
,
417 ELFYAML::ELF_EF
&Value
) {
418 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
419 assert(Object
&& "The IO context is not initialized");
420 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
421 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
422 switch (Object
->getMachine()) {
424 BCase(EF_ARM_SOFT_FLOAT
);
425 BCase(EF_ARM_VFP_FLOAT
);
426 BCaseMask(EF_ARM_EABI_UNKNOWN
, EF_ARM_EABIMASK
);
427 BCaseMask(EF_ARM_EABI_VER1
, EF_ARM_EABIMASK
);
428 BCaseMask(EF_ARM_EABI_VER2
, EF_ARM_EABIMASK
);
429 BCaseMask(EF_ARM_EABI_VER3
, EF_ARM_EABIMASK
);
430 BCaseMask(EF_ARM_EABI_VER4
, EF_ARM_EABIMASK
);
431 BCaseMask(EF_ARM_EABI_VER5
, EF_ARM_EABIMASK
);
432 BCaseMask(EF_ARM_BE8
, EF_ARM_BE8
);
435 BCase(EF_MIPS_NOREORDER
);
439 BCase(EF_MIPS_32BITMODE
);
441 BCase(EF_MIPS_NAN2008
);
442 BCase(EF_MIPS_MICROMIPS
);
443 BCase(EF_MIPS_ARCH_ASE_M16
);
444 BCase(EF_MIPS_ARCH_ASE_MDMX
);
445 BCaseMask(EF_MIPS_ABI_O32
, EF_MIPS_ABI
);
446 BCaseMask(EF_MIPS_ABI_O64
, EF_MIPS_ABI
);
447 BCaseMask(EF_MIPS_ABI_EABI32
, EF_MIPS_ABI
);
448 BCaseMask(EF_MIPS_ABI_EABI64
, EF_MIPS_ABI
);
449 BCaseMask(EF_MIPS_MACH_3900
, EF_MIPS_MACH
);
450 BCaseMask(EF_MIPS_MACH_4010
, EF_MIPS_MACH
);
451 BCaseMask(EF_MIPS_MACH_4100
, EF_MIPS_MACH
);
452 BCaseMask(EF_MIPS_MACH_4650
, EF_MIPS_MACH
);
453 BCaseMask(EF_MIPS_MACH_4120
, EF_MIPS_MACH
);
454 BCaseMask(EF_MIPS_MACH_4111
, EF_MIPS_MACH
);
455 BCaseMask(EF_MIPS_MACH_SB1
, EF_MIPS_MACH
);
456 BCaseMask(EF_MIPS_MACH_OCTEON
, EF_MIPS_MACH
);
457 BCaseMask(EF_MIPS_MACH_XLR
, EF_MIPS_MACH
);
458 BCaseMask(EF_MIPS_MACH_OCTEON2
, EF_MIPS_MACH
);
459 BCaseMask(EF_MIPS_MACH_OCTEON3
, EF_MIPS_MACH
);
460 BCaseMask(EF_MIPS_MACH_5400
, EF_MIPS_MACH
);
461 BCaseMask(EF_MIPS_MACH_5900
, EF_MIPS_MACH
);
462 BCaseMask(EF_MIPS_MACH_5500
, EF_MIPS_MACH
);
463 BCaseMask(EF_MIPS_MACH_9000
, EF_MIPS_MACH
);
464 BCaseMask(EF_MIPS_MACH_LS2E
, EF_MIPS_MACH
);
465 BCaseMask(EF_MIPS_MACH_LS2F
, EF_MIPS_MACH
);
466 BCaseMask(EF_MIPS_MACH_LS3A
, EF_MIPS_MACH
);
467 BCaseMask(EF_MIPS_ARCH_1
, EF_MIPS_ARCH
);
468 BCaseMask(EF_MIPS_ARCH_2
, EF_MIPS_ARCH
);
469 BCaseMask(EF_MIPS_ARCH_3
, EF_MIPS_ARCH
);
470 BCaseMask(EF_MIPS_ARCH_4
, EF_MIPS_ARCH
);
471 BCaseMask(EF_MIPS_ARCH_5
, EF_MIPS_ARCH
);
472 BCaseMask(EF_MIPS_ARCH_32
, EF_MIPS_ARCH
);
473 BCaseMask(EF_MIPS_ARCH_64
, EF_MIPS_ARCH
);
474 BCaseMask(EF_MIPS_ARCH_32R2
, EF_MIPS_ARCH
);
475 BCaseMask(EF_MIPS_ARCH_64R2
, EF_MIPS_ARCH
);
476 BCaseMask(EF_MIPS_ARCH_32R6
, EF_MIPS_ARCH
);
477 BCaseMask(EF_MIPS_ARCH_64R6
, EF_MIPS_ARCH
);
479 case ELF::EM_HEXAGON
:
480 BCaseMask(EF_HEXAGON_MACH_V2
, EF_HEXAGON_MACH
);
481 BCaseMask(EF_HEXAGON_MACH_V3
, EF_HEXAGON_MACH
);
482 BCaseMask(EF_HEXAGON_MACH_V4
, EF_HEXAGON_MACH
);
483 BCaseMask(EF_HEXAGON_MACH_V5
, EF_HEXAGON_MACH
);
484 BCaseMask(EF_HEXAGON_MACH_V55
, EF_HEXAGON_MACH
);
485 BCaseMask(EF_HEXAGON_MACH_V60
, EF_HEXAGON_MACH
);
486 BCaseMask(EF_HEXAGON_MACH_V62
, EF_HEXAGON_MACH
);
487 BCaseMask(EF_HEXAGON_MACH_V65
, EF_HEXAGON_MACH
);
488 BCaseMask(EF_HEXAGON_MACH_V66
, EF_HEXAGON_MACH
);
489 BCaseMask(EF_HEXAGON_MACH_V67
, EF_HEXAGON_MACH
);
490 BCaseMask(EF_HEXAGON_MACH_V67T
, EF_HEXAGON_MACH
);
491 BCaseMask(EF_HEXAGON_MACH_V68
, EF_HEXAGON_MACH
);
492 BCaseMask(EF_HEXAGON_MACH_V69
, EF_HEXAGON_MACH
);
493 BCaseMask(EF_HEXAGON_MACH_V71
, EF_HEXAGON_MACH
);
494 BCaseMask(EF_HEXAGON_MACH_V71T
, EF_HEXAGON_MACH
);
495 BCaseMask(EF_HEXAGON_MACH_V73
, EF_HEXAGON_MACH
);
496 BCaseMask(EF_HEXAGON_ISA_V2
, EF_HEXAGON_ISA
);
497 BCaseMask(EF_HEXAGON_ISA_V3
, EF_HEXAGON_ISA
);
498 BCaseMask(EF_HEXAGON_ISA_V4
, EF_HEXAGON_ISA
);
499 BCaseMask(EF_HEXAGON_ISA_V5
, EF_HEXAGON_ISA
);
500 BCaseMask(EF_HEXAGON_ISA_V55
, EF_HEXAGON_ISA
);
501 BCaseMask(EF_HEXAGON_ISA_V60
, EF_HEXAGON_ISA
);
502 BCaseMask(EF_HEXAGON_ISA_V62
, EF_HEXAGON_ISA
);
503 BCaseMask(EF_HEXAGON_ISA_V65
, EF_HEXAGON_ISA
);
504 BCaseMask(EF_HEXAGON_ISA_V66
, EF_HEXAGON_ISA
);
505 BCaseMask(EF_HEXAGON_ISA_V67
, EF_HEXAGON_ISA
);
506 BCaseMask(EF_HEXAGON_ISA_V68
, EF_HEXAGON_ISA
);
507 BCaseMask(EF_HEXAGON_ISA_V69
, EF_HEXAGON_ISA
);
508 BCaseMask(EF_HEXAGON_ISA_V71
, EF_HEXAGON_ISA
);
509 BCaseMask(EF_HEXAGON_ISA_V73
, EF_HEXAGON_ISA
);
512 BCaseMask(EF_AVR_ARCH_AVR1
, EF_AVR_ARCH_MASK
);
513 BCaseMask(EF_AVR_ARCH_AVR2
, EF_AVR_ARCH_MASK
);
514 BCaseMask(EF_AVR_ARCH_AVR25
, EF_AVR_ARCH_MASK
);
515 BCaseMask(EF_AVR_ARCH_AVR3
, EF_AVR_ARCH_MASK
);
516 BCaseMask(EF_AVR_ARCH_AVR31
, EF_AVR_ARCH_MASK
);
517 BCaseMask(EF_AVR_ARCH_AVR35
, EF_AVR_ARCH_MASK
);
518 BCaseMask(EF_AVR_ARCH_AVR4
, EF_AVR_ARCH_MASK
);
519 BCaseMask(EF_AVR_ARCH_AVR5
, EF_AVR_ARCH_MASK
);
520 BCaseMask(EF_AVR_ARCH_AVR51
, EF_AVR_ARCH_MASK
);
521 BCaseMask(EF_AVR_ARCH_AVR6
, EF_AVR_ARCH_MASK
);
522 BCaseMask(EF_AVR_ARCH_AVRTINY
, EF_AVR_ARCH_MASK
);
523 BCaseMask(EF_AVR_ARCH_XMEGA1
, EF_AVR_ARCH_MASK
);
524 BCaseMask(EF_AVR_ARCH_XMEGA2
, EF_AVR_ARCH_MASK
);
525 BCaseMask(EF_AVR_ARCH_XMEGA3
, EF_AVR_ARCH_MASK
);
526 BCaseMask(EF_AVR_ARCH_XMEGA4
, EF_AVR_ARCH_MASK
);
527 BCaseMask(EF_AVR_ARCH_XMEGA5
, EF_AVR_ARCH_MASK
);
528 BCaseMask(EF_AVR_ARCH_XMEGA6
, EF_AVR_ARCH_MASK
);
529 BCaseMask(EF_AVR_ARCH_XMEGA7
, EF_AVR_ARCH_MASK
);
530 BCase(EF_AVR_LINKRELAX_PREPARED
);
532 case ELF::EM_LOONGARCH
:
533 BCaseMask(EF_LOONGARCH_ABI_SOFT_FLOAT
, EF_LOONGARCH_ABI_MODIFIER_MASK
);
534 BCaseMask(EF_LOONGARCH_ABI_SINGLE_FLOAT
, EF_LOONGARCH_ABI_MODIFIER_MASK
);
535 BCaseMask(EF_LOONGARCH_ABI_DOUBLE_FLOAT
, EF_LOONGARCH_ABI_MODIFIER_MASK
);
536 BCaseMask(EF_LOONGARCH_OBJABI_V0
, EF_LOONGARCH_OBJABI_MASK
);
537 BCaseMask(EF_LOONGARCH_OBJABI_V1
, EF_LOONGARCH_OBJABI_MASK
);
541 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT
, EF_RISCV_FLOAT_ABI
);
542 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE
, EF_RISCV_FLOAT_ABI
);
543 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE
, EF_RISCV_FLOAT_ABI
);
544 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD
, EF_RISCV_FLOAT_ABI
);
549 BCase(EF_XTENSA_XT_INSN
);
550 BCaseMask(EF_XTENSA_MACH_NONE
, EF_XTENSA_MACH
);
551 BCase(EF_XTENSA_XT_LIT
);
554 BCaseMask(EF_AMDGPU_MACH_NONE
, EF_AMDGPU_MACH
);
555 BCaseMask(EF_AMDGPU_MACH_R600_R600
, EF_AMDGPU_MACH
);
556 BCaseMask(EF_AMDGPU_MACH_R600_R630
, EF_AMDGPU_MACH
);
557 BCaseMask(EF_AMDGPU_MACH_R600_RS880
, EF_AMDGPU_MACH
);
558 BCaseMask(EF_AMDGPU_MACH_R600_RV670
, EF_AMDGPU_MACH
);
559 BCaseMask(EF_AMDGPU_MACH_R600_RV710
, EF_AMDGPU_MACH
);
560 BCaseMask(EF_AMDGPU_MACH_R600_RV730
, EF_AMDGPU_MACH
);
561 BCaseMask(EF_AMDGPU_MACH_R600_RV770
, EF_AMDGPU_MACH
);
562 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR
, EF_AMDGPU_MACH
);
563 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS
, EF_AMDGPU_MACH
);
564 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER
, EF_AMDGPU_MACH
);
565 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD
, EF_AMDGPU_MACH
);
566 BCaseMask(EF_AMDGPU_MACH_R600_SUMO
, EF_AMDGPU_MACH
);
567 BCaseMask(EF_AMDGPU_MACH_R600_BARTS
, EF_AMDGPU_MACH
);
568 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS
, EF_AMDGPU_MACH
);
569 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN
, EF_AMDGPU_MACH
);
570 BCaseMask(EF_AMDGPU_MACH_R600_TURKS
, EF_AMDGPU_MACH
);
571 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600
, EF_AMDGPU_MACH
);
572 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601
, EF_AMDGPU_MACH
);
573 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX602
, EF_AMDGPU_MACH
);
574 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700
, EF_AMDGPU_MACH
);
575 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701
, EF_AMDGPU_MACH
);
576 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702
, EF_AMDGPU_MACH
);
577 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703
, EF_AMDGPU_MACH
);
578 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704
, EF_AMDGPU_MACH
);
579 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX705
, EF_AMDGPU_MACH
);
580 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801
, EF_AMDGPU_MACH
);
581 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802
, EF_AMDGPU_MACH
);
582 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803
, EF_AMDGPU_MACH
);
583 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX805
, EF_AMDGPU_MACH
);
584 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810
, EF_AMDGPU_MACH
);
585 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900
, EF_AMDGPU_MACH
);
586 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902
, EF_AMDGPU_MACH
);
587 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904
, EF_AMDGPU_MACH
);
588 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906
, EF_AMDGPU_MACH
);
589 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908
, EF_AMDGPU_MACH
);
590 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909
, EF_AMDGPU_MACH
);
591 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90A
, EF_AMDGPU_MACH
);
592 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90C
, EF_AMDGPU_MACH
);
593 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX940
, EF_AMDGPU_MACH
);
594 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX941
, EF_AMDGPU_MACH
);
595 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX942
, EF_AMDGPU_MACH
);
596 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010
, EF_AMDGPU_MACH
);
597 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011
, EF_AMDGPU_MACH
);
598 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012
, EF_AMDGPU_MACH
);
599 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1013
, EF_AMDGPU_MACH
);
600 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1030
, EF_AMDGPU_MACH
);
601 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1031
, EF_AMDGPU_MACH
);
602 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1032
, EF_AMDGPU_MACH
);
603 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1033
, EF_AMDGPU_MACH
);
604 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1034
, EF_AMDGPU_MACH
);
605 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1035
, EF_AMDGPU_MACH
);
606 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1036
, EF_AMDGPU_MACH
);
607 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1100
, EF_AMDGPU_MACH
);
608 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1101
, EF_AMDGPU_MACH
);
609 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1102
, EF_AMDGPU_MACH
);
610 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1103
, EF_AMDGPU_MACH
);
611 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1150
, EF_AMDGPU_MACH
);
612 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1151
, EF_AMDGPU_MACH
);
613 switch (Object
->Header
.ABIVersion
) {
615 // ELFOSABI_AMDGPU_PAL, ELFOSABI_AMDGPU_MESA3D support *_V3 flags.
617 case ELF::ELFABIVERSION_AMDGPU_HSA_V3
:
618 BCase(EF_AMDGPU_FEATURE_XNACK_V3
);
619 BCase(EF_AMDGPU_FEATURE_SRAMECC_V3
);
621 case ELF::ELFABIVERSION_AMDGPU_HSA_V4
:
622 case ELF::ELFABIVERSION_AMDGPU_HSA_V5
:
623 BCaseMask(EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
,
624 EF_AMDGPU_FEATURE_XNACK_V4
);
625 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ANY_V4
,
626 EF_AMDGPU_FEATURE_XNACK_V4
);
627 BCaseMask(EF_AMDGPU_FEATURE_XNACK_OFF_V4
,
628 EF_AMDGPU_FEATURE_XNACK_V4
);
629 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ON_V4
,
630 EF_AMDGPU_FEATURE_XNACK_V4
);
631 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
,
632 EF_AMDGPU_FEATURE_SRAMECC_V4
);
633 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
,
634 EF_AMDGPU_FEATURE_SRAMECC_V4
);
635 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
,
636 EF_AMDGPU_FEATURE_SRAMECC_V4
);
637 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ON_V4
,
638 EF_AMDGPU_FEATURE_SRAMECC_V4
);
649 void ScalarEnumerationTraits
<ELFYAML::ELF_SHT
>::enumeration(
650 IO
&IO
, ELFYAML::ELF_SHT
&Value
) {
651 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
652 assert(Object
&& "The IO context is not initialized");
653 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
657 // FIXME: Issue a diagnostic with this information.
667 ECase(SHT_INIT_ARRAY
);
668 ECase(SHT_FINI_ARRAY
);
669 ECase(SHT_PREINIT_ARRAY
);
671 ECase(SHT_SYMTAB_SHNDX
);
673 ECase(SHT_ANDROID_REL
);
674 ECase(SHT_ANDROID_RELA
);
675 ECase(SHT_ANDROID_RELR
);
676 ECase(SHT_LLVM_ODRTAB
);
677 ECase(SHT_LLVM_LINKER_OPTIONS
);
678 ECase(SHT_LLVM_CALL_GRAPH_PROFILE
);
679 ECase(SHT_LLVM_ADDRSIG
);
680 ECase(SHT_LLVM_DEPENDENT_LIBRARIES
);
681 ECase(SHT_LLVM_SYMPART
);
682 ECase(SHT_LLVM_PART_EHDR
);
683 ECase(SHT_LLVM_PART_PHDR
);
684 ECase(SHT_LLVM_BB_ADDR_MAP_V0
);
685 ECase(SHT_LLVM_BB_ADDR_MAP
);
686 ECase(SHT_LLVM_OFFLOADING
);
688 ECase(SHT_GNU_ATTRIBUTES
);
690 ECase(SHT_GNU_verdef
);
691 ECase(SHT_GNU_verneed
);
692 ECase(SHT_GNU_versym
);
693 switch (Object
->getMachine()) {
695 ECase(SHT_ARM_EXIDX
);
696 ECase(SHT_ARM_PREEMPTMAP
);
697 ECase(SHT_ARM_ATTRIBUTES
);
698 ECase(SHT_ARM_DEBUGOVERLAY
);
699 ECase(SHT_ARM_OVERLAYSECTION
);
701 case ELF::EM_HEXAGON
:
702 ECase(SHT_HEX_ORDERED
);
705 ECase(SHT_X86_64_UNWIND
);
708 ECase(SHT_MIPS_REGINFO
);
709 ECase(SHT_MIPS_OPTIONS
);
710 ECase(SHT_MIPS_DWARF
);
711 ECase(SHT_MIPS_ABIFLAGS
);
714 ECase(SHT_RISCV_ATTRIBUTES
);
717 ECase(SHT_MSP430_ATTRIBUTES
);
719 case ELF::EM_AARCH64
:
720 ECase(SHT_AARCH64_MEMTAG_GLOBALS_STATIC
);
721 ECase(SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC
);
728 IO
.enumFallback
<Hex32
>(Value
);
731 void ScalarBitSetTraits
<ELFYAML::ELF_PF
>::bitset(IO
&IO
,
732 ELFYAML::ELF_PF
&Value
) {
733 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
739 void ScalarBitSetTraits
<ELFYAML::ELF_SHF
>::bitset(IO
&IO
,
740 ELFYAML::ELF_SHF
&Value
) {
741 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
742 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
746 BCase(SHF_EXECINSTR
);
749 BCase(SHF_INFO_LINK
);
750 BCase(SHF_LINK_ORDER
);
751 BCase(SHF_OS_NONCONFORMING
);
754 BCase(SHF_COMPRESSED
);
755 switch (Object
->getOSAbi()) {
756 case ELF::ELFOSABI_SOLARIS
:
757 BCase(SHF_SUNW_NODISCARD
);
760 BCase(SHF_GNU_RETAIN
);
763 switch (Object
->getMachine()) {
765 BCase(SHF_ARM_PURECODE
);
767 case ELF::EM_HEXAGON
:
768 BCase(SHF_HEX_GPREL
);
771 BCase(SHF_MIPS_NODUPES
);
772 BCase(SHF_MIPS_NAMES
);
773 BCase(SHF_MIPS_LOCAL
);
774 BCase(SHF_MIPS_NOSTRIP
);
775 BCase(SHF_MIPS_GPREL
);
776 BCase(SHF_MIPS_MERGE
);
777 BCase(SHF_MIPS_ADDR
);
778 BCase(SHF_MIPS_STRING
);
781 BCase(SHF_X86_64_LARGE
);
790 void ScalarEnumerationTraits
<ELFYAML::ELF_SHN
>::enumeration(
791 IO
&IO
, ELFYAML::ELF_SHN
&Value
) {
792 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
793 assert(Object
&& "The IO context is not initialized");
794 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
796 ECase(SHN_LORESERVE
);
804 ECase(SHN_HIRESERVE
);
805 ECase(SHN_AMDGPU_LDS
);
807 if (!IO
.outputting() || Object
->getMachine() == ELF::EM_MIPS
) {
808 ECase(SHN_MIPS_ACOMMON
);
809 ECase(SHN_MIPS_TEXT
);
810 ECase(SHN_MIPS_DATA
);
811 ECase(SHN_MIPS_SCOMMON
);
812 ECase(SHN_MIPS_SUNDEFINED
);
815 ECase(SHN_HEXAGON_SCOMMON
);
816 ECase(SHN_HEXAGON_SCOMMON_1
);
817 ECase(SHN_HEXAGON_SCOMMON_2
);
818 ECase(SHN_HEXAGON_SCOMMON_4
);
819 ECase(SHN_HEXAGON_SCOMMON_8
);
821 IO
.enumFallback
<Hex16
>(Value
);
824 void ScalarEnumerationTraits
<ELFYAML::ELF_STB
>::enumeration(
825 IO
&IO
, ELFYAML::ELF_STB
&Value
) {
826 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
830 ECase(STB_GNU_UNIQUE
);
832 IO
.enumFallback
<Hex8
>(Value
);
835 void ScalarEnumerationTraits
<ELFYAML::ELF_STT
>::enumeration(
836 IO
&IO
, ELFYAML::ELF_STT
&Value
) {
837 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
845 ECase(STT_GNU_IFUNC
);
847 IO
.enumFallback
<Hex8
>(Value
);
851 void ScalarEnumerationTraits
<ELFYAML::ELF_RSS
>::enumeration(
852 IO
&IO
, ELFYAML::ELF_RSS
&Value
) {
853 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
861 void ScalarEnumerationTraits
<ELFYAML::ELF_REL
>::enumeration(
862 IO
&IO
, ELFYAML::ELF_REL
&Value
) {
863 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
864 assert(Object
&& "The IO context is not initialized");
865 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
866 switch (Object
->getMachine()) {
868 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
871 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
873 case ELF::EM_HEXAGON
:
874 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
878 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
880 case ELF::EM_AARCH64
:
881 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
884 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
887 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
890 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
893 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
896 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
899 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
902 #include "llvm/BinaryFormat/ELFRelocs/VE.def"
905 #include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
908 #include "llvm/BinaryFormat/ELFRelocs/PowerPC.def"
911 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
914 #include "llvm/BinaryFormat/ELFRelocs/M68k.def"
916 case ELF::EM_LOONGARCH
:
917 #include "llvm/BinaryFormat/ELFRelocs/LoongArch.def"
920 #include "llvm/BinaryFormat/ELFRelocs/Xtensa.def"
927 IO
.enumFallback
<Hex32
>(Value
);
930 void ScalarEnumerationTraits
<ELFYAML::ELF_DYNTAG
>::enumeration(
931 IO
&IO
, ELFYAML::ELF_DYNTAG
&Value
) {
932 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
933 assert(Object
&& "The IO context is not initialized");
935 // Disable architecture specific tags by default. We might enable them below.
936 #define AARCH64_DYNAMIC_TAG(name, value)
937 #define MIPS_DYNAMIC_TAG(name, value)
938 #define HEXAGON_DYNAMIC_TAG(name, value)
939 #define PPC_DYNAMIC_TAG(name, value)
940 #define PPC64_DYNAMIC_TAG(name, value)
941 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
942 #define DYNAMIC_TAG_MARKER(name, value)
944 #define STRINGIFY(X) (#X)
945 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
946 switch (Object
->getMachine()) {
947 case ELF::EM_AARCH64
:
948 #undef AARCH64_DYNAMIC_TAG
949 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
950 #include "llvm/BinaryFormat/DynamicTags.def"
951 #undef AARCH64_DYNAMIC_TAG
952 #define AARCH64_DYNAMIC_TAG(name, value)
955 #undef MIPS_DYNAMIC_TAG
956 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
957 #include "llvm/BinaryFormat/DynamicTags.def"
958 #undef MIPS_DYNAMIC_TAG
959 #define MIPS_DYNAMIC_TAG(name, value)
961 case ELF::EM_HEXAGON
:
962 #undef HEXAGON_DYNAMIC_TAG
963 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
964 #include "llvm/BinaryFormat/DynamicTags.def"
965 #undef HEXAGON_DYNAMIC_TAG
966 #define HEXAGON_DYNAMIC_TAG(name, value)
969 #undef PPC_DYNAMIC_TAG
970 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
971 #include "llvm/BinaryFormat/DynamicTags.def"
972 #undef PPC_DYNAMIC_TAG
973 #define PPC_DYNAMIC_TAG(name, value)
976 #undef PPC64_DYNAMIC_TAG
977 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
978 #include "llvm/BinaryFormat/DynamicTags.def"
979 #undef PPC64_DYNAMIC_TAG
980 #define PPC64_DYNAMIC_TAG(name, value)
983 #undef RISCV_DYNAMIC_TAG
984 #define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
985 #include "llvm/BinaryFormat/DynamicTags.def"
986 #undef RISCV_DYNAMIC_TAG
987 #define RISCV_DYNAMIC_TAG(name, value)
990 #include "llvm/BinaryFormat/DynamicTags.def"
993 #undef AARCH64_DYNAMIC_TAG
994 #undef MIPS_DYNAMIC_TAG
995 #undef HEXAGON_DYNAMIC_TAG
996 #undef PPC_DYNAMIC_TAG
997 #undef PPC64_DYNAMIC_TAG
998 #undef DYNAMIC_TAG_MARKER
1002 IO
.enumFallback
<Hex64
>(Value
);
1005 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_REG
>::enumeration(
1006 IO
&IO
, ELFYAML::MIPS_AFL_REG
&Value
) {
1007 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1015 void ScalarEnumerationTraits
<ELFYAML::MIPS_ABI_FP
>::enumeration(
1016 IO
&IO
, ELFYAML::MIPS_ABI_FP
&Value
) {
1017 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
1029 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_EXT
>::enumeration(
1030 IO
&IO
, ELFYAML::MIPS_AFL_EXT
&Value
) {
1031 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1036 ECase(EXT_LOONGSON_3A
);
1049 ECase(EXT_LOONGSON_2E
);
1050 ECase(EXT_LOONGSON_2F
);
1055 void ScalarEnumerationTraits
<ELFYAML::MIPS_ISA
>::enumeration(
1056 IO
&IO
, ELFYAML::MIPS_ISA
&Value
) {
1057 IO
.enumCase(Value
, "MIPS1", 1);
1058 IO
.enumCase(Value
, "MIPS2", 2);
1059 IO
.enumCase(Value
, "MIPS3", 3);
1060 IO
.enumCase(Value
, "MIPS4", 4);
1061 IO
.enumCase(Value
, "MIPS5", 5);
1062 IO
.enumCase(Value
, "MIPS32", 32);
1063 IO
.enumCase(Value
, "MIPS64", 64);
1064 IO
.enumFallback
<Hex32
>(Value
);
1067 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_ASE
>::bitset(
1068 IO
&IO
, ELFYAML::MIPS_AFL_ASE
&Value
) {
1069 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
1088 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_FLAGS1
>::bitset(
1089 IO
&IO
, ELFYAML::MIPS_AFL_FLAGS1
&Value
) {
1090 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
1095 void MappingTraits
<ELFYAML::SectionHeader
>::mapping(
1096 IO
&IO
, ELFYAML::SectionHeader
&SHdr
) {
1097 IO
.mapRequired("Name", SHdr
.Name
);
1100 void MappingTraits
<ELFYAML::FileHeader
>::mapping(IO
&IO
,
1101 ELFYAML::FileHeader
&FileHdr
) {
1102 IO
.mapRequired("Class", FileHdr
.Class
);
1103 IO
.mapRequired("Data", FileHdr
.Data
);
1104 IO
.mapOptional("OSABI", FileHdr
.OSABI
, ELFYAML::ELF_ELFOSABI(0));
1105 IO
.mapOptional("ABIVersion", FileHdr
.ABIVersion
, Hex8(0));
1106 IO
.mapRequired("Type", FileHdr
.Type
);
1107 IO
.mapOptional("Machine", FileHdr
.Machine
);
1108 IO
.mapOptional("Flags", FileHdr
.Flags
, ELFYAML::ELF_EF(0));
1109 IO
.mapOptional("Entry", FileHdr
.Entry
, Hex64(0));
1110 IO
.mapOptional("SectionHeaderStringTable", FileHdr
.SectionHeaderStringTable
);
1112 // obj2yaml does not dump these fields.
1113 assert(!IO
.outputting() ||
1114 (!FileHdr
.EPhOff
&& !FileHdr
.EPhEntSize
&& !FileHdr
.EPhNum
));
1115 IO
.mapOptional("EPhOff", FileHdr
.EPhOff
);
1116 IO
.mapOptional("EPhEntSize", FileHdr
.EPhEntSize
);
1117 IO
.mapOptional("EPhNum", FileHdr
.EPhNum
);
1118 IO
.mapOptional("EShEntSize", FileHdr
.EShEntSize
);
1119 IO
.mapOptional("EShOff", FileHdr
.EShOff
);
1120 IO
.mapOptional("EShNum", FileHdr
.EShNum
);
1121 IO
.mapOptional("EShStrNdx", FileHdr
.EShStrNdx
);
1124 void MappingTraits
<ELFYAML::ProgramHeader
>::mapping(
1125 IO
&IO
, ELFYAML::ProgramHeader
&Phdr
) {
1126 IO
.mapRequired("Type", Phdr
.Type
);
1127 IO
.mapOptional("Flags", Phdr
.Flags
, ELFYAML::ELF_PF(0));
1128 IO
.mapOptional("FirstSec", Phdr
.FirstSec
);
1129 IO
.mapOptional("LastSec", Phdr
.LastSec
);
1130 IO
.mapOptional("VAddr", Phdr
.VAddr
, Hex64(0));
1131 IO
.mapOptional("PAddr", Phdr
.PAddr
, Phdr
.VAddr
);
1132 IO
.mapOptional("Align", Phdr
.Align
);
1133 IO
.mapOptional("FileSize", Phdr
.FileSize
);
1134 IO
.mapOptional("MemSize", Phdr
.MemSize
);
1135 IO
.mapOptional("Offset", Phdr
.Offset
);
1138 std::string MappingTraits
<ELFYAML::ProgramHeader
>::validate(
1139 IO
&IO
, ELFYAML::ProgramHeader
&FileHdr
) {
1140 if (!FileHdr
.FirstSec
&& FileHdr
.LastSec
)
1141 return "the \"LastSec\" key can't be used without the \"FirstSec\" key";
1142 if (FileHdr
.FirstSec
&& !FileHdr
.LastSec
)
1143 return "the \"FirstSec\" key can't be used without the \"LastSec\" key";
1147 LLVM_YAML_STRONG_TYPEDEF(StringRef
, StOtherPiece
)
1149 template <> struct ScalarTraits
<StOtherPiece
> {
1150 static void output(const StOtherPiece
&Val
, void *, raw_ostream
&Out
) {
1153 static StringRef
input(StringRef Scalar
, void *, StOtherPiece
&Val
) {
1157 static QuotingType
mustQuote(StringRef
) { return QuotingType::None
; }
1159 template <> struct SequenceElementTraits
<StOtherPiece
> {
1160 static const bool flow
= true;
1163 template <> struct ScalarTraits
<ELFYAML::YAMLFlowString
> {
1164 static void output(const ELFYAML::YAMLFlowString
&Val
, void *,
1168 static StringRef
input(StringRef Scalar
, void *,
1169 ELFYAML::YAMLFlowString
&Val
) {
1173 static QuotingType
mustQuote(StringRef S
) {
1174 return ScalarTraits
<StringRef
>::mustQuote(S
);
1177 template <> struct SequenceElementTraits
<ELFYAML::YAMLFlowString
> {
1178 static const bool flow
= true;
1183 struct NormalizedOther
{
1184 NormalizedOther(IO
&IO
) : YamlIO(IO
) {}
1185 NormalizedOther(IO
&IO
, std::optional
<uint8_t> Original
) : YamlIO(IO
) {
1186 assert(Original
&& "This constructor is only used for outputting YAML and "
1187 "assumes a non-empty Original");
1188 std::vector
<StOtherPiece
> Ret
;
1189 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
1190 for (std::pair
<StringRef
, uint8_t> &P
:
1191 getFlags(Object
->getMachine()).takeVector()) {
1192 uint8_t FlagValue
= P
.second
;
1193 if ((*Original
& FlagValue
) != FlagValue
)
1195 *Original
&= ~FlagValue
;
1196 Ret
.push_back({P
.first
});
1199 if (*Original
!= 0) {
1200 UnknownFlagsHolder
= std::to_string(*Original
);
1201 Ret
.push_back({UnknownFlagsHolder
});
1205 Other
= std::move(Ret
);
1208 uint8_t toValue(StringRef Name
) {
1209 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
1210 MapVector
<StringRef
, uint8_t> Flags
= getFlags(Object
->getMachine());
1212 auto It
= Flags
.find(Name
);
1213 if (It
!= Flags
.end())
1217 if (to_integer(Name
, Val
))
1220 YamlIO
.setError("an unknown value is used for symbol's 'Other' field: " +
1225 std::optional
<uint8_t> denormalize(IO
&) {
1227 return std::nullopt
;
1229 for (StOtherPiece
&Val
: *Other
)
1230 Ret
|= toValue(Val
);
1234 // st_other field is used to encode symbol visibility and platform-dependent
1235 // flags and values. This method returns a name to value map that is used for
1236 // parsing and encoding this field.
1237 MapVector
<StringRef
, uint8_t> getFlags(unsigned EMachine
) {
1238 MapVector
<StringRef
, uint8_t> Map
;
1239 // STV_* values are just enumeration values. We add them in a reversed order
1240 // because when we convert the st_other to named constants when printing
1241 // YAML we want to use a maximum number of bits on each step:
1242 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
1243 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
1244 Map
["STV_PROTECTED"] = ELF::STV_PROTECTED
;
1245 Map
["STV_HIDDEN"] = ELF::STV_HIDDEN
;
1246 Map
["STV_INTERNAL"] = ELF::STV_INTERNAL
;
1247 // STV_DEFAULT is used to represent the default visibility and has a value
1248 // 0. We want to be able to read it from YAML documents, but there is no
1249 // reason to print it.
1250 if (!YamlIO
.outputting())
1251 Map
["STV_DEFAULT"] = ELF::STV_DEFAULT
;
1253 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
1254 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
1255 // consumed first when we print the output, because we do not want to print
1256 // any other flags that have the same bits instead.
1257 if (EMachine
== ELF::EM_MIPS
) {
1258 Map
["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16
;
1259 Map
["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS
;
1260 Map
["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC
;
1261 Map
["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT
;
1262 Map
["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL
;
1265 if (EMachine
== ELF::EM_AARCH64
)
1266 Map
["STO_AARCH64_VARIANT_PCS"] = ELF::STO_AARCH64_VARIANT_PCS
;
1267 if (EMachine
== ELF::EM_RISCV
)
1268 Map
["STO_RISCV_VARIANT_CC"] = ELF::STO_RISCV_VARIANT_CC
;
1273 std::optional
<std::vector
<StOtherPiece
>> Other
;
1274 std::string UnknownFlagsHolder
;
1277 } // end anonymous namespace
1279 void ScalarTraits
<ELFYAML::YAMLIntUInt
>::output(const ELFYAML::YAMLIntUInt
&Val
,
1280 void *Ctx
, raw_ostream
&Out
) {
1284 StringRef ScalarTraits
<ELFYAML::YAMLIntUInt
>::input(StringRef Scalar
, void *Ctx
,
1285 ELFYAML::YAMLIntUInt
&Val
) {
1286 const bool Is64
= static_cast<ELFYAML::Object
*>(Ctx
)->Header
.Class
==
1287 ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
);
1288 StringRef ErrMsg
= "invalid number";
1289 // We do not accept negative hex numbers because their meaning is ambiguous.
1290 // For example, would -0xfffffffff mean 1 or INT32_MIN?
1291 if (Scalar
.empty() || Scalar
.startswith("-0x"))
1294 if (Scalar
.startswith("-")) {
1295 const int64_t MinVal
= Is64
? INT64_MIN
: INT32_MIN
;
1297 if (getAsSignedInteger(Scalar
, /*Radix=*/0, Int
) || (Int
< MinVal
))
1303 const uint64_t MaxVal
= Is64
? UINT64_MAX
: UINT32_MAX
;
1304 unsigned long long UInt
;
1305 if (getAsUnsignedInteger(Scalar
, /*Radix=*/0, UInt
) || (UInt
> MaxVal
))
1311 void MappingTraits
<ELFYAML::Symbol
>::mapping(IO
&IO
, ELFYAML::Symbol
&Symbol
) {
1312 IO
.mapOptional("Name", Symbol
.Name
, StringRef());
1313 IO
.mapOptional("StName", Symbol
.StName
);
1314 IO
.mapOptional("Type", Symbol
.Type
, ELFYAML::ELF_STT(0));
1315 IO
.mapOptional("Section", Symbol
.Section
);
1316 IO
.mapOptional("Index", Symbol
.Index
);
1317 IO
.mapOptional("Binding", Symbol
.Binding
, ELFYAML::ELF_STB(0));
1318 IO
.mapOptional("Value", Symbol
.Value
);
1319 IO
.mapOptional("Size", Symbol
.Size
);
1321 // Symbol's Other field is a bit special. It is usually a field that
1322 // represents st_other and holds the symbol visibility. However, on some
1323 // platforms, it can contain bit fields and regular values, or even sometimes
1324 // a crazy mix of them (see comments for NormalizedOther). Because of this, we
1325 // need special handling.
1326 MappingNormalization
<NormalizedOther
, std::optional
<uint8_t>> Keys(
1328 IO
.mapOptional("Other", Keys
->Other
);
1331 std::string MappingTraits
<ELFYAML::Symbol
>::validate(IO
&IO
,
1332 ELFYAML::Symbol
&Symbol
) {
1333 if (Symbol
.Index
&& Symbol
.Section
)
1334 return "Index and Section cannot both be specified for Symbol";
1338 static void commonSectionMapping(IO
&IO
, ELFYAML::Section
&Section
) {
1339 IO
.mapOptional("Name", Section
.Name
, StringRef());
1340 IO
.mapRequired("Type", Section
.Type
);
1341 IO
.mapOptional("Flags", Section
.Flags
);
1342 IO
.mapOptional("Address", Section
.Address
);
1343 IO
.mapOptional("Link", Section
.Link
);
1344 IO
.mapOptional("AddressAlign", Section
.AddressAlign
, Hex64(0));
1345 IO
.mapOptional("EntSize", Section
.EntSize
);
1346 IO
.mapOptional("Offset", Section
.Offset
);
1348 IO
.mapOptional("Content", Section
.Content
);
1349 IO
.mapOptional("Size", Section
.Size
);
1351 // obj2yaml does not dump these fields. They are expected to be empty when we
1352 // are producing YAML, because yaml2obj sets appropriate values for them
1353 // automatically when they are not explicitly defined.
1354 assert(!IO
.outputting() ||
1355 (!Section
.ShOffset
&& !Section
.ShSize
&& !Section
.ShName
&&
1356 !Section
.ShFlags
&& !Section
.ShType
&& !Section
.ShAddrAlign
));
1357 IO
.mapOptional("ShAddrAlign", Section
.ShAddrAlign
);
1358 IO
.mapOptional("ShName", Section
.ShName
);
1359 IO
.mapOptional("ShOffset", Section
.ShOffset
);
1360 IO
.mapOptional("ShSize", Section
.ShSize
);
1361 IO
.mapOptional("ShFlags", Section
.ShFlags
);
1362 IO
.mapOptional("ShType", Section
.ShType
);
1365 static void sectionMapping(IO
&IO
, ELFYAML::DynamicSection
&Section
) {
1366 commonSectionMapping(IO
, Section
);
1367 IO
.mapOptional("Entries", Section
.Entries
);
1370 static void sectionMapping(IO
&IO
, ELFYAML::RawContentSection
&Section
) {
1371 commonSectionMapping(IO
, Section
);
1373 // We also support reading a content as array of bytes using the ContentArray
1374 // key. obj2yaml never prints this field.
1375 assert(!IO
.outputting() || !Section
.ContentBuf
);
1376 IO
.mapOptional("ContentArray", Section
.ContentBuf
);
1377 if (Section
.ContentBuf
) {
1378 if (Section
.Content
)
1379 IO
.setError("Content and ContentArray can't be used together");
1380 Section
.Content
= yaml::BinaryRef(*Section
.ContentBuf
);
1383 IO
.mapOptional("Info", Section
.Info
);
1386 static void sectionMapping(IO
&IO
, ELFYAML::BBAddrMapSection
&Section
) {
1387 commonSectionMapping(IO
, Section
);
1388 IO
.mapOptional("Content", Section
.Content
);
1389 IO
.mapOptional("Entries", Section
.Entries
);
1392 static void sectionMapping(IO
&IO
, ELFYAML::StackSizesSection
&Section
) {
1393 commonSectionMapping(IO
, Section
);
1394 IO
.mapOptional("Entries", Section
.Entries
);
1397 static void sectionMapping(IO
&IO
, ELFYAML::HashSection
&Section
) {
1398 commonSectionMapping(IO
, Section
);
1399 IO
.mapOptional("Bucket", Section
.Bucket
);
1400 IO
.mapOptional("Chain", Section
.Chain
);
1402 // obj2yaml does not dump these fields. They can be used to override nchain
1403 // and nbucket values for creating broken sections.
1404 assert(!IO
.outputting() || (!Section
.NBucket
&& !Section
.NChain
));
1405 IO
.mapOptional("NChain", Section
.NChain
);
1406 IO
.mapOptional("NBucket", Section
.NBucket
);
1409 static void sectionMapping(IO
&IO
, ELFYAML::NoteSection
&Section
) {
1410 commonSectionMapping(IO
, Section
);
1411 IO
.mapOptional("Notes", Section
.Notes
);
1415 static void sectionMapping(IO
&IO
, ELFYAML::GnuHashSection
&Section
) {
1416 commonSectionMapping(IO
, Section
);
1417 IO
.mapOptional("Header", Section
.Header
);
1418 IO
.mapOptional("BloomFilter", Section
.BloomFilter
);
1419 IO
.mapOptional("HashBuckets", Section
.HashBuckets
);
1420 IO
.mapOptional("HashValues", Section
.HashValues
);
1422 static void sectionMapping(IO
&IO
, ELFYAML::NoBitsSection
&Section
) {
1423 commonSectionMapping(IO
, Section
);
1426 static void sectionMapping(IO
&IO
, ELFYAML::VerdefSection
&Section
) {
1427 commonSectionMapping(IO
, Section
);
1428 IO
.mapOptional("Info", Section
.Info
);
1429 IO
.mapOptional("Entries", Section
.Entries
);
1432 static void sectionMapping(IO
&IO
, ELFYAML::SymverSection
&Section
) {
1433 commonSectionMapping(IO
, Section
);
1434 IO
.mapOptional("Entries", Section
.Entries
);
1437 static void sectionMapping(IO
&IO
, ELFYAML::VerneedSection
&Section
) {
1438 commonSectionMapping(IO
, Section
);
1439 IO
.mapOptional("Info", Section
.Info
);
1440 IO
.mapOptional("Dependencies", Section
.VerneedV
);
1443 static void sectionMapping(IO
&IO
, ELFYAML::RelocationSection
&Section
) {
1444 commonSectionMapping(IO
, Section
);
1445 IO
.mapOptional("Info", Section
.RelocatableSec
, StringRef());
1446 IO
.mapOptional("Relocations", Section
.Relocations
);
1449 static void sectionMapping(IO
&IO
, ELFYAML::RelrSection
&Section
) {
1450 commonSectionMapping(IO
, Section
);
1451 IO
.mapOptional("Entries", Section
.Entries
);
1454 static void groupSectionMapping(IO
&IO
, ELFYAML::GroupSection
&Group
) {
1455 commonSectionMapping(IO
, Group
);
1456 IO
.mapOptional("Info", Group
.Signature
);
1457 IO
.mapOptional("Members", Group
.Members
);
1460 static void sectionMapping(IO
&IO
, ELFYAML::SymtabShndxSection
&Section
) {
1461 commonSectionMapping(IO
, Section
);
1462 IO
.mapOptional("Entries", Section
.Entries
);
1465 static void sectionMapping(IO
&IO
, ELFYAML::AddrsigSection
&Section
) {
1466 commonSectionMapping(IO
, Section
);
1467 IO
.mapOptional("Symbols", Section
.Symbols
);
1470 static void fillMapping(IO
&IO
, ELFYAML::Fill
&Fill
) {
1471 IO
.mapOptional("Name", Fill
.Name
, StringRef());
1472 IO
.mapOptional("Pattern", Fill
.Pattern
);
1473 IO
.mapOptional("Offset", Fill
.Offset
);
1474 IO
.mapRequired("Size", Fill
.Size
);
1477 static void sectionHeaderTableMapping(IO
&IO
,
1478 ELFYAML::SectionHeaderTable
&SHT
) {
1479 IO
.mapOptional("Offset", SHT
.Offset
);
1480 IO
.mapOptional("Sections", SHT
.Sections
);
1481 IO
.mapOptional("Excluded", SHT
.Excluded
);
1482 IO
.mapOptional("NoHeaders", SHT
.NoHeaders
);
1485 static void sectionMapping(IO
&IO
, ELFYAML::LinkerOptionsSection
&Section
) {
1486 commonSectionMapping(IO
, Section
);
1487 IO
.mapOptional("Options", Section
.Options
);
1490 static void sectionMapping(IO
&IO
,
1491 ELFYAML::DependentLibrariesSection
&Section
) {
1492 commonSectionMapping(IO
, Section
);
1493 IO
.mapOptional("Libraries", Section
.Libs
);
1496 static void sectionMapping(IO
&IO
, ELFYAML::CallGraphProfileSection
&Section
) {
1497 commonSectionMapping(IO
, Section
);
1498 IO
.mapOptional("Entries", Section
.Entries
);
1501 void MappingTraits
<ELFYAML::SectionOrType
>::mapping(
1502 IO
&IO
, ELFYAML::SectionOrType
§ionOrType
) {
1503 IO
.mapRequired("SectionOrType", sectionOrType
.sectionNameOrType
);
1506 static void sectionMapping(IO
&IO
, ELFYAML::ARMIndexTableSection
&Section
) {
1507 commonSectionMapping(IO
, Section
);
1508 IO
.mapOptional("Entries", Section
.Entries
);
1511 static void sectionMapping(IO
&IO
, ELFYAML::MipsABIFlags
&Section
) {
1512 commonSectionMapping(IO
, Section
);
1513 IO
.mapOptional("Version", Section
.Version
, Hex16(0));
1514 IO
.mapRequired("ISA", Section
.ISALevel
);
1515 IO
.mapOptional("ISARevision", Section
.ISARevision
, Hex8(0));
1516 IO
.mapOptional("ISAExtension", Section
.ISAExtension
,
1517 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE
));
1518 IO
.mapOptional("ASEs", Section
.ASEs
, ELFYAML::MIPS_AFL_ASE(0));
1519 IO
.mapOptional("FpABI", Section
.FpABI
,
1520 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY
));
1521 IO
.mapOptional("GPRSize", Section
.GPRSize
,
1522 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1523 IO
.mapOptional("CPR1Size", Section
.CPR1Size
,
1524 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1525 IO
.mapOptional("CPR2Size", Section
.CPR2Size
,
1526 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1527 IO
.mapOptional("Flags1", Section
.Flags1
, ELFYAML::MIPS_AFL_FLAGS1(0));
1528 IO
.mapOptional("Flags2", Section
.Flags2
, Hex32(0));
1531 static StringRef
getStringValue(IO
&IO
, const char *Key
) {
1533 IO
.mapRequired(Key
, Val
);
1537 static void setStringValue(IO
&IO
, const char *Key
, StringRef Val
) {
1538 IO
.mapRequired(Key
, Val
);
1541 static bool isInteger(StringRef Val
) {
1543 return !Val
.getAsInteger(0, Tmp
);
1546 void MappingTraits
<std::unique_ptr
<ELFYAML::Chunk
>>::mapping(
1547 IO
&IO
, std::unique_ptr
<ELFYAML::Chunk
> &Section
) {
1548 ELFYAML::ELF_SHT Type
;
1550 if (IO
.outputting()) {
1551 if (auto *S
= dyn_cast
<ELFYAML::Section
>(Section
.get()))
1553 else if (auto *SHT
= dyn_cast
<ELFYAML::SectionHeaderTable
>(Section
.get()))
1554 TypeStr
= SHT
->TypeStr
;
1556 // When the Type string does not have a "SHT_" prefix, we know it is not a
1557 // description of a regular ELF output section.
1558 TypeStr
= getStringValue(IO
, "Type");
1559 if (TypeStr
.startswith("SHT_") || isInteger(TypeStr
))
1560 IO
.mapRequired("Type", Type
);
1563 if (TypeStr
== "Fill") {
1564 assert(!IO
.outputting()); // We don't dump fills currently.
1565 Section
.reset(new ELFYAML::Fill());
1566 fillMapping(IO
, *cast
<ELFYAML::Fill
>(Section
.get()));
1570 if (TypeStr
== ELFYAML::SectionHeaderTable::TypeStr
) {
1571 if (IO
.outputting())
1572 setStringValue(IO
, "Type", TypeStr
);
1574 Section
.reset(new ELFYAML::SectionHeaderTable(/*IsImplicit=*/false));
1576 sectionHeaderTableMapping(
1577 IO
, *cast
<ELFYAML::SectionHeaderTable
>(Section
.get()));
1581 const auto &Obj
= *static_cast<ELFYAML::Object
*>(IO
.getContext());
1582 if (Obj
.getMachine() == ELF::EM_MIPS
&& Type
== ELF::SHT_MIPS_ABIFLAGS
) {
1583 if (!IO
.outputting())
1584 Section
.reset(new ELFYAML::MipsABIFlags());
1585 sectionMapping(IO
, *cast
<ELFYAML::MipsABIFlags
>(Section
.get()));
1589 if (Obj
.getMachine() == ELF::EM_ARM
&& Type
== ELF::SHT_ARM_EXIDX
) {
1590 if (!IO
.outputting())
1591 Section
.reset(new ELFYAML::ARMIndexTableSection());
1592 sectionMapping(IO
, *cast
<ELFYAML::ARMIndexTableSection
>(Section
.get()));
1597 case ELF::SHT_DYNAMIC
:
1598 if (!IO
.outputting())
1599 Section
.reset(new ELFYAML::DynamicSection());
1600 sectionMapping(IO
, *cast
<ELFYAML::DynamicSection
>(Section
.get()));
1604 if (!IO
.outputting())
1605 Section
.reset(new ELFYAML::RelocationSection());
1606 sectionMapping(IO
, *cast
<ELFYAML::RelocationSection
>(Section
.get()));
1609 if (!IO
.outputting())
1610 Section
.reset(new ELFYAML::RelrSection());
1611 sectionMapping(IO
, *cast
<ELFYAML::RelrSection
>(Section
.get()));
1613 case ELF::SHT_GROUP
:
1614 if (!IO
.outputting())
1615 Section
.reset(new ELFYAML::GroupSection());
1616 groupSectionMapping(IO
, *cast
<ELFYAML::GroupSection
>(Section
.get()));
1618 case ELF::SHT_NOBITS
:
1619 if (!IO
.outputting())
1620 Section
.reset(new ELFYAML::NoBitsSection());
1621 sectionMapping(IO
, *cast
<ELFYAML::NoBitsSection
>(Section
.get()));
1624 if (!IO
.outputting())
1625 Section
.reset(new ELFYAML::HashSection());
1626 sectionMapping(IO
, *cast
<ELFYAML::HashSection
>(Section
.get()));
1629 if (!IO
.outputting())
1630 Section
.reset(new ELFYAML::NoteSection());
1631 sectionMapping(IO
, *cast
<ELFYAML::NoteSection
>(Section
.get()));
1633 case ELF::SHT_GNU_HASH
:
1634 if (!IO
.outputting())
1635 Section
.reset(new ELFYAML::GnuHashSection());
1636 sectionMapping(IO
, *cast
<ELFYAML::GnuHashSection
>(Section
.get()));
1638 case ELF::SHT_GNU_verdef
:
1639 if (!IO
.outputting())
1640 Section
.reset(new ELFYAML::VerdefSection());
1641 sectionMapping(IO
, *cast
<ELFYAML::VerdefSection
>(Section
.get()));
1643 case ELF::SHT_GNU_versym
:
1644 if (!IO
.outputting())
1645 Section
.reset(new ELFYAML::SymverSection());
1646 sectionMapping(IO
, *cast
<ELFYAML::SymverSection
>(Section
.get()));
1648 case ELF::SHT_GNU_verneed
:
1649 if (!IO
.outputting())
1650 Section
.reset(new ELFYAML::VerneedSection());
1651 sectionMapping(IO
, *cast
<ELFYAML::VerneedSection
>(Section
.get()));
1653 case ELF::SHT_SYMTAB_SHNDX
:
1654 if (!IO
.outputting())
1655 Section
.reset(new ELFYAML::SymtabShndxSection());
1656 sectionMapping(IO
, *cast
<ELFYAML::SymtabShndxSection
>(Section
.get()));
1658 case ELF::SHT_LLVM_ADDRSIG
:
1659 if (!IO
.outputting())
1660 Section
.reset(new ELFYAML::AddrsigSection());
1661 sectionMapping(IO
, *cast
<ELFYAML::AddrsigSection
>(Section
.get()));
1663 case ELF::SHT_LLVM_LINKER_OPTIONS
:
1664 if (!IO
.outputting())
1665 Section
.reset(new ELFYAML::LinkerOptionsSection());
1666 sectionMapping(IO
, *cast
<ELFYAML::LinkerOptionsSection
>(Section
.get()));
1668 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES
:
1669 if (!IO
.outputting())
1670 Section
.reset(new ELFYAML::DependentLibrariesSection());
1672 *cast
<ELFYAML::DependentLibrariesSection
>(Section
.get()));
1674 case ELF::SHT_LLVM_CALL_GRAPH_PROFILE
:
1675 if (!IO
.outputting())
1676 Section
.reset(new ELFYAML::CallGraphProfileSection());
1677 sectionMapping(IO
, *cast
<ELFYAML::CallGraphProfileSection
>(Section
.get()));
1679 case ELF::SHT_LLVM_BB_ADDR_MAP_V0
:
1680 case ELF::SHT_LLVM_BB_ADDR_MAP
:
1681 if (!IO
.outputting())
1682 Section
.reset(new ELFYAML::BBAddrMapSection());
1683 sectionMapping(IO
, *cast
<ELFYAML::BBAddrMapSection
>(Section
.get()));
1686 if (!IO
.outputting()) {
1688 IO
.mapOptional("Name", Name
, StringRef());
1689 Name
= ELFYAML::dropUniqueSuffix(Name
);
1691 if (ELFYAML::StackSizesSection::nameMatches(Name
))
1692 Section
= std::make_unique
<ELFYAML::StackSizesSection
>();
1694 Section
= std::make_unique
<ELFYAML::RawContentSection
>();
1697 if (auto S
= dyn_cast
<ELFYAML::RawContentSection
>(Section
.get()))
1698 sectionMapping(IO
, *S
);
1700 sectionMapping(IO
, *cast
<ELFYAML::StackSizesSection
>(Section
.get()));
1704 std::string MappingTraits
<std::unique_ptr
<ELFYAML::Chunk
>>::validate(
1705 IO
&io
, std::unique_ptr
<ELFYAML::Chunk
> &C
) {
1706 if (const auto *F
= dyn_cast
<ELFYAML::Fill
>(C
.get())) {
1707 if (F
->Pattern
&& F
->Pattern
->binary_size() != 0 && !F
->Size
)
1708 return "\"Size\" can't be 0 when \"Pattern\" is not empty";
1712 if (const auto *SHT
= dyn_cast
<ELFYAML::SectionHeaderTable
>(C
.get())) {
1713 if (SHT
->NoHeaders
&& (SHT
->Sections
|| SHT
->Excluded
|| SHT
->Offset
))
1714 return "NoHeaders can't be used together with Offset/Sections/Excluded";
1718 const ELFYAML::Section
&Sec
= *cast
<ELFYAML::Section
>(C
.get());
1719 if (Sec
.Size
&& Sec
.Content
&&
1720 (uint64_t)(*Sec
.Size
) < Sec
.Content
->binary_size())
1721 return "Section size must be greater than or equal to the content size";
1723 auto BuildErrPrefix
= [](ArrayRef
<std::pair
<StringRef
, bool>> EntV
) {
1725 for (size_t I
= 0, E
= EntV
.size(); I
!= E
; ++I
) {
1726 StringRef Name
= EntV
[I
].first
;
1728 Msg
= "\"" + Name
.str() + "\"";
1731 if (I
!= EntV
.size() - 1)
1732 Msg
+= ", \"" + Name
.str() + "\"";
1734 Msg
+= " and \"" + Name
.str() + "\"";
1739 std::vector
<std::pair
<StringRef
, bool>> Entries
= Sec
.getEntries();
1740 const size_t NumUsedEntries
= llvm::count_if(
1741 Entries
, [](const std::pair
<StringRef
, bool> &P
) { return P
.second
; });
1743 if ((Sec
.Size
|| Sec
.Content
) && NumUsedEntries
> 0)
1744 return BuildErrPrefix(Entries
) +
1745 " cannot be used with \"Content\" or \"Size\"";
1747 if (NumUsedEntries
> 0 && Entries
.size() != NumUsedEntries
)
1748 return BuildErrPrefix(Entries
) + " must be used together";
1750 if (const auto *RawSection
= dyn_cast
<ELFYAML::RawContentSection
>(C
.get())) {
1751 if (RawSection
->Flags
&& RawSection
->ShFlags
)
1752 return "ShFlags and Flags cannot be used together";
1756 if (const auto *NB
= dyn_cast
<ELFYAML::NoBitsSection
>(C
.get())) {
1758 return "SHT_NOBITS section cannot have \"Content\"";
1762 if (const auto *MF
= dyn_cast
<ELFYAML::MipsABIFlags
>(C
.get())) {
1764 return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS "
1767 return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections";
1776 struct NormalizedMips64RelType
{
1777 NormalizedMips64RelType(IO
&)
1778 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1779 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1780 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1781 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF
)) {}
1782 NormalizedMips64RelType(IO
&, ELFYAML::ELF_REL Original
)
1783 : Type(Original
& 0xFF), Type2(Original
>> 8 & 0xFF),
1784 Type3(Original
>> 16 & 0xFF), SpecSym(Original
>> 24 & 0xFF) {}
1786 ELFYAML::ELF_REL
denormalize(IO
&) {
1787 ELFYAML::ELF_REL Res
= Type
| Type2
<< 8 | Type3
<< 16 | SpecSym
<< 24;
1791 ELFYAML::ELF_REL Type
;
1792 ELFYAML::ELF_REL Type2
;
1793 ELFYAML::ELF_REL Type3
;
1794 ELFYAML::ELF_RSS SpecSym
;
1797 } // end anonymous namespace
1799 void MappingTraits
<ELFYAML::StackSizeEntry
>::mapping(
1800 IO
&IO
, ELFYAML::StackSizeEntry
&E
) {
1801 assert(IO
.getContext() && "The IO context is not initialized");
1802 IO
.mapOptional("Address", E
.Address
, Hex64(0));
1803 IO
.mapRequired("Size", E
.Size
);
1806 void MappingTraits
<ELFYAML::BBAddrMapEntry
>::mapping(
1807 IO
&IO
, ELFYAML::BBAddrMapEntry
&E
) {
1808 assert(IO
.getContext() && "The IO context is not initialized");
1809 IO
.mapRequired("Version", E
.Version
);
1810 IO
.mapOptional("Feature", E
.Feature
, Hex8(0));
1811 IO
.mapOptional("Address", E
.Address
, Hex64(0));
1812 IO
.mapOptional("NumBlocks", E
.NumBlocks
);
1813 IO
.mapOptional("BBEntries", E
.BBEntries
);
1816 void MappingTraits
<ELFYAML::BBAddrMapEntry::BBEntry
>::mapping(
1817 IO
&IO
, ELFYAML::BBAddrMapEntry::BBEntry
&E
) {
1818 assert(IO
.getContext() && "The IO context is not initialized");
1819 IO
.mapOptional("ID", E
.ID
);
1820 IO
.mapRequired("AddressOffset", E
.AddressOffset
);
1821 IO
.mapRequired("Size", E
.Size
);
1822 IO
.mapRequired("Metadata", E
.Metadata
);
1825 void MappingTraits
<ELFYAML::GnuHashHeader
>::mapping(IO
&IO
,
1826 ELFYAML::GnuHashHeader
&E
) {
1827 assert(IO
.getContext() && "The IO context is not initialized");
1828 IO
.mapOptional("NBuckets", E
.NBuckets
);
1829 IO
.mapRequired("SymNdx", E
.SymNdx
);
1830 IO
.mapOptional("MaskWords", E
.MaskWords
);
1831 IO
.mapRequired("Shift2", E
.Shift2
);
1834 void MappingTraits
<ELFYAML::DynamicEntry
>::mapping(IO
&IO
,
1835 ELFYAML::DynamicEntry
&Rel
) {
1836 assert(IO
.getContext() && "The IO context is not initialized");
1838 IO
.mapRequired("Tag", Rel
.Tag
);
1839 IO
.mapRequired("Value", Rel
.Val
);
1842 void MappingTraits
<ELFYAML::NoteEntry
>::mapping(IO
&IO
, ELFYAML::NoteEntry
&N
) {
1843 assert(IO
.getContext() && "The IO context is not initialized");
1845 IO
.mapOptional("Name", N
.Name
);
1846 IO
.mapOptional("Desc", N
.Desc
);
1847 IO
.mapRequired("Type", N
.Type
);
1850 void MappingTraits
<ELFYAML::VerdefEntry
>::mapping(IO
&IO
,
1851 ELFYAML::VerdefEntry
&E
) {
1852 assert(IO
.getContext() && "The IO context is not initialized");
1854 IO
.mapOptional("Version", E
.Version
);
1855 IO
.mapOptional("Flags", E
.Flags
);
1856 IO
.mapOptional("VersionNdx", E
.VersionNdx
);
1857 IO
.mapOptional("Hash", E
.Hash
);
1858 IO
.mapRequired("Names", E
.VerNames
);
1861 void MappingTraits
<ELFYAML::VerneedEntry
>::mapping(IO
&IO
,
1862 ELFYAML::VerneedEntry
&E
) {
1863 assert(IO
.getContext() && "The IO context is not initialized");
1865 IO
.mapRequired("Version", E
.Version
);
1866 IO
.mapRequired("File", E
.File
);
1867 IO
.mapRequired("Entries", E
.AuxV
);
1870 void MappingTraits
<ELFYAML::VernauxEntry
>::mapping(IO
&IO
,
1871 ELFYAML::VernauxEntry
&E
) {
1872 assert(IO
.getContext() && "The IO context is not initialized");
1874 IO
.mapRequired("Name", E
.Name
);
1875 IO
.mapRequired("Hash", E
.Hash
);
1876 IO
.mapRequired("Flags", E
.Flags
);
1877 IO
.mapRequired("Other", E
.Other
);
1880 void MappingTraits
<ELFYAML::Relocation
>::mapping(IO
&IO
,
1881 ELFYAML::Relocation
&Rel
) {
1882 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
1883 assert(Object
&& "The IO context is not initialized");
1885 IO
.mapOptional("Offset", Rel
.Offset
, (Hex64
)0);
1886 IO
.mapOptional("Symbol", Rel
.Symbol
);
1888 if (Object
->getMachine() == ELFYAML::ELF_EM(ELF::EM_MIPS
) &&
1889 Object
->Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
)) {
1890 MappingNormalization
<NormalizedMips64RelType
, ELFYAML::ELF_REL
> Key(
1892 IO
.mapRequired("Type", Key
->Type
);
1893 IO
.mapOptional("Type2", Key
->Type2
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1894 IO
.mapOptional("Type3", Key
->Type3
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1895 IO
.mapOptional("SpecSym", Key
->SpecSym
, ELFYAML::ELF_RSS(ELF::RSS_UNDEF
));
1897 IO
.mapRequired("Type", Rel
.Type
);
1899 IO
.mapOptional("Addend", Rel
.Addend
, (ELFYAML::YAMLIntUInt
)0);
1902 void MappingTraits
<ELFYAML::ARMIndexTableEntry
>::mapping(
1903 IO
&IO
, ELFYAML::ARMIndexTableEntry
&E
) {
1904 assert(IO
.getContext() && "The IO context is not initialized");
1905 IO
.mapRequired("Offset", E
.Offset
);
1907 StringRef CantUnwind
= "EXIDX_CANTUNWIND";
1908 if (IO
.outputting() && (uint32_t)E
.Value
== ARM::EHABI::EXIDX_CANTUNWIND
)
1909 IO
.mapRequired("Value", CantUnwind
);
1910 else if (!IO
.outputting() && getStringValue(IO
, "Value") == CantUnwind
)
1911 E
.Value
= ARM::EHABI::EXIDX_CANTUNWIND
;
1913 IO
.mapRequired("Value", E
.Value
);
1916 void MappingTraits
<ELFYAML::Object
>::mapping(IO
&IO
, ELFYAML::Object
&Object
) {
1917 assert(!IO
.getContext() && "The IO context is initialized already");
1918 IO
.setContext(&Object
);
1919 IO
.mapTag("!ELF", true);
1920 IO
.mapRequired("FileHeader", Object
.Header
);
1921 IO
.mapOptional("ProgramHeaders", Object
.ProgramHeaders
);
1922 IO
.mapOptional("Sections", Object
.Chunks
);
1923 IO
.mapOptional("Symbols", Object
.Symbols
);
1924 IO
.mapOptional("DynamicSymbols", Object
.DynamicSymbols
);
1925 IO
.mapOptional("DWARF", Object
.DWARF
);
1927 Object
.DWARF
->IsLittleEndian
=
1928 Object
.Header
.Data
== ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB
);
1929 Object
.DWARF
->Is64BitAddrSize
=
1930 Object
.Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
);
1932 IO
.setContext(nullptr);
1935 void MappingTraits
<ELFYAML::LinkerOption
>::mapping(IO
&IO
,
1936 ELFYAML::LinkerOption
&Opt
) {
1937 assert(IO
.getContext() && "The IO context is not initialized");
1938 IO
.mapRequired("Name", Opt
.Key
);
1939 IO
.mapRequired("Value", Opt
.Value
);
1942 void MappingTraits
<ELFYAML::CallGraphEntryWeight
>::mapping(
1943 IO
&IO
, ELFYAML::CallGraphEntryWeight
&E
) {
1944 assert(IO
.getContext() && "The IO context is not initialized");
1945 IO
.mapRequired("Weight", E
.Weight
);
1948 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG
)
1949 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP
)
1950 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT
)
1951 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE
)
1952 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1
)
1954 } // end namespace yaml
1956 } // end namespace llvm