1 //===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines classes for handling the YAML representation of ELF.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ObjectYAML/ELFYAML.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/BinaryFormat/ELF.h"
17 #include "llvm/Support/Casting.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/MipsABIFlags.h"
20 #include "llvm/Support/YAMLTraits.h"
26 ELFYAML::Section::~Section() = default;
30 void ScalarEnumerationTraits
<ELFYAML::ELF_ET
>::enumeration(
31 IO
&IO
, ELFYAML::ELF_ET
&Value
) {
32 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
39 IO
.enumFallback
<Hex16
>(Value
);
42 void ScalarEnumerationTraits
<ELFYAML::ELF_PT
>::enumeration(
43 IO
&IO
, ELFYAML::ELF_PT
&Value
) {
44 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
53 ECase(PT_GNU_EH_FRAME
);
55 IO
.enumFallback
<Hex32
>(Value
);
58 void ScalarEnumerationTraits
<ELFYAML::ELF_EM
>::enumeration(
59 IO
&IO
, ELFYAML::ELF_EM
&Value
) {
60 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
71 ECase(EM_MIPS_RS3_LE
);
74 ECase(EM_SPARC32PLUS
);
137 ECase(EM_ARC_COMPACT
);
157 ECase(EM_ALTERA_NIOS2
);
171 ECase(EM_VIDEOCORE3
);
172 ECase(EM_LATTICEMICO32
);
177 ECase(EM_MMDSP_PLUS
);
178 ECase(EM_CYPRESS_M8C
);
193 ECase(EM_MCST_ELBRUS
);
207 ECase(EM_CLOUDSHIELD
);
210 ECase(EM_ARC_COMPACT2
);
213 ECase(EM_VIDEOCORE5
);
223 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFCLASS
>::enumeration(
224 IO
&IO
, ELFYAML::ELF_ELFCLASS
&Value
) {
225 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
226 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
233 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFDATA
>::enumeration(
234 IO
&IO
, ELFYAML::ELF_ELFDATA
&Value
) {
235 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
236 // Since the semantics of ELFDATANONE is "invalid", just don't accept it
243 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFOSABI
>::enumeration(
244 IO
&IO
, ELFYAML::ELF_ELFOSABI
&Value
) {
245 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
246 ECase(ELFOSABI_NONE
);
247 ECase(ELFOSABI_HPUX
);
248 ECase(ELFOSABI_NETBSD
);
250 ECase(ELFOSABI_HURD
);
251 ECase(ELFOSABI_SOLARIS
);
253 ECase(ELFOSABI_IRIX
);
254 ECase(ELFOSABI_FREEBSD
);
255 ECase(ELFOSABI_TRU64
);
256 ECase(ELFOSABI_MODESTO
);
257 ECase(ELFOSABI_OPENBSD
);
258 ECase(ELFOSABI_OPENVMS
);
260 ECase(ELFOSABI_AROS
);
261 ECase(ELFOSABI_FENIXOS
);
262 ECase(ELFOSABI_CLOUDABI
);
263 ECase(ELFOSABI_AMDGPU_HSA
);
264 ECase(ELFOSABI_AMDGPU_PAL
);
265 ECase(ELFOSABI_AMDGPU_MESA3D
);
267 ECase(ELFOSABI_C6000_ELFABI
);
268 ECase(ELFOSABI_C6000_LINUX
);
269 ECase(ELFOSABI_STANDALONE
);
273 void ScalarBitSetTraits
<ELFYAML::ELF_EF
>::bitset(IO
&IO
,
274 ELFYAML::ELF_EF
&Value
) {
275 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
276 assert(Object
&& "The IO context is not initialized");
277 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
278 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
279 switch (Object
->Header
.Machine
) {
281 BCase(EF_ARM_SOFT_FLOAT
);
282 BCase(EF_ARM_VFP_FLOAT
);
283 BCaseMask(EF_ARM_EABI_UNKNOWN
, EF_ARM_EABIMASK
);
284 BCaseMask(EF_ARM_EABI_VER1
, EF_ARM_EABIMASK
);
285 BCaseMask(EF_ARM_EABI_VER2
, EF_ARM_EABIMASK
);
286 BCaseMask(EF_ARM_EABI_VER3
, EF_ARM_EABIMASK
);
287 BCaseMask(EF_ARM_EABI_VER4
, EF_ARM_EABIMASK
);
288 BCaseMask(EF_ARM_EABI_VER5
, EF_ARM_EABIMASK
);
291 BCase(EF_MIPS_NOREORDER
);
295 BCase(EF_MIPS_32BITMODE
);
297 BCase(EF_MIPS_NAN2008
);
298 BCase(EF_MIPS_MICROMIPS
);
299 BCase(EF_MIPS_ARCH_ASE_M16
);
300 BCase(EF_MIPS_ARCH_ASE_MDMX
);
301 BCaseMask(EF_MIPS_ABI_O32
, EF_MIPS_ABI
);
302 BCaseMask(EF_MIPS_ABI_O64
, EF_MIPS_ABI
);
303 BCaseMask(EF_MIPS_ABI_EABI32
, EF_MIPS_ABI
);
304 BCaseMask(EF_MIPS_ABI_EABI64
, EF_MIPS_ABI
);
305 BCaseMask(EF_MIPS_MACH_3900
, EF_MIPS_MACH
);
306 BCaseMask(EF_MIPS_MACH_4010
, EF_MIPS_MACH
);
307 BCaseMask(EF_MIPS_MACH_4100
, EF_MIPS_MACH
);
308 BCaseMask(EF_MIPS_MACH_4650
, EF_MIPS_MACH
);
309 BCaseMask(EF_MIPS_MACH_4120
, EF_MIPS_MACH
);
310 BCaseMask(EF_MIPS_MACH_4111
, EF_MIPS_MACH
);
311 BCaseMask(EF_MIPS_MACH_SB1
, EF_MIPS_MACH
);
312 BCaseMask(EF_MIPS_MACH_OCTEON
, EF_MIPS_MACH
);
313 BCaseMask(EF_MIPS_MACH_XLR
, EF_MIPS_MACH
);
314 BCaseMask(EF_MIPS_MACH_OCTEON2
, EF_MIPS_MACH
);
315 BCaseMask(EF_MIPS_MACH_OCTEON3
, EF_MIPS_MACH
);
316 BCaseMask(EF_MIPS_MACH_5400
, EF_MIPS_MACH
);
317 BCaseMask(EF_MIPS_MACH_5900
, EF_MIPS_MACH
);
318 BCaseMask(EF_MIPS_MACH_5500
, EF_MIPS_MACH
);
319 BCaseMask(EF_MIPS_MACH_9000
, EF_MIPS_MACH
);
320 BCaseMask(EF_MIPS_MACH_LS2E
, EF_MIPS_MACH
);
321 BCaseMask(EF_MIPS_MACH_LS2F
, EF_MIPS_MACH
);
322 BCaseMask(EF_MIPS_MACH_LS3A
, EF_MIPS_MACH
);
323 BCaseMask(EF_MIPS_ARCH_1
, EF_MIPS_ARCH
);
324 BCaseMask(EF_MIPS_ARCH_2
, EF_MIPS_ARCH
);
325 BCaseMask(EF_MIPS_ARCH_3
, EF_MIPS_ARCH
);
326 BCaseMask(EF_MIPS_ARCH_4
, EF_MIPS_ARCH
);
327 BCaseMask(EF_MIPS_ARCH_5
, EF_MIPS_ARCH
);
328 BCaseMask(EF_MIPS_ARCH_32
, EF_MIPS_ARCH
);
329 BCaseMask(EF_MIPS_ARCH_64
, EF_MIPS_ARCH
);
330 BCaseMask(EF_MIPS_ARCH_32R2
, EF_MIPS_ARCH
);
331 BCaseMask(EF_MIPS_ARCH_64R2
, EF_MIPS_ARCH
);
332 BCaseMask(EF_MIPS_ARCH_32R6
, EF_MIPS_ARCH
);
333 BCaseMask(EF_MIPS_ARCH_64R6
, EF_MIPS_ARCH
);
335 case ELF::EM_HEXAGON
:
336 BCase(EF_HEXAGON_MACH_V2
);
337 BCase(EF_HEXAGON_MACH_V3
);
338 BCase(EF_HEXAGON_MACH_V4
);
339 BCase(EF_HEXAGON_MACH_V5
);
340 BCase(EF_HEXAGON_ISA_V2
);
341 BCase(EF_HEXAGON_ISA_V3
);
342 BCase(EF_HEXAGON_ISA_V4
);
343 BCase(EF_HEXAGON_ISA_V5
);
346 BCase(EF_AVR_ARCH_AVR1
);
347 BCase(EF_AVR_ARCH_AVR2
);
348 BCase(EF_AVR_ARCH_AVR25
);
349 BCase(EF_AVR_ARCH_AVR3
);
350 BCase(EF_AVR_ARCH_AVR31
);
351 BCase(EF_AVR_ARCH_AVR35
);
352 BCase(EF_AVR_ARCH_AVR4
);
353 BCase(EF_AVR_ARCH_AVR51
);
354 BCase(EF_AVR_ARCH_AVR6
);
355 BCase(EF_AVR_ARCH_AVRTINY
);
356 BCase(EF_AVR_ARCH_XMEGA1
);
357 BCase(EF_AVR_ARCH_XMEGA2
);
358 BCase(EF_AVR_ARCH_XMEGA3
);
359 BCase(EF_AVR_ARCH_XMEGA4
);
360 BCase(EF_AVR_ARCH_XMEGA5
);
361 BCase(EF_AVR_ARCH_XMEGA6
);
362 BCase(EF_AVR_ARCH_XMEGA7
);
366 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT
, EF_RISCV_FLOAT_ABI
);
367 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE
, EF_RISCV_FLOAT_ABI
);
368 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE
, EF_RISCV_FLOAT_ABI
);
369 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD
, EF_RISCV_FLOAT_ABI
);
373 BCaseMask(EF_AMDGPU_MACH_NONE
, EF_AMDGPU_MACH
);
374 BCaseMask(EF_AMDGPU_MACH_R600_R600
, EF_AMDGPU_MACH
);
375 BCaseMask(EF_AMDGPU_MACH_R600_R630
, EF_AMDGPU_MACH
);
376 BCaseMask(EF_AMDGPU_MACH_R600_RS880
, EF_AMDGPU_MACH
);
377 BCaseMask(EF_AMDGPU_MACH_R600_RV670
, EF_AMDGPU_MACH
);
378 BCaseMask(EF_AMDGPU_MACH_R600_RV710
, EF_AMDGPU_MACH
);
379 BCaseMask(EF_AMDGPU_MACH_R600_RV730
, EF_AMDGPU_MACH
);
380 BCaseMask(EF_AMDGPU_MACH_R600_RV770
, EF_AMDGPU_MACH
);
381 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR
, EF_AMDGPU_MACH
);
382 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS
, EF_AMDGPU_MACH
);
383 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER
, EF_AMDGPU_MACH
);
384 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD
, EF_AMDGPU_MACH
);
385 BCaseMask(EF_AMDGPU_MACH_R600_SUMO
, EF_AMDGPU_MACH
);
386 BCaseMask(EF_AMDGPU_MACH_R600_BARTS
, EF_AMDGPU_MACH
);
387 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS
, EF_AMDGPU_MACH
);
388 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN
, EF_AMDGPU_MACH
);
389 BCaseMask(EF_AMDGPU_MACH_R600_TURKS
, EF_AMDGPU_MACH
);
390 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600
, EF_AMDGPU_MACH
);
391 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601
, EF_AMDGPU_MACH
);
392 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700
, EF_AMDGPU_MACH
);
393 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701
, EF_AMDGPU_MACH
);
394 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702
, EF_AMDGPU_MACH
);
395 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703
, EF_AMDGPU_MACH
);
396 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704
, EF_AMDGPU_MACH
);
397 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801
, EF_AMDGPU_MACH
);
398 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802
, EF_AMDGPU_MACH
);
399 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803
, EF_AMDGPU_MACH
);
400 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810
, EF_AMDGPU_MACH
);
401 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900
, EF_AMDGPU_MACH
);
402 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902
, EF_AMDGPU_MACH
);
403 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904
, EF_AMDGPU_MACH
);
404 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906
, EF_AMDGPU_MACH
);
405 BCase(EF_AMDGPU_XNACK
);
410 llvm_unreachable("Unsupported architecture");
416 void ScalarEnumerationTraits
<ELFYAML::ELF_SHT
>::enumeration(
417 IO
&IO
, ELFYAML::ELF_SHT
&Value
) {
418 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
419 assert(Object
&& "The IO context is not initialized");
420 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
424 // FIXME: Issue a diagnostic with this information.
434 ECase(SHT_INIT_ARRAY
);
435 ECase(SHT_FINI_ARRAY
);
436 ECase(SHT_PREINIT_ARRAY
);
438 ECase(SHT_SYMTAB_SHNDX
);
441 ECase(SHT_ANDROID_REL
);
442 ECase(SHT_ANDROID_RELA
);
443 ECase(SHT_ANDROID_RELR
);
444 ECase(SHT_LLVM_ODRTAB
);
445 ECase(SHT_LLVM_LINKER_OPTIONS
);
446 ECase(SHT_LLVM_CALL_GRAPH_PROFILE
);
447 ECase(SHT_LLVM_ADDRSIG
);
448 ECase(SHT_GNU_ATTRIBUTES
);
450 ECase(SHT_GNU_verdef
);
451 ECase(SHT_GNU_verneed
);
452 ECase(SHT_GNU_versym
);
455 switch (Object
->Header
.Machine
) {
457 ECase(SHT_ARM_EXIDX
);
458 ECase(SHT_ARM_PREEMPTMAP
);
459 ECase(SHT_ARM_ATTRIBUTES
);
460 ECase(SHT_ARM_DEBUGOVERLAY
);
461 ECase(SHT_ARM_OVERLAYSECTION
);
463 case ELF::EM_HEXAGON
:
464 ECase(SHT_HEX_ORDERED
);
467 ECase(SHT_X86_64_UNWIND
);
470 ECase(SHT_MIPS_REGINFO
);
471 ECase(SHT_MIPS_OPTIONS
);
472 ECase(SHT_MIPS_ABIFLAGS
);
481 void ScalarBitSetTraits
<ELFYAML::ELF_PF
>::bitset(IO
&IO
,
482 ELFYAML::ELF_PF
&Value
) {
483 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
489 void ScalarBitSetTraits
<ELFYAML::ELF_SHF
>::bitset(IO
&IO
,
490 ELFYAML::ELF_SHF
&Value
) {
491 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
492 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
496 BCase(SHF_EXECINSTR
);
499 BCase(SHF_INFO_LINK
);
500 BCase(SHF_LINK_ORDER
);
501 BCase(SHF_OS_NONCONFORMING
);
504 BCase(SHF_COMPRESSED
);
505 switch (Object
->Header
.Machine
) {
507 BCase(SHF_ARM_PURECODE
);
509 case ELF::EM_HEXAGON
:
510 BCase(SHF_HEX_GPREL
);
513 BCase(SHF_MIPS_NODUPES
);
514 BCase(SHF_MIPS_NAMES
);
515 BCase(SHF_MIPS_LOCAL
);
516 BCase(SHF_MIPS_NOSTRIP
);
517 BCase(SHF_MIPS_GPREL
);
518 BCase(SHF_MIPS_MERGE
);
519 BCase(SHF_MIPS_ADDR
);
520 BCase(SHF_MIPS_STRING
);
523 BCase(SHF_X86_64_LARGE
);
532 void ScalarEnumerationTraits
<ELFYAML::ELF_SHN
>::enumeration(
533 IO
&IO
, ELFYAML::ELF_SHN
&Value
) {
534 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
536 ECase(SHN_LORESERVE
);
544 ECase(SHN_HIRESERVE
);
545 ECase(SHN_HEXAGON_SCOMMON
);
546 ECase(SHN_HEXAGON_SCOMMON_1
);
547 ECase(SHN_HEXAGON_SCOMMON_2
);
548 ECase(SHN_HEXAGON_SCOMMON_4
);
549 ECase(SHN_HEXAGON_SCOMMON_8
);
551 IO
.enumFallback
<Hex32
>(Value
);
554 void ScalarEnumerationTraits
<ELFYAML::ELF_STT
>::enumeration(
555 IO
&IO
, ELFYAML::ELF_STT
&Value
) {
556 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
564 ECase(STT_GNU_IFUNC
);
568 void ScalarEnumerationTraits
<ELFYAML::ELF_STV
>::enumeration(
569 IO
&IO
, ELFYAML::ELF_STV
&Value
) {
570 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
574 ECase(STV_PROTECTED
);
578 void ScalarBitSetTraits
<ELFYAML::ELF_STO
>::bitset(IO
&IO
,
579 ELFYAML::ELF_STO
&Value
) {
580 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
581 assert(Object
&& "The IO context is not initialized");
582 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
583 switch (Object
->Header
.Machine
) {
585 BCase(STO_MIPS_OPTIONAL
);
588 BCase(STO_MIPS_MICROMIPS
);
591 break; // Nothing to do
597 void ScalarEnumerationTraits
<ELFYAML::ELF_RSS
>::enumeration(
598 IO
&IO
, ELFYAML::ELF_RSS
&Value
) {
599 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
607 void ScalarEnumerationTraits
<ELFYAML::ELF_REL
>::enumeration(
608 IO
&IO
, ELFYAML::ELF_REL
&Value
) {
609 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
610 assert(Object
&& "The IO context is not initialized");
611 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
612 switch (Object
->Header
.Machine
) {
614 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
617 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
619 case ELF::EM_HEXAGON
:
620 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
624 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
626 case ELF::EM_AARCH64
:
627 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
630 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
633 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
636 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
639 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
642 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
645 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
648 llvm_unreachable("Unsupported architecture");
651 IO
.enumFallback
<Hex32
>(Value
);
654 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_REG
>::enumeration(
655 IO
&IO
, ELFYAML::MIPS_AFL_REG
&Value
) {
656 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
664 void ScalarEnumerationTraits
<ELFYAML::MIPS_ABI_FP
>::enumeration(
665 IO
&IO
, ELFYAML::MIPS_ABI_FP
&Value
) {
666 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
678 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_EXT
>::enumeration(
679 IO
&IO
, ELFYAML::MIPS_AFL_EXT
&Value
) {
680 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
685 ECase(EXT_LOONGSON_3A
);
698 ECase(EXT_LOONGSON_2E
);
699 ECase(EXT_LOONGSON_2F
);
704 void ScalarEnumerationTraits
<ELFYAML::MIPS_ISA
>::enumeration(
705 IO
&IO
, ELFYAML::MIPS_ISA
&Value
) {
706 IO
.enumCase(Value
, "MIPS1", 1);
707 IO
.enumCase(Value
, "MIPS2", 2);
708 IO
.enumCase(Value
, "MIPS3", 3);
709 IO
.enumCase(Value
, "MIPS4", 4);
710 IO
.enumCase(Value
, "MIPS5", 5);
711 IO
.enumCase(Value
, "MIPS32", 32);
712 IO
.enumCase(Value
, "MIPS64", 64);
715 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_ASE
>::bitset(
716 IO
&IO
, ELFYAML::MIPS_AFL_ASE
&Value
) {
717 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
734 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_FLAGS1
>::bitset(
735 IO
&IO
, ELFYAML::MIPS_AFL_FLAGS1
&Value
) {
736 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
741 void MappingTraits
<ELFYAML::FileHeader
>::mapping(IO
&IO
,
742 ELFYAML::FileHeader
&FileHdr
) {
743 IO
.mapRequired("Class", FileHdr
.Class
);
744 IO
.mapRequired("Data", FileHdr
.Data
);
745 IO
.mapOptional("OSABI", FileHdr
.OSABI
, ELFYAML::ELF_ELFOSABI(0));
746 IO
.mapRequired("Type", FileHdr
.Type
);
747 IO
.mapRequired("Machine", FileHdr
.Machine
);
748 IO
.mapOptional("Flags", FileHdr
.Flags
, ELFYAML::ELF_EF(0));
749 IO
.mapOptional("Entry", FileHdr
.Entry
, Hex64(0));
752 void MappingTraits
<ELFYAML::ProgramHeader
>::mapping(
753 IO
&IO
, ELFYAML::ProgramHeader
&Phdr
) {
754 IO
.mapRequired("Type", Phdr
.Type
);
755 IO
.mapOptional("Flags", Phdr
.Flags
, ELFYAML::ELF_PF(0));
756 IO
.mapOptional("Sections", Phdr
.Sections
);
757 IO
.mapOptional("VAddr", Phdr
.VAddr
, Hex64(0));
758 IO
.mapOptional("PAddr", Phdr
.PAddr
, Hex64(0));
759 IO
.mapOptional("Align", Phdr
.Align
);
764 struct NormalizedOther
{
765 NormalizedOther(IO
&)
766 : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
767 NormalizedOther(IO
&, uint8_t Original
)
768 : Visibility(Original
& 0x3), Other(Original
& ~0x3) {}
770 uint8_t denormalize(IO
&) { return Visibility
| Other
; }
772 ELFYAML::ELF_STV Visibility
;
773 ELFYAML::ELF_STO Other
;
776 } // end anonymous namespace
778 void MappingTraits
<ELFYAML::Symbol
>::mapping(IO
&IO
, ELFYAML::Symbol
&Symbol
) {
779 IO
.mapOptional("Name", Symbol
.Name
, StringRef());
780 IO
.mapOptional("Type", Symbol
.Type
, ELFYAML::ELF_STT(0));
781 IO
.mapOptional("Section", Symbol
.Section
, StringRef());
782 IO
.mapOptional("Index", Symbol
.Index
);
783 IO
.mapOptional("Value", Symbol
.Value
, Hex64(0));
784 IO
.mapOptional("Size", Symbol
.Size
, Hex64(0));
786 MappingNormalization
<NormalizedOther
, uint8_t> Keys(IO
, Symbol
.Other
);
787 IO
.mapOptional("Visibility", Keys
->Visibility
, ELFYAML::ELF_STV(0));
788 IO
.mapOptional("Other", Keys
->Other
, ELFYAML::ELF_STO(0));
791 StringRef MappingTraits
<ELFYAML::Symbol
>::validate(IO
&IO
,
792 ELFYAML::Symbol
&Symbol
) {
793 if (Symbol
.Index
&& Symbol
.Section
.data()) {
794 return "Index and Section cannot both be specified for Symbol";
796 if (Symbol
.Index
&& *Symbol
.Index
== ELFYAML::ELF_SHN(ELF::SHN_XINDEX
)) {
797 return "Large indexes are not supported";
799 if (Symbol
.Index
&& *Symbol
.Index
< ELFYAML::ELF_SHN(ELF::SHN_LORESERVE
)) {
800 return "Use a section name to define which section a symbol is defined in";
805 void MappingTraits
<ELFYAML::LocalGlobalWeakSymbols
>::mapping(
806 IO
&IO
, ELFYAML::LocalGlobalWeakSymbols
&Symbols
) {
807 IO
.mapOptional("Local", Symbols
.Local
);
808 IO
.mapOptional("Global", Symbols
.Global
);
809 IO
.mapOptional("Weak", Symbols
.Weak
);
812 static void commonSectionMapping(IO
&IO
, ELFYAML::Section
&Section
) {
813 IO
.mapOptional("Name", Section
.Name
, StringRef());
814 IO
.mapRequired("Type", Section
.Type
);
815 IO
.mapOptional("Flags", Section
.Flags
, ELFYAML::ELF_SHF(0));
816 IO
.mapOptional("Address", Section
.Address
, Hex64(0));
817 IO
.mapOptional("Link", Section
.Link
, StringRef());
818 IO
.mapOptional("AddressAlign", Section
.AddressAlign
, Hex64(0));
819 IO
.mapOptional("EntSize", Section
.EntSize
);
820 IO
.mapOptional("Info", Section
.Info
, StringRef());
823 static void sectionMapping(IO
&IO
, ELFYAML::RawContentSection
&Section
) {
824 commonSectionMapping(IO
, Section
);
825 IO
.mapOptional("Content", Section
.Content
);
826 IO
.mapOptional("Size", Section
.Size
, Hex64(Section
.Content
.binary_size()));
829 static void sectionMapping(IO
&IO
, ELFYAML::NoBitsSection
&Section
) {
830 commonSectionMapping(IO
, Section
);
831 IO
.mapOptional("Size", Section
.Size
, Hex64(0));
834 static void sectionMapping(IO
&IO
, ELFYAML::RelocationSection
&Section
) {
835 commonSectionMapping(IO
, Section
);
836 IO
.mapOptional("Relocations", Section
.Relocations
);
839 static void groupSectionMapping(IO
&IO
, ELFYAML::Group
&group
) {
840 commonSectionMapping(IO
, group
);
841 IO
.mapRequired("Members", group
.Members
);
844 void MappingTraits
<ELFYAML::SectionOrType
>::mapping(
845 IO
&IO
, ELFYAML::SectionOrType
§ionOrType
) {
846 IO
.mapRequired("SectionOrType", sectionOrType
.sectionNameOrType
);
849 void MappingTraits
<ELFYAML::SectionName
>::mapping(
850 IO
&IO
, ELFYAML::SectionName
§ionName
) {
851 IO
.mapRequired("Section", sectionName
.Section
);
854 static void sectionMapping(IO
&IO
, ELFYAML::MipsABIFlags
&Section
) {
855 commonSectionMapping(IO
, Section
);
856 IO
.mapOptional("Version", Section
.Version
, Hex16(0));
857 IO
.mapRequired("ISA", Section
.ISALevel
);
858 IO
.mapOptional("ISARevision", Section
.ISARevision
, Hex8(0));
859 IO
.mapOptional("ISAExtension", Section
.ISAExtension
,
860 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE
));
861 IO
.mapOptional("ASEs", Section
.ASEs
, ELFYAML::MIPS_AFL_ASE(0));
862 IO
.mapOptional("FpABI", Section
.FpABI
,
863 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY
));
864 IO
.mapOptional("GPRSize", Section
.GPRSize
,
865 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
866 IO
.mapOptional("CPR1Size", Section
.CPR1Size
,
867 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
868 IO
.mapOptional("CPR2Size", Section
.CPR2Size
,
869 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
870 IO
.mapOptional("Flags1", Section
.Flags1
, ELFYAML::MIPS_AFL_FLAGS1(0));
871 IO
.mapOptional("Flags2", Section
.Flags2
, Hex32(0));
874 void MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::mapping(
875 IO
&IO
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
876 ELFYAML::ELF_SHT sectionType
;
878 sectionType
= Section
->Type
;
880 IO
.mapRequired("Type", sectionType
);
882 switch (sectionType
) {
885 if (!IO
.outputting())
886 Section
.reset(new ELFYAML::RelocationSection());
887 sectionMapping(IO
, *cast
<ELFYAML::RelocationSection
>(Section
.get()));
890 if (!IO
.outputting())
891 Section
.reset(new ELFYAML::Group());
892 groupSectionMapping(IO
, *cast
<ELFYAML::Group
>(Section
.get()));
894 case ELF::SHT_NOBITS
:
895 if (!IO
.outputting())
896 Section
.reset(new ELFYAML::NoBitsSection());
897 sectionMapping(IO
, *cast
<ELFYAML::NoBitsSection
>(Section
.get()));
899 case ELF::SHT_MIPS_ABIFLAGS
:
900 if (!IO
.outputting())
901 Section
.reset(new ELFYAML::MipsABIFlags());
902 sectionMapping(IO
, *cast
<ELFYAML::MipsABIFlags
>(Section
.get()));
905 if (!IO
.outputting())
906 Section
.reset(new ELFYAML::RawContentSection());
907 sectionMapping(IO
, *cast
<ELFYAML::RawContentSection
>(Section
.get()));
911 StringRef MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::validate(
912 IO
&io
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
913 const auto *RawSection
= dyn_cast
<ELFYAML::RawContentSection
>(Section
.get());
914 if (!RawSection
|| RawSection
->Size
>= RawSection
->Content
.binary_size())
916 return "Section size must be greater or equal to the content size";
921 struct NormalizedMips64RelType
{
922 NormalizedMips64RelType(IO
&)
923 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
924 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
925 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
926 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF
)) {}
927 NormalizedMips64RelType(IO
&, ELFYAML::ELF_REL Original
)
928 : Type(Original
& 0xFF), Type2(Original
>> 8 & 0xFF),
929 Type3(Original
>> 16 & 0xFF), SpecSym(Original
>> 24 & 0xFF) {}
931 ELFYAML::ELF_REL
denormalize(IO
&) {
932 ELFYAML::ELF_REL Res
= Type
| Type2
<< 8 | Type3
<< 16 | SpecSym
<< 24;
936 ELFYAML::ELF_REL Type
;
937 ELFYAML::ELF_REL Type2
;
938 ELFYAML::ELF_REL Type3
;
939 ELFYAML::ELF_RSS SpecSym
;
942 } // end anonymous namespace
944 void MappingTraits
<ELFYAML::Relocation
>::mapping(IO
&IO
,
945 ELFYAML::Relocation
&Rel
) {
946 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
947 assert(Object
&& "The IO context is not initialized");
949 IO
.mapRequired("Offset", Rel
.Offset
);
950 IO
.mapOptional("Symbol", Rel
.Symbol
);
952 if (Object
->Header
.Machine
== ELFYAML::ELF_EM(ELF::EM_MIPS
) &&
953 Object
->Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
)) {
954 MappingNormalization
<NormalizedMips64RelType
, ELFYAML::ELF_REL
> Key(
956 IO
.mapRequired("Type", Key
->Type
);
957 IO
.mapOptional("Type2", Key
->Type2
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
958 IO
.mapOptional("Type3", Key
->Type3
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
959 IO
.mapOptional("SpecSym", Key
->SpecSym
, ELFYAML::ELF_RSS(ELF::RSS_UNDEF
));
961 IO
.mapRequired("Type", Rel
.Type
);
963 IO
.mapOptional("Addend", Rel
.Addend
, (int64_t)0);
966 void MappingTraits
<ELFYAML::Object
>::mapping(IO
&IO
, ELFYAML::Object
&Object
) {
967 assert(!IO
.getContext() && "The IO context is initialized already");
968 IO
.setContext(&Object
);
969 IO
.mapTag("!ELF", true);
970 IO
.mapRequired("FileHeader", Object
.Header
);
971 IO
.mapOptional("ProgramHeaders", Object
.ProgramHeaders
);
972 IO
.mapOptional("Sections", Object
.Sections
);
973 IO
.mapOptional("Symbols", Object
.Symbols
);
974 IO
.mapOptional("DynamicSymbols", Object
.DynamicSymbols
);
975 IO
.setContext(nullptr);
978 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG
)
979 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP
)
980 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT
)
981 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE
)
982 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1
)
984 } // end namespace yaml
986 } // end namespace llvm