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"
29 ELFYAML::Chunk::~Chunk() = default;
32 unsigned Object::getMachine() const {
34 return *Header
.Machine
;
35 return llvm::ELF::EM_NONE
;
38 constexpr StringRef
SectionHeaderTable::TypeStr
;
39 } // namespace ELFYAML
43 void ScalarEnumerationTraits
<ELFYAML::ELF_ET
>::enumeration(
44 IO
&IO
, ELFYAML::ELF_ET
&Value
) {
45 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
52 IO
.enumFallback
<Hex16
>(Value
);
55 void ScalarEnumerationTraits
<ELFYAML::ELF_PT
>::enumeration(
56 IO
&IO
, ELFYAML::ELF_PT
&Value
) {
57 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
66 ECase(PT_GNU_EH_FRAME
);
69 ECase(PT_GNU_PROPERTY
);
71 IO
.enumFallback
<Hex32
>(Value
);
74 void ScalarEnumerationTraits
<ELFYAML::ELF_NT
>::enumeration(
75 IO
&IO
, ELFYAML::ELF_NT
&Value
) {
76 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
77 // Generic note types.
80 ECase(NT_GNU_BUILD_ATTRIBUTE_OPEN
);
81 ECase(NT_GNU_BUILD_ATTRIBUTE_FUNC
);
93 ECase(NT_WIN32PSTATUS
);
101 ECase(NT_PPC_TM_CGPR
);
102 ECase(NT_PPC_TM_CFPR
);
103 ECase(NT_PPC_TM_CVMX
);
104 ECase(NT_PPC_TM_CVSX
);
105 ECase(NT_PPC_TM_SPR
);
106 ECase(NT_PPC_TM_CTAR
);
107 ECase(NT_PPC_TM_CPPR
);
108 ECase(NT_PPC_TM_CDSCR
);
110 ECase(NT_386_IOPERM
);
111 ECase(NT_X86_XSTATE
);
112 ECase(NT_S390_HIGH_GPRS
);
113 ECase(NT_S390_TIMER
);
114 ECase(NT_S390_TODCMP
);
115 ECase(NT_S390_TODPREG
);
117 ECase(NT_S390_PREFIX
);
118 ECase(NT_S390_LAST_BREAK
);
119 ECase(NT_S390_SYSTEM_CALL
);
121 ECase(NT_S390_VXRS_LOW
);
122 ECase(NT_S390_VXRS_HIGH
);
123 ECase(NT_S390_GS_CB
);
124 ECase(NT_S390_GS_BC
);
127 ECase(NT_ARM_HW_BREAK
);
128 ECase(NT_ARM_HW_WATCH
);
130 ECase(NT_ARM_PAC_MASK
);
134 // LLVM-specific notes.
135 ECase(NT_LLVM_HWASAN_GLOBALS
);
137 ECase(NT_GNU_ABI_TAG
);
139 ECase(NT_GNU_BUILD_ID
);
140 ECase(NT_GNU_GOLD_VERSION
);
141 ECase(NT_GNU_PROPERTY_TYPE_0
);
142 // FreeBSD note types.
143 ECase(NT_FREEBSD_ABI_TAG
);
144 ECase(NT_FREEBSD_NOINIT_TAG
);
145 ECase(NT_FREEBSD_ARCH_TAG
);
146 ECase(NT_FREEBSD_FEATURE_CTL
);
147 // FreeBSD core note types.
148 ECase(NT_FREEBSD_THRMISC
);
149 ECase(NT_FREEBSD_PROCSTAT_PROC
);
150 ECase(NT_FREEBSD_PROCSTAT_FILES
);
151 ECase(NT_FREEBSD_PROCSTAT_VMMAP
);
152 ECase(NT_FREEBSD_PROCSTAT_GROUPS
);
153 ECase(NT_FREEBSD_PROCSTAT_UMASK
);
154 ECase(NT_FREEBSD_PROCSTAT_RLIMIT
);
155 ECase(NT_FREEBSD_PROCSTAT_OSREL
);
156 ECase(NT_FREEBSD_PROCSTAT_PSSTRINGS
);
157 ECase(NT_FREEBSD_PROCSTAT_AUXV
);
158 // AMD specific notes. (Code Object V2)
159 ECase(NT_AMD_HSA_CODE_OBJECT_VERSION
);
160 ECase(NT_AMD_HSA_HSAIL
);
161 ECase(NT_AMD_HSA_ISA_VERSION
);
162 ECase(NT_AMD_HSA_METADATA
);
163 ECase(NT_AMD_HSA_ISA_NAME
);
164 ECase(NT_AMD_PAL_METADATA
);
165 // AMDGPU specific notes. (Code Object V3)
166 ECase(NT_AMDGPU_METADATA
);
168 IO
.enumFallback
<Hex32
>(Value
);
171 void ScalarEnumerationTraits
<ELFYAML::ELF_EM
>::enumeration(
172 IO
&IO
, ELFYAML::ELF_EM
&Value
) {
173 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
184 ECase(EM_MIPS_RS3_LE
);
187 ECase(EM_SPARC32PLUS
);
250 ECase(EM_ARC_COMPACT
);
270 ECase(EM_ALTERA_NIOS2
);
284 ECase(EM_VIDEOCORE3
);
285 ECase(EM_LATTICEMICO32
);
290 ECase(EM_MMDSP_PLUS
);
291 ECase(EM_CYPRESS_M8C
);
306 ECase(EM_MCST_ELBRUS
);
318 ECase(EM_MICROBLAZE
);
321 ECase(EM_CLOUDSHIELD
);
324 ECase(EM_ARC_COMPACT2
);
327 ECase(EM_VIDEOCORE5
);
337 IO
.enumFallback
<Hex16
>(Value
);
340 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFCLASS
>::enumeration(
341 IO
&IO
, ELFYAML::ELF_ELFCLASS
&Value
) {
342 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
343 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
350 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFDATA
>::enumeration(
351 IO
&IO
, ELFYAML::ELF_ELFDATA
&Value
) {
352 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
353 // ELFDATANONE is an invalid data encoding, but we accept it because
354 // we want to be able to produce invalid binaries for the tests.
361 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFOSABI
>::enumeration(
362 IO
&IO
, ELFYAML::ELF_ELFOSABI
&Value
) {
363 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
364 ECase(ELFOSABI_NONE
);
365 ECase(ELFOSABI_HPUX
);
366 ECase(ELFOSABI_NETBSD
);
368 ECase(ELFOSABI_LINUX
);
369 ECase(ELFOSABI_HURD
);
370 ECase(ELFOSABI_SOLARIS
);
372 ECase(ELFOSABI_IRIX
);
373 ECase(ELFOSABI_FREEBSD
);
374 ECase(ELFOSABI_TRU64
);
375 ECase(ELFOSABI_MODESTO
);
376 ECase(ELFOSABI_OPENBSD
);
377 ECase(ELFOSABI_OPENVMS
);
379 ECase(ELFOSABI_AROS
);
380 ECase(ELFOSABI_FENIXOS
);
381 ECase(ELFOSABI_CLOUDABI
);
382 ECase(ELFOSABI_AMDGPU_HSA
);
383 ECase(ELFOSABI_AMDGPU_PAL
);
384 ECase(ELFOSABI_AMDGPU_MESA3D
);
386 ECase(ELFOSABI_C6000_ELFABI
);
387 ECase(ELFOSABI_C6000_LINUX
);
388 ECase(ELFOSABI_STANDALONE
);
390 IO
.enumFallback
<Hex8
>(Value
);
393 void ScalarBitSetTraits
<ELFYAML::ELF_EF
>::bitset(IO
&IO
,
394 ELFYAML::ELF_EF
&Value
) {
395 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
396 assert(Object
&& "The IO context is not initialized");
397 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
398 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
399 switch (Object
->getMachine()) {
401 BCase(EF_ARM_SOFT_FLOAT
);
402 BCase(EF_ARM_VFP_FLOAT
);
403 BCaseMask(EF_ARM_EABI_UNKNOWN
, EF_ARM_EABIMASK
);
404 BCaseMask(EF_ARM_EABI_VER1
, EF_ARM_EABIMASK
);
405 BCaseMask(EF_ARM_EABI_VER2
, EF_ARM_EABIMASK
);
406 BCaseMask(EF_ARM_EABI_VER3
, EF_ARM_EABIMASK
);
407 BCaseMask(EF_ARM_EABI_VER4
, EF_ARM_EABIMASK
);
408 BCaseMask(EF_ARM_EABI_VER5
, EF_ARM_EABIMASK
);
411 BCase(EF_MIPS_NOREORDER
);
415 BCase(EF_MIPS_32BITMODE
);
417 BCase(EF_MIPS_NAN2008
);
418 BCase(EF_MIPS_MICROMIPS
);
419 BCase(EF_MIPS_ARCH_ASE_M16
);
420 BCase(EF_MIPS_ARCH_ASE_MDMX
);
421 BCaseMask(EF_MIPS_ABI_O32
, EF_MIPS_ABI
);
422 BCaseMask(EF_MIPS_ABI_O64
, EF_MIPS_ABI
);
423 BCaseMask(EF_MIPS_ABI_EABI32
, EF_MIPS_ABI
);
424 BCaseMask(EF_MIPS_ABI_EABI64
, EF_MIPS_ABI
);
425 BCaseMask(EF_MIPS_MACH_3900
, EF_MIPS_MACH
);
426 BCaseMask(EF_MIPS_MACH_4010
, EF_MIPS_MACH
);
427 BCaseMask(EF_MIPS_MACH_4100
, EF_MIPS_MACH
);
428 BCaseMask(EF_MIPS_MACH_4650
, EF_MIPS_MACH
);
429 BCaseMask(EF_MIPS_MACH_4120
, EF_MIPS_MACH
);
430 BCaseMask(EF_MIPS_MACH_4111
, EF_MIPS_MACH
);
431 BCaseMask(EF_MIPS_MACH_SB1
, EF_MIPS_MACH
);
432 BCaseMask(EF_MIPS_MACH_OCTEON
, EF_MIPS_MACH
);
433 BCaseMask(EF_MIPS_MACH_XLR
, EF_MIPS_MACH
);
434 BCaseMask(EF_MIPS_MACH_OCTEON2
, EF_MIPS_MACH
);
435 BCaseMask(EF_MIPS_MACH_OCTEON3
, EF_MIPS_MACH
);
436 BCaseMask(EF_MIPS_MACH_5400
, EF_MIPS_MACH
);
437 BCaseMask(EF_MIPS_MACH_5900
, EF_MIPS_MACH
);
438 BCaseMask(EF_MIPS_MACH_5500
, EF_MIPS_MACH
);
439 BCaseMask(EF_MIPS_MACH_9000
, EF_MIPS_MACH
);
440 BCaseMask(EF_MIPS_MACH_LS2E
, EF_MIPS_MACH
);
441 BCaseMask(EF_MIPS_MACH_LS2F
, EF_MIPS_MACH
);
442 BCaseMask(EF_MIPS_MACH_LS3A
, EF_MIPS_MACH
);
443 BCaseMask(EF_MIPS_ARCH_1
, EF_MIPS_ARCH
);
444 BCaseMask(EF_MIPS_ARCH_2
, EF_MIPS_ARCH
);
445 BCaseMask(EF_MIPS_ARCH_3
, EF_MIPS_ARCH
);
446 BCaseMask(EF_MIPS_ARCH_4
, EF_MIPS_ARCH
);
447 BCaseMask(EF_MIPS_ARCH_5
, EF_MIPS_ARCH
);
448 BCaseMask(EF_MIPS_ARCH_32
, EF_MIPS_ARCH
);
449 BCaseMask(EF_MIPS_ARCH_64
, EF_MIPS_ARCH
);
450 BCaseMask(EF_MIPS_ARCH_32R2
, EF_MIPS_ARCH
);
451 BCaseMask(EF_MIPS_ARCH_64R2
, EF_MIPS_ARCH
);
452 BCaseMask(EF_MIPS_ARCH_32R6
, EF_MIPS_ARCH
);
453 BCaseMask(EF_MIPS_ARCH_64R6
, EF_MIPS_ARCH
);
455 case ELF::EM_HEXAGON
:
456 BCase(EF_HEXAGON_MACH_V2
);
457 BCase(EF_HEXAGON_MACH_V3
);
458 BCase(EF_HEXAGON_MACH_V4
);
459 BCase(EF_HEXAGON_MACH_V5
);
460 BCase(EF_HEXAGON_MACH_V55
);
461 BCase(EF_HEXAGON_MACH_V60
);
462 BCase(EF_HEXAGON_MACH_V62
);
463 BCase(EF_HEXAGON_MACH_V65
);
464 BCase(EF_HEXAGON_MACH_V66
);
465 BCase(EF_HEXAGON_MACH_V67
);
466 BCase(EF_HEXAGON_MACH_V67T
);
467 BCase(EF_HEXAGON_MACH_V68
);
468 BCase(EF_HEXAGON_ISA_V2
);
469 BCase(EF_HEXAGON_ISA_V3
);
470 BCase(EF_HEXAGON_ISA_V4
);
471 BCase(EF_HEXAGON_ISA_V5
);
472 BCase(EF_HEXAGON_ISA_V55
);
473 BCase(EF_HEXAGON_ISA_V60
);
474 BCase(EF_HEXAGON_ISA_V62
);
475 BCase(EF_HEXAGON_ISA_V65
);
476 BCase(EF_HEXAGON_ISA_V66
);
477 BCase(EF_HEXAGON_ISA_V67
);
478 BCase(EF_HEXAGON_ISA_V68
);
481 BCaseMask(EF_AVR_ARCH_AVR1
, EF_AVR_ARCH_MASK
);
482 BCaseMask(EF_AVR_ARCH_AVR2
, EF_AVR_ARCH_MASK
);
483 BCaseMask(EF_AVR_ARCH_AVR25
, EF_AVR_ARCH_MASK
);
484 BCaseMask(EF_AVR_ARCH_AVR3
, EF_AVR_ARCH_MASK
);
485 BCaseMask(EF_AVR_ARCH_AVR31
, EF_AVR_ARCH_MASK
);
486 BCaseMask(EF_AVR_ARCH_AVR35
, EF_AVR_ARCH_MASK
);
487 BCaseMask(EF_AVR_ARCH_AVR4
, EF_AVR_ARCH_MASK
);
488 BCaseMask(EF_AVR_ARCH_AVR5
, EF_AVR_ARCH_MASK
);
489 BCaseMask(EF_AVR_ARCH_AVR51
, EF_AVR_ARCH_MASK
);
490 BCaseMask(EF_AVR_ARCH_AVR6
, EF_AVR_ARCH_MASK
);
491 BCaseMask(EF_AVR_ARCH_AVRTINY
, EF_AVR_ARCH_MASK
);
492 BCaseMask(EF_AVR_ARCH_XMEGA1
, EF_AVR_ARCH_MASK
);
493 BCaseMask(EF_AVR_ARCH_XMEGA2
, EF_AVR_ARCH_MASK
);
494 BCaseMask(EF_AVR_ARCH_XMEGA3
, EF_AVR_ARCH_MASK
);
495 BCaseMask(EF_AVR_ARCH_XMEGA4
, EF_AVR_ARCH_MASK
);
496 BCaseMask(EF_AVR_ARCH_XMEGA5
, EF_AVR_ARCH_MASK
);
497 BCaseMask(EF_AVR_ARCH_XMEGA6
, EF_AVR_ARCH_MASK
);
498 BCaseMask(EF_AVR_ARCH_XMEGA7
, EF_AVR_ARCH_MASK
);
499 BCase(EF_AVR_LINKRELAX_PREPARED
);
503 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT
, EF_RISCV_FLOAT_ABI
);
504 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE
, EF_RISCV_FLOAT_ABI
);
505 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE
, EF_RISCV_FLOAT_ABI
);
506 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD
, EF_RISCV_FLOAT_ABI
);
510 BCaseMask(EF_AMDGPU_MACH_NONE
, EF_AMDGPU_MACH
);
511 BCaseMask(EF_AMDGPU_MACH_R600_R600
, EF_AMDGPU_MACH
);
512 BCaseMask(EF_AMDGPU_MACH_R600_R630
, EF_AMDGPU_MACH
);
513 BCaseMask(EF_AMDGPU_MACH_R600_RS880
, EF_AMDGPU_MACH
);
514 BCaseMask(EF_AMDGPU_MACH_R600_RV670
, EF_AMDGPU_MACH
);
515 BCaseMask(EF_AMDGPU_MACH_R600_RV710
, EF_AMDGPU_MACH
);
516 BCaseMask(EF_AMDGPU_MACH_R600_RV730
, EF_AMDGPU_MACH
);
517 BCaseMask(EF_AMDGPU_MACH_R600_RV770
, EF_AMDGPU_MACH
);
518 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR
, EF_AMDGPU_MACH
);
519 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS
, EF_AMDGPU_MACH
);
520 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER
, EF_AMDGPU_MACH
);
521 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD
, EF_AMDGPU_MACH
);
522 BCaseMask(EF_AMDGPU_MACH_R600_SUMO
, EF_AMDGPU_MACH
);
523 BCaseMask(EF_AMDGPU_MACH_R600_BARTS
, EF_AMDGPU_MACH
);
524 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS
, EF_AMDGPU_MACH
);
525 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN
, EF_AMDGPU_MACH
);
526 BCaseMask(EF_AMDGPU_MACH_R600_TURKS
, EF_AMDGPU_MACH
);
527 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600
, EF_AMDGPU_MACH
);
528 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601
, EF_AMDGPU_MACH
);
529 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX602
, EF_AMDGPU_MACH
);
530 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700
, EF_AMDGPU_MACH
);
531 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701
, EF_AMDGPU_MACH
);
532 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702
, EF_AMDGPU_MACH
);
533 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703
, EF_AMDGPU_MACH
);
534 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704
, EF_AMDGPU_MACH
);
535 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX705
, EF_AMDGPU_MACH
);
536 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801
, EF_AMDGPU_MACH
);
537 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802
, EF_AMDGPU_MACH
);
538 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803
, EF_AMDGPU_MACH
);
539 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX805
, EF_AMDGPU_MACH
);
540 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810
, EF_AMDGPU_MACH
);
541 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900
, EF_AMDGPU_MACH
);
542 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902
, EF_AMDGPU_MACH
);
543 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904
, EF_AMDGPU_MACH
);
544 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906
, EF_AMDGPU_MACH
);
545 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908
, EF_AMDGPU_MACH
);
546 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909
, EF_AMDGPU_MACH
);
547 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90A
, EF_AMDGPU_MACH
);
548 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90C
, EF_AMDGPU_MACH
);
549 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010
, EF_AMDGPU_MACH
);
550 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011
, EF_AMDGPU_MACH
);
551 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012
, EF_AMDGPU_MACH
);
552 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1013
, EF_AMDGPU_MACH
);
553 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1030
, EF_AMDGPU_MACH
);
554 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1031
, EF_AMDGPU_MACH
);
555 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1032
, EF_AMDGPU_MACH
);
556 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1033
, EF_AMDGPU_MACH
);
557 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1034
, EF_AMDGPU_MACH
);
558 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1035
, EF_AMDGPU_MACH
);
559 switch (Object
->Header
.ABIVersion
) {
561 // ELFOSABI_AMDGPU_PAL, ELFOSABI_AMDGPU_MESA3D support *_V3 flags.
563 case ELF::ELFABIVERSION_AMDGPU_HSA_V3
:
564 BCase(EF_AMDGPU_FEATURE_XNACK_V3
);
565 BCase(EF_AMDGPU_FEATURE_SRAMECC_V3
);
567 case ELF::ELFABIVERSION_AMDGPU_HSA_V4
:
568 BCaseMask(EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
,
569 EF_AMDGPU_FEATURE_XNACK_V4
);
570 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ANY_V4
,
571 EF_AMDGPU_FEATURE_XNACK_V4
);
572 BCaseMask(EF_AMDGPU_FEATURE_XNACK_OFF_V4
,
573 EF_AMDGPU_FEATURE_XNACK_V4
);
574 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ON_V4
,
575 EF_AMDGPU_FEATURE_XNACK_V4
);
576 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
,
577 EF_AMDGPU_FEATURE_SRAMECC_V4
);
578 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
,
579 EF_AMDGPU_FEATURE_SRAMECC_V4
);
580 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
,
581 EF_AMDGPU_FEATURE_SRAMECC_V4
);
582 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ON_V4
,
583 EF_AMDGPU_FEATURE_SRAMECC_V4
);
594 void ScalarEnumerationTraits
<ELFYAML::ELF_SHT
>::enumeration(
595 IO
&IO
, ELFYAML::ELF_SHT
&Value
) {
596 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
597 assert(Object
&& "The IO context is not initialized");
598 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
602 // FIXME: Issue a diagnostic with this information.
612 ECase(SHT_INIT_ARRAY
);
613 ECase(SHT_FINI_ARRAY
);
614 ECase(SHT_PREINIT_ARRAY
);
616 ECase(SHT_SYMTAB_SHNDX
);
618 ECase(SHT_ANDROID_REL
);
619 ECase(SHT_ANDROID_RELA
);
620 ECase(SHT_ANDROID_RELR
);
621 ECase(SHT_LLVM_ODRTAB
);
622 ECase(SHT_LLVM_LINKER_OPTIONS
);
623 ECase(SHT_LLVM_CALL_GRAPH_PROFILE
);
624 ECase(SHT_LLVM_ADDRSIG
);
625 ECase(SHT_LLVM_DEPENDENT_LIBRARIES
);
626 ECase(SHT_LLVM_SYMPART
);
627 ECase(SHT_LLVM_PART_EHDR
);
628 ECase(SHT_LLVM_PART_PHDR
);
629 ECase(SHT_LLVM_BB_ADDR_MAP
);
630 ECase(SHT_GNU_ATTRIBUTES
);
632 ECase(SHT_GNU_verdef
);
633 ECase(SHT_GNU_verneed
);
634 ECase(SHT_GNU_versym
);
635 switch (Object
->getMachine()) {
637 ECase(SHT_ARM_EXIDX
);
638 ECase(SHT_ARM_PREEMPTMAP
);
639 ECase(SHT_ARM_ATTRIBUTES
);
640 ECase(SHT_ARM_DEBUGOVERLAY
);
641 ECase(SHT_ARM_OVERLAYSECTION
);
643 case ELF::EM_HEXAGON
:
644 ECase(SHT_HEX_ORDERED
);
647 ECase(SHT_X86_64_UNWIND
);
650 ECase(SHT_MIPS_REGINFO
);
651 ECase(SHT_MIPS_OPTIONS
);
652 ECase(SHT_MIPS_DWARF
);
653 ECase(SHT_MIPS_ABIFLAGS
);
656 ECase(SHT_RISCV_ATTRIBUTES
);
663 IO
.enumFallback
<Hex32
>(Value
);
666 void ScalarBitSetTraits
<ELFYAML::ELF_PF
>::bitset(IO
&IO
,
667 ELFYAML::ELF_PF
&Value
) {
668 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
674 void ScalarBitSetTraits
<ELFYAML::ELF_SHF
>::bitset(IO
&IO
,
675 ELFYAML::ELF_SHF
&Value
) {
676 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
677 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
681 BCase(SHF_EXECINSTR
);
684 BCase(SHF_INFO_LINK
);
685 BCase(SHF_LINK_ORDER
);
686 BCase(SHF_OS_NONCONFORMING
);
689 BCase(SHF_COMPRESSED
);
690 BCase(SHF_GNU_RETAIN
);
691 switch (Object
->getMachine()) {
693 BCase(SHF_ARM_PURECODE
);
695 case ELF::EM_HEXAGON
:
696 BCase(SHF_HEX_GPREL
);
699 BCase(SHF_MIPS_NODUPES
);
700 BCase(SHF_MIPS_NAMES
);
701 BCase(SHF_MIPS_LOCAL
);
702 BCase(SHF_MIPS_NOSTRIP
);
703 BCase(SHF_MIPS_GPREL
);
704 BCase(SHF_MIPS_MERGE
);
705 BCase(SHF_MIPS_ADDR
);
706 BCase(SHF_MIPS_STRING
);
709 BCase(SHF_X86_64_LARGE
);
718 void ScalarEnumerationTraits
<ELFYAML::ELF_SHN
>::enumeration(
719 IO
&IO
, ELFYAML::ELF_SHN
&Value
) {
720 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
722 ECase(SHN_LORESERVE
);
730 ECase(SHN_HIRESERVE
);
731 ECase(SHN_AMDGPU_LDS
);
732 ECase(SHN_HEXAGON_SCOMMON
);
733 ECase(SHN_HEXAGON_SCOMMON_1
);
734 ECase(SHN_HEXAGON_SCOMMON_2
);
735 ECase(SHN_HEXAGON_SCOMMON_4
);
736 ECase(SHN_HEXAGON_SCOMMON_8
);
738 IO
.enumFallback
<Hex16
>(Value
);
741 void ScalarEnumerationTraits
<ELFYAML::ELF_STB
>::enumeration(
742 IO
&IO
, ELFYAML::ELF_STB
&Value
) {
743 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
747 ECase(STB_GNU_UNIQUE
);
749 IO
.enumFallback
<Hex8
>(Value
);
752 void ScalarEnumerationTraits
<ELFYAML::ELF_STT
>::enumeration(
753 IO
&IO
, ELFYAML::ELF_STT
&Value
) {
754 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
762 ECase(STT_GNU_IFUNC
);
764 IO
.enumFallback
<Hex8
>(Value
);
768 void ScalarEnumerationTraits
<ELFYAML::ELF_RSS
>::enumeration(
769 IO
&IO
, ELFYAML::ELF_RSS
&Value
) {
770 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
778 void ScalarEnumerationTraits
<ELFYAML::ELF_REL
>::enumeration(
779 IO
&IO
, ELFYAML::ELF_REL
&Value
) {
780 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
781 assert(Object
&& "The IO context is not initialized");
782 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
783 switch (Object
->getMachine()) {
785 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
788 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
790 case ELF::EM_HEXAGON
:
791 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
795 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
797 case ELF::EM_AARCH64
:
798 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
801 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
804 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
807 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
810 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
813 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
816 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
819 #include "llvm/BinaryFormat/ELFRelocs/VE.def"
822 #include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
825 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
828 #include "llvm/BinaryFormat/ELFRelocs/M68k.def"
835 IO
.enumFallback
<Hex32
>(Value
);
838 void ScalarEnumerationTraits
<ELFYAML::ELF_DYNTAG
>::enumeration(
839 IO
&IO
, ELFYAML::ELF_DYNTAG
&Value
) {
840 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
841 assert(Object
&& "The IO context is not initialized");
843 // Disable architecture specific tags by default. We might enable them below.
844 #define AARCH64_DYNAMIC_TAG(name, value)
845 #define MIPS_DYNAMIC_TAG(name, value)
846 #define HEXAGON_DYNAMIC_TAG(name, value)
847 #define PPC_DYNAMIC_TAG(name, value)
848 #define PPC64_DYNAMIC_TAG(name, value)
849 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
850 #define DYNAMIC_TAG_MARKER(name, value)
852 #define STRINGIFY(X) (#X)
853 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
854 switch (Object
->getMachine()) {
855 case ELF::EM_AARCH64
:
856 #undef AARCH64_DYNAMIC_TAG
857 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
858 #include "llvm/BinaryFormat/DynamicTags.def"
859 #undef AARCH64_DYNAMIC_TAG
860 #define AARCH64_DYNAMIC_TAG(name, value)
863 #undef MIPS_DYNAMIC_TAG
864 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
865 #include "llvm/BinaryFormat/DynamicTags.def"
866 #undef MIPS_DYNAMIC_TAG
867 #define MIPS_DYNAMIC_TAG(name, value)
869 case ELF::EM_HEXAGON
:
870 #undef HEXAGON_DYNAMIC_TAG
871 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
872 #include "llvm/BinaryFormat/DynamicTags.def"
873 #undef HEXAGON_DYNAMIC_TAG
874 #define HEXAGON_DYNAMIC_TAG(name, value)
877 #undef PPC_DYNAMIC_TAG
878 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
879 #include "llvm/BinaryFormat/DynamicTags.def"
880 #undef PPC_DYNAMIC_TAG
881 #define PPC_DYNAMIC_TAG(name, value)
884 #undef PPC64_DYNAMIC_TAG
885 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
886 #include "llvm/BinaryFormat/DynamicTags.def"
887 #undef PPC64_DYNAMIC_TAG
888 #define PPC64_DYNAMIC_TAG(name, value)
891 #include "llvm/BinaryFormat/DynamicTags.def"
894 #undef AARCH64_DYNAMIC_TAG
895 #undef MIPS_DYNAMIC_TAG
896 #undef HEXAGON_DYNAMIC_TAG
897 #undef PPC_DYNAMIC_TAG
898 #undef PPC64_DYNAMIC_TAG
899 #undef DYNAMIC_TAG_MARKER
903 IO
.enumFallback
<Hex64
>(Value
);
906 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_REG
>::enumeration(
907 IO
&IO
, ELFYAML::MIPS_AFL_REG
&Value
) {
908 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
916 void ScalarEnumerationTraits
<ELFYAML::MIPS_ABI_FP
>::enumeration(
917 IO
&IO
, ELFYAML::MIPS_ABI_FP
&Value
) {
918 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
930 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_EXT
>::enumeration(
931 IO
&IO
, ELFYAML::MIPS_AFL_EXT
&Value
) {
932 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
937 ECase(EXT_LOONGSON_3A
);
950 ECase(EXT_LOONGSON_2E
);
951 ECase(EXT_LOONGSON_2F
);
956 void ScalarEnumerationTraits
<ELFYAML::MIPS_ISA
>::enumeration(
957 IO
&IO
, ELFYAML::MIPS_ISA
&Value
) {
958 IO
.enumCase(Value
, "MIPS1", 1);
959 IO
.enumCase(Value
, "MIPS2", 2);
960 IO
.enumCase(Value
, "MIPS3", 3);
961 IO
.enumCase(Value
, "MIPS4", 4);
962 IO
.enumCase(Value
, "MIPS5", 5);
963 IO
.enumCase(Value
, "MIPS32", 32);
964 IO
.enumCase(Value
, "MIPS64", 64);
965 IO
.enumFallback
<Hex32
>(Value
);
968 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_ASE
>::bitset(
969 IO
&IO
, ELFYAML::MIPS_AFL_ASE
&Value
) {
970 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
989 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_FLAGS1
>::bitset(
990 IO
&IO
, ELFYAML::MIPS_AFL_FLAGS1
&Value
) {
991 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
996 void MappingTraits
<ELFYAML::SectionHeader
>::mapping(
997 IO
&IO
, ELFYAML::SectionHeader
&SHdr
) {
998 IO
.mapRequired("Name", SHdr
.Name
);
1001 void MappingTraits
<ELFYAML::FileHeader
>::mapping(IO
&IO
,
1002 ELFYAML::FileHeader
&FileHdr
) {
1003 IO
.mapRequired("Class", FileHdr
.Class
);
1004 IO
.mapRequired("Data", FileHdr
.Data
);
1005 IO
.mapOptional("OSABI", FileHdr
.OSABI
, ELFYAML::ELF_ELFOSABI(0));
1006 IO
.mapOptional("ABIVersion", FileHdr
.ABIVersion
, Hex8(0));
1007 IO
.mapRequired("Type", FileHdr
.Type
);
1008 IO
.mapOptional("Machine", FileHdr
.Machine
);
1009 IO
.mapOptional("Flags", FileHdr
.Flags
, ELFYAML::ELF_EF(0));
1010 IO
.mapOptional("Entry", FileHdr
.Entry
, Hex64(0));
1011 IO
.mapOptional("SectionHeaderStringTable", FileHdr
.SectionHeaderStringTable
);
1013 // obj2yaml does not dump these fields.
1014 assert(!IO
.outputting() ||
1015 (!FileHdr
.EPhOff
&& !FileHdr
.EPhEntSize
&& !FileHdr
.EPhNum
));
1016 IO
.mapOptional("EPhOff", FileHdr
.EPhOff
);
1017 IO
.mapOptional("EPhEntSize", FileHdr
.EPhEntSize
);
1018 IO
.mapOptional("EPhNum", FileHdr
.EPhNum
);
1019 IO
.mapOptional("EShEntSize", FileHdr
.EShEntSize
);
1020 IO
.mapOptional("EShOff", FileHdr
.EShOff
);
1021 IO
.mapOptional("EShNum", FileHdr
.EShNum
);
1022 IO
.mapOptional("EShStrNdx", FileHdr
.EShStrNdx
);
1025 void MappingTraits
<ELFYAML::ProgramHeader
>::mapping(
1026 IO
&IO
, ELFYAML::ProgramHeader
&Phdr
) {
1027 IO
.mapRequired("Type", Phdr
.Type
);
1028 IO
.mapOptional("Flags", Phdr
.Flags
, ELFYAML::ELF_PF(0));
1029 IO
.mapOptional("FirstSec", Phdr
.FirstSec
);
1030 IO
.mapOptional("LastSec", Phdr
.LastSec
);
1031 IO
.mapOptional("VAddr", Phdr
.VAddr
, Hex64(0));
1032 IO
.mapOptional("PAddr", Phdr
.PAddr
, Phdr
.VAddr
);
1033 IO
.mapOptional("Align", Phdr
.Align
);
1034 IO
.mapOptional("FileSize", Phdr
.FileSize
);
1035 IO
.mapOptional("MemSize", Phdr
.MemSize
);
1036 IO
.mapOptional("Offset", Phdr
.Offset
);
1039 std::string MappingTraits
<ELFYAML::ProgramHeader
>::validate(
1040 IO
&IO
, ELFYAML::ProgramHeader
&FileHdr
) {
1041 if (!FileHdr
.FirstSec
&& FileHdr
.LastSec
)
1042 return "the \"LastSec\" key can't be used without the \"FirstSec\" key";
1043 if (FileHdr
.FirstSec
&& !FileHdr
.LastSec
)
1044 return "the \"FirstSec\" key can't be used without the \"LastSec\" key";
1048 LLVM_YAML_STRONG_TYPEDEF(StringRef
, StOtherPiece
)
1050 template <> struct ScalarTraits
<StOtherPiece
> {
1051 static void output(const StOtherPiece
&Val
, void *, raw_ostream
&Out
) {
1054 static StringRef
input(StringRef Scalar
, void *, StOtherPiece
&Val
) {
1058 static QuotingType
mustQuote(StringRef
) { return QuotingType::None
; }
1060 template <> struct SequenceElementTraits
<StOtherPiece
> {
1061 static const bool flow
= true;
1064 template <> struct ScalarTraits
<ELFYAML::YAMLFlowString
> {
1065 static void output(const ELFYAML::YAMLFlowString
&Val
, void *,
1069 static StringRef
input(StringRef Scalar
, void *,
1070 ELFYAML::YAMLFlowString
&Val
) {
1074 static QuotingType
mustQuote(StringRef S
) {
1075 return ScalarTraits
<StringRef
>::mustQuote(S
);
1078 template <> struct SequenceElementTraits
<ELFYAML::YAMLFlowString
> {
1079 static const bool flow
= true;
1084 struct NormalizedOther
{
1085 NormalizedOther(IO
&IO
) : YamlIO(IO
) {}
1086 NormalizedOther(IO
&IO
, Optional
<uint8_t> Original
) : YamlIO(IO
) {
1087 assert(Original
&& "This constructor is only used for outputting YAML and "
1088 "assumes a non-empty Original");
1089 std::vector
<StOtherPiece
> Ret
;
1090 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
1091 for (std::pair
<StringRef
, uint8_t> &P
:
1092 getFlags(Object
->getMachine()).takeVector()) {
1093 uint8_t FlagValue
= P
.second
;
1094 if ((*Original
& FlagValue
) != FlagValue
)
1096 *Original
&= ~FlagValue
;
1097 Ret
.push_back({P
.first
});
1100 if (*Original
!= 0) {
1101 UnknownFlagsHolder
= std::to_string(*Original
);
1102 Ret
.push_back({UnknownFlagsHolder
});
1106 Other
= std::move(Ret
);
1109 uint8_t toValue(StringRef Name
) {
1110 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
1111 MapVector
<StringRef
, uint8_t> Flags
= getFlags(Object
->getMachine());
1113 auto It
= Flags
.find(Name
);
1114 if (It
!= Flags
.end())
1118 if (to_integer(Name
, Val
))
1121 YamlIO
.setError("an unknown value is used for symbol's 'Other' field: " +
1126 Optional
<uint8_t> denormalize(IO
&) {
1130 for (StOtherPiece
&Val
: *Other
)
1131 Ret
|= toValue(Val
);
1135 // st_other field is used to encode symbol visibility and platform-dependent
1136 // flags and values. This method returns a name to value map that is used for
1137 // parsing and encoding this field.
1138 MapVector
<StringRef
, uint8_t> getFlags(unsigned EMachine
) {
1139 MapVector
<StringRef
, uint8_t> Map
;
1140 // STV_* values are just enumeration values. We add them in a reversed order
1141 // because when we convert the st_other to named constants when printing
1142 // YAML we want to use a maximum number of bits on each step:
1143 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
1144 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
1145 Map
["STV_PROTECTED"] = ELF::STV_PROTECTED
;
1146 Map
["STV_HIDDEN"] = ELF::STV_HIDDEN
;
1147 Map
["STV_INTERNAL"] = ELF::STV_INTERNAL
;
1148 // STV_DEFAULT is used to represent the default visibility and has a value
1149 // 0. We want to be able to read it from YAML documents, but there is no
1150 // reason to print it.
1151 if (!YamlIO
.outputting())
1152 Map
["STV_DEFAULT"] = ELF::STV_DEFAULT
;
1154 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
1155 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
1156 // consumed first when we print the output, because we do not want to print
1157 // any other flags that have the same bits instead.
1158 if (EMachine
== ELF::EM_MIPS
) {
1159 Map
["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16
;
1160 Map
["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS
;
1161 Map
["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC
;
1162 Map
["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT
;
1163 Map
["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL
;
1166 if (EMachine
== ELF::EM_AARCH64
)
1167 Map
["STO_AARCH64_VARIANT_PCS"] = ELF::STO_AARCH64_VARIANT_PCS
;
1172 Optional
<std::vector
<StOtherPiece
>> Other
;
1173 std::string UnknownFlagsHolder
;
1176 } // end anonymous namespace
1178 void ScalarTraits
<ELFYAML::YAMLIntUInt
>::output(const ELFYAML::YAMLIntUInt
&Val
,
1179 void *Ctx
, raw_ostream
&Out
) {
1183 StringRef ScalarTraits
<ELFYAML::YAMLIntUInt
>::input(StringRef Scalar
, void *Ctx
,
1184 ELFYAML::YAMLIntUInt
&Val
) {
1185 const bool Is64
= static_cast<ELFYAML::Object
*>(Ctx
)->Header
.Class
==
1186 ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
);
1187 StringRef ErrMsg
= "invalid number";
1188 // We do not accept negative hex numbers because their meaning is ambiguous.
1189 // For example, would -0xfffffffff mean 1 or INT32_MIN?
1190 if (Scalar
.empty() || Scalar
.startswith("-0x"))
1193 if (Scalar
.startswith("-")) {
1194 const int64_t MinVal
= Is64
? INT64_MIN
: INT32_MIN
;
1196 if (getAsSignedInteger(Scalar
, /*Radix=*/0, Int
) || (Int
< MinVal
))
1202 const uint64_t MaxVal
= Is64
? UINT64_MAX
: UINT32_MAX
;
1203 unsigned long long UInt
;
1204 if (getAsUnsignedInteger(Scalar
, /*Radix=*/0, UInt
) || (UInt
> MaxVal
))
1210 void MappingTraits
<ELFYAML::Symbol
>::mapping(IO
&IO
, ELFYAML::Symbol
&Symbol
) {
1211 IO
.mapOptional("Name", Symbol
.Name
, StringRef());
1212 IO
.mapOptional("StName", Symbol
.StName
);
1213 IO
.mapOptional("Type", Symbol
.Type
, ELFYAML::ELF_STT(0));
1214 IO
.mapOptional("Section", Symbol
.Section
);
1215 IO
.mapOptional("Index", Symbol
.Index
);
1216 IO
.mapOptional("Binding", Symbol
.Binding
, ELFYAML::ELF_STB(0));
1217 IO
.mapOptional("Value", Symbol
.Value
);
1218 IO
.mapOptional("Size", Symbol
.Size
);
1220 // Symbol's Other field is a bit special. It is usually a field that
1221 // represents st_other and holds the symbol visibility. However, on some
1222 // platforms, it can contain bit fields and regular values, or even sometimes a
1223 // crazy mix of them (see comments for NormalizedOther). Because of this, we
1224 // need special handling.
1225 MappingNormalization
<NormalizedOther
, Optional
<uint8_t>> Keys(IO
,
1227 IO
.mapOptional("Other", Keys
->Other
);
1230 std::string MappingTraits
<ELFYAML::Symbol
>::validate(IO
&IO
,
1231 ELFYAML::Symbol
&Symbol
) {
1232 if (Symbol
.Index
&& Symbol
.Section
)
1233 return "Index and Section cannot both be specified for Symbol";
1237 static void commonSectionMapping(IO
&IO
, ELFYAML::Section
&Section
) {
1238 IO
.mapOptional("Name", Section
.Name
, StringRef());
1239 IO
.mapRequired("Type", Section
.Type
);
1240 IO
.mapOptional("Flags", Section
.Flags
);
1241 IO
.mapOptional("Address", Section
.Address
);
1242 IO
.mapOptional("Link", Section
.Link
);
1243 IO
.mapOptional("AddressAlign", Section
.AddressAlign
, Hex64(0));
1244 IO
.mapOptional("EntSize", Section
.EntSize
);
1245 IO
.mapOptional("Offset", Section
.Offset
);
1247 IO
.mapOptional("Content", Section
.Content
);
1248 IO
.mapOptional("Size", Section
.Size
);
1250 // obj2yaml does not dump these fields. They are expected to be empty when we
1251 // are producing YAML, because yaml2obj sets appropriate values for them
1252 // automatically when they are not explicitly defined.
1253 assert(!IO
.outputting() ||
1254 (!Section
.ShOffset
&& !Section
.ShSize
&& !Section
.ShName
&&
1255 !Section
.ShFlags
&& !Section
.ShType
&& !Section
.ShAddrAlign
));
1256 IO
.mapOptional("ShAddrAlign", Section
.ShAddrAlign
);
1257 IO
.mapOptional("ShName", Section
.ShName
);
1258 IO
.mapOptional("ShOffset", Section
.ShOffset
);
1259 IO
.mapOptional("ShSize", Section
.ShSize
);
1260 IO
.mapOptional("ShFlags", Section
.ShFlags
);
1261 IO
.mapOptional("ShType", Section
.ShType
);
1264 static void sectionMapping(IO
&IO
, ELFYAML::DynamicSection
&Section
) {
1265 commonSectionMapping(IO
, Section
);
1266 IO
.mapOptional("Entries", Section
.Entries
);
1269 static void sectionMapping(IO
&IO
, ELFYAML::RawContentSection
&Section
) {
1270 commonSectionMapping(IO
, Section
);
1272 // We also support reading a content as array of bytes using the ContentArray
1273 // key. obj2yaml never prints this field.
1274 assert(!IO
.outputting() || !Section
.ContentBuf
.hasValue());
1275 IO
.mapOptional("ContentArray", Section
.ContentBuf
);
1276 if (Section
.ContentBuf
) {
1277 if (Section
.Content
)
1278 IO
.setError("Content and ContentArray can't be used together");
1279 Section
.Content
= yaml::BinaryRef(*Section
.ContentBuf
);
1282 IO
.mapOptional("Info", Section
.Info
);
1285 static void sectionMapping(IO
&IO
, ELFYAML::BBAddrMapSection
&Section
) {
1286 commonSectionMapping(IO
, Section
);
1287 IO
.mapOptional("Content", Section
.Content
);
1288 IO
.mapOptional("Entries", Section
.Entries
);
1291 static void sectionMapping(IO
&IO
, ELFYAML::StackSizesSection
&Section
) {
1292 commonSectionMapping(IO
, Section
);
1293 IO
.mapOptional("Entries", Section
.Entries
);
1296 static void sectionMapping(IO
&IO
, ELFYAML::HashSection
&Section
) {
1297 commonSectionMapping(IO
, Section
);
1298 IO
.mapOptional("Bucket", Section
.Bucket
);
1299 IO
.mapOptional("Chain", Section
.Chain
);
1301 // obj2yaml does not dump these fields. They can be used to override nchain
1302 // and nbucket values for creating broken sections.
1303 assert(!IO
.outputting() ||
1304 (!Section
.NBucket
.hasValue() && !Section
.NChain
.hasValue()));
1305 IO
.mapOptional("NChain", Section
.NChain
);
1306 IO
.mapOptional("NBucket", Section
.NBucket
);
1309 static void sectionMapping(IO
&IO
, ELFYAML::NoteSection
&Section
) {
1310 commonSectionMapping(IO
, Section
);
1311 IO
.mapOptional("Notes", Section
.Notes
);
1315 static void sectionMapping(IO
&IO
, ELFYAML::GnuHashSection
&Section
) {
1316 commonSectionMapping(IO
, Section
);
1317 IO
.mapOptional("Header", Section
.Header
);
1318 IO
.mapOptional("BloomFilter", Section
.BloomFilter
);
1319 IO
.mapOptional("HashBuckets", Section
.HashBuckets
);
1320 IO
.mapOptional("HashValues", Section
.HashValues
);
1322 static void sectionMapping(IO
&IO
, ELFYAML::NoBitsSection
&Section
) {
1323 commonSectionMapping(IO
, Section
);
1326 static void sectionMapping(IO
&IO
, ELFYAML::VerdefSection
&Section
) {
1327 commonSectionMapping(IO
, Section
);
1328 IO
.mapOptional("Info", Section
.Info
);
1329 IO
.mapOptional("Entries", Section
.Entries
);
1332 static void sectionMapping(IO
&IO
, ELFYAML::SymverSection
&Section
) {
1333 commonSectionMapping(IO
, Section
);
1334 IO
.mapOptional("Entries", Section
.Entries
);
1337 static void sectionMapping(IO
&IO
, ELFYAML::VerneedSection
&Section
) {
1338 commonSectionMapping(IO
, Section
);
1339 IO
.mapOptional("Info", Section
.Info
);
1340 IO
.mapOptional("Dependencies", Section
.VerneedV
);
1343 static void sectionMapping(IO
&IO
, ELFYAML::RelocationSection
&Section
) {
1344 commonSectionMapping(IO
, Section
);
1345 IO
.mapOptional("Info", Section
.RelocatableSec
, StringRef());
1346 IO
.mapOptional("Relocations", Section
.Relocations
);
1349 static void sectionMapping(IO
&IO
, ELFYAML::RelrSection
&Section
) {
1350 commonSectionMapping(IO
, Section
);
1351 IO
.mapOptional("Entries", Section
.Entries
);
1354 static void groupSectionMapping(IO
&IO
, ELFYAML::GroupSection
&Group
) {
1355 commonSectionMapping(IO
, Group
);
1356 IO
.mapOptional("Info", Group
.Signature
);
1357 IO
.mapOptional("Members", Group
.Members
);
1360 static void sectionMapping(IO
&IO
, ELFYAML::SymtabShndxSection
&Section
) {
1361 commonSectionMapping(IO
, Section
);
1362 IO
.mapOptional("Entries", Section
.Entries
);
1365 static void sectionMapping(IO
&IO
, ELFYAML::AddrsigSection
&Section
) {
1366 commonSectionMapping(IO
, Section
);
1367 IO
.mapOptional("Symbols", Section
.Symbols
);
1370 static void fillMapping(IO
&IO
, ELFYAML::Fill
&Fill
) {
1371 IO
.mapOptional("Name", Fill
.Name
, StringRef());
1372 IO
.mapOptional("Pattern", Fill
.Pattern
);
1373 IO
.mapOptional("Offset", Fill
.Offset
);
1374 IO
.mapRequired("Size", Fill
.Size
);
1377 static void sectionHeaderTableMapping(IO
&IO
,
1378 ELFYAML::SectionHeaderTable
&SHT
) {
1379 IO
.mapOptional("Offset", SHT
.Offset
);
1380 IO
.mapOptional("Sections", SHT
.Sections
);
1381 IO
.mapOptional("Excluded", SHT
.Excluded
);
1382 IO
.mapOptional("NoHeaders", SHT
.NoHeaders
);
1385 static void sectionMapping(IO
&IO
, ELFYAML::LinkerOptionsSection
&Section
) {
1386 commonSectionMapping(IO
, Section
);
1387 IO
.mapOptional("Options", Section
.Options
);
1390 static void sectionMapping(IO
&IO
,
1391 ELFYAML::DependentLibrariesSection
&Section
) {
1392 commonSectionMapping(IO
, Section
);
1393 IO
.mapOptional("Libraries", Section
.Libs
);
1396 static void sectionMapping(IO
&IO
, ELFYAML::CallGraphProfileSection
&Section
) {
1397 commonSectionMapping(IO
, Section
);
1398 IO
.mapOptional("Entries", Section
.Entries
);
1401 void MappingTraits
<ELFYAML::SectionOrType
>::mapping(
1402 IO
&IO
, ELFYAML::SectionOrType
§ionOrType
) {
1403 IO
.mapRequired("SectionOrType", sectionOrType
.sectionNameOrType
);
1406 static void sectionMapping(IO
&IO
, ELFYAML::ARMIndexTableSection
&Section
) {
1407 commonSectionMapping(IO
, Section
);
1408 IO
.mapOptional("Entries", Section
.Entries
);
1411 static void sectionMapping(IO
&IO
, ELFYAML::MipsABIFlags
&Section
) {
1412 commonSectionMapping(IO
, Section
);
1413 IO
.mapOptional("Version", Section
.Version
, Hex16(0));
1414 IO
.mapRequired("ISA", Section
.ISALevel
);
1415 IO
.mapOptional("ISARevision", Section
.ISARevision
, Hex8(0));
1416 IO
.mapOptional("ISAExtension", Section
.ISAExtension
,
1417 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE
));
1418 IO
.mapOptional("ASEs", Section
.ASEs
, ELFYAML::MIPS_AFL_ASE(0));
1419 IO
.mapOptional("FpABI", Section
.FpABI
,
1420 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY
));
1421 IO
.mapOptional("GPRSize", Section
.GPRSize
,
1422 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1423 IO
.mapOptional("CPR1Size", Section
.CPR1Size
,
1424 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1425 IO
.mapOptional("CPR2Size", Section
.CPR2Size
,
1426 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1427 IO
.mapOptional("Flags1", Section
.Flags1
, ELFYAML::MIPS_AFL_FLAGS1(0));
1428 IO
.mapOptional("Flags2", Section
.Flags2
, Hex32(0));
1431 static StringRef
getStringValue(IO
&IO
, const char *Key
) {
1433 IO
.mapRequired(Key
, Val
);
1437 static void setStringValue(IO
&IO
, const char *Key
, StringRef Val
) {
1438 IO
.mapRequired(Key
, Val
);
1441 static bool isInteger(StringRef Val
) {
1443 return !Val
.getAsInteger(0, Tmp
);
1446 void MappingTraits
<std::unique_ptr
<ELFYAML::Chunk
>>::mapping(
1447 IO
&IO
, std::unique_ptr
<ELFYAML::Chunk
> &Section
) {
1448 ELFYAML::ELF_SHT Type
;
1450 if (IO
.outputting()) {
1451 if (auto *S
= dyn_cast
<ELFYAML::Section
>(Section
.get()))
1453 else if (auto *SHT
= dyn_cast
<ELFYAML::SectionHeaderTable
>(Section
.get()))
1454 TypeStr
= SHT
->TypeStr
;
1456 // When the Type string does not have a "SHT_" prefix, we know it is not a
1457 // description of a regular ELF output section.
1458 TypeStr
= getStringValue(IO
, "Type");
1459 if (TypeStr
.startswith("SHT_") || isInteger(TypeStr
))
1460 IO
.mapRequired("Type", Type
);
1463 if (TypeStr
== "Fill") {
1464 assert(!IO
.outputting()); // We don't dump fills currently.
1465 Section
.reset(new ELFYAML::Fill());
1466 fillMapping(IO
, *cast
<ELFYAML::Fill
>(Section
.get()));
1470 if (TypeStr
== ELFYAML::SectionHeaderTable::TypeStr
) {
1471 if (IO
.outputting())
1472 setStringValue(IO
, "Type", TypeStr
);
1474 Section
.reset(new ELFYAML::SectionHeaderTable(/*IsImplicit=*/false));
1476 sectionHeaderTableMapping(
1477 IO
, *cast
<ELFYAML::SectionHeaderTable
>(Section
.get()));
1481 const auto &Obj
= *static_cast<ELFYAML::Object
*>(IO
.getContext());
1482 if (Obj
.getMachine() == ELF::EM_MIPS
&& Type
== ELF::SHT_MIPS_ABIFLAGS
) {
1483 if (!IO
.outputting())
1484 Section
.reset(new ELFYAML::MipsABIFlags());
1485 sectionMapping(IO
, *cast
<ELFYAML::MipsABIFlags
>(Section
.get()));
1489 if (Obj
.getMachine() == ELF::EM_ARM
&& Type
== ELF::SHT_ARM_EXIDX
) {
1490 if (!IO
.outputting())
1491 Section
.reset(new ELFYAML::ARMIndexTableSection());
1492 sectionMapping(IO
, *cast
<ELFYAML::ARMIndexTableSection
>(Section
.get()));
1497 case ELF::SHT_DYNAMIC
:
1498 if (!IO
.outputting())
1499 Section
.reset(new ELFYAML::DynamicSection());
1500 sectionMapping(IO
, *cast
<ELFYAML::DynamicSection
>(Section
.get()));
1504 if (!IO
.outputting())
1505 Section
.reset(new ELFYAML::RelocationSection());
1506 sectionMapping(IO
, *cast
<ELFYAML::RelocationSection
>(Section
.get()));
1509 if (!IO
.outputting())
1510 Section
.reset(new ELFYAML::RelrSection());
1511 sectionMapping(IO
, *cast
<ELFYAML::RelrSection
>(Section
.get()));
1513 case ELF::SHT_GROUP
:
1514 if (!IO
.outputting())
1515 Section
.reset(new ELFYAML::GroupSection());
1516 groupSectionMapping(IO
, *cast
<ELFYAML::GroupSection
>(Section
.get()));
1518 case ELF::SHT_NOBITS
:
1519 if (!IO
.outputting())
1520 Section
.reset(new ELFYAML::NoBitsSection());
1521 sectionMapping(IO
, *cast
<ELFYAML::NoBitsSection
>(Section
.get()));
1524 if (!IO
.outputting())
1525 Section
.reset(new ELFYAML::HashSection());
1526 sectionMapping(IO
, *cast
<ELFYAML::HashSection
>(Section
.get()));
1529 if (!IO
.outputting())
1530 Section
.reset(new ELFYAML::NoteSection());
1531 sectionMapping(IO
, *cast
<ELFYAML::NoteSection
>(Section
.get()));
1533 case ELF::SHT_GNU_HASH
:
1534 if (!IO
.outputting())
1535 Section
.reset(new ELFYAML::GnuHashSection());
1536 sectionMapping(IO
, *cast
<ELFYAML::GnuHashSection
>(Section
.get()));
1538 case ELF::SHT_GNU_verdef
:
1539 if (!IO
.outputting())
1540 Section
.reset(new ELFYAML::VerdefSection());
1541 sectionMapping(IO
, *cast
<ELFYAML::VerdefSection
>(Section
.get()));
1543 case ELF::SHT_GNU_versym
:
1544 if (!IO
.outputting())
1545 Section
.reset(new ELFYAML::SymverSection());
1546 sectionMapping(IO
, *cast
<ELFYAML::SymverSection
>(Section
.get()));
1548 case ELF::SHT_GNU_verneed
:
1549 if (!IO
.outputting())
1550 Section
.reset(new ELFYAML::VerneedSection());
1551 sectionMapping(IO
, *cast
<ELFYAML::VerneedSection
>(Section
.get()));
1553 case ELF::SHT_SYMTAB_SHNDX
:
1554 if (!IO
.outputting())
1555 Section
.reset(new ELFYAML::SymtabShndxSection());
1556 sectionMapping(IO
, *cast
<ELFYAML::SymtabShndxSection
>(Section
.get()));
1558 case ELF::SHT_LLVM_ADDRSIG
:
1559 if (!IO
.outputting())
1560 Section
.reset(new ELFYAML::AddrsigSection());
1561 sectionMapping(IO
, *cast
<ELFYAML::AddrsigSection
>(Section
.get()));
1563 case ELF::SHT_LLVM_LINKER_OPTIONS
:
1564 if (!IO
.outputting())
1565 Section
.reset(new ELFYAML::LinkerOptionsSection());
1566 sectionMapping(IO
, *cast
<ELFYAML::LinkerOptionsSection
>(Section
.get()));
1568 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES
:
1569 if (!IO
.outputting())
1570 Section
.reset(new ELFYAML::DependentLibrariesSection());
1572 *cast
<ELFYAML::DependentLibrariesSection
>(Section
.get()));
1574 case ELF::SHT_LLVM_CALL_GRAPH_PROFILE
:
1575 if (!IO
.outputting())
1576 Section
.reset(new ELFYAML::CallGraphProfileSection());
1577 sectionMapping(IO
, *cast
<ELFYAML::CallGraphProfileSection
>(Section
.get()));
1579 case ELF::SHT_LLVM_BB_ADDR_MAP
:
1580 if (!IO
.outputting())
1581 Section
.reset(new ELFYAML::BBAddrMapSection());
1582 sectionMapping(IO
, *cast
<ELFYAML::BBAddrMapSection
>(Section
.get()));
1585 if (!IO
.outputting()) {
1587 IO
.mapOptional("Name", Name
, StringRef());
1588 Name
= ELFYAML::dropUniqueSuffix(Name
);
1590 if (ELFYAML::StackSizesSection::nameMatches(Name
))
1591 Section
= std::make_unique
<ELFYAML::StackSizesSection
>();
1593 Section
= std::make_unique
<ELFYAML::RawContentSection
>();
1596 if (auto S
= dyn_cast
<ELFYAML::RawContentSection
>(Section
.get()))
1597 sectionMapping(IO
, *S
);
1599 sectionMapping(IO
, *cast
<ELFYAML::StackSizesSection
>(Section
.get()));
1603 std::string MappingTraits
<std::unique_ptr
<ELFYAML::Chunk
>>::validate(
1604 IO
&io
, std::unique_ptr
<ELFYAML::Chunk
> &C
) {
1605 if (const auto *F
= dyn_cast
<ELFYAML::Fill
>(C
.get())) {
1606 if (F
->Pattern
&& F
->Pattern
->binary_size() != 0 && !F
->Size
)
1607 return "\"Size\" can't be 0 when \"Pattern\" is not empty";
1611 if (const auto *SHT
= dyn_cast
<ELFYAML::SectionHeaderTable
>(C
.get())) {
1612 if (SHT
->NoHeaders
&& (SHT
->Sections
|| SHT
->Excluded
|| SHT
->Offset
))
1613 return "NoHeaders can't be used together with Offset/Sections/Excluded";
1617 const ELFYAML::Section
&Sec
= *cast
<ELFYAML::Section
>(C
.get());
1618 if (Sec
.Size
&& Sec
.Content
&&
1619 (uint64_t)(*Sec
.Size
) < Sec
.Content
->binary_size())
1620 return "Section size must be greater than or equal to the content size";
1622 auto BuildErrPrefix
= [](ArrayRef
<std::pair
<StringRef
, bool>> EntV
) {
1624 for (size_t I
= 0, E
= EntV
.size(); I
!= E
; ++I
) {
1625 StringRef Name
= EntV
[I
].first
;
1627 Msg
= "\"" + Name
.str() + "\"";
1630 if (I
!= EntV
.size() - 1)
1631 Msg
+= ", \"" + Name
.str() + "\"";
1633 Msg
+= " and \"" + Name
.str() + "\"";
1638 std::vector
<std::pair
<StringRef
, bool>> Entries
= Sec
.getEntries();
1639 const size_t NumUsedEntries
= llvm::count_if(
1640 Entries
, [](const std::pair
<StringRef
, bool> &P
) { return P
.second
; });
1642 if ((Sec
.Size
|| Sec
.Content
) && NumUsedEntries
> 0)
1643 return BuildErrPrefix(Entries
) +
1644 " cannot be used with \"Content\" or \"Size\"";
1646 if (NumUsedEntries
> 0 && Entries
.size() != NumUsedEntries
)
1647 return BuildErrPrefix(Entries
) + " must be used together";
1649 if (const auto *RawSection
= dyn_cast
<ELFYAML::RawContentSection
>(C
.get())) {
1650 if (RawSection
->Flags
&& RawSection
->ShFlags
)
1651 return "ShFlags and Flags cannot be used together";
1655 if (const auto *NB
= dyn_cast
<ELFYAML::NoBitsSection
>(C
.get())) {
1657 return "SHT_NOBITS section cannot have \"Content\"";
1661 if (const auto *MF
= dyn_cast
<ELFYAML::MipsABIFlags
>(C
.get())) {
1663 return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS "
1666 return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections";
1675 struct NormalizedMips64RelType
{
1676 NormalizedMips64RelType(IO
&)
1677 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1678 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1679 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1680 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF
)) {}
1681 NormalizedMips64RelType(IO
&, ELFYAML::ELF_REL Original
)
1682 : Type(Original
& 0xFF), Type2(Original
>> 8 & 0xFF),
1683 Type3(Original
>> 16 & 0xFF), SpecSym(Original
>> 24 & 0xFF) {}
1685 ELFYAML::ELF_REL
denormalize(IO
&) {
1686 ELFYAML::ELF_REL Res
= Type
| Type2
<< 8 | Type3
<< 16 | SpecSym
<< 24;
1690 ELFYAML::ELF_REL Type
;
1691 ELFYAML::ELF_REL Type2
;
1692 ELFYAML::ELF_REL Type3
;
1693 ELFYAML::ELF_RSS SpecSym
;
1696 } // end anonymous namespace
1698 void MappingTraits
<ELFYAML::StackSizeEntry
>::mapping(
1699 IO
&IO
, ELFYAML::StackSizeEntry
&E
) {
1700 assert(IO
.getContext() && "The IO context is not initialized");
1701 IO
.mapOptional("Address", E
.Address
, Hex64(0));
1702 IO
.mapRequired("Size", E
.Size
);
1705 void MappingTraits
<ELFYAML::BBAddrMapEntry
>::mapping(
1706 IO
&IO
, ELFYAML::BBAddrMapEntry
&E
) {
1707 assert(IO
.getContext() && "The IO context is not initialized");
1708 IO
.mapOptional("Address", E
.Address
, Hex64(0));
1709 IO
.mapOptional("NumBlocks", E
.NumBlocks
);
1710 IO
.mapOptional("BBEntries", E
.BBEntries
);
1713 void MappingTraits
<ELFYAML::BBAddrMapEntry::BBEntry
>::mapping(
1714 IO
&IO
, ELFYAML::BBAddrMapEntry::BBEntry
&E
) {
1715 assert(IO
.getContext() && "The IO context is not initialized");
1716 IO
.mapRequired("AddressOffset", E
.AddressOffset
);
1717 IO
.mapRequired("Size", E
.Size
);
1718 IO
.mapRequired("Metadata", E
.Metadata
);
1721 void MappingTraits
<ELFYAML::GnuHashHeader
>::mapping(IO
&IO
,
1722 ELFYAML::GnuHashHeader
&E
) {
1723 assert(IO
.getContext() && "The IO context is not initialized");
1724 IO
.mapOptional("NBuckets", E
.NBuckets
);
1725 IO
.mapRequired("SymNdx", E
.SymNdx
);
1726 IO
.mapOptional("MaskWords", E
.MaskWords
);
1727 IO
.mapRequired("Shift2", E
.Shift2
);
1730 void MappingTraits
<ELFYAML::DynamicEntry
>::mapping(IO
&IO
,
1731 ELFYAML::DynamicEntry
&Rel
) {
1732 assert(IO
.getContext() && "The IO context is not initialized");
1734 IO
.mapRequired("Tag", Rel
.Tag
);
1735 IO
.mapRequired("Value", Rel
.Val
);
1738 void MappingTraits
<ELFYAML::NoteEntry
>::mapping(IO
&IO
, ELFYAML::NoteEntry
&N
) {
1739 assert(IO
.getContext() && "The IO context is not initialized");
1741 IO
.mapOptional("Name", N
.Name
);
1742 IO
.mapOptional("Desc", N
.Desc
);
1743 IO
.mapRequired("Type", N
.Type
);
1746 void MappingTraits
<ELFYAML::VerdefEntry
>::mapping(IO
&IO
,
1747 ELFYAML::VerdefEntry
&E
) {
1748 assert(IO
.getContext() && "The IO context is not initialized");
1750 IO
.mapOptional("Version", E
.Version
);
1751 IO
.mapOptional("Flags", E
.Flags
);
1752 IO
.mapOptional("VersionNdx", E
.VersionNdx
);
1753 IO
.mapOptional("Hash", E
.Hash
);
1754 IO
.mapRequired("Names", E
.VerNames
);
1757 void MappingTraits
<ELFYAML::VerneedEntry
>::mapping(IO
&IO
,
1758 ELFYAML::VerneedEntry
&E
) {
1759 assert(IO
.getContext() && "The IO context is not initialized");
1761 IO
.mapRequired("Version", E
.Version
);
1762 IO
.mapRequired("File", E
.File
);
1763 IO
.mapRequired("Entries", E
.AuxV
);
1766 void MappingTraits
<ELFYAML::VernauxEntry
>::mapping(IO
&IO
,
1767 ELFYAML::VernauxEntry
&E
) {
1768 assert(IO
.getContext() && "The IO context is not initialized");
1770 IO
.mapRequired("Name", E
.Name
);
1771 IO
.mapRequired("Hash", E
.Hash
);
1772 IO
.mapRequired("Flags", E
.Flags
);
1773 IO
.mapRequired("Other", E
.Other
);
1776 void MappingTraits
<ELFYAML::Relocation
>::mapping(IO
&IO
,
1777 ELFYAML::Relocation
&Rel
) {
1778 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
1779 assert(Object
&& "The IO context is not initialized");
1781 IO
.mapOptional("Offset", Rel
.Offset
, (Hex64
)0);
1782 IO
.mapOptional("Symbol", Rel
.Symbol
);
1784 if (Object
->getMachine() == ELFYAML::ELF_EM(ELF::EM_MIPS
) &&
1785 Object
->Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
)) {
1786 MappingNormalization
<NormalizedMips64RelType
, ELFYAML::ELF_REL
> Key(
1788 IO
.mapRequired("Type", Key
->Type
);
1789 IO
.mapOptional("Type2", Key
->Type2
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1790 IO
.mapOptional("Type3", Key
->Type3
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1791 IO
.mapOptional("SpecSym", Key
->SpecSym
, ELFYAML::ELF_RSS(ELF::RSS_UNDEF
));
1793 IO
.mapRequired("Type", Rel
.Type
);
1795 IO
.mapOptional("Addend", Rel
.Addend
, (ELFYAML::YAMLIntUInt
)0);
1798 void MappingTraits
<ELFYAML::ARMIndexTableEntry
>::mapping(
1799 IO
&IO
, ELFYAML::ARMIndexTableEntry
&E
) {
1800 assert(IO
.getContext() && "The IO context is not initialized");
1801 IO
.mapRequired("Offset", E
.Offset
);
1803 StringRef CantUnwind
= "EXIDX_CANTUNWIND";
1804 if (IO
.outputting() && (uint32_t)E
.Value
== ARM::EHABI::EXIDX_CANTUNWIND
)
1805 IO
.mapRequired("Value", CantUnwind
);
1806 else if (!IO
.outputting() && getStringValue(IO
, "Value") == CantUnwind
)
1807 E
.Value
= ARM::EHABI::EXIDX_CANTUNWIND
;
1809 IO
.mapRequired("Value", E
.Value
);
1812 void MappingTraits
<ELFYAML::Object
>::mapping(IO
&IO
, ELFYAML::Object
&Object
) {
1813 assert(!IO
.getContext() && "The IO context is initialized already");
1814 IO
.setContext(&Object
);
1815 IO
.mapTag("!ELF", true);
1816 IO
.mapRequired("FileHeader", Object
.Header
);
1817 IO
.mapOptional("ProgramHeaders", Object
.ProgramHeaders
);
1818 IO
.mapOptional("Sections", Object
.Chunks
);
1819 IO
.mapOptional("Symbols", Object
.Symbols
);
1820 IO
.mapOptional("DynamicSymbols", Object
.DynamicSymbols
);
1821 IO
.mapOptional("DWARF", Object
.DWARF
);
1823 Object
.DWARF
->IsLittleEndian
=
1824 Object
.Header
.Data
== ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB
);
1825 Object
.DWARF
->Is64BitAddrSize
=
1826 Object
.Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
);
1828 IO
.setContext(nullptr);
1831 void MappingTraits
<ELFYAML::LinkerOption
>::mapping(IO
&IO
,
1832 ELFYAML::LinkerOption
&Opt
) {
1833 assert(IO
.getContext() && "The IO context is not initialized");
1834 IO
.mapRequired("Name", Opt
.Key
);
1835 IO
.mapRequired("Value", Opt
.Value
);
1838 void MappingTraits
<ELFYAML::CallGraphEntryWeight
>::mapping(
1839 IO
&IO
, ELFYAML::CallGraphEntryWeight
&E
) {
1840 assert(IO
.getContext() && "The IO context is not initialized");
1841 IO
.mapRequired("Weight", E
.Weight
);
1844 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG
)
1845 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP
)
1846 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT
)
1847 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE
)
1848 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1
)
1850 } // end namespace yaml
1852 } // end namespace llvm