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/StringRef.h"
15 #include "llvm/BinaryFormat/ELF.h"
16 #include "llvm/Support/Casting.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include "llvm/Support/MipsABIFlags.h"
19 #include "llvm/Support/YAMLTraits.h"
25 ELFYAML::Section::~Section() = default;
29 void ScalarEnumerationTraits
<ELFYAML::ELF_ET
>::enumeration(
30 IO
&IO
, ELFYAML::ELF_ET
&Value
) {
31 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
38 IO
.enumFallback
<Hex16
>(Value
);
41 void ScalarEnumerationTraits
<ELFYAML::ELF_PT
>::enumeration(
42 IO
&IO
, ELFYAML::ELF_PT
&Value
) {
43 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
52 ECase(PT_GNU_EH_FRAME
);
54 IO
.enumFallback
<Hex32
>(Value
);
57 void ScalarEnumerationTraits
<ELFYAML::ELF_EM
>::enumeration(
58 IO
&IO
, ELFYAML::ELF_EM
&Value
) {
59 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
70 ECase(EM_MIPS_RS3_LE
);
73 ECase(EM_SPARC32PLUS
);
136 ECase(EM_ARC_COMPACT
);
156 ECase(EM_ALTERA_NIOS2
);
170 ECase(EM_VIDEOCORE3
);
171 ECase(EM_LATTICEMICO32
);
176 ECase(EM_MMDSP_PLUS
);
177 ECase(EM_CYPRESS_M8C
);
192 ECase(EM_MCST_ELBRUS
);
206 ECase(EM_CLOUDSHIELD
);
209 ECase(EM_ARC_COMPACT2
);
212 ECase(EM_VIDEOCORE5
);
222 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFCLASS
>::enumeration(
223 IO
&IO
, ELFYAML::ELF_ELFCLASS
&Value
) {
224 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
225 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
232 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFDATA
>::enumeration(
233 IO
&IO
, ELFYAML::ELF_ELFDATA
&Value
) {
234 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
235 // Since the semantics of ELFDATANONE is "invalid", just don't accept it
242 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFOSABI
>::enumeration(
243 IO
&IO
, ELFYAML::ELF_ELFOSABI
&Value
) {
244 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
245 ECase(ELFOSABI_NONE
);
246 ECase(ELFOSABI_HPUX
);
247 ECase(ELFOSABI_NETBSD
);
249 ECase(ELFOSABI_HURD
);
250 ECase(ELFOSABI_SOLARIS
);
252 ECase(ELFOSABI_IRIX
);
253 ECase(ELFOSABI_FREEBSD
);
254 ECase(ELFOSABI_TRU64
);
255 ECase(ELFOSABI_MODESTO
);
256 ECase(ELFOSABI_OPENBSD
);
257 ECase(ELFOSABI_OPENVMS
);
259 ECase(ELFOSABI_AROS
);
260 ECase(ELFOSABI_FENIXOS
);
261 ECase(ELFOSABI_CLOUDABI
);
262 ECase(ELFOSABI_AMDGPU_HSA
);
263 ECase(ELFOSABI_AMDGPU_PAL
);
264 ECase(ELFOSABI_AMDGPU_MESA3D
);
266 ECase(ELFOSABI_C6000_ELFABI
);
267 ECase(ELFOSABI_C6000_LINUX
);
268 ECase(ELFOSABI_STANDALONE
);
272 void ScalarBitSetTraits
<ELFYAML::ELF_EF
>::bitset(IO
&IO
,
273 ELFYAML::ELF_EF
&Value
) {
274 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
275 assert(Object
&& "The IO context is not initialized");
276 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
277 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
278 switch (Object
->Header
.Machine
) {
280 BCase(EF_ARM_SOFT_FLOAT
);
281 BCase(EF_ARM_VFP_FLOAT
);
282 BCaseMask(EF_ARM_EABI_UNKNOWN
, EF_ARM_EABIMASK
);
283 BCaseMask(EF_ARM_EABI_VER1
, EF_ARM_EABIMASK
);
284 BCaseMask(EF_ARM_EABI_VER2
, EF_ARM_EABIMASK
);
285 BCaseMask(EF_ARM_EABI_VER3
, EF_ARM_EABIMASK
);
286 BCaseMask(EF_ARM_EABI_VER4
, EF_ARM_EABIMASK
);
287 BCaseMask(EF_ARM_EABI_VER5
, EF_ARM_EABIMASK
);
290 BCase(EF_MIPS_NOREORDER
);
294 BCase(EF_MIPS_32BITMODE
);
296 BCase(EF_MIPS_NAN2008
);
297 BCase(EF_MIPS_MICROMIPS
);
298 BCase(EF_MIPS_ARCH_ASE_M16
);
299 BCase(EF_MIPS_ARCH_ASE_MDMX
);
300 BCaseMask(EF_MIPS_ABI_O32
, EF_MIPS_ABI
);
301 BCaseMask(EF_MIPS_ABI_O64
, EF_MIPS_ABI
);
302 BCaseMask(EF_MIPS_ABI_EABI32
, EF_MIPS_ABI
);
303 BCaseMask(EF_MIPS_ABI_EABI64
, EF_MIPS_ABI
);
304 BCaseMask(EF_MIPS_MACH_3900
, EF_MIPS_MACH
);
305 BCaseMask(EF_MIPS_MACH_4010
, EF_MIPS_MACH
);
306 BCaseMask(EF_MIPS_MACH_4100
, EF_MIPS_MACH
);
307 BCaseMask(EF_MIPS_MACH_4650
, EF_MIPS_MACH
);
308 BCaseMask(EF_MIPS_MACH_4120
, EF_MIPS_MACH
);
309 BCaseMask(EF_MIPS_MACH_4111
, EF_MIPS_MACH
);
310 BCaseMask(EF_MIPS_MACH_SB1
, EF_MIPS_MACH
);
311 BCaseMask(EF_MIPS_MACH_OCTEON
, EF_MIPS_MACH
);
312 BCaseMask(EF_MIPS_MACH_XLR
, EF_MIPS_MACH
);
313 BCaseMask(EF_MIPS_MACH_OCTEON2
, EF_MIPS_MACH
);
314 BCaseMask(EF_MIPS_MACH_OCTEON3
, EF_MIPS_MACH
);
315 BCaseMask(EF_MIPS_MACH_5400
, EF_MIPS_MACH
);
316 BCaseMask(EF_MIPS_MACH_5900
, EF_MIPS_MACH
);
317 BCaseMask(EF_MIPS_MACH_5500
, EF_MIPS_MACH
);
318 BCaseMask(EF_MIPS_MACH_9000
, EF_MIPS_MACH
);
319 BCaseMask(EF_MIPS_MACH_LS2E
, EF_MIPS_MACH
);
320 BCaseMask(EF_MIPS_MACH_LS2F
, EF_MIPS_MACH
);
321 BCaseMask(EF_MIPS_MACH_LS3A
, EF_MIPS_MACH
);
322 BCaseMask(EF_MIPS_ARCH_1
, EF_MIPS_ARCH
);
323 BCaseMask(EF_MIPS_ARCH_2
, EF_MIPS_ARCH
);
324 BCaseMask(EF_MIPS_ARCH_3
, EF_MIPS_ARCH
);
325 BCaseMask(EF_MIPS_ARCH_4
, EF_MIPS_ARCH
);
326 BCaseMask(EF_MIPS_ARCH_5
, EF_MIPS_ARCH
);
327 BCaseMask(EF_MIPS_ARCH_32
, EF_MIPS_ARCH
);
328 BCaseMask(EF_MIPS_ARCH_64
, EF_MIPS_ARCH
);
329 BCaseMask(EF_MIPS_ARCH_32R2
, EF_MIPS_ARCH
);
330 BCaseMask(EF_MIPS_ARCH_64R2
, EF_MIPS_ARCH
);
331 BCaseMask(EF_MIPS_ARCH_32R6
, EF_MIPS_ARCH
);
332 BCaseMask(EF_MIPS_ARCH_64R6
, EF_MIPS_ARCH
);
334 case ELF::EM_HEXAGON
:
335 BCase(EF_HEXAGON_MACH_V2
);
336 BCase(EF_HEXAGON_MACH_V3
);
337 BCase(EF_HEXAGON_MACH_V4
);
338 BCase(EF_HEXAGON_MACH_V5
);
339 BCase(EF_HEXAGON_MACH_V55
);
340 BCase(EF_HEXAGON_MACH_V60
);
341 BCase(EF_HEXAGON_MACH_V62
);
342 BCase(EF_HEXAGON_MACH_V65
);
343 BCase(EF_HEXAGON_ISA_V2
);
344 BCase(EF_HEXAGON_ISA_V3
);
345 BCase(EF_HEXAGON_ISA_V4
);
346 BCase(EF_HEXAGON_ISA_V5
);
347 BCase(EF_HEXAGON_ISA_V55
);
348 BCase(EF_HEXAGON_ISA_V60
);
349 BCase(EF_HEXAGON_ISA_V62
);
350 BCase(EF_HEXAGON_ISA_V65
);
353 BCase(EF_AVR_ARCH_AVR1
);
354 BCase(EF_AVR_ARCH_AVR2
);
355 BCase(EF_AVR_ARCH_AVR25
);
356 BCase(EF_AVR_ARCH_AVR3
);
357 BCase(EF_AVR_ARCH_AVR31
);
358 BCase(EF_AVR_ARCH_AVR35
);
359 BCase(EF_AVR_ARCH_AVR4
);
360 BCase(EF_AVR_ARCH_AVR51
);
361 BCase(EF_AVR_ARCH_AVR6
);
362 BCase(EF_AVR_ARCH_AVRTINY
);
363 BCase(EF_AVR_ARCH_XMEGA1
);
364 BCase(EF_AVR_ARCH_XMEGA2
);
365 BCase(EF_AVR_ARCH_XMEGA3
);
366 BCase(EF_AVR_ARCH_XMEGA4
);
367 BCase(EF_AVR_ARCH_XMEGA5
);
368 BCase(EF_AVR_ARCH_XMEGA6
);
369 BCase(EF_AVR_ARCH_XMEGA7
);
373 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT
, EF_RISCV_FLOAT_ABI
);
374 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE
, EF_RISCV_FLOAT_ABI
);
375 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE
, EF_RISCV_FLOAT_ABI
);
376 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD
, EF_RISCV_FLOAT_ABI
);
380 BCaseMask(EF_AMDGPU_MACH_NONE
, EF_AMDGPU_MACH
);
381 BCaseMask(EF_AMDGPU_MACH_R600_R600
, EF_AMDGPU_MACH
);
382 BCaseMask(EF_AMDGPU_MACH_R600_R630
, EF_AMDGPU_MACH
);
383 BCaseMask(EF_AMDGPU_MACH_R600_RS880
, EF_AMDGPU_MACH
);
384 BCaseMask(EF_AMDGPU_MACH_R600_RV670
, EF_AMDGPU_MACH
);
385 BCaseMask(EF_AMDGPU_MACH_R600_RV710
, EF_AMDGPU_MACH
);
386 BCaseMask(EF_AMDGPU_MACH_R600_RV730
, EF_AMDGPU_MACH
);
387 BCaseMask(EF_AMDGPU_MACH_R600_RV770
, EF_AMDGPU_MACH
);
388 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR
, EF_AMDGPU_MACH
);
389 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS
, EF_AMDGPU_MACH
);
390 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER
, EF_AMDGPU_MACH
);
391 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD
, EF_AMDGPU_MACH
);
392 BCaseMask(EF_AMDGPU_MACH_R600_SUMO
, EF_AMDGPU_MACH
);
393 BCaseMask(EF_AMDGPU_MACH_R600_BARTS
, EF_AMDGPU_MACH
);
394 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS
, EF_AMDGPU_MACH
);
395 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN
, EF_AMDGPU_MACH
);
396 BCaseMask(EF_AMDGPU_MACH_R600_TURKS
, EF_AMDGPU_MACH
);
397 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600
, EF_AMDGPU_MACH
);
398 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601
, EF_AMDGPU_MACH
);
399 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700
, EF_AMDGPU_MACH
);
400 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701
, EF_AMDGPU_MACH
);
401 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702
, EF_AMDGPU_MACH
);
402 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703
, EF_AMDGPU_MACH
);
403 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704
, EF_AMDGPU_MACH
);
404 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801
, EF_AMDGPU_MACH
);
405 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802
, EF_AMDGPU_MACH
);
406 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803
, EF_AMDGPU_MACH
);
407 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810
, EF_AMDGPU_MACH
);
408 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900
, EF_AMDGPU_MACH
);
409 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902
, EF_AMDGPU_MACH
);
410 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904
, EF_AMDGPU_MACH
);
411 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906
, EF_AMDGPU_MACH
);
412 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909
, EF_AMDGPU_MACH
);
413 BCase(EF_AMDGPU_XNACK
);
414 BCase(EF_AMDGPU_SRAM_ECC
);
419 llvm_unreachable("Unsupported architecture");
425 void ScalarEnumerationTraits
<ELFYAML::ELF_SHT
>::enumeration(
426 IO
&IO
, ELFYAML::ELF_SHT
&Value
) {
427 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
428 assert(Object
&& "The IO context is not initialized");
429 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
433 // FIXME: Issue a diagnostic with this information.
443 ECase(SHT_INIT_ARRAY
);
444 ECase(SHT_FINI_ARRAY
);
445 ECase(SHT_PREINIT_ARRAY
);
447 ECase(SHT_SYMTAB_SHNDX
);
450 ECase(SHT_ANDROID_REL
);
451 ECase(SHT_ANDROID_RELA
);
452 ECase(SHT_ANDROID_RELR
);
453 ECase(SHT_LLVM_ODRTAB
);
454 ECase(SHT_LLVM_LINKER_OPTIONS
);
455 ECase(SHT_LLVM_CALL_GRAPH_PROFILE
);
456 ECase(SHT_LLVM_ADDRSIG
);
457 ECase(SHT_GNU_ATTRIBUTES
);
459 ECase(SHT_GNU_verdef
);
460 ECase(SHT_GNU_verneed
);
461 ECase(SHT_GNU_versym
);
464 switch (Object
->Header
.Machine
) {
466 ECase(SHT_ARM_EXIDX
);
467 ECase(SHT_ARM_PREEMPTMAP
);
468 ECase(SHT_ARM_ATTRIBUTES
);
469 ECase(SHT_ARM_DEBUGOVERLAY
);
470 ECase(SHT_ARM_OVERLAYSECTION
);
472 case ELF::EM_HEXAGON
:
473 ECase(SHT_HEX_ORDERED
);
476 ECase(SHT_X86_64_UNWIND
);
479 ECase(SHT_MIPS_REGINFO
);
480 ECase(SHT_MIPS_OPTIONS
);
481 ECase(SHT_MIPS_ABIFLAGS
);
490 void ScalarBitSetTraits
<ELFYAML::ELF_PF
>::bitset(IO
&IO
,
491 ELFYAML::ELF_PF
&Value
) {
492 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
498 void ScalarBitSetTraits
<ELFYAML::ELF_SHF
>::bitset(IO
&IO
,
499 ELFYAML::ELF_SHF
&Value
) {
500 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
501 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
505 BCase(SHF_EXECINSTR
);
508 BCase(SHF_INFO_LINK
);
509 BCase(SHF_LINK_ORDER
);
510 BCase(SHF_OS_NONCONFORMING
);
513 BCase(SHF_COMPRESSED
);
514 switch (Object
->Header
.Machine
) {
516 BCase(SHF_ARM_PURECODE
);
518 case ELF::EM_HEXAGON
:
519 BCase(SHF_HEX_GPREL
);
522 BCase(SHF_MIPS_NODUPES
);
523 BCase(SHF_MIPS_NAMES
);
524 BCase(SHF_MIPS_LOCAL
);
525 BCase(SHF_MIPS_NOSTRIP
);
526 BCase(SHF_MIPS_GPREL
);
527 BCase(SHF_MIPS_MERGE
);
528 BCase(SHF_MIPS_ADDR
);
529 BCase(SHF_MIPS_STRING
);
532 BCase(SHF_X86_64_LARGE
);
541 void ScalarEnumerationTraits
<ELFYAML::ELF_SHN
>::enumeration(
542 IO
&IO
, ELFYAML::ELF_SHN
&Value
) {
543 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
545 ECase(SHN_LORESERVE
);
553 ECase(SHN_HIRESERVE
);
554 ECase(SHN_HEXAGON_SCOMMON
);
555 ECase(SHN_HEXAGON_SCOMMON_1
);
556 ECase(SHN_HEXAGON_SCOMMON_2
);
557 ECase(SHN_HEXAGON_SCOMMON_4
);
558 ECase(SHN_HEXAGON_SCOMMON_8
);
560 IO
.enumFallback
<Hex32
>(Value
);
563 void ScalarEnumerationTraits
<ELFYAML::ELF_STT
>::enumeration(
564 IO
&IO
, ELFYAML::ELF_STT
&Value
) {
565 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
573 ECase(STT_GNU_IFUNC
);
575 IO
.enumFallback
<Hex8
>(Value
);
578 void ScalarEnumerationTraits
<ELFYAML::ELF_STV
>::enumeration(
579 IO
&IO
, ELFYAML::ELF_STV
&Value
) {
580 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
584 ECase(STV_PROTECTED
);
588 void ScalarBitSetTraits
<ELFYAML::ELF_STO
>::bitset(IO
&IO
,
589 ELFYAML::ELF_STO
&Value
) {
590 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
591 assert(Object
&& "The IO context is not initialized");
592 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
593 switch (Object
->Header
.Machine
) {
595 BCase(STO_MIPS_OPTIONAL
);
598 BCase(STO_MIPS_MICROMIPS
);
601 break; // Nothing to do
607 void ScalarEnumerationTraits
<ELFYAML::ELF_RSS
>::enumeration(
608 IO
&IO
, ELFYAML::ELF_RSS
&Value
) {
609 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
617 void ScalarEnumerationTraits
<ELFYAML::ELF_REL
>::enumeration(
618 IO
&IO
, ELFYAML::ELF_REL
&Value
) {
619 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
620 assert(Object
&& "The IO context is not initialized");
621 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
622 switch (Object
->Header
.Machine
) {
624 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
627 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
629 case ELF::EM_HEXAGON
:
630 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
634 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
636 case ELF::EM_AARCH64
:
637 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
640 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
643 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
646 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
649 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
652 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
655 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
658 llvm_unreachable("Unsupported architecture");
661 IO
.enumFallback
<Hex32
>(Value
);
664 void ScalarEnumerationTraits
<ELFYAML::ELF_DYNTAG
>::enumeration(
665 IO
&IO
, ELFYAML::ELF_DYNTAG
&Value
) {
666 assert(IO
.getContext() && "The IO context is not initialized");
668 // TODO: For simplicity we do not handle target specific flags. They are
669 // still supported and will be shown as a raw numeric values in the output.
670 #define MIPS_DYNAMIC_TAG(name, value)
671 #define HEXAGON_DYNAMIC_TAG(name, value)
672 #define PPC64_DYNAMIC_TAG(name, value)
673 // Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
674 #define DYNAMIC_TAG_MARKER(name, value)
676 #define STRINGIFY(X) (#X)
677 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
678 #include "llvm/BinaryFormat/DynamicTags.def"
680 #undef MIPS_DYNAMIC_TAG
681 #undef HEXAGON_DYNAMIC_TAG
682 #undef PPC64_DYNAMIC_TAG
683 #undef DYNAMIC_TAG_MARKER
687 IO
.enumFallback
<Hex64
>(Value
);
690 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_REG
>::enumeration(
691 IO
&IO
, ELFYAML::MIPS_AFL_REG
&Value
) {
692 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
700 void ScalarEnumerationTraits
<ELFYAML::MIPS_ABI_FP
>::enumeration(
701 IO
&IO
, ELFYAML::MIPS_ABI_FP
&Value
) {
702 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
714 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_EXT
>::enumeration(
715 IO
&IO
, ELFYAML::MIPS_AFL_EXT
&Value
) {
716 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
721 ECase(EXT_LOONGSON_3A
);
734 ECase(EXT_LOONGSON_2E
);
735 ECase(EXT_LOONGSON_2F
);
740 void ScalarEnumerationTraits
<ELFYAML::MIPS_ISA
>::enumeration(
741 IO
&IO
, ELFYAML::MIPS_ISA
&Value
) {
742 IO
.enumCase(Value
, "MIPS1", 1);
743 IO
.enumCase(Value
, "MIPS2", 2);
744 IO
.enumCase(Value
, "MIPS3", 3);
745 IO
.enumCase(Value
, "MIPS4", 4);
746 IO
.enumCase(Value
, "MIPS5", 5);
747 IO
.enumCase(Value
, "MIPS32", 32);
748 IO
.enumCase(Value
, "MIPS64", 64);
751 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_ASE
>::bitset(
752 IO
&IO
, ELFYAML::MIPS_AFL_ASE
&Value
) {
753 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
770 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_FLAGS1
>::bitset(
771 IO
&IO
, ELFYAML::MIPS_AFL_FLAGS1
&Value
) {
772 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
777 void MappingTraits
<ELFYAML::FileHeader
>::mapping(IO
&IO
,
778 ELFYAML::FileHeader
&FileHdr
) {
779 IO
.mapRequired("Class", FileHdr
.Class
);
780 IO
.mapRequired("Data", FileHdr
.Data
);
781 IO
.mapOptional("OSABI", FileHdr
.OSABI
, ELFYAML::ELF_ELFOSABI(0));
782 IO
.mapOptional("ABIVersion", FileHdr
.ABIVersion
, Hex8(0));
783 IO
.mapRequired("Type", FileHdr
.Type
);
784 IO
.mapRequired("Machine", FileHdr
.Machine
);
785 IO
.mapOptional("Flags", FileHdr
.Flags
, ELFYAML::ELF_EF(0));
786 IO
.mapOptional("Entry", FileHdr
.Entry
, Hex64(0));
789 void MappingTraits
<ELFYAML::ProgramHeader
>::mapping(
790 IO
&IO
, ELFYAML::ProgramHeader
&Phdr
) {
791 IO
.mapRequired("Type", Phdr
.Type
);
792 IO
.mapOptional("Flags", Phdr
.Flags
, ELFYAML::ELF_PF(0));
793 IO
.mapOptional("Sections", Phdr
.Sections
);
794 IO
.mapOptional("VAddr", Phdr
.VAddr
, Hex64(0));
795 IO
.mapOptional("PAddr", Phdr
.PAddr
, Hex64(0));
796 IO
.mapOptional("Align", Phdr
.Align
);
801 struct NormalizedOther
{
802 NormalizedOther(IO
&)
803 : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
804 NormalizedOther(IO
&, uint8_t Original
)
805 : Visibility(Original
& 0x3), Other(Original
& ~0x3) {}
807 uint8_t denormalize(IO
&) { return Visibility
| Other
; }
809 ELFYAML::ELF_STV Visibility
;
810 ELFYAML::ELF_STO Other
;
813 } // end anonymous namespace
815 void MappingTraits
<ELFYAML::Symbol
>::mapping(IO
&IO
, ELFYAML::Symbol
&Symbol
) {
816 IO
.mapOptional("Name", Symbol
.Name
, StringRef());
817 IO
.mapOptional("Type", Symbol
.Type
, ELFYAML::ELF_STT(0));
818 IO
.mapOptional("Section", Symbol
.Section
, StringRef());
819 IO
.mapOptional("Index", Symbol
.Index
);
820 IO
.mapOptional("Value", Symbol
.Value
, Hex64(0));
821 IO
.mapOptional("Size", Symbol
.Size
, Hex64(0));
823 MappingNormalization
<NormalizedOther
, uint8_t> Keys(IO
, Symbol
.Other
);
824 IO
.mapOptional("Visibility", Keys
->Visibility
, ELFYAML::ELF_STV(0));
825 IO
.mapOptional("Other", Keys
->Other
, ELFYAML::ELF_STO(0));
828 StringRef MappingTraits
<ELFYAML::Symbol
>::validate(IO
&IO
,
829 ELFYAML::Symbol
&Symbol
) {
830 if (Symbol
.Index
&& Symbol
.Section
.data()) {
831 return "Index and Section cannot both be specified for Symbol";
833 if (Symbol
.Index
&& *Symbol
.Index
== ELFYAML::ELF_SHN(ELF::SHN_XINDEX
)) {
834 return "Large indexes are not supported";
836 if (Symbol
.Index
&& *Symbol
.Index
< ELFYAML::ELF_SHN(ELF::SHN_LORESERVE
)) {
837 return "Use a section name to define which section a symbol is defined in";
842 void MappingTraits
<ELFYAML::LocalGlobalWeakSymbols
>::mapping(
843 IO
&IO
, ELFYAML::LocalGlobalWeakSymbols
&Symbols
) {
844 IO
.mapOptional("Local", Symbols
.Local
);
845 IO
.mapOptional("Global", Symbols
.Global
);
846 IO
.mapOptional("Weak", Symbols
.Weak
);
849 static void commonSectionMapping(IO
&IO
, ELFYAML::Section
&Section
) {
850 IO
.mapOptional("Name", Section
.Name
, StringRef());
851 IO
.mapRequired("Type", Section
.Type
);
852 IO
.mapOptional("Flags", Section
.Flags
, ELFYAML::ELF_SHF(0));
853 IO
.mapOptional("Address", Section
.Address
, Hex64(0));
854 IO
.mapOptional("Link", Section
.Link
, StringRef());
855 IO
.mapOptional("AddressAlign", Section
.AddressAlign
, Hex64(0));
856 IO
.mapOptional("EntSize", Section
.EntSize
);
859 static void sectionMapping(IO
&IO
, ELFYAML::DynamicSection
&Section
) {
860 commonSectionMapping(IO
, Section
);
861 IO
.mapOptional("Entries", Section
.Entries
);
864 static void sectionMapping(IO
&IO
, ELFYAML::RawContentSection
&Section
) {
865 commonSectionMapping(IO
, Section
);
866 IO
.mapOptional("Content", Section
.Content
);
867 IO
.mapOptional("Size", Section
.Size
, Hex64(Section
.Content
.binary_size()));
870 static void sectionMapping(IO
&IO
, ELFYAML::NoBitsSection
&Section
) {
871 commonSectionMapping(IO
, Section
);
872 IO
.mapOptional("Size", Section
.Size
, Hex64(0));
875 static void sectionMapping(IO
&IO
, ELFYAML::RelocationSection
&Section
) {
876 commonSectionMapping(IO
, Section
);
877 IO
.mapOptional("Info", Section
.RelocatableSec
, StringRef());
878 IO
.mapOptional("Relocations", Section
.Relocations
);
881 static void groupSectionMapping(IO
&IO
, ELFYAML::Group
&Group
) {
882 commonSectionMapping(IO
, Group
);
883 IO
.mapOptional("Info", Group
.Signature
, StringRef());
884 IO
.mapRequired("Members", Group
.Members
);
887 void MappingTraits
<ELFYAML::SectionOrType
>::mapping(
888 IO
&IO
, ELFYAML::SectionOrType
§ionOrType
) {
889 IO
.mapRequired("SectionOrType", sectionOrType
.sectionNameOrType
);
892 void MappingTraits
<ELFYAML::SectionName
>::mapping(
893 IO
&IO
, ELFYAML::SectionName
§ionName
) {
894 IO
.mapRequired("Section", sectionName
.Section
);
897 static void sectionMapping(IO
&IO
, ELFYAML::MipsABIFlags
&Section
) {
898 commonSectionMapping(IO
, Section
);
899 IO
.mapOptional("Version", Section
.Version
, Hex16(0));
900 IO
.mapRequired("ISA", Section
.ISALevel
);
901 IO
.mapOptional("ISARevision", Section
.ISARevision
, Hex8(0));
902 IO
.mapOptional("ISAExtension", Section
.ISAExtension
,
903 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE
));
904 IO
.mapOptional("ASEs", Section
.ASEs
, ELFYAML::MIPS_AFL_ASE(0));
905 IO
.mapOptional("FpABI", Section
.FpABI
,
906 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY
));
907 IO
.mapOptional("GPRSize", Section
.GPRSize
,
908 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
909 IO
.mapOptional("CPR1Size", Section
.CPR1Size
,
910 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
911 IO
.mapOptional("CPR2Size", Section
.CPR2Size
,
912 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
913 IO
.mapOptional("Flags1", Section
.Flags1
, ELFYAML::MIPS_AFL_FLAGS1(0));
914 IO
.mapOptional("Flags2", Section
.Flags2
, Hex32(0));
917 void MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::mapping(
918 IO
&IO
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
919 ELFYAML::ELF_SHT sectionType
;
921 sectionType
= Section
->Type
;
923 IO
.mapRequired("Type", sectionType
);
925 switch (sectionType
) {
926 case ELF::SHT_DYNAMIC
:
927 if (!IO
.outputting())
928 Section
.reset(new ELFYAML::DynamicSection());
929 sectionMapping(IO
, *cast
<ELFYAML::DynamicSection
>(Section
.get()));
933 if (!IO
.outputting())
934 Section
.reset(new ELFYAML::RelocationSection());
935 sectionMapping(IO
, *cast
<ELFYAML::RelocationSection
>(Section
.get()));
938 if (!IO
.outputting())
939 Section
.reset(new ELFYAML::Group());
940 groupSectionMapping(IO
, *cast
<ELFYAML::Group
>(Section
.get()));
942 case ELF::SHT_NOBITS
:
943 if (!IO
.outputting())
944 Section
.reset(new ELFYAML::NoBitsSection());
945 sectionMapping(IO
, *cast
<ELFYAML::NoBitsSection
>(Section
.get()));
947 case ELF::SHT_MIPS_ABIFLAGS
:
948 if (!IO
.outputting())
949 Section
.reset(new ELFYAML::MipsABIFlags());
950 sectionMapping(IO
, *cast
<ELFYAML::MipsABIFlags
>(Section
.get()));
953 if (!IO
.outputting())
954 Section
.reset(new ELFYAML::RawContentSection());
955 sectionMapping(IO
, *cast
<ELFYAML::RawContentSection
>(Section
.get()));
959 StringRef MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::validate(
960 IO
&io
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
961 const auto *RawSection
= dyn_cast
<ELFYAML::RawContentSection
>(Section
.get());
962 if (!RawSection
|| RawSection
->Size
>= RawSection
->Content
.binary_size())
964 return "Section size must be greater or equal to the content size";
969 struct NormalizedMips64RelType
{
970 NormalizedMips64RelType(IO
&)
971 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
972 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
973 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
974 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF
)) {}
975 NormalizedMips64RelType(IO
&, ELFYAML::ELF_REL Original
)
976 : Type(Original
& 0xFF), Type2(Original
>> 8 & 0xFF),
977 Type3(Original
>> 16 & 0xFF), SpecSym(Original
>> 24 & 0xFF) {}
979 ELFYAML::ELF_REL
denormalize(IO
&) {
980 ELFYAML::ELF_REL Res
= Type
| Type2
<< 8 | Type3
<< 16 | SpecSym
<< 24;
984 ELFYAML::ELF_REL Type
;
985 ELFYAML::ELF_REL Type2
;
986 ELFYAML::ELF_REL Type3
;
987 ELFYAML::ELF_RSS SpecSym
;
990 } // end anonymous namespace
992 void MappingTraits
<ELFYAML::DynamicEntry
>::mapping(IO
&IO
,
993 ELFYAML::DynamicEntry
&Rel
) {
994 assert(IO
.getContext() && "The IO context is not initialized");
996 IO
.mapRequired("Tag", Rel
.Tag
);
997 IO
.mapRequired("Value", Rel
.Val
);
1000 void MappingTraits
<ELFYAML::Relocation
>::mapping(IO
&IO
,
1001 ELFYAML::Relocation
&Rel
) {
1002 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
1003 assert(Object
&& "The IO context is not initialized");
1005 IO
.mapRequired("Offset", Rel
.Offset
);
1006 IO
.mapOptional("Symbol", Rel
.Symbol
);
1008 if (Object
->Header
.Machine
== ELFYAML::ELF_EM(ELF::EM_MIPS
) &&
1009 Object
->Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
)) {
1010 MappingNormalization
<NormalizedMips64RelType
, ELFYAML::ELF_REL
> Key(
1012 IO
.mapRequired("Type", Key
->Type
);
1013 IO
.mapOptional("Type2", Key
->Type2
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1014 IO
.mapOptional("Type3", Key
->Type3
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1015 IO
.mapOptional("SpecSym", Key
->SpecSym
, ELFYAML::ELF_RSS(ELF::RSS_UNDEF
));
1017 IO
.mapRequired("Type", Rel
.Type
);
1019 IO
.mapOptional("Addend", Rel
.Addend
, (int64_t)0);
1022 void MappingTraits
<ELFYAML::Object
>::mapping(IO
&IO
, ELFYAML::Object
&Object
) {
1023 assert(!IO
.getContext() && "The IO context is initialized already");
1024 IO
.setContext(&Object
);
1025 IO
.mapTag("!ELF", true);
1026 IO
.mapRequired("FileHeader", Object
.Header
);
1027 IO
.mapOptional("ProgramHeaders", Object
.ProgramHeaders
);
1028 IO
.mapOptional("Sections", Object
.Sections
);
1029 IO
.mapOptional("Symbols", Object
.Symbols
);
1030 IO
.mapOptional("DynamicSymbols", Object
.DynamicSymbols
);
1031 IO
.setContext(nullptr);
1034 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG
)
1035 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP
)
1036 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT
)
1037 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE
)
1038 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1
)
1040 } // end namespace yaml
1042 } // end namespace llvm