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
);
224 IO
.enumFallback
<Hex16
>(Value
);
227 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFCLASS
>::enumeration(
228 IO
&IO
, ELFYAML::ELF_ELFCLASS
&Value
) {
229 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
230 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
237 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFDATA
>::enumeration(
238 IO
&IO
, ELFYAML::ELF_ELFDATA
&Value
) {
239 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
240 // ELFDATANONE is an invalid data encoding, but we accept it because
241 // we want to be able to produce invalid binaries for the tests.
248 void ScalarEnumerationTraits
<ELFYAML::ELF_ELFOSABI
>::enumeration(
249 IO
&IO
, ELFYAML::ELF_ELFOSABI
&Value
) {
250 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
251 ECase(ELFOSABI_NONE
);
252 ECase(ELFOSABI_HPUX
);
253 ECase(ELFOSABI_NETBSD
);
255 ECase(ELFOSABI_HURD
);
256 ECase(ELFOSABI_SOLARIS
);
258 ECase(ELFOSABI_IRIX
);
259 ECase(ELFOSABI_FREEBSD
);
260 ECase(ELFOSABI_TRU64
);
261 ECase(ELFOSABI_MODESTO
);
262 ECase(ELFOSABI_OPENBSD
);
263 ECase(ELFOSABI_OPENVMS
);
265 ECase(ELFOSABI_AROS
);
266 ECase(ELFOSABI_FENIXOS
);
267 ECase(ELFOSABI_CLOUDABI
);
268 ECase(ELFOSABI_AMDGPU_HSA
);
269 ECase(ELFOSABI_AMDGPU_PAL
);
270 ECase(ELFOSABI_AMDGPU_MESA3D
);
272 ECase(ELFOSABI_C6000_ELFABI
);
273 ECase(ELFOSABI_C6000_LINUX
);
274 ECase(ELFOSABI_STANDALONE
);
278 void ScalarBitSetTraits
<ELFYAML::ELF_EF
>::bitset(IO
&IO
,
279 ELFYAML::ELF_EF
&Value
) {
280 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
281 assert(Object
&& "The IO context is not initialized");
282 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
283 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
284 switch (Object
->Header
.Machine
) {
286 BCase(EF_ARM_SOFT_FLOAT
);
287 BCase(EF_ARM_VFP_FLOAT
);
288 BCaseMask(EF_ARM_EABI_UNKNOWN
, EF_ARM_EABIMASK
);
289 BCaseMask(EF_ARM_EABI_VER1
, EF_ARM_EABIMASK
);
290 BCaseMask(EF_ARM_EABI_VER2
, EF_ARM_EABIMASK
);
291 BCaseMask(EF_ARM_EABI_VER3
, EF_ARM_EABIMASK
);
292 BCaseMask(EF_ARM_EABI_VER4
, EF_ARM_EABIMASK
);
293 BCaseMask(EF_ARM_EABI_VER5
, EF_ARM_EABIMASK
);
296 BCase(EF_MIPS_NOREORDER
);
300 BCase(EF_MIPS_32BITMODE
);
302 BCase(EF_MIPS_NAN2008
);
303 BCase(EF_MIPS_MICROMIPS
);
304 BCase(EF_MIPS_ARCH_ASE_M16
);
305 BCase(EF_MIPS_ARCH_ASE_MDMX
);
306 BCaseMask(EF_MIPS_ABI_O32
, EF_MIPS_ABI
);
307 BCaseMask(EF_MIPS_ABI_O64
, EF_MIPS_ABI
);
308 BCaseMask(EF_MIPS_ABI_EABI32
, EF_MIPS_ABI
);
309 BCaseMask(EF_MIPS_ABI_EABI64
, EF_MIPS_ABI
);
310 BCaseMask(EF_MIPS_MACH_3900
, EF_MIPS_MACH
);
311 BCaseMask(EF_MIPS_MACH_4010
, EF_MIPS_MACH
);
312 BCaseMask(EF_MIPS_MACH_4100
, EF_MIPS_MACH
);
313 BCaseMask(EF_MIPS_MACH_4650
, EF_MIPS_MACH
);
314 BCaseMask(EF_MIPS_MACH_4120
, EF_MIPS_MACH
);
315 BCaseMask(EF_MIPS_MACH_4111
, EF_MIPS_MACH
);
316 BCaseMask(EF_MIPS_MACH_SB1
, EF_MIPS_MACH
);
317 BCaseMask(EF_MIPS_MACH_OCTEON
, EF_MIPS_MACH
);
318 BCaseMask(EF_MIPS_MACH_XLR
, EF_MIPS_MACH
);
319 BCaseMask(EF_MIPS_MACH_OCTEON2
, EF_MIPS_MACH
);
320 BCaseMask(EF_MIPS_MACH_OCTEON3
, EF_MIPS_MACH
);
321 BCaseMask(EF_MIPS_MACH_5400
, EF_MIPS_MACH
);
322 BCaseMask(EF_MIPS_MACH_5900
, EF_MIPS_MACH
);
323 BCaseMask(EF_MIPS_MACH_5500
, EF_MIPS_MACH
);
324 BCaseMask(EF_MIPS_MACH_9000
, EF_MIPS_MACH
);
325 BCaseMask(EF_MIPS_MACH_LS2E
, EF_MIPS_MACH
);
326 BCaseMask(EF_MIPS_MACH_LS2F
, EF_MIPS_MACH
);
327 BCaseMask(EF_MIPS_MACH_LS3A
, EF_MIPS_MACH
);
328 BCaseMask(EF_MIPS_ARCH_1
, EF_MIPS_ARCH
);
329 BCaseMask(EF_MIPS_ARCH_2
, EF_MIPS_ARCH
);
330 BCaseMask(EF_MIPS_ARCH_3
, EF_MIPS_ARCH
);
331 BCaseMask(EF_MIPS_ARCH_4
, EF_MIPS_ARCH
);
332 BCaseMask(EF_MIPS_ARCH_5
, EF_MIPS_ARCH
);
333 BCaseMask(EF_MIPS_ARCH_32
, EF_MIPS_ARCH
);
334 BCaseMask(EF_MIPS_ARCH_64
, EF_MIPS_ARCH
);
335 BCaseMask(EF_MIPS_ARCH_32R2
, EF_MIPS_ARCH
);
336 BCaseMask(EF_MIPS_ARCH_64R2
, EF_MIPS_ARCH
);
337 BCaseMask(EF_MIPS_ARCH_32R6
, EF_MIPS_ARCH
);
338 BCaseMask(EF_MIPS_ARCH_64R6
, EF_MIPS_ARCH
);
340 case ELF::EM_HEXAGON
:
341 BCase(EF_HEXAGON_MACH_V2
);
342 BCase(EF_HEXAGON_MACH_V3
);
343 BCase(EF_HEXAGON_MACH_V4
);
344 BCase(EF_HEXAGON_MACH_V5
);
345 BCase(EF_HEXAGON_MACH_V55
);
346 BCase(EF_HEXAGON_MACH_V60
);
347 BCase(EF_HEXAGON_MACH_V62
);
348 BCase(EF_HEXAGON_MACH_V65
);
349 BCase(EF_HEXAGON_ISA_V2
);
350 BCase(EF_HEXAGON_ISA_V3
);
351 BCase(EF_HEXAGON_ISA_V4
);
352 BCase(EF_HEXAGON_ISA_V5
);
353 BCase(EF_HEXAGON_ISA_V55
);
354 BCase(EF_HEXAGON_ISA_V60
);
355 BCase(EF_HEXAGON_ISA_V62
);
356 BCase(EF_HEXAGON_ISA_V65
);
359 BCase(EF_AVR_ARCH_AVR1
);
360 BCase(EF_AVR_ARCH_AVR2
);
361 BCase(EF_AVR_ARCH_AVR25
);
362 BCase(EF_AVR_ARCH_AVR3
);
363 BCase(EF_AVR_ARCH_AVR31
);
364 BCase(EF_AVR_ARCH_AVR35
);
365 BCase(EF_AVR_ARCH_AVR4
);
366 BCase(EF_AVR_ARCH_AVR51
);
367 BCase(EF_AVR_ARCH_AVR6
);
368 BCase(EF_AVR_ARCH_AVRTINY
);
369 BCase(EF_AVR_ARCH_XMEGA1
);
370 BCase(EF_AVR_ARCH_XMEGA2
);
371 BCase(EF_AVR_ARCH_XMEGA3
);
372 BCase(EF_AVR_ARCH_XMEGA4
);
373 BCase(EF_AVR_ARCH_XMEGA5
);
374 BCase(EF_AVR_ARCH_XMEGA6
);
375 BCase(EF_AVR_ARCH_XMEGA7
);
379 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT
, EF_RISCV_FLOAT_ABI
);
380 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE
, EF_RISCV_FLOAT_ABI
);
381 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE
, EF_RISCV_FLOAT_ABI
);
382 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD
, EF_RISCV_FLOAT_ABI
);
386 BCaseMask(EF_AMDGPU_MACH_NONE
, EF_AMDGPU_MACH
);
387 BCaseMask(EF_AMDGPU_MACH_R600_R600
, EF_AMDGPU_MACH
);
388 BCaseMask(EF_AMDGPU_MACH_R600_R630
, EF_AMDGPU_MACH
);
389 BCaseMask(EF_AMDGPU_MACH_R600_RS880
, EF_AMDGPU_MACH
);
390 BCaseMask(EF_AMDGPU_MACH_R600_RV670
, EF_AMDGPU_MACH
);
391 BCaseMask(EF_AMDGPU_MACH_R600_RV710
, EF_AMDGPU_MACH
);
392 BCaseMask(EF_AMDGPU_MACH_R600_RV730
, EF_AMDGPU_MACH
);
393 BCaseMask(EF_AMDGPU_MACH_R600_RV770
, EF_AMDGPU_MACH
);
394 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR
, EF_AMDGPU_MACH
);
395 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS
, EF_AMDGPU_MACH
);
396 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER
, EF_AMDGPU_MACH
);
397 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD
, EF_AMDGPU_MACH
);
398 BCaseMask(EF_AMDGPU_MACH_R600_SUMO
, EF_AMDGPU_MACH
);
399 BCaseMask(EF_AMDGPU_MACH_R600_BARTS
, EF_AMDGPU_MACH
);
400 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS
, EF_AMDGPU_MACH
);
401 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN
, EF_AMDGPU_MACH
);
402 BCaseMask(EF_AMDGPU_MACH_R600_TURKS
, EF_AMDGPU_MACH
);
403 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600
, EF_AMDGPU_MACH
);
404 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601
, EF_AMDGPU_MACH
);
405 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700
, EF_AMDGPU_MACH
);
406 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701
, EF_AMDGPU_MACH
);
407 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702
, EF_AMDGPU_MACH
);
408 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703
, EF_AMDGPU_MACH
);
409 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704
, EF_AMDGPU_MACH
);
410 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801
, EF_AMDGPU_MACH
);
411 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802
, EF_AMDGPU_MACH
);
412 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803
, EF_AMDGPU_MACH
);
413 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810
, EF_AMDGPU_MACH
);
414 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900
, EF_AMDGPU_MACH
);
415 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902
, EF_AMDGPU_MACH
);
416 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904
, EF_AMDGPU_MACH
);
417 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906
, EF_AMDGPU_MACH
);
418 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908
, EF_AMDGPU_MACH
);
419 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909
, EF_AMDGPU_MACH
);
420 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010
, EF_AMDGPU_MACH
);
421 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011
, EF_AMDGPU_MACH
);
422 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012
, EF_AMDGPU_MACH
);
423 BCase(EF_AMDGPU_XNACK
);
424 BCase(EF_AMDGPU_SRAM_ECC
);
429 llvm_unreachable("Unsupported architecture");
435 void ScalarEnumerationTraits
<ELFYAML::ELF_SHT
>::enumeration(
436 IO
&IO
, ELFYAML::ELF_SHT
&Value
) {
437 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
438 assert(Object
&& "The IO context is not initialized");
439 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
443 // FIXME: Issue a diagnostic with this information.
453 ECase(SHT_INIT_ARRAY
);
454 ECase(SHT_FINI_ARRAY
);
455 ECase(SHT_PREINIT_ARRAY
);
457 ECase(SHT_SYMTAB_SHNDX
);
459 ECase(SHT_ANDROID_REL
);
460 ECase(SHT_ANDROID_RELA
);
461 ECase(SHT_ANDROID_RELR
);
462 ECase(SHT_LLVM_ODRTAB
);
463 ECase(SHT_LLVM_LINKER_OPTIONS
);
464 ECase(SHT_LLVM_CALL_GRAPH_PROFILE
);
465 ECase(SHT_LLVM_ADDRSIG
);
466 ECase(SHT_LLVM_DEPENDENT_LIBRARIES
);
467 ECase(SHT_LLVM_SYMPART
);
468 ECase(SHT_LLVM_PART_EHDR
);
469 ECase(SHT_LLVM_PART_PHDR
);
470 ECase(SHT_GNU_ATTRIBUTES
);
472 ECase(SHT_GNU_verdef
);
473 ECase(SHT_GNU_verneed
);
474 ECase(SHT_GNU_versym
);
475 switch (Object
->Header
.Machine
) {
477 ECase(SHT_ARM_EXIDX
);
478 ECase(SHT_ARM_PREEMPTMAP
);
479 ECase(SHT_ARM_ATTRIBUTES
);
480 ECase(SHT_ARM_DEBUGOVERLAY
);
481 ECase(SHT_ARM_OVERLAYSECTION
);
483 case ELF::EM_HEXAGON
:
484 ECase(SHT_HEX_ORDERED
);
487 ECase(SHT_X86_64_UNWIND
);
490 ECase(SHT_MIPS_REGINFO
);
491 ECase(SHT_MIPS_OPTIONS
);
492 ECase(SHT_MIPS_DWARF
);
493 ECase(SHT_MIPS_ABIFLAGS
);
500 IO
.enumFallback
<Hex32
>(Value
);
503 void ScalarBitSetTraits
<ELFYAML::ELF_PF
>::bitset(IO
&IO
,
504 ELFYAML::ELF_PF
&Value
) {
505 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
511 void ScalarBitSetTraits
<ELFYAML::ELF_SHF
>::bitset(IO
&IO
,
512 ELFYAML::ELF_SHF
&Value
) {
513 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
514 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
518 BCase(SHF_EXECINSTR
);
521 BCase(SHF_INFO_LINK
);
522 BCase(SHF_LINK_ORDER
);
523 BCase(SHF_OS_NONCONFORMING
);
526 BCase(SHF_COMPRESSED
);
527 switch (Object
->Header
.Machine
) {
529 BCase(SHF_ARM_PURECODE
);
531 case ELF::EM_HEXAGON
:
532 BCase(SHF_HEX_GPREL
);
535 BCase(SHF_MIPS_NODUPES
);
536 BCase(SHF_MIPS_NAMES
);
537 BCase(SHF_MIPS_LOCAL
);
538 BCase(SHF_MIPS_NOSTRIP
);
539 BCase(SHF_MIPS_GPREL
);
540 BCase(SHF_MIPS_MERGE
);
541 BCase(SHF_MIPS_ADDR
);
542 BCase(SHF_MIPS_STRING
);
545 BCase(SHF_X86_64_LARGE
);
554 void ScalarEnumerationTraits
<ELFYAML::ELF_SHN
>::enumeration(
555 IO
&IO
, ELFYAML::ELF_SHN
&Value
) {
556 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
558 ECase(SHN_LORESERVE
);
566 ECase(SHN_HIRESERVE
);
567 ECase(SHN_AMDGPU_LDS
);
568 ECase(SHN_HEXAGON_SCOMMON
);
569 ECase(SHN_HEXAGON_SCOMMON_1
);
570 ECase(SHN_HEXAGON_SCOMMON_2
);
571 ECase(SHN_HEXAGON_SCOMMON_4
);
572 ECase(SHN_HEXAGON_SCOMMON_8
);
574 IO
.enumFallback
<Hex16
>(Value
);
577 void ScalarEnumerationTraits
<ELFYAML::ELF_STB
>::enumeration(
578 IO
&IO
, ELFYAML::ELF_STB
&Value
) {
579 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
583 ECase(STB_GNU_UNIQUE
);
585 IO
.enumFallback
<Hex8
>(Value
);
588 void ScalarEnumerationTraits
<ELFYAML::ELF_STT
>::enumeration(
589 IO
&IO
, ELFYAML::ELF_STT
&Value
) {
590 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
598 ECase(STT_GNU_IFUNC
);
600 IO
.enumFallback
<Hex8
>(Value
);
604 void ScalarEnumerationTraits
<ELFYAML::ELF_RSS
>::enumeration(
605 IO
&IO
, ELFYAML::ELF_RSS
&Value
) {
606 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
614 void ScalarEnumerationTraits
<ELFYAML::ELF_REL
>::enumeration(
615 IO
&IO
, ELFYAML::ELF_REL
&Value
) {
616 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
617 assert(Object
&& "The IO context is not initialized");
618 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
619 switch (Object
->Header
.Machine
) {
621 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
624 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
626 case ELF::EM_HEXAGON
:
627 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
631 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
633 case ELF::EM_AARCH64
:
634 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
637 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
640 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
643 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
646 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
649 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
652 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
655 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
662 IO
.enumFallback
<Hex32
>(Value
);
665 void ScalarEnumerationTraits
<ELFYAML::ELF_DYNTAG
>::enumeration(
666 IO
&IO
, ELFYAML::ELF_DYNTAG
&Value
) {
667 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
668 assert(Object
&& "The IO context is not initialized");
670 // Disable architecture specific tags by default. We might enable them below.
671 #define AARCH64_DYNAMIC_TAG(name, value)
672 #define MIPS_DYNAMIC_TAG(name, value)
673 #define HEXAGON_DYNAMIC_TAG(name, value)
674 #define PPC_DYNAMIC_TAG(name, value)
675 #define PPC64_DYNAMIC_TAG(name, value)
676 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
677 #define DYNAMIC_TAG_MARKER(name, value)
679 #define STRINGIFY(X) (#X)
680 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
681 switch (Object
->Header
.Machine
) {
682 case ELF::EM_AARCH64
:
683 #undef AARCH64_DYNAMIC_TAG
684 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
685 #include "llvm/BinaryFormat/DynamicTags.def"
686 #undef AARCH64_DYNAMIC_TAG
687 #define AARCH64_DYNAMIC_TAG(name, value)
690 #undef MIPS_DYNAMIC_TAG
691 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
692 #include "llvm/BinaryFormat/DynamicTags.def"
693 #undef MIPS_DYNAMIC_TAG
694 #define MIPS_DYNAMIC_TAG(name, value)
696 case ELF::EM_HEXAGON
:
697 #undef HEXAGON_DYNAMIC_TAG
698 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
699 #include "llvm/BinaryFormat/DynamicTags.def"
700 #undef HEXAGON_DYNAMIC_TAG
701 #define HEXAGON_DYNAMIC_TAG(name, value)
704 #undef PPC_DYNAMIC_TAG
705 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
706 #include "llvm/BinaryFormat/DynamicTags.def"
707 #undef PPC_DYNAMIC_TAG
708 #define PPC_DYNAMIC_TAG(name, value)
711 #undef PPC64_DYNAMIC_TAG
712 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
713 #include "llvm/BinaryFormat/DynamicTags.def"
714 #undef PPC64_DYNAMIC_TAG
715 #define PPC64_DYNAMIC_TAG(name, value)
718 #include "llvm/BinaryFormat/DynamicTags.def"
721 #undef AARCH64_DYNAMIC_TAG
722 #undef MIPS_DYNAMIC_TAG
723 #undef HEXAGON_DYNAMIC_TAG
724 #undef PPC_DYNAMIC_TAG
725 #undef PPC64_DYNAMIC_TAG
726 #undef DYNAMIC_TAG_MARKER
730 IO
.enumFallback
<Hex64
>(Value
);
733 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_REG
>::enumeration(
734 IO
&IO
, ELFYAML::MIPS_AFL_REG
&Value
) {
735 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
743 void ScalarEnumerationTraits
<ELFYAML::MIPS_ABI_FP
>::enumeration(
744 IO
&IO
, ELFYAML::MIPS_ABI_FP
&Value
) {
745 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
757 void ScalarEnumerationTraits
<ELFYAML::MIPS_AFL_EXT
>::enumeration(
758 IO
&IO
, ELFYAML::MIPS_AFL_EXT
&Value
) {
759 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
764 ECase(EXT_LOONGSON_3A
);
777 ECase(EXT_LOONGSON_2E
);
778 ECase(EXT_LOONGSON_2F
);
783 void ScalarEnumerationTraits
<ELFYAML::MIPS_ISA
>::enumeration(
784 IO
&IO
, ELFYAML::MIPS_ISA
&Value
) {
785 IO
.enumCase(Value
, "MIPS1", 1);
786 IO
.enumCase(Value
, "MIPS2", 2);
787 IO
.enumCase(Value
, "MIPS3", 3);
788 IO
.enumCase(Value
, "MIPS4", 4);
789 IO
.enumCase(Value
, "MIPS5", 5);
790 IO
.enumCase(Value
, "MIPS32", 32);
791 IO
.enumCase(Value
, "MIPS64", 64);
794 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_ASE
>::bitset(
795 IO
&IO
, ELFYAML::MIPS_AFL_ASE
&Value
) {
796 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
813 void ScalarBitSetTraits
<ELFYAML::MIPS_AFL_FLAGS1
>::bitset(
814 IO
&IO
, ELFYAML::MIPS_AFL_FLAGS1
&Value
) {
815 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
820 void MappingTraits
<ELFYAML::FileHeader
>::mapping(IO
&IO
,
821 ELFYAML::FileHeader
&FileHdr
) {
822 IO
.mapRequired("Class", FileHdr
.Class
);
823 IO
.mapRequired("Data", FileHdr
.Data
);
824 IO
.mapOptional("OSABI", FileHdr
.OSABI
, ELFYAML::ELF_ELFOSABI(0));
825 IO
.mapOptional("ABIVersion", FileHdr
.ABIVersion
, Hex8(0));
826 IO
.mapRequired("Type", FileHdr
.Type
);
827 IO
.mapRequired("Machine", FileHdr
.Machine
);
828 IO
.mapOptional("Flags", FileHdr
.Flags
, ELFYAML::ELF_EF(0));
829 IO
.mapOptional("Entry", FileHdr
.Entry
, Hex64(0));
831 IO
.mapOptional("SHEntSize", FileHdr
.SHEntSize
);
832 IO
.mapOptional("SHOff", FileHdr
.SHOff
);
833 IO
.mapOptional("SHNum", FileHdr
.SHNum
);
834 IO
.mapOptional("SHStrNdx", FileHdr
.SHStrNdx
);
837 void MappingTraits
<ELFYAML::ProgramHeader
>::mapping(
838 IO
&IO
, ELFYAML::ProgramHeader
&Phdr
) {
839 IO
.mapRequired("Type", Phdr
.Type
);
840 IO
.mapOptional("Flags", Phdr
.Flags
, ELFYAML::ELF_PF(0));
841 IO
.mapOptional("Sections", Phdr
.Sections
);
842 IO
.mapOptional("VAddr", Phdr
.VAddr
, Hex64(0));
843 IO
.mapOptional("PAddr", Phdr
.PAddr
, Hex64(0));
844 IO
.mapOptional("Align", Phdr
.Align
);
845 IO
.mapOptional("FileSize", Phdr
.FileSize
);
846 IO
.mapOptional("MemSize", Phdr
.MemSize
);
847 IO
.mapOptional("Offset", Phdr
.Offset
);
850 LLVM_YAML_STRONG_TYPEDEF(StringRef
, StOtherPiece
)
852 template <> struct ScalarTraits
<StOtherPiece
> {
853 static void output(const StOtherPiece
&Val
, void *, raw_ostream
&Out
) {
856 static StringRef
input(StringRef Scalar
, void *, StOtherPiece
&Val
) {
860 static QuotingType
mustQuote(StringRef
) { return QuotingType::None
; }
862 template <> struct SequenceElementTraits
<StOtherPiece
> {
863 static const bool flow
= true;
868 struct NormalizedOther
{
869 NormalizedOther(IO
&IO
) : YamlIO(IO
) {}
870 NormalizedOther(IO
&IO
, Optional
<uint8_t> Original
) : YamlIO(IO
) {
871 assert(Original
&& "This constructor is only used for outputting YAML and "
872 "assumes a non-empty Original");
873 std::vector
<StOtherPiece
> Ret
;
874 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
875 for (std::pair
<StringRef
, uint8_t> &P
:
876 getFlags(Object
->Header
.Machine
).takeVector()) {
877 uint8_t FlagValue
= P
.second
;
878 if ((*Original
& FlagValue
) != FlagValue
)
880 *Original
&= ~FlagValue
;
881 Ret
.push_back({P
.first
});
884 if (*Original
!= 0) {
885 UnknownFlagsHolder
= std::to_string(*Original
);
886 Ret
.push_back({UnknownFlagsHolder
});
890 Other
= std::move(Ret
);
893 uint8_t toValue(StringRef Name
) {
894 const auto *Object
= static_cast<ELFYAML::Object
*>(YamlIO
.getContext());
895 MapVector
<StringRef
, uint8_t> Flags
= getFlags(Object
->Header
.Machine
);
897 auto It
= Flags
.find(Name
);
898 if (It
!= Flags
.end())
902 if (to_integer(Name
, Val
))
905 YamlIO
.setError("an unknown value is used for symbol's 'Other' field: " +
910 Optional
<uint8_t> denormalize(IO
&) {
914 for (StOtherPiece
&Val
: *Other
)
919 // st_other field is used to encode symbol visibility and platform-dependent
920 // flags and values. This method returns a name to value map that is used for
921 // parsing and encoding this field.
922 MapVector
<StringRef
, uint8_t> getFlags(unsigned EMachine
) {
923 MapVector
<StringRef
, uint8_t> Map
;
924 // STV_* values are just enumeration values. We add them in a reversed order
925 // because when we convert the st_other to named constants when printing
926 // YAML we want to use a maximum number of bits on each step:
927 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
928 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
929 Map
["STV_PROTECTED"] = ELF::STV_PROTECTED
;
930 Map
["STV_HIDDEN"] = ELF::STV_HIDDEN
;
931 Map
["STV_INTERNAL"] = ELF::STV_INTERNAL
;
932 // STV_DEFAULT is used to represent the default visibility and has a value
933 // 0. We want to be able to read it from YAML documents, but there is no
934 // reason to print it.
935 if (!YamlIO
.outputting())
936 Map
["STV_DEFAULT"] = ELF::STV_DEFAULT
;
938 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
939 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
940 // consumed first when we print the output, because we do not want to print
941 // any other flags that have the same bits instead.
942 if (EMachine
== ELF::EM_MIPS
) {
943 Map
["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16
;
944 Map
["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS
;
945 Map
["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC
;
946 Map
["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT
;
947 Map
["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL
;
953 Optional
<std::vector
<StOtherPiece
>> Other
;
954 std::string UnknownFlagsHolder
;
957 } // end anonymous namespace
959 void MappingTraits
<ELFYAML::Symbol
>::mapping(IO
&IO
, ELFYAML::Symbol
&Symbol
) {
960 IO
.mapOptional("Name", Symbol
.Name
, StringRef());
961 IO
.mapOptional("NameIndex", Symbol
.NameIndex
);
962 IO
.mapOptional("Type", Symbol
.Type
, ELFYAML::ELF_STT(0));
963 IO
.mapOptional("Section", Symbol
.Section
, StringRef());
964 IO
.mapOptional("Index", Symbol
.Index
);
965 IO
.mapOptional("Binding", Symbol
.Binding
, ELFYAML::ELF_STB(0));
966 IO
.mapOptional("Value", Symbol
.Value
, Hex64(0));
967 IO
.mapOptional("Size", Symbol
.Size
, Hex64(0));
969 // Symbol's Other field is a bit special. It is usually a field that
970 // represents st_other and holds the symbol visibility. However, on some
971 // platforms, it can contain bit fields and regular values, or even sometimes a
972 // crazy mix of them (see comments for NormalizedOther). Because of this, we
973 // need special handling.
974 MappingNormalization
<NormalizedOther
, Optional
<uint8_t>> Keys(IO
,
976 IO
.mapOptional("Other", Keys
->Other
);
979 StringRef MappingTraits
<ELFYAML::Symbol
>::validate(IO
&IO
,
980 ELFYAML::Symbol
&Symbol
) {
981 if (Symbol
.Index
&& Symbol
.Section
.data())
982 return "Index and Section cannot both be specified for Symbol";
983 if (Symbol
.NameIndex
&& !Symbol
.Name
.empty())
984 return "Name and NameIndex cannot both be specified for Symbol";
988 static void commonSectionMapping(IO
&IO
, ELFYAML::Section
&Section
) {
989 IO
.mapOptional("Name", Section
.Name
, StringRef());
990 IO
.mapRequired("Type", Section
.Type
);
991 IO
.mapOptional("Flags", Section
.Flags
);
992 IO
.mapOptional("Address", Section
.Address
, Hex64(0));
993 IO
.mapOptional("Link", Section
.Link
, StringRef());
994 IO
.mapOptional("AddressAlign", Section
.AddressAlign
, Hex64(0));
995 IO
.mapOptional("EntSize", Section
.EntSize
);
997 // obj2yaml does not dump these fields. They are expected to be empty when we
998 // are producing YAML, because yaml2obj sets appropriate values for them
999 // automatically when they are not explicitly defined.
1000 assert(!IO
.outputting() ||
1001 (!Section
.ShOffset
.hasValue() && !Section
.ShSize
.hasValue()));
1002 IO
.mapOptional("ShName", Section
.ShName
);
1003 IO
.mapOptional("ShOffset", Section
.ShOffset
);
1004 IO
.mapOptional("ShSize", Section
.ShSize
);
1007 static void sectionMapping(IO
&IO
, ELFYAML::DynamicSection
&Section
) {
1008 commonSectionMapping(IO
, Section
);
1009 IO
.mapOptional("Entries", Section
.Entries
);
1010 IO
.mapOptional("Content", Section
.Content
);
1013 static void sectionMapping(IO
&IO
, ELFYAML::RawContentSection
&Section
) {
1014 commonSectionMapping(IO
, Section
);
1015 IO
.mapOptional("Content", Section
.Content
);
1016 IO
.mapOptional("Size", Section
.Size
);
1017 IO
.mapOptional("Info", Section
.Info
);
1020 static void sectionMapping(IO
&IO
, ELFYAML::StackSizesSection
&Section
) {
1021 commonSectionMapping(IO
, Section
);
1022 IO
.mapOptional("Content", Section
.Content
);
1023 IO
.mapOptional("Size", Section
.Size
);
1024 IO
.mapOptional("Entries", Section
.Entries
);
1027 static void sectionMapping(IO
&IO
, ELFYAML::HashSection
&Section
) {
1028 commonSectionMapping(IO
, Section
);
1029 IO
.mapOptional("Content", Section
.Content
);
1030 IO
.mapOptional("Bucket", Section
.Bucket
);
1031 IO
.mapOptional("Chain", Section
.Chain
);
1032 IO
.mapOptional("Size", Section
.Size
);
1035 static void sectionMapping(IO
&IO
, ELFYAML::NoBitsSection
&Section
) {
1036 commonSectionMapping(IO
, Section
);
1037 IO
.mapOptional("Size", Section
.Size
, Hex64(0));
1040 static void sectionMapping(IO
&IO
, ELFYAML::VerdefSection
&Section
) {
1041 commonSectionMapping(IO
, Section
);
1042 IO
.mapRequired("Info", Section
.Info
);
1043 IO
.mapRequired("Entries", Section
.Entries
);
1046 static void sectionMapping(IO
&IO
, ELFYAML::SymverSection
&Section
) {
1047 commonSectionMapping(IO
, Section
);
1048 IO
.mapRequired("Entries", Section
.Entries
);
1051 static void sectionMapping(IO
&IO
, ELFYAML::VerneedSection
&Section
) {
1052 commonSectionMapping(IO
, Section
);
1053 IO
.mapRequired("Info", Section
.Info
);
1054 IO
.mapRequired("Dependencies", Section
.VerneedV
);
1057 static void sectionMapping(IO
&IO
, ELFYAML::RelocationSection
&Section
) {
1058 commonSectionMapping(IO
, Section
);
1059 IO
.mapOptional("Info", Section
.RelocatableSec
, StringRef());
1060 IO
.mapOptional("Relocations", Section
.Relocations
);
1063 static void groupSectionMapping(IO
&IO
, ELFYAML::Group
&Group
) {
1064 commonSectionMapping(IO
, Group
);
1065 IO
.mapOptional("Info", Group
.Signature
, StringRef());
1066 IO
.mapRequired("Members", Group
.Members
);
1069 static void sectionMapping(IO
&IO
, ELFYAML::SymtabShndxSection
&Section
) {
1070 commonSectionMapping(IO
, Section
);
1071 IO
.mapRequired("Entries", Section
.Entries
);
1074 static void sectionMapping(IO
&IO
, ELFYAML::AddrsigSection
&Section
) {
1075 commonSectionMapping(IO
, Section
);
1076 IO
.mapOptional("Content", Section
.Content
);
1077 IO
.mapOptional("Size", Section
.Size
);
1078 IO
.mapOptional("Symbols", Section
.Symbols
);
1081 void MappingTraits
<ELFYAML::SectionOrType
>::mapping(
1082 IO
&IO
, ELFYAML::SectionOrType
§ionOrType
) {
1083 IO
.mapRequired("SectionOrType", sectionOrType
.sectionNameOrType
);
1086 void MappingTraits
<ELFYAML::SectionName
>::mapping(
1087 IO
&IO
, ELFYAML::SectionName
§ionName
) {
1088 IO
.mapRequired("Section", sectionName
.Section
);
1091 static void sectionMapping(IO
&IO
, ELFYAML::MipsABIFlags
&Section
) {
1092 commonSectionMapping(IO
, Section
);
1093 IO
.mapOptional("Version", Section
.Version
, Hex16(0));
1094 IO
.mapRequired("ISA", Section
.ISALevel
);
1095 IO
.mapOptional("ISARevision", Section
.ISARevision
, Hex8(0));
1096 IO
.mapOptional("ISAExtension", Section
.ISAExtension
,
1097 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE
));
1098 IO
.mapOptional("ASEs", Section
.ASEs
, ELFYAML::MIPS_AFL_ASE(0));
1099 IO
.mapOptional("FpABI", Section
.FpABI
,
1100 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY
));
1101 IO
.mapOptional("GPRSize", Section
.GPRSize
,
1102 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1103 IO
.mapOptional("CPR1Size", Section
.CPR1Size
,
1104 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1105 IO
.mapOptional("CPR2Size", Section
.CPR2Size
,
1106 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE
));
1107 IO
.mapOptional("Flags1", Section
.Flags1
, ELFYAML::MIPS_AFL_FLAGS1(0));
1108 IO
.mapOptional("Flags2", Section
.Flags2
, Hex32(0));
1111 void MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::mapping(
1112 IO
&IO
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
1113 ELFYAML::ELF_SHT sectionType
;
1114 if (IO
.outputting())
1115 sectionType
= Section
->Type
;
1117 IO
.mapRequired("Type", sectionType
);
1119 switch (sectionType
) {
1120 case ELF::SHT_DYNAMIC
:
1121 if (!IO
.outputting())
1122 Section
.reset(new ELFYAML::DynamicSection());
1123 sectionMapping(IO
, *cast
<ELFYAML::DynamicSection
>(Section
.get()));
1127 if (!IO
.outputting())
1128 Section
.reset(new ELFYAML::RelocationSection());
1129 sectionMapping(IO
, *cast
<ELFYAML::RelocationSection
>(Section
.get()));
1131 case ELF::SHT_GROUP
:
1132 if (!IO
.outputting())
1133 Section
.reset(new ELFYAML::Group());
1134 groupSectionMapping(IO
, *cast
<ELFYAML::Group
>(Section
.get()));
1136 case ELF::SHT_NOBITS
:
1137 if (!IO
.outputting())
1138 Section
.reset(new ELFYAML::NoBitsSection());
1139 sectionMapping(IO
, *cast
<ELFYAML::NoBitsSection
>(Section
.get()));
1142 if (!IO
.outputting())
1143 Section
.reset(new ELFYAML::HashSection());
1144 sectionMapping(IO
, *cast
<ELFYAML::HashSection
>(Section
.get()));
1146 case ELF::SHT_MIPS_ABIFLAGS
:
1147 if (!IO
.outputting())
1148 Section
.reset(new ELFYAML::MipsABIFlags());
1149 sectionMapping(IO
, *cast
<ELFYAML::MipsABIFlags
>(Section
.get()));
1151 case ELF::SHT_GNU_verdef
:
1152 if (!IO
.outputting())
1153 Section
.reset(new ELFYAML::VerdefSection());
1154 sectionMapping(IO
, *cast
<ELFYAML::VerdefSection
>(Section
.get()));
1156 case ELF::SHT_GNU_versym
:
1157 if (!IO
.outputting())
1158 Section
.reset(new ELFYAML::SymverSection());
1159 sectionMapping(IO
, *cast
<ELFYAML::SymverSection
>(Section
.get()));
1161 case ELF::SHT_GNU_verneed
:
1162 if (!IO
.outputting())
1163 Section
.reset(new ELFYAML::VerneedSection());
1164 sectionMapping(IO
, *cast
<ELFYAML::VerneedSection
>(Section
.get()));
1166 case ELF::SHT_SYMTAB_SHNDX
:
1167 if (!IO
.outputting())
1168 Section
.reset(new ELFYAML::SymtabShndxSection());
1169 sectionMapping(IO
, *cast
<ELFYAML::SymtabShndxSection
>(Section
.get()));
1171 case ELF::SHT_LLVM_ADDRSIG
:
1172 if (!IO
.outputting())
1173 Section
.reset(new ELFYAML::AddrsigSection());
1174 sectionMapping(IO
, *cast
<ELFYAML::AddrsigSection
>(Section
.get()));
1177 if (!IO
.outputting()) {
1179 IO
.mapOptional("Name", Name
, StringRef());
1180 Name
= ELFYAML::dropUniqueSuffix(Name
);
1182 if (ELFYAML::StackSizesSection::nameMatches(Name
))
1183 Section
= std::make_unique
<ELFYAML::StackSizesSection
>();
1185 Section
= std::make_unique
<ELFYAML::RawContentSection
>();
1188 if (auto S
= dyn_cast
<ELFYAML::RawContentSection
>(Section
.get()))
1189 sectionMapping(IO
, *S
);
1191 sectionMapping(IO
, *cast
<ELFYAML::StackSizesSection
>(Section
.get()));
1195 StringRef MappingTraits
<std::unique_ptr
<ELFYAML::Section
>>::validate(
1196 IO
&io
, std::unique_ptr
<ELFYAML::Section
> &Section
) {
1197 if (const auto *RawSection
=
1198 dyn_cast
<ELFYAML::RawContentSection
>(Section
.get())) {
1199 if (RawSection
->Size
&& RawSection
->Content
&&
1200 (uint64_t)(*RawSection
->Size
) < RawSection
->Content
->binary_size())
1201 return "Section size must be greater than or equal to the content size";
1205 if (const auto *SS
= dyn_cast
<ELFYAML::StackSizesSection
>(Section
.get())) {
1206 if (!SS
->Entries
&& !SS
->Content
&& !SS
->Size
)
1207 return ".stack_sizes: one of Content, Entries and Size must be specified";
1209 if (SS
->Size
&& SS
->Content
&&
1210 (uint64_t)(*SS
->Size
) < SS
->Content
->binary_size())
1211 return ".stack_sizes: Size must be greater than or equal to the content "
1214 // We accept Content, Size or both together when there are no Entries.
1219 return ".stack_sizes: Size and Entries cannot be used together";
1221 return ".stack_sizes: Content and Entries cannot be used together";
1225 if (const auto *HS
= dyn_cast
<ELFYAML::HashSection
>(Section
.get())) {
1226 if (!HS
->Content
&& !HS
->Bucket
&& !HS
->Chain
&& !HS
->Size
)
1227 return "one of \"Content\", \"Size\", \"Bucket\" or \"Chain\" must be "
1230 if (HS
->Content
|| HS
->Size
) {
1231 if (HS
->Size
&& HS
->Content
&&
1232 (uint64_t)*HS
->Size
< HS
->Content
->binary_size())
1233 return "\"Size\" must be greater than or equal to the content "
1237 return "\"Bucket\" cannot be used with \"Content\" or \"Size\"";
1239 return "\"Chain\" cannot be used with \"Content\" or \"Size\"";
1243 if ((HS
->Bucket
&& !HS
->Chain
) || (!HS
->Bucket
&& HS
->Chain
))
1244 return "\"Bucket\" and \"Chain\" must be used together";
1248 if (const auto *Sec
= dyn_cast
<ELFYAML::AddrsigSection
>(Section
.get())) {
1249 if (!Sec
->Symbols
&& !Sec
->Content
&& !Sec
->Size
)
1250 return "one of \"Content\", \"Size\" or \"Symbols\" must be specified";
1252 if (Sec
->Content
|| Sec
->Size
) {
1253 if (Sec
->Size
&& Sec
->Content
&&
1254 (uint64_t)*Sec
->Size
< Sec
->Content
->binary_size())
1255 return "\"Size\" must be greater than or equal to the content "
1259 return "\"Symbols\" cannot be used with \"Content\" or \"Size\"";
1266 for (const ELFYAML::AddrsigSymbol
&AS
: *Sec
->Symbols
)
1267 if (AS
.Index
&& AS
.Name
)
1268 return "\"Index\" and \"Name\" cannot be used together when defining a "
1278 struct NormalizedMips64RelType
{
1279 NormalizedMips64RelType(IO
&)
1280 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1281 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1282 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE
)),
1283 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF
)) {}
1284 NormalizedMips64RelType(IO
&, ELFYAML::ELF_REL Original
)
1285 : Type(Original
& 0xFF), Type2(Original
>> 8 & 0xFF),
1286 Type3(Original
>> 16 & 0xFF), SpecSym(Original
>> 24 & 0xFF) {}
1288 ELFYAML::ELF_REL
denormalize(IO
&) {
1289 ELFYAML::ELF_REL Res
= Type
| Type2
<< 8 | Type3
<< 16 | SpecSym
<< 24;
1293 ELFYAML::ELF_REL Type
;
1294 ELFYAML::ELF_REL Type2
;
1295 ELFYAML::ELF_REL Type3
;
1296 ELFYAML::ELF_RSS SpecSym
;
1299 } // end anonymous namespace
1301 void MappingTraits
<ELFYAML::StackSizeEntry
>::mapping(
1302 IO
&IO
, ELFYAML::StackSizeEntry
&E
) {
1303 assert(IO
.getContext() && "The IO context is not initialized");
1304 IO
.mapOptional("Address", E
.Address
, Hex64(0));
1305 IO
.mapRequired("Size", E
.Size
);
1308 void MappingTraits
<ELFYAML::DynamicEntry
>::mapping(IO
&IO
,
1309 ELFYAML::DynamicEntry
&Rel
) {
1310 assert(IO
.getContext() && "The IO context is not initialized");
1312 IO
.mapRequired("Tag", Rel
.Tag
);
1313 IO
.mapRequired("Value", Rel
.Val
);
1316 void MappingTraits
<ELFYAML::VerdefEntry
>::mapping(IO
&IO
,
1317 ELFYAML::VerdefEntry
&E
) {
1318 assert(IO
.getContext() && "The IO context is not initialized");
1320 IO
.mapRequired("Version", E
.Version
);
1321 IO
.mapRequired("Flags", E
.Flags
);
1322 IO
.mapRequired("VersionNdx", E
.VersionNdx
);
1323 IO
.mapRequired("Hash", E
.Hash
);
1324 IO
.mapRequired("Names", E
.VerNames
);
1327 void MappingTraits
<ELFYAML::VerneedEntry
>::mapping(IO
&IO
,
1328 ELFYAML::VerneedEntry
&E
) {
1329 assert(IO
.getContext() && "The IO context is not initialized");
1331 IO
.mapRequired("Version", E
.Version
);
1332 IO
.mapRequired("File", E
.File
);
1333 IO
.mapRequired("Entries", E
.AuxV
);
1336 void MappingTraits
<ELFYAML::VernauxEntry
>::mapping(IO
&IO
,
1337 ELFYAML::VernauxEntry
&E
) {
1338 assert(IO
.getContext() && "The IO context is not initialized");
1340 IO
.mapRequired("Name", E
.Name
);
1341 IO
.mapRequired("Hash", E
.Hash
);
1342 IO
.mapRequired("Flags", E
.Flags
);
1343 IO
.mapRequired("Other", E
.Other
);
1346 void MappingTraits
<ELFYAML::Relocation
>::mapping(IO
&IO
,
1347 ELFYAML::Relocation
&Rel
) {
1348 const auto *Object
= static_cast<ELFYAML::Object
*>(IO
.getContext());
1349 assert(Object
&& "The IO context is not initialized");
1351 IO
.mapRequired("Offset", Rel
.Offset
);
1352 IO
.mapOptional("Symbol", Rel
.Symbol
);
1354 if (Object
->Header
.Machine
== ELFYAML::ELF_EM(ELF::EM_MIPS
) &&
1355 Object
->Header
.Class
== ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64
)) {
1356 MappingNormalization
<NormalizedMips64RelType
, ELFYAML::ELF_REL
> Key(
1358 IO
.mapRequired("Type", Key
->Type
);
1359 IO
.mapOptional("Type2", Key
->Type2
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1360 IO
.mapOptional("Type3", Key
->Type3
, ELFYAML::ELF_REL(ELF::R_MIPS_NONE
));
1361 IO
.mapOptional("SpecSym", Key
->SpecSym
, ELFYAML::ELF_RSS(ELF::RSS_UNDEF
));
1363 IO
.mapRequired("Type", Rel
.Type
);
1365 IO
.mapOptional("Addend", Rel
.Addend
, (int64_t)0);
1368 void MappingTraits
<ELFYAML::Object
>::mapping(IO
&IO
, ELFYAML::Object
&Object
) {
1369 assert(!IO
.getContext() && "The IO context is initialized already");
1370 IO
.setContext(&Object
);
1371 IO
.mapTag("!ELF", true);
1372 IO
.mapRequired("FileHeader", Object
.Header
);
1373 IO
.mapOptional("ProgramHeaders", Object
.ProgramHeaders
);
1374 IO
.mapOptional("Sections", Object
.Sections
);
1375 IO
.mapOptional("Symbols", Object
.Symbols
);
1376 IO
.mapOptional("DynamicSymbols", Object
.DynamicSymbols
);
1377 IO
.setContext(nullptr);
1380 void MappingTraits
<ELFYAML::AddrsigSymbol
>::mapping(IO
&IO
, ELFYAML::AddrsigSymbol
&Sym
) {
1381 assert(IO
.getContext() && "The IO context is not initialized");
1382 IO
.mapOptional("Name", Sym
.Name
);
1383 IO
.mapOptional("Index", Sym
.Index
);
1386 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG
)
1387 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP
)
1388 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT
)
1389 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE
)
1390 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1
)
1392 } // end namespace yaml
1394 } // end namespace llvm