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/MapVector.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"
21 #include "llvm/Support/WithColor.h"
27 ELFYAML::Section::~Section() = default;
31 void ScalarEnumerationTraits
<ELFYAML::ELF_ET
>::enumeration(
32 IO
&IO
, ELFYAML::ELF_ET
&Value
) {
33 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
40 IO
.enumFallback
<Hex16
>(Value
);
43 void ScalarEnumerationTraits
<ELFYAML::ELF_PT
>::enumeration(
44 IO
&IO
, ELFYAML::ELF_PT
&Value
) {
45 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
54 ECase(PT_GNU_EH_FRAME
);
58 IO
.enumFallback
<Hex32
>(Value
);
61 void ScalarEnumerationTraits
<ELFYAML::ELF_EM
>::enumeration(
62 IO
&IO
, ELFYAML::ELF_EM
&Value
) {
63 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
74 ECase(EM_MIPS_RS3_LE
);
77 ECase(EM_SPARC32PLUS
);
140 ECase(EM_ARC_COMPACT
);
160 ECase(EM_ALTERA_NIOS2
);
174 ECase(EM_VIDEOCORE3
);
175 ECase(EM_LATTICEMICO32
);
180 ECase(EM_MMDSP_PLUS
);
181 ECase(EM_CYPRESS_M8C
);
196 ECase(EM_MCST_ELBRUS
);
210 ECase(EM_CLOUDSHIELD
);
213 ECase(EM_ARC_COMPACT2
);
216 ECase(EM_VIDEOCORE5
);
226 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFCLASS
>::enumeration(
227 IO
&IO
, ELFYAML::ELF_ELFCLASS
&Value
) {
228 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
229 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
236 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFDATA
>::enumeration(
237 IO
&IO
, ELFYAML::ELF_ELFDATA
&Value
) {
238 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
239 // ELFDATANONE is an invalid data encoding, but we accept it because
240 // we want to be able to produce invalid binaries for the tests.
247 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFOSABI
>::enumeration(
248 IO
&IO
, ELFYAML::ELF_ELFOSABI
&Value
) {
249 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
250 ECase(ELFOSABI_NONE
);
251 ECase(ELFOSABI_HPUX
);
252 ECase(ELFOSABI_NETBSD
);
254 ECase(ELFOSABI_HURD
);
255 ECase(ELFOSABI_SOLARIS
);
257 ECase(ELFOSABI_IRIX
);
258 ECase(ELFOSABI_FREEBSD
);
259 ECase(ELFOSABI_TRU64
);
260 ECase(ELFOSABI_MODESTO
);
261 ECase(ELFOSABI_OPENBSD
);
262 ECase(ELFOSABI_OPENVMS
);
264 ECase(ELFOSABI_AROS
);
265 ECase(ELFOSABI_FENIXOS
);
266 ECase(ELFOSABI_CLOUDABI
);
267 ECase(ELFOSABI_AMDGPU_HSA
);
268 ECase(ELFOSABI_AMDGPU_PAL
);
269 ECase(ELFOSABI_AMDGPU_MESA3D
);
271 ECase(ELFOSABI_C6000_ELFABI
);
272 ECase(ELFOSABI_C6000_LINUX
);
273 ECase(ELFOSABI_STANDALONE
);
277 void ScalarBitSetTraits
<ELFYAML::ELF_EF
>::bitset(IO
&IO
,
278 ELFYAML::ELF_EF
&Value
) {
279 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
280 assert(Object
&& "The IO context is not initialized");
281 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
282 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
283 switch (Object
->Header
.Machine
) {
285 BCase(EF_ARM_SOFT_FLOAT
);
286 BCase(EF_ARM_VFP_FLOAT
);
287 BCaseMask(EF_ARM_EABI_UNKNOWN
, EF_ARM_EABIMASK
);
288 BCaseMask(EF_ARM_EABI_VER1
, EF_ARM_EABIMASK
);
289 BCaseMask(EF_ARM_EABI_VER2
, EF_ARM_EABIMASK
);
290 BCaseMask(EF_ARM_EABI_VER3
, EF_ARM_EABIMASK
);
291 BCaseMask(EF_ARM_EABI_VER4
, EF_ARM_EABIMASK
);
292 BCaseMask(EF_ARM_EABI_VER5
, EF_ARM_EABIMASK
);
295 BCase(EF_MIPS_NOREORDER
);
299 BCase(EF_MIPS_32BITMODE
);
301 BCase(EF_MIPS_NAN2008
);
302 BCase(EF_MIPS_MICROMIPS
);
303 BCase(EF_MIPS_ARCH_ASE_M16
);
304 BCase(EF_MIPS_ARCH_ASE_MDMX
);
305 BCaseMask(EF_MIPS_ABI_O32
, EF_MIPS_ABI
);
306 BCaseMask(EF_MIPS_ABI_O64
, EF_MIPS_ABI
);
307 BCaseMask(EF_MIPS_ABI_EABI32
, EF_MIPS_ABI
);
308 BCaseMask(EF_MIPS_ABI_EABI64
, EF_MIPS_ABI
);
309 BCaseMask(EF_MIPS_MACH_3900
, EF_MIPS_MACH
);
310 BCaseMask(EF_MIPS_MACH_4010
, EF_MIPS_MACH
);
311 BCaseMask(EF_MIPS_MACH_4100
, EF_MIPS_MACH
);
312 BCaseMask(EF_MIPS_MACH_4650
, EF_MIPS_MACH
);
313 BCaseMask(EF_MIPS_MACH_4120
, EF_MIPS_MACH
);
314 BCaseMask(EF_MIPS_MACH_4111
, EF_MIPS_MACH
);
315 BCaseMask(EF_MIPS_MACH_SB1
, EF_MIPS_MACH
);
316 BCaseMask(EF_MIPS_MACH_OCTEON
, EF_MIPS_MACH
);
317 BCaseMask(EF_MIPS_MACH_XLR
, EF_MIPS_MACH
);
318 BCaseMask(EF_MIPS_MACH_OCTEON2
, EF_MIPS_MACH
);
319 BCaseMask(EF_MIPS_MACH_OCTEON3
, EF_MIPS_MACH
);
320 BCaseMask(EF_MIPS_MACH_5400
, EF_MIPS_MACH
);
321 BCaseMask(EF_MIPS_MACH_5900
, EF_MIPS_MACH
);
322 BCaseMask(EF_MIPS_MACH_5500
, EF_MIPS_MACH
);
323 BCaseMask(EF_MIPS_MACH_9000
, EF_MIPS_MACH
);
324 BCaseMask(EF_MIPS_MACH_LS2E
, EF_MIPS_MACH
);
325 BCaseMask(EF_MIPS_MACH_LS2F
, EF_MIPS_MACH
);
326 BCaseMask(EF_MIPS_MACH_LS3A
, EF_MIPS_MACH
);
327 BCaseMask(EF_MIPS_ARCH_1
, EF_MIPS_ARCH
);
328 BCaseMask(EF_MIPS_ARCH_2
, EF_MIPS_ARCH
);
329 BCaseMask(EF_MIPS_ARCH_3
, EF_MIPS_ARCH
);
330 BCaseMask(EF_MIPS_ARCH_4
, EF_MIPS_ARCH
);
331 BCaseMask(EF_MIPS_ARCH_5
, EF_MIPS_ARCH
);
332 BCaseMask(EF_MIPS_ARCH_32
, EF_MIPS_ARCH
);
333 BCaseMask(EF_MIPS_ARCH_64
, EF_MIPS_ARCH
);
334 BCaseMask(EF_MIPS_ARCH_32R2
, EF_MIPS_ARCH
);
335 BCaseMask(EF_MIPS_ARCH_64R2
, EF_MIPS_ARCH
);
336 BCaseMask(EF_MIPS_ARCH_32R6
, EF_MIPS_ARCH
);
337 BCaseMask(EF_MIPS_ARCH_64R6
, EF_MIPS_ARCH
);
339 case ELF::EM_HEXAGON
:
340 BCase(EF_HEXAGON_MACH_V2
);
341 BCase(EF_HEXAGON_MACH_V3
);
342 BCase(EF_HEXAGON_MACH_V4
);
343 BCase(EF_HEXAGON_MACH_V5
);
344 BCase(EF_HEXAGON_MACH_V55
);
345 BCase(EF_HEXAGON_MACH_V60
);
346 BCase(EF_HEXAGON_MACH_V62
);
347 BCase(EF_HEXAGON_MACH_V65
);
348 BCase(EF_HEXAGON_ISA_V2
);
349 BCase(EF_HEXAGON_ISA_V3
);
350 BCase(EF_HEXAGON_ISA_V4
);
351 BCase(EF_HEXAGON_ISA_V5
);
352 BCase(EF_HEXAGON_ISA_V55
);
353 BCase(EF_HEXAGON_ISA_V60
);
354 BCase(EF_HEXAGON_ISA_V62
);
355 BCase(EF_HEXAGON_ISA_V65
);
358 BCase(EF_AVR_ARCH_AVR1
);
359 BCase(EF_AVR_ARCH_AVR2
);
360 BCase(EF_AVR_ARCH_AVR25
);
361 BCase(EF_AVR_ARCH_AVR3
);
362 BCase(EF_AVR_ARCH_AVR31
);
363 BCase(EF_AVR_ARCH_AVR35
);
364 BCase(EF_AVR_ARCH_AVR4
);
365 BCase(EF_AVR_ARCH_AVR51
);
366 BCase(EF_AVR_ARCH_AVR6
);
367 BCase(EF_AVR_ARCH_AVRTINY
);
368 BCase(EF_AVR_ARCH_XMEGA1
);
369 BCase(EF_AVR_ARCH_XMEGA2
);
370 BCase(EF_AVR_ARCH_XMEGA3
);
371 BCase(EF_AVR_ARCH_XMEGA4
);
372 BCase(EF_AVR_ARCH_XMEGA5
);
373 BCase(EF_AVR_ARCH_XMEGA6
);
374 BCase(EF_AVR_ARCH_XMEGA7
);
378 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT
, EF_RISCV_FLOAT_ABI
);
379 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE
, EF_RISCV_FLOAT_ABI
);
380 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE
, EF_RISCV_FLOAT_ABI
);
381 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD
, EF_RISCV_FLOAT_ABI
);
385 BCaseMask(EF_AMDGPU_MACH_NONE
, EF_AMDGPU_MACH
);
386 BCaseMask(EF_AMDGPU_MACH_R600_R600
, EF_AMDGPU_MACH
);
387 BCaseMask(EF_AMDGPU_MACH_R600_R630
, EF_AMDGPU_MACH
);
388 BCaseMask(EF_AMDGPU_MACH_R600_RS880
, EF_AMDGPU_MACH
);
389 BCaseMask(EF_AMDGPU_MACH_R600_RV670
, EF_AMDGPU_MACH
);
390 BCaseMask(EF_AMDGPU_MACH_R600_RV710
, EF_AMDGPU_MACH
);
391 BCaseMask(EF_AMDGPU_MACH_R600_RV730
, EF_AMDGPU_MACH
);
392 BCaseMask(EF_AMDGPU_MACH_R600_RV770
, EF_AMDGPU_MACH
);
393 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR
, EF_AMDGPU_MACH
);
394 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS
, EF_AMDGPU_MACH
);
395 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER
, EF_AMDGPU_MACH
);
396 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD
, EF_AMDGPU_MACH
);
397 BCaseMask(EF_AMDGPU_MACH_R600_SUMO
, EF_AMDGPU_MACH
);
398 BCaseMask(EF_AMDGPU_MACH_R600_BARTS
, EF_AMDGPU_MACH
);
399 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS
, EF_AMDGPU_MACH
);
400 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN
, EF_AMDGPU_MACH
);
401 BCaseMask(EF_AMDGPU_MACH_R600_TURKS
, EF_AMDGPU_MACH
);
402 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600
, EF_AMDGPU_MACH
);
403 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601
, EF_AMDGPU_MACH
);
404 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700
, EF_AMDGPU_MACH
);
405 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701
, EF_AMDGPU_MACH
);
406 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702
, EF_AMDGPU_MACH
);
407 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703
, EF_AMDGPU_MACH
);
408 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704
, EF_AMDGPU_MACH
);
409 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801
, EF_AMDGPU_MACH
);
410 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802
, EF_AMDGPU_MACH
);
411 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803
, EF_AMDGPU_MACH
);
412 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810
, EF_AMDGPU_MACH
);
413 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900
, EF_AMDGPU_MACH
);
414 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902
, EF_AMDGPU_MACH
);
415 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904
, EF_AMDGPU_MACH
);
416 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906
, EF_AMDGPU_MACH
);
417 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908
, EF_AMDGPU_MACH
);
418 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909
, EF_AMDGPU_MACH
);
419 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010
, EF_AMDGPU_MACH
);
420 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011
, EF_AMDGPU_MACH
);
421 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012
, EF_AMDGPU_MACH
);
422 BCase(EF_AMDGPU_XNACK
);
423 BCase(EF_AMDGPU_SRAM_ECC
);
428 llvm_unreachable("Unsupported architecture");
434 void ScalarEnumerationTraits
<ELFYAML::ELF_SHT
>::enumeration(
435 IO
&IO
, ELFYAML::ELF_SHT
&Value
) {
436 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
437 assert(Object
&& "The IO context is not initialized");
438 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
442 // FIXME: Issue a diagnostic with this information.
452 ECase(SHT_INIT_ARRAY
);
453 ECase(SHT_FINI_ARRAY
);
454 ECase(SHT_PREINIT_ARRAY
);
456 ECase(SHT_SYMTAB_SHNDX
);
458 ECase(SHT_ANDROID_REL
);
459 ECase(SHT_ANDROID_RELA
);
460 ECase(SHT_ANDROID_RELR
);
461 ECase(SHT_LLVM_ODRTAB
);
462 ECase(SHT_LLVM_LINKER_OPTIONS
);
463 ECase(SHT_LLVM_CALL_GRAPH_PROFILE
);
464 ECase(SHT_LLVM_ADDRSIG
);
465 ECase(SHT_LLVM_DEPENDENT_LIBRARIES
);
466 ECase(SHT_LLVM_SYMPART
);
467 ECase(SHT_LLVM_PART_EHDR
);
468 ECase(SHT_LLVM_PART_PHDR
);
469 ECase(SHT_GNU_ATTRIBUTES
);
471 ECase(SHT_GNU_verdef
);
472 ECase(SHT_GNU_verneed
);
473 ECase(SHT_GNU_versym
);
474 switch (Object
->Header
.Machine
) {
476 ECase(SHT_ARM_EXIDX
);
477 ECase(SHT_ARM_PREEMPTMAP
);
478 ECase(SHT_ARM_ATTRIBUTES
);
479 ECase(SHT_ARM_DEBUGOVERLAY
);
480 ECase(SHT_ARM_OVERLAYSECTION
);
482 case ELF::EM_HEXAGON
:
483 ECase(SHT_HEX_ORDERED
);
486 ECase(SHT_X86_64_UNWIND
);
489 ECase(SHT_MIPS_REGINFO
);
490 ECase(SHT_MIPS_OPTIONS
);
491 ECase(SHT_MIPS_DWARF
);
492 ECase(SHT_MIPS_ABIFLAGS
);
499 IO
.enumFallback
<Hex32
>(Value
);
502 void ScalarBitSetTraits
<ELFYAML::ELF_PF
>::bitset(IO
&IO
,
503 ELFYAML::ELF_PF
&Value
) {
504 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
510 void ScalarBitSetTraits
<ELFYAML::ELF_SHF
>::bitset(IO
&IO
,
511 ELFYAML::ELF_SHF
&Value
) {
512 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
513 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
517 BCase(SHF_EXECINSTR
);
520 BCase(SHF_INFO_LINK
);
521 BCase(SHF_LINK_ORDER
);
522 BCase(SHF_OS_NONCONFORMING
);
525 BCase(SHF_COMPRESSED
);
526 switch (Object
->Header
.Machine
) {
528 BCase(SHF_ARM_PURECODE
);
530 case ELF::EM_HEXAGON
:
531 BCase(SHF_HEX_GPREL
);
534 BCase(SHF_MIPS_NODUPES
);
535 BCase(SHF_MIPS_NAMES
);
536 BCase(SHF_MIPS_LOCAL
);
537 BCase(SHF_MIPS_NOSTRIP
);
538 BCase(SHF_MIPS_GPREL
);
539 BCase(SHF_MIPS_MERGE
);
540 BCase(SHF_MIPS_ADDR
);
541 BCase(SHF_MIPS_STRING
);
544 BCase(SHF_X86_64_LARGE
);
553 void ScalarEnumerationTraits
<ELFYAML::ELF_SHN
>::enumeration(
554 IO
&IO
, ELFYAML::ELF_SHN
&Value
) {
555 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
557 ECase(SHN_LORESERVE
);
565 ECase(SHN_HIRESERVE
);
566 ECase(SHN_AMDGPU_LDS
);
567 ECase(SHN_HEXAGON_SCOMMON
);
568 ECase(SHN_HEXAGON_SCOMMON_1
);
569 ECase(SHN_HEXAGON_SCOMMON_2
);
570 ECase(SHN_HEXAGON_SCOMMON_4
);
571 ECase(SHN_HEXAGON_SCOMMON_8
);
573 IO
.enumFallback
<Hex16
>(Value
);
576 void ScalarEnumerationTraits
<ELFYAML::ELF_STB
>::enumeration(
577 IO
&IO
, ELFYAML::ELF_STB
&Value
) {
578 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
582 ECase(STB_GNU_UNIQUE
);
584 IO
.enumFallback
<Hex8
>(Value
);
587 void ScalarEnumerationTraits
<ELFYAML::ELF_STT
>::enumeration(
588 IO
&IO
, ELFYAML::ELF_STT
&Value
) {
589 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
597 ECase(STT_GNU_IFUNC
);
599 IO
.enumFallback
<Hex8
>(Value
);
603 void ScalarEnumerationTraits
<ELFYAML::ELF_RSS
>::enumeration(
604 IO
&IO
, ELFYAML::ELF_RSS
&Value
) {
605 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
613 void ScalarEnumerationTraits
<ELFYAML::ELF_REL
>::enumeration(
614 IO
&IO
, ELFYAML::ELF_REL
&Value
) {
615 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
616 assert(Object
&& "The IO context is not initialized");
617 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
618 switch (Object
->Header
.Machine
) {
620 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
623 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
625 case ELF::EM_HEXAGON
:
626 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
630 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
632 case ELF::EM_AARCH64
:
633 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
636 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
639 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
642 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
645 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
648 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
651 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
654 llvm_unreachable("Unsupported architecture");
657 IO
.enumFallback
<Hex32
>(Value
);
660 void ScalarEnumerationTraits
<ELFYAML::ELF_DYNTAG
>::enumeration(
661 IO
&IO
, ELFYAML::ELF_DYNTAG
&Value
) {
662 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
663 assert(Object
&& "The IO context is not initialized");
665 // Disable architecture specific tags by default. We might enable them below.
666 #define AARCH64_DYNAMIC_TAG(name, value)
667 #define MIPS_DYNAMIC_TAG(name, value)
668 #define HEXAGON_DYNAMIC_TAG(name, value)
669 #define PPC_DYNAMIC_TAG(name, value)
670 #define PPC64_DYNAMIC_TAG(name, value)
671 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
672 #define DYNAMIC_TAG_MARKER(name, value)
674 #define STRINGIFY(X) (#X)
675 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
676 switch (Object
->Header
.Machine
) {
677 case ELF::EM_AARCH64
:
678 #undef AARCH64_DYNAMIC_TAG
679 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
680 #include "llvm/BinaryFormat/DynamicTags.def"
681 #undef AARCH64_DYNAMIC_TAG
682 #define AARCH64_DYNAMIC_TAG(name, value)
685 #undef MIPS_DYNAMIC_TAG
686 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
687 #include "llvm/BinaryFormat/DynamicTags.def"
688 #undef MIPS_DYNAMIC_TAG
689 #define MIPS_DYNAMIC_TAG(name, value)
691 case ELF::EM_HEXAGON
:
692 #undef HEXAGON_DYNAMIC_TAG
693 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
694 #include "llvm/BinaryFormat/DynamicTags.def"
695 #undef HEXAGON_DYNAMIC_TAG
696 #define HEXAGON_DYNAMIC_TAG(name, value)
699 #undef PPC_DYNAMIC_TAG
700 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
701 #include "llvm/BinaryFormat/DynamicTags.def"
702 #undef PPC_DYNAMIC_TAG
703 #define PPC_DYNAMIC_TAG(name, value)
706 #undef PPC64_DYNAMIC_TAG
707 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
708 #include "llvm/BinaryFormat/DynamicTags.def"
709 #undef PPC64_DYNAMIC_TAG
710 #define PPC64_DYNAMIC_TAG(name, value)
713 #include "llvm/BinaryFormat/DynamicTags.def"
716 #undef AARCH64_DYNAMIC_TAG
717 #undef MIPS_DYNAMIC_TAG
718 #undef HEXAGON_DYNAMIC_TAG
719 #undef PPC_DYNAMIC_TAG
720 #undef PPC64_DYNAMIC_TAG
721 #undef DYNAMIC_TAG_MARKER
725 IO
.enumFallback
<Hex64
>(Value
);
728 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_REG
>::enumeration(
729 IO
&IO
, ELFYAML::MIPS_AFL_REG
&Value
) {
730 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
738 void ScalarEnumerationTraits
<ELFYAML::MIPS_ABI_FP
>::enumeration(
739 IO
&IO
, ELFYAML::MIPS_ABI_FP
&Value
) {
740 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
752 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_EXT
>::enumeration(
753 IO
&IO
, ELFYAML::MIPS_AFL_EXT
&Value
) {
754 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
759 ECase(EXT_LOONGSON_3A
);
772 ECase(EXT_LOONGSON_2E
);
773 ECase(EXT_LOONGSON_2F
);
778 void ScalarEnumerationTraits
<ELFYAML::MIPS_ISA
>::enumeration(
779 IO
&IO
, ELFYAML::MIPS_ISA
&Value
) {
780 IO
.enumCase(Value
, "MIPS1", 1);
781 IO
.enumCase(Value
, "MIPS2", 2);
782 IO
.enumCase(Value
, "MIPS3", 3);
783 IO
.enumCase(Value
, "MIPS4", 4);
784 IO
.enumCase(Value
, "MIPS5", 5);
785 IO
.enumCase(Value
, "MIPS32", 32);
786 IO
.enumCase(Value
, "MIPS64", 64);
789 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_ASE
>::bitset(
790 IO
&IO
, ELFYAML::MIPS_AFL_ASE
&Value
) {
791 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
808 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_FLAGS1
>::bitset(
809 IO
&IO
, ELFYAML::MIPS_AFL_FLAGS1
&Value
) {
810 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
815 void MappingTraits
<ELFYAML::FileHeader
>::mapping(IO
&IO
,
816 ELFYAML::FileHeader
&FileHdr
) {
817 IO
.mapRequired("Class", FileHdr
.Class
);
818 IO
.mapRequired("Data", FileHdr
.Data
);
819 IO
.mapOptional("OSABI", FileHdr
.OSABI
, ELFYAML::ELF_ELFOSABI(0));
820 IO
.mapOptional("ABIVersion", FileHdr
.ABIVersion
, Hex8(0));
821 IO
.mapRequired("Type", FileHdr
.Type
);
822 IO
.mapRequired("Machine", FileHdr
.Machine
);
823 IO
.mapOptional("Flags", FileHdr
.Flags
, ELFYAML::ELF_EF(0));
824 IO
.mapOptional("Entry", FileHdr
.Entry
, Hex64(0));
826 IO
.mapOptional("SHEntSize", FileHdr
.SHEntSize
);
827 IO
.mapOptional("SHOff", FileHdr
.SHOff
);
828 IO
.mapOptional("SHNum", FileHdr
.SHNum
);
829 IO
.mapOptional("SHStrNdx", FileHdr
.SHStrNdx
);
832 void MappingTraits
<ELFYAML::ProgramHeader
>::mapping(
833 IO
&IO
, ELFYAML::ProgramHeader
&Phdr
) {
834 IO
.mapRequired("Type", Phdr
.Type
);
835 IO
.mapOptional("Flags", Phdr
.Flags
, ELFYAML::ELF_PF(0));
836 IO
.mapOptional("Sections", Phdr
.Sections
);
837 IO
.mapOptional("VAddr", Phdr
.VAddr
, Hex64(0));
838 IO
.mapOptional("PAddr", Phdr
.PAddr
, Hex64(0));
839 IO
.mapOptional("Align", Phdr
.Align
);
840 IO
.mapOptional("FileSize", Phdr
.FileSize
);
841 IO
.mapOptional("MemSize", Phdr
.MemSize
);
842 IO
.mapOptional("Offset", Phdr
.Offset
);
845 LLVM_YAML_STRONG_TYPEDEF(StringRef
, StOtherPiece
)
847 template <> struct ScalarTraits
<StOtherPiece
> {
848 static void output(const StOtherPiece
&Val
, void *, raw_ostream
&Out
) {
851 static StringRef
input(StringRef Scalar
, void *, StOtherPiece
&Val
) {
855 static QuotingType
mustQuote(StringRef
) { return QuotingType::None
; }
857 template <> struct SequenceElementTraits
<StOtherPiece
> {
858 static const bool flow
= true;
863 struct NormalizedOther
{
864 NormalizedOther(IO
&IO
) : YamlIO(IO
) {}
865 NormalizedOther(IO
&IO
, Optional
<uint8_t> Original
) : YamlIO(IO
) {
866 assert(Original
&& "This constructor is only used for outputting YAML and "
867 "assumes a non-empty Original");
868 std::vector
<StOtherPiece
> Ret
;
869 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
870 for (std::pair
<StringRef
, uint8_t> &P
:
871 getFlags(Object
->Header
.Machine
).takeVector()) {
872 uint8_t FlagValue
= P
.second
;
873 if ((*Original
& FlagValue
) != FlagValue
)
875 *Original
&= ~FlagValue
;
876 Ret
.push_back({P
.first
});
879 if (*Original
!= 0) {
880 UnknownFlagsHolder
= std::to_string(*Original
);
881 Ret
.push_back({UnknownFlagsHolder
});
885 Other
= std::move(Ret
);
888 uint8_t toValue(StringRef Name
) {
889 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
890 MapVector
<StringRef
, uint8_t> Flags
= getFlags(Object
->Header
.Machine
);
892 auto It
= Flags
.find(Name
);
893 if (It
!= Flags
.end())
897 if (to_integer(Name
, Val
))
900 YamlIO
.setError("an unknown value is used for symbol's 'Other' field: " +
905 Optional
<uint8_t> denormalize(IO
&) {
909 for (StOtherPiece
&Val
: *Other
)
914 // st_other field is used to encode symbol visibility and platform-dependent
915 // flags and values. This method returns a name to value map that is used for
916 // parsing and encoding this field.
917 MapVector
<StringRef
, uint8_t> getFlags(unsigned EMachine
) {
918 MapVector
<StringRef
, uint8_t> Map
;
919 // STV_* values are just enumeration values. We add them in a reversed order
920 // because when we convert the st_other to named constants when printing
921 // YAML we want to use a maximum number of bits on each step:
922 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
923 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
924 Map
["STV_PROTECTED"] = ELF::STV_PROTECTED
;
925 Map
["STV_HIDDEN"] = ELF::STV_HIDDEN
;
926 Map
["STV_INTERNAL"] = ELF::STV_INTERNAL
;
927 // STV_DEFAULT is used to represent the default visibility and has a value
928 // 0. We want to be able to read it from YAML documents, but there is no
929 // reason to print it.
930 if (!YamlIO
.outputting())
931 Map
["STV_DEFAULT"] = ELF::STV_DEFAULT
;
933 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
934 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
935 // consumed first when we print the output, because we do not want to print
936 // any other flags that have the same bits instead.
937 if (EMachine
== ELF::EM_MIPS
) {
938 Map
["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16
;
939 Map
["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS
;
940 Map
["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC
;
941 Map
["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT
;
942 Map
["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL
;
948 Optional
<std::vector
<StOtherPiece
>> Other
;
949 std::string UnknownFlagsHolder
;
952 } // end anonymous namespace
954 void MappingTraits
<ELFYAML::Symbol
>::mapping(IO
&IO
, ELFYAML::Symbol
&Symbol
) {
955 IO
.mapOptional("Name", Symbol
.Name
, StringRef());
956 IO
.mapOptional("NameIndex", Symbol
.NameIndex
);
957 IO
.mapOptional("Type", Symbol
.Type
, ELFYAML::ELF_STT(0));
958 IO
.mapOptional("Section", Symbol
.Section
, StringRef());
959 IO
.mapOptional("Index", Symbol
.Index
);
960 IO
.mapOptional("Binding", Symbol
.Binding
, ELFYAML::ELF_STB(0));
961 IO
.mapOptional("Value", Symbol
.Value
, Hex64(0));
962 IO
.mapOptional("Size", Symbol
.Size
, Hex64(0));
964 // Symbol's Other field is a bit special. It is usually a field that
965 // represents st_other and holds the symbol visibility. However, on some
966 // platforms, it can contain bit fields and regular values, or even sometimes a
967 // crazy mix of them (see comments for NormalizedOther). Because of this, we
968 // need special handling.
969 MappingNormalization
<NormalizedOther
, Optional
<uint8_t>> Keys(IO
,
971 IO
.mapOptional("Other", Keys
->Other
);
974 StringRef MappingTraits
<ELFYAML::Symbol
>::validate(IO
&IO
,
975 ELFYAML::Symbol
&Symbol
) {
976 if (Symbol
.Index
&& Symbol
.Section
.data())
977 return "Index and Section cannot both be specified for Symbol";
978 if (Symbol
.NameIndex
&& !Symbol
.Name
.empty())
979 return "Name and NameIndex cannot both be specified for Symbol";
983 static void commonSectionMapping(IO
&IO
, ELFYAML::Section
&Section
) {
984 IO
.mapOptional("Name", Section
.Name
, StringRef());
985 IO
.mapRequired("Type", Section
.Type
);
986 IO
.mapOptional("Flags", Section
.Flags
);
987 IO
.mapOptional("Address", Section
.Address
, Hex64(0));
988 IO
.mapOptional("Link", Section
.Link
, StringRef());
989 IO
.mapOptional("AddressAlign", Section
.AddressAlign
, Hex64(0));
990 IO
.mapOptional("EntSize", Section
.EntSize
);
992 // obj2yaml does not dump these fields. They are expected to be empty when we
993 // are producing YAML, because yaml2obj sets appropriate values for them
994 // automatically when they are not explicitly defined.
995 assert(!IO
.outputting() ||
996 (!Section
.ShOffset
.hasValue() && !Section
.ShSize
.hasValue()));
997 IO
.mapOptional("ShName", Section
.ShName
);
998 IO
.mapOptional("ShOffset", Section
.ShOffset
);
999 IO
.mapOptional("ShSize", Section
.ShSize
);
1002 static void sectionMapping(IO
&IO
, ELFYAML::DynamicSection
&Section
) {
1003 commonSectionMapping(IO
, Section
);
1004 IO
.mapOptional("Entries", Section
.Entries
);
1005 IO
.mapOptional("Content", Section
.Content
);
1008 static void sectionMapping(IO
&IO
, ELFYAML::RawContentSection
&Section
) {
1009 commonSectionMapping(IO
, Section
);
1010 IO
.mapOptional("Content", Section
.Content
);
1011 IO
.mapOptional("Size", Section
.Size
);
1012 IO
.mapOptional("Info", Section
.Info
);
1015 static void sectionMapping(IO
&IO
, ELFYAML::NoBitsSection
&Section
) {
1016 commonSectionMapping(IO
, Section
);
1017 IO
.mapOptional("Size", Section
.Size
, Hex64(0));
1020 static void sectionMapping(IO
&IO
, ELFYAML::VerdefSection
&Section
) {
1021 commonSectionMapping(IO
, Section
);
1022 IO
.mapRequired("Info", Section
.Info
);
1023 IO
.mapRequired("Entries", Section
.Entries
);
1026 static void sectionMapping(IO
&IO
, ELFYAML::SymverSection
&Section
) {
1027 commonSectionMapping(IO
, Section
);
1028 IO
.mapRequired("Entries", Section
.Entries
);
1031 static void sectionMapping(IO
&IO
, ELFYAML::VerneedSection
&Section
) {
1032 commonSectionMapping(IO
, Section
);
1033 IO
.mapRequired("Info", Section
.Info
);
1034 IO
.mapRequired("Dependencies", Section
.VerneedV
);
1037 static void sectionMapping(IO
&IO
, ELFYAML::RelocationSection
&Section
) {
1038 commonSectionMapping(IO
, Section
);
1039 IO
.mapOptional("Info", Section
.RelocatableSec
, StringRef());
1040 IO
.mapOptional("Relocations", Section
.Relocations
);
1043 static void groupSectionMapping(IO
&IO
, ELFYAML::Group
&Group
) {
1044 commonSectionMapping(IO
, Group
);
1045 IO
.mapOptional("Info", Group
.Signature
, StringRef());
1046 IO
.mapRequired("Members", Group
.Members
);
1049 static void sectionMapping(IO
&IO
, ELFYAML::SymtabShndxSection
&Section
) {
1050 commonSectionMapping(IO
, Section
);
1051 IO
.mapRequired("Entries", Section
.Entries
);
1054 void MappingTraits
<ELFYAML::SectionOrType
>::mapping(
1055 IO
&IO
, ELFYAML::SectionOrType
§ionOrType
) {
1056 IO
.mapRequired("SectionOrType", sectionOrType
.sectionNameOrType
);
1059 void MappingTraits
<ELFYAML::SectionName
>::mapping(
1060 IO
&IO
, ELFYAML::SectionName
§ionName
) {
1061 IO
.mapRequired("Section", sectionName
.Section
);
1064 static void sectionMapping(IO
&IO
, ELFYAML::MipsABIFlags
&Section
) {
1065 commonSectionMapping(IO
, Section
);
1066 IO
.mapOptional("Version", Section
.Version
, Hex16(0));
1067 IO
.mapRequired("ISA", Section
.ISALevel
);
1068 IO
.mapOptional("ISARevision", Section
.ISARevision
, Hex8(0));
1069 IO
.mapOptional("ISAExtension", Section
.ISAExtension
,
1070 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE
));
1071 IO
.mapOptional("ASEs", Section
.ASEs
, ELFYAML::MIPS_AFL_ASE(0));
1072 IO
.mapOptional("FpABI", Section
.FpABI
,
1073 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY
));
1074 IO
.mapOptional("GPRSize", Section
.GPRSize
,
1075 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1076 IO
.mapOptional("CPR1Size", Section
.CPR1Size
,
1077 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1078 IO
.mapOptional("CPR2Size", Section
.CPR2Size
,
1079 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1080 IO
.mapOptional("Flags1", Section
.Flags1
, ELFYAML::MIPS_AFL_FLAGS1(0));
1081 IO
.mapOptional("Flags2", Section
.Flags2
, Hex32(0));
1084 void MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::mapping(
1085 IO
&IO
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
1086 ELFYAML::ELF_SHT sectionType
;
1087 if (IO
.outputting())
1088 sectionType
= Section
->Type
;
1090 IO
.mapRequired("Type", sectionType
);
1092 switch (sectionType
) {
1093 case ELF::SHT_DYNAMIC
:
1094 if (!IO
.outputting())
1095 Section
.reset(new ELFYAML::DynamicSection());
1096 sectionMapping(IO
, *cast
<ELFYAML::DynamicSection
>(Section
.get()));
1100 if (!IO
.outputting())
1101 Section
.reset(new ELFYAML::RelocationSection());
1102 sectionMapping(IO
, *cast
<ELFYAML::RelocationSection
>(Section
.get()));
1104 case ELF::SHT_GROUP
:
1105 if (!IO
.outputting())
1106 Section
.reset(new ELFYAML::Group());
1107 groupSectionMapping(IO
, *cast
<ELFYAML::Group
>(Section
.get()));
1109 case ELF::SHT_NOBITS
:
1110 if (!IO
.outputting())
1111 Section
.reset(new ELFYAML::NoBitsSection());
1112 sectionMapping(IO
, *cast
<ELFYAML::NoBitsSection
>(Section
.get()));
1114 case ELF::SHT_MIPS_ABIFLAGS
:
1115 if (!IO
.outputting())
1116 Section
.reset(new ELFYAML::MipsABIFlags());
1117 sectionMapping(IO
, *cast
<ELFYAML::MipsABIFlags
>(Section
.get()));
1119 case ELF::SHT_GNU_verdef
:
1120 if (!IO
.outputting())
1121 Section
.reset(new ELFYAML::VerdefSection());
1122 sectionMapping(IO
, *cast
<ELFYAML::VerdefSection
>(Section
.get()));
1124 case ELF::SHT_GNU_versym
:
1125 if (!IO
.outputting())
1126 Section
.reset(new ELFYAML::SymverSection());
1127 sectionMapping(IO
, *cast
<ELFYAML::SymverSection
>(Section
.get()));
1129 case ELF::SHT_GNU_verneed
:
1130 if (!IO
.outputting())
1131 Section
.reset(new ELFYAML::VerneedSection());
1132 sectionMapping(IO
, *cast
<ELFYAML::VerneedSection
>(Section
.get()));
1134 case ELF::SHT_SYMTAB_SHNDX
:
1135 if (!IO
.outputting())
1136 Section
.reset(new ELFYAML::SymtabShndxSection());
1137 sectionMapping(IO
, *cast
<ELFYAML::SymtabShndxSection
>(Section
.get()));
1140 if (!IO
.outputting())
1141 Section
.reset(new ELFYAML::RawContentSection());
1142 sectionMapping(IO
, *cast
<ELFYAML::RawContentSection
>(Section
.get()));
1146 StringRef MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::validate(
1147 IO
&io
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
1148 const auto *RawSection
= dyn_cast
<ELFYAML::RawContentSection
>(Section
.get());
1151 if (RawSection
->Size
&& RawSection
->Content
&&
1152 (uint64_t)(*RawSection
->Size
) < RawSection
->Content
->binary_size())
1153 return "Section size must be greater than or equal to the content size";
1159 struct NormalizedMips64RelType
{
1160 NormalizedMips64RelType(IO
&)
1161 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1162 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1163 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1164 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF
)) {}
1165 NormalizedMips64RelType(IO
&, ELFYAML::ELF_REL Original
)
1166 : Type(Original
& 0xFF), Type2(Original
>> 8 & 0xFF),
1167 Type3(Original
>> 16 & 0xFF), SpecSym(Original
>> 24 & 0xFF) {}
1169 ELFYAML::ELF_REL
denormalize(IO
&) {
1170 ELFYAML::ELF_REL Res
= Type
| Type2
<< 8 | Type3
<< 16 | SpecSym
<< 24;
1174 ELFYAML::ELF_REL Type
;
1175 ELFYAML::ELF_REL Type2
;
1176 ELFYAML::ELF_REL Type3
;
1177 ELFYAML::ELF_RSS SpecSym
;
1180 } // end anonymous namespace
1182 void MappingTraits
<ELFYAML::DynamicEntry
>::mapping(IO
&IO
,
1183 ELFYAML::DynamicEntry
&Rel
) {
1184 assert(IO
.getContext() && "The IO context is not initialized");
1186 IO
.mapRequired("Tag", Rel
.Tag
);
1187 IO
.mapRequired("Value", Rel
.Val
);
1190 void MappingTraits
<ELFYAML::VerdefEntry
>::mapping(IO
&IO
,
1191 ELFYAML::VerdefEntry
&E
) {
1192 assert(IO
.getContext() && "The IO context is not initialized");
1194 IO
.mapRequired("Version", E
.Version
);
1195 IO
.mapRequired("Flags", E
.Flags
);
1196 IO
.mapRequired("VersionNdx", E
.VersionNdx
);
1197 IO
.mapRequired("Hash", E
.Hash
);
1198 IO
.mapRequired("Names", E
.VerNames
);
1201 void MappingTraits
<ELFYAML::VerneedEntry
>::mapping(IO
&IO
,
1202 ELFYAML::VerneedEntry
&E
) {
1203 assert(IO
.getContext() && "The IO context is not initialized");
1205 IO
.mapRequired("Version", E
.Version
);
1206 IO
.mapRequired("File", E
.File
);
1207 IO
.mapRequired("Entries", E
.AuxV
);
1210 void MappingTraits
<ELFYAML::VernauxEntry
>::mapping(IO
&IO
,
1211 ELFYAML::VernauxEntry
&E
) {
1212 assert(IO
.getContext() && "The IO context is not initialized");
1214 IO
.mapRequired("Name", E
.Name
);
1215 IO
.mapRequired("Hash", E
.Hash
);
1216 IO
.mapRequired("Flags", E
.Flags
);
1217 IO
.mapRequired("Other", E
.Other
);
1220 void MappingTraits
<ELFYAML::Relocation
>::mapping(IO
&IO
,
1221 ELFYAML::Relocation
&Rel
) {
1222 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
1223 assert(Object
&& "The IO context is not initialized");
1225 IO
.mapRequired("Offset", Rel
.Offset
);
1226 IO
.mapOptional("Symbol", Rel
.Symbol
);
1228 if (Object
->Header
.Machine
== ELFYAML::ELF_EM(ELF::EM_MIPS
) &&
1229 Object
->Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
)) {
1230 MappingNormalization
<NormalizedMips64RelType
, ELFYAML::ELF_REL
> Key(
1232 IO
.mapRequired("Type", Key
->Type
);
1233 IO
.mapOptional("Type2", Key
->Type2
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1234 IO
.mapOptional("Type3", Key
->Type3
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1235 IO
.mapOptional("SpecSym", Key
->SpecSym
, ELFYAML::ELF_RSS(ELF::RSS_UNDEF
));
1237 IO
.mapRequired("Type", Rel
.Type
);
1239 IO
.mapOptional("Addend", Rel
.Addend
, (int64_t)0);
1242 void MappingTraits
<ELFYAML::Object
>::mapping(IO
&IO
, ELFYAML::Object
&Object
) {
1243 assert(!IO
.getContext() && "The IO context is initialized already");
1244 IO
.setContext(&Object
);
1245 IO
.mapTag("!ELF", true);
1246 IO
.mapRequired("FileHeader", Object
.Header
);
1247 IO
.mapOptional("ProgramHeaders", Object
.ProgramHeaders
);
1248 IO
.mapOptional("Sections", Object
.Sections
);
1249 IO
.mapOptional("Symbols", Object
.Symbols
);
1250 IO
.mapOptional("DynamicSymbols", Object
.DynamicSymbols
);
1251 IO
.setContext(nullptr);
1254 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG
)
1255 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP
)
1256 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT
)
1257 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE
)
1258 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1
)
1260 } // end namespace yaml
1262 } // end namespace llvm