LLVM 20.0.0git
ELFYAML.cpp
Go to the documentation of this file.
1//===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines classes for handling the YAML representation of ELF.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/APInt.h"
15#include "llvm/ADT/MapVector.h"
16#include "llvm/ADT/StringRef.h"
24#include <cassert>
25#include <cstdint>
26#include <optional>
27
28namespace llvm {
29
30ELFYAML::Chunk::~Chunk() = default;
31
32namespace ELFYAML {
33ELF_ELFOSABI Object::getOSAbi() const { return Header.OSABI; }
34
35unsigned Object::getMachine() const {
36 if (Header.Machine)
37 return *Header.Machine;
38 return llvm::ELF::EM_NONE;
39}
40
42} // namespace ELFYAML
43
44namespace yaml {
45
46void ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(
47 IO &IO, ELFYAML::ELF_ET &Value) {
48#define ECase(X) IO.enumCase(Value, #X, ELF::X)
49 ECase(ET_NONE);
50 ECase(ET_REL);
51 ECase(ET_EXEC);
52 ECase(ET_DYN);
53 ECase(ET_CORE);
54#undef ECase
55 IO.enumFallback<Hex16>(Value);
56}
57
58void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration(
59 IO &IO, ELFYAML::ELF_PT &Value) {
60#define ECase(X) IO.enumCase(Value, #X, ELF::X)
61 ECase(PT_NULL);
62 ECase(PT_LOAD);
63 ECase(PT_DYNAMIC);
64 ECase(PT_INTERP);
65 ECase(PT_NOTE);
66 ECase(PT_SHLIB);
67 ECase(PT_PHDR);
68 ECase(PT_TLS);
69 ECase(PT_GNU_EH_FRAME);
70 ECase(PT_GNU_STACK);
71 ECase(PT_GNU_RELRO);
72 ECase(PT_GNU_PROPERTY);
73#undef ECase
74 IO.enumFallback<Hex32>(Value);
75}
76
77void ScalarEnumerationTraits<ELFYAML::ELF_NT>::enumeration(
78 IO &IO, ELFYAML::ELF_NT &Value) {
79#define ECase(X) IO.enumCase(Value, #X, ELF::X)
80 // Generic note types.
81 ECase(NT_VERSION);
82 ECase(NT_ARCH);
83 ECase(NT_GNU_BUILD_ATTRIBUTE_OPEN);
84 ECase(NT_GNU_BUILD_ATTRIBUTE_FUNC);
85 // Core note types.
86 ECase(NT_PRSTATUS);
87 ECase(NT_FPREGSET);
88 ECase(NT_PRPSINFO);
89 ECase(NT_TASKSTRUCT);
90 ECase(NT_AUXV);
91 ECase(NT_PSTATUS);
92 ECase(NT_FPREGS);
93 ECase(NT_PSINFO);
94 ECase(NT_LWPSTATUS);
95 ECase(NT_LWPSINFO);
96 ECase(NT_WIN32PSTATUS);
97 ECase(NT_PPC_VMX);
98 ECase(NT_PPC_VSX);
99 ECase(NT_PPC_TAR);
100 ECase(NT_PPC_PPR);
101 ECase(NT_PPC_DSCR);
102 ECase(NT_PPC_EBB);
103 ECase(NT_PPC_PMU);
104 ECase(NT_PPC_TM_CGPR);
105 ECase(NT_PPC_TM_CFPR);
106 ECase(NT_PPC_TM_CVMX);
107 ECase(NT_PPC_TM_CVSX);
108 ECase(NT_PPC_TM_SPR);
109 ECase(NT_PPC_TM_CTAR);
110 ECase(NT_PPC_TM_CPPR);
111 ECase(NT_PPC_TM_CDSCR);
112 ECase(NT_386_TLS);
113 ECase(NT_386_IOPERM);
114 ECase(NT_X86_XSTATE);
115 ECase(NT_S390_HIGH_GPRS);
116 ECase(NT_S390_TIMER);
117 ECase(NT_S390_TODCMP);
118 ECase(NT_S390_TODPREG);
119 ECase(NT_S390_CTRS);
120 ECase(NT_S390_PREFIX);
121 ECase(NT_S390_LAST_BREAK);
122 ECase(NT_S390_SYSTEM_CALL);
123 ECase(NT_S390_TDB);
124 ECase(NT_S390_VXRS_LOW);
125 ECase(NT_S390_VXRS_HIGH);
126 ECase(NT_S390_GS_CB);
127 ECase(NT_S390_GS_BC);
128 ECase(NT_ARM_VFP);
129 ECase(NT_ARM_TLS);
130 ECase(NT_ARM_HW_BREAK);
131 ECase(NT_ARM_HW_WATCH);
132 ECase(NT_ARM_SVE);
133 ECase(NT_ARM_PAC_MASK);
134 ECase(NT_ARM_TAGGED_ADDR_CTRL);
135 ECase(NT_ARM_SSVE);
136 ECase(NT_ARM_ZA);
137 ECase(NT_ARM_ZT);
138 ECase(NT_ARM_FPMR);
139 ECase(NT_ARM_GCS);
140 ECase(NT_FILE);
141 ECase(NT_PRXFPREG);
142 ECase(NT_SIGINFO);
143 // LLVM-specific notes.
144 ECase(NT_LLVM_HWASAN_GLOBALS);
145 // GNU note types
146 ECase(NT_GNU_ABI_TAG);
147 ECase(NT_GNU_HWCAP);
148 ECase(NT_GNU_BUILD_ID);
149 ECase(NT_GNU_GOLD_VERSION);
150 ECase(NT_GNU_PROPERTY_TYPE_0);
151 // FreeBSD note types.
152 ECase(NT_FREEBSD_ABI_TAG);
153 ECase(NT_FREEBSD_NOINIT_TAG);
154 ECase(NT_FREEBSD_ARCH_TAG);
155 ECase(NT_FREEBSD_FEATURE_CTL);
156 // FreeBSD core note types.
157 ECase(NT_FREEBSD_THRMISC);
158 ECase(NT_FREEBSD_PROCSTAT_PROC);
159 ECase(NT_FREEBSD_PROCSTAT_FILES);
160 ECase(NT_FREEBSD_PROCSTAT_VMMAP);
161 ECase(NT_FREEBSD_PROCSTAT_GROUPS);
162 ECase(NT_FREEBSD_PROCSTAT_UMASK);
163 ECase(NT_FREEBSD_PROCSTAT_RLIMIT);
164 ECase(NT_FREEBSD_PROCSTAT_OSREL);
165 ECase(NT_FREEBSD_PROCSTAT_PSSTRINGS);
166 ECase(NT_FREEBSD_PROCSTAT_AUXV);
167 // NetBSD core note types.
168 ECase(NT_NETBSDCORE_PROCINFO);
169 ECase(NT_NETBSDCORE_AUXV);
170 ECase(NT_NETBSDCORE_LWPSTATUS);
171 // OpenBSD core note types.
172 ECase(NT_OPENBSD_PROCINFO);
173 ECase(NT_OPENBSD_AUXV);
174 ECase(NT_OPENBSD_REGS);
175 ECase(NT_OPENBSD_FPREGS);
176 ECase(NT_OPENBSD_XFPREGS);
177 ECase(NT_OPENBSD_WCOOKIE);
178 // AMD specific notes. (Code Object V2)
179 ECase(NT_AMD_HSA_CODE_OBJECT_VERSION);
180 ECase(NT_AMD_HSA_HSAIL);
181 ECase(NT_AMD_HSA_ISA_VERSION);
182 ECase(NT_AMD_HSA_METADATA);
183 ECase(NT_AMD_HSA_ISA_NAME);
184 ECase(NT_AMD_PAL_METADATA);
185 // AMDGPU specific notes. (Code Object V3)
186 ECase(NT_AMDGPU_METADATA);
187 // Android specific notes.
188 ECase(NT_ANDROID_TYPE_IDENT);
189 ECase(NT_ANDROID_TYPE_KUSER);
190 ECase(NT_ANDROID_TYPE_MEMTAG);
191#undef ECase
192 IO.enumFallback<Hex32>(Value);
193}
194
195void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(
196 IO &IO, ELFYAML::ELF_EM &Value) {
197#define ECase(X) IO.enumCase(Value, #X, ELF::X)
198 ECase(EM_NONE);
199 ECase(EM_M32);
200 ECase(EM_SPARC);
201 ECase(EM_386);
202 ECase(EM_68K);
203 ECase(EM_88K);
204 ECase(EM_IAMCU);
205 ECase(EM_860);
206 ECase(EM_MIPS);
207 ECase(EM_S370);
208 ECase(EM_MIPS_RS3_LE);
209 ECase(EM_PARISC);
210 ECase(EM_VPP500);
211 ECase(EM_SPARC32PLUS);
212 ECase(EM_960);
213 ECase(EM_PPC);
214 ECase(EM_PPC64);
215 ECase(EM_S390);
216 ECase(EM_SPU);
217 ECase(EM_V800);
218 ECase(EM_FR20);
219 ECase(EM_RH32);
220 ECase(EM_RCE);
221 ECase(EM_ARM);
222 ECase(EM_ALPHA);
223 ECase(EM_SH);
224 ECase(EM_SPARCV9);
225 ECase(EM_TRICORE);
226 ECase(EM_ARC);
227 ECase(EM_H8_300);
228 ECase(EM_H8_300H);
229 ECase(EM_H8S);
230 ECase(EM_H8_500);
231 ECase(EM_IA_64);
232 ECase(EM_MIPS_X);
233 ECase(EM_COLDFIRE);
234 ECase(EM_68HC12);
235 ECase(EM_MMA);
236 ECase(EM_PCP);
237 ECase(EM_NCPU);
238 ECase(EM_NDR1);
239 ECase(EM_STARCORE);
240 ECase(EM_ME16);
241 ECase(EM_ST100);
242 ECase(EM_TINYJ);
243 ECase(EM_X86_64);
244 ECase(EM_PDSP);
245 ECase(EM_PDP10);
246 ECase(EM_PDP11);
247 ECase(EM_FX66);
248 ECase(EM_ST9PLUS);
249 ECase(EM_ST7);
250 ECase(EM_68HC16);
251 ECase(EM_68HC11);
252 ECase(EM_68HC08);
253 ECase(EM_68HC05);
254 ECase(EM_SVX);
255 ECase(EM_ST19);
256 ECase(EM_VAX);
257 ECase(EM_CRIS);
258 ECase(EM_JAVELIN);
259 ECase(EM_FIREPATH);
260 ECase(EM_ZSP);
261 ECase(EM_MMIX);
262 ECase(EM_HUANY);
263 ECase(EM_PRISM);
264 ECase(EM_AVR);
265 ECase(EM_FR30);
266 ECase(EM_D10V);
267 ECase(EM_D30V);
268 ECase(EM_V850);
269 ECase(EM_M32R);
270 ECase(EM_MN10300);
271 ECase(EM_MN10200);
272 ECase(EM_PJ);
273 ECase(EM_OPENRISC);
274 ECase(EM_ARC_COMPACT);
275 ECase(EM_XTENSA);
276 ECase(EM_VIDEOCORE);
277 ECase(EM_TMM_GPP);
278 ECase(EM_NS32K);
279 ECase(EM_TPC);
280 ECase(EM_SNP1K);
281 ECase(EM_ST200);
282 ECase(EM_IP2K);
283 ECase(EM_MAX);
284 ECase(EM_CR);
285 ECase(EM_F2MC16);
286 ECase(EM_MSP430);
287 ECase(EM_BLACKFIN);
288 ECase(EM_SE_C33);
289 ECase(EM_SEP);
290 ECase(EM_ARCA);
291 ECase(EM_UNICORE);
292 ECase(EM_EXCESS);
293 ECase(EM_DXP);
294 ECase(EM_ALTERA_NIOS2);
295 ECase(EM_CRX);
296 ECase(EM_XGATE);
297 ECase(EM_C166);
298 ECase(EM_M16C);
299 ECase(EM_DSPIC30F);
300 ECase(EM_CE);
301 ECase(EM_M32C);
302 ECase(EM_TSK3000);
303 ECase(EM_RS08);
304 ECase(EM_SHARC);
305 ECase(EM_ECOG2);
306 ECase(EM_SCORE7);
307 ECase(EM_DSP24);
308 ECase(EM_VIDEOCORE3);
309 ECase(EM_LATTICEMICO32);
310 ECase(EM_SE_C17);
311 ECase(EM_TI_C6000);
312 ECase(EM_TI_C2000);
313 ECase(EM_TI_C5500);
314 ECase(EM_MMDSP_PLUS);
315 ECase(EM_CYPRESS_M8C);
316 ECase(EM_R32C);
317 ECase(EM_TRIMEDIA);
318 ECase(EM_HEXAGON);
319 ECase(EM_8051);
320 ECase(EM_STXP7X);
321 ECase(EM_NDS32);
322 ECase(EM_ECOG1);
323 ECase(EM_ECOG1X);
324 ECase(EM_MAXQ30);
325 ECase(EM_XIMO16);
326 ECase(EM_MANIK);
327 ECase(EM_CRAYNV2);
328 ECase(EM_RX);
329 ECase(EM_METAG);
330 ECase(EM_MCST_ELBRUS);
331 ECase(EM_ECOG16);
332 ECase(EM_CR16);
333 ECase(EM_ETPU);
334 ECase(EM_SLE9X);
335 ECase(EM_L10M);
336 ECase(EM_K10M);
337 ECase(EM_AARCH64);
338 ECase(EM_AVR32);
339 ECase(EM_STM8);
340 ECase(EM_TILE64);
341 ECase(EM_TILEPRO);
342 ECase(EM_MICROBLAZE);
343 ECase(EM_CUDA);
344 ECase(EM_TILEGX);
345 ECase(EM_CLOUDSHIELD);
346 ECase(EM_COREA_1ST);
347 ECase(EM_COREA_2ND);
348 ECase(EM_ARC_COMPACT2);
349 ECase(EM_OPEN8);
350 ECase(EM_RL78);
351 ECase(EM_VIDEOCORE5);
352 ECase(EM_78KOR);
353 ECase(EM_56800EX);
354 ECase(EM_AMDGPU);
355 ECase(EM_RISCV);
356 ECase(EM_LANAI);
357 ECase(EM_BPF);
358 ECase(EM_VE);
359 ECase(EM_CSKY);
360 ECase(EM_LOONGARCH);
361#undef ECase
362 IO.enumFallback<Hex16>(Value);
363}
364
365void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration(
366 IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
367#define ECase(X) IO.enumCase(Value, #X, ELF::X)
368 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
369 // here.
370 ECase(ELFCLASS32);
371 ECase(ELFCLASS64);
372#undef ECase
373}
374
375void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
376 IO &IO, ELFYAML::ELF_ELFDATA &Value) {
377#define ECase(X) IO.enumCase(Value, #X, ELF::X)
378 // ELFDATANONE is an invalid data encoding, but we accept it because
379 // we want to be able to produce invalid binaries for the tests.
380 ECase(ELFDATANONE);
381 ECase(ELFDATA2LSB);
382 ECase(ELFDATA2MSB);
383#undef ECase
384}
385
386void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
387 IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
388#define ECase(X) IO.enumCase(Value, #X, ELF::X)
389 ECase(ELFOSABI_NONE);
390 ECase(ELFOSABI_HPUX);
391 ECase(ELFOSABI_NETBSD);
392 ECase(ELFOSABI_GNU);
393 ECase(ELFOSABI_LINUX);
394 ECase(ELFOSABI_HURD);
395 ECase(ELFOSABI_SOLARIS);
396 ECase(ELFOSABI_AIX);
397 ECase(ELFOSABI_IRIX);
398 ECase(ELFOSABI_FREEBSD);
399 ECase(ELFOSABI_TRU64);
400 ECase(ELFOSABI_MODESTO);
401 ECase(ELFOSABI_OPENBSD);
402 ECase(ELFOSABI_OPENVMS);
403 ECase(ELFOSABI_NSK);
404 ECase(ELFOSABI_AROS);
405 ECase(ELFOSABI_FENIXOS);
406 ECase(ELFOSABI_CLOUDABI);
407 ECase(ELFOSABI_AMDGPU_HSA);
408 ECase(ELFOSABI_AMDGPU_PAL);
409 ECase(ELFOSABI_AMDGPU_MESA3D);
410 ECase(ELFOSABI_ARM);
411 ECase(ELFOSABI_ARM_FDPIC);
412 ECase(ELFOSABI_C6000_ELFABI);
413 ECase(ELFOSABI_C6000_LINUX);
414 ECase(ELFOSABI_STANDALONE);
415#undef ECase
416 IO.enumFallback<Hex8>(Value);
417}
418
419void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
420 ELFYAML::ELF_EF &Value) {
421 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
422 assert(Object && "The IO context is not initialized");
423#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
424#define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
425 switch (Object->getMachine()) {
426 case ELF::EM_ARM:
427 BCase(EF_ARM_SOFT_FLOAT);
428 BCase(EF_ARM_VFP_FLOAT);
429 BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK);
430 BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK);
431 BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK);
432 BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK);
433 BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK);
434 BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK);
435 BCaseMask(EF_ARM_BE8, EF_ARM_BE8);
436 break;
437 case ELF::EM_MIPS:
438 BCase(EF_MIPS_NOREORDER);
439 BCase(EF_MIPS_PIC);
440 BCase(EF_MIPS_CPIC);
441 BCase(EF_MIPS_ABI2);
442 BCase(EF_MIPS_32BITMODE);
443 BCase(EF_MIPS_FP64);
444 BCase(EF_MIPS_NAN2008);
445 BCase(EF_MIPS_MICROMIPS);
446 BCase(EF_MIPS_ARCH_ASE_M16);
447 BCase(EF_MIPS_ARCH_ASE_MDMX);
448 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI);
449 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI);
450 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI);
451 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI);
452 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH);
453 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH);
454 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH);
455 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH);
456 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH);
457 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH);
458 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH);
459 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH);
460 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH);
461 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH);
462 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH);
463 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH);
464 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH);
465 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH);
466 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH);
467 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH);
468 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH);
469 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH);
470 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH);
471 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH);
472 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH);
473 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH);
474 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH);
475 BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH);
476 BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH);
477 BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH);
478 BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH);
479 BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH);
480 BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH);
481 break;
482 case ELF::EM_HEXAGON:
483 BCaseMask(EF_HEXAGON_MACH_V2, EF_HEXAGON_MACH);
484 BCaseMask(EF_HEXAGON_MACH_V3, EF_HEXAGON_MACH);
485 BCaseMask(EF_HEXAGON_MACH_V4, EF_HEXAGON_MACH);
486 BCaseMask(EF_HEXAGON_MACH_V5, EF_HEXAGON_MACH);
487 BCaseMask(EF_HEXAGON_MACH_V55, EF_HEXAGON_MACH);
488 BCaseMask(EF_HEXAGON_MACH_V60, EF_HEXAGON_MACH);
489 BCaseMask(EF_HEXAGON_MACH_V62, EF_HEXAGON_MACH);
490 BCaseMask(EF_HEXAGON_MACH_V65, EF_HEXAGON_MACH);
491 BCaseMask(EF_HEXAGON_MACH_V66, EF_HEXAGON_MACH);
492 BCaseMask(EF_HEXAGON_MACH_V67, EF_HEXAGON_MACH);
493 BCaseMask(EF_HEXAGON_MACH_V67T, EF_HEXAGON_MACH);
494 BCaseMask(EF_HEXAGON_MACH_V68, EF_HEXAGON_MACH);
495 BCaseMask(EF_HEXAGON_MACH_V69, EF_HEXAGON_MACH);
496 BCaseMask(EF_HEXAGON_MACH_V71, EF_HEXAGON_MACH);
497 BCaseMask(EF_HEXAGON_MACH_V71T, EF_HEXAGON_MACH);
498 BCaseMask(EF_HEXAGON_MACH_V73, EF_HEXAGON_MACH);
499 BCaseMask(EF_HEXAGON_ISA_V2, EF_HEXAGON_ISA);
500 BCaseMask(EF_HEXAGON_ISA_V3, EF_HEXAGON_ISA);
501 BCaseMask(EF_HEXAGON_ISA_V4, EF_HEXAGON_ISA);
502 BCaseMask(EF_HEXAGON_ISA_V5, EF_HEXAGON_ISA);
503 BCaseMask(EF_HEXAGON_ISA_V55, EF_HEXAGON_ISA);
504 BCaseMask(EF_HEXAGON_ISA_V60, EF_HEXAGON_ISA);
505 BCaseMask(EF_HEXAGON_ISA_V62, EF_HEXAGON_ISA);
506 BCaseMask(EF_HEXAGON_ISA_V65, EF_HEXAGON_ISA);
507 BCaseMask(EF_HEXAGON_ISA_V66, EF_HEXAGON_ISA);
508 BCaseMask(EF_HEXAGON_ISA_V67, EF_HEXAGON_ISA);
509 BCaseMask(EF_HEXAGON_ISA_V68, EF_HEXAGON_ISA);
510 BCaseMask(EF_HEXAGON_ISA_V69, EF_HEXAGON_ISA);
511 BCaseMask(EF_HEXAGON_ISA_V71, EF_HEXAGON_ISA);
512 BCaseMask(EF_HEXAGON_ISA_V73, EF_HEXAGON_ISA);
513 break;
514 case ELF::EM_AVR:
515 BCaseMask(EF_AVR_ARCH_AVR1, EF_AVR_ARCH_MASK);
516 BCaseMask(EF_AVR_ARCH_AVR2, EF_AVR_ARCH_MASK);
517 BCaseMask(EF_AVR_ARCH_AVR25, EF_AVR_ARCH_MASK);
518 BCaseMask(EF_AVR_ARCH_AVR3, EF_AVR_ARCH_MASK);
519 BCaseMask(EF_AVR_ARCH_AVR31, EF_AVR_ARCH_MASK);
520 BCaseMask(EF_AVR_ARCH_AVR35, EF_AVR_ARCH_MASK);
521 BCaseMask(EF_AVR_ARCH_AVR4, EF_AVR_ARCH_MASK);
522 BCaseMask(EF_AVR_ARCH_AVR5, EF_AVR_ARCH_MASK);
523 BCaseMask(EF_AVR_ARCH_AVR51, EF_AVR_ARCH_MASK);
524 BCaseMask(EF_AVR_ARCH_AVR6, EF_AVR_ARCH_MASK);
525 BCaseMask(EF_AVR_ARCH_AVRTINY, EF_AVR_ARCH_MASK);
526 BCaseMask(EF_AVR_ARCH_XMEGA1, EF_AVR_ARCH_MASK);
527 BCaseMask(EF_AVR_ARCH_XMEGA2, EF_AVR_ARCH_MASK);
528 BCaseMask(EF_AVR_ARCH_XMEGA3, EF_AVR_ARCH_MASK);
529 BCaseMask(EF_AVR_ARCH_XMEGA4, EF_AVR_ARCH_MASK);
530 BCaseMask(EF_AVR_ARCH_XMEGA5, EF_AVR_ARCH_MASK);
531 BCaseMask(EF_AVR_ARCH_XMEGA6, EF_AVR_ARCH_MASK);
532 BCaseMask(EF_AVR_ARCH_XMEGA7, EF_AVR_ARCH_MASK);
533 BCase(EF_AVR_LINKRELAX_PREPARED);
534 break;
536 BCaseMask(EF_LOONGARCH_ABI_SOFT_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK);
537 BCaseMask(EF_LOONGARCH_ABI_SINGLE_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK);
538 BCaseMask(EF_LOONGARCH_ABI_DOUBLE_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK);
539 BCaseMask(EF_LOONGARCH_OBJABI_V0, EF_LOONGARCH_OBJABI_MASK);
540 BCaseMask(EF_LOONGARCH_OBJABI_V1, EF_LOONGARCH_OBJABI_MASK);
541 break;
542 case ELF::EM_RISCV:
543 BCase(EF_RISCV_RVC);
544 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT, EF_RISCV_FLOAT_ABI);
545 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE, EF_RISCV_FLOAT_ABI);
546 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_FLOAT_ABI);
547 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD, EF_RISCV_FLOAT_ABI);
548 BCase(EF_RISCV_RVE);
549 BCase(EF_RISCV_TSO);
550 break;
552 BCase(EF_SPARC_32PLUS);
553 BCase(EF_SPARC_SUN_US1);
554 BCase(EF_SPARC_SUN_US3);
555 BCase(EF_SPARC_HAL_R1);
556 break;
557 case ELF::EM_SPARCV9:
558 BCase(EF_SPARC_SUN_US1);
559 BCase(EF_SPARC_SUN_US3);
560 BCase(EF_SPARC_HAL_R1);
561 BCaseMask(EF_SPARCV9_RMO, EF_SPARCV9_MM);
562 BCaseMask(EF_SPARCV9_PSO, EF_SPARCV9_MM);
563 BCaseMask(EF_SPARCV9_TSO, EF_SPARCV9_MM);
564 break;
565 case ELF::EM_XTENSA:
566 BCase(EF_XTENSA_XT_INSN);
567 BCaseMask(EF_XTENSA_MACH_NONE, EF_XTENSA_MACH);
568 BCase(EF_XTENSA_XT_LIT);
569 break;
570 case ELF::EM_AMDGPU:
571 BCaseMask(EF_AMDGPU_MACH_NONE, EF_AMDGPU_MACH);
572 BCaseMask(EF_AMDGPU_MACH_R600_R600, EF_AMDGPU_MACH);
573 BCaseMask(EF_AMDGPU_MACH_R600_R630, EF_AMDGPU_MACH);
574 BCaseMask(EF_AMDGPU_MACH_R600_RS880, EF_AMDGPU_MACH);
575 BCaseMask(EF_AMDGPU_MACH_R600_RV670, EF_AMDGPU_MACH);
576 BCaseMask(EF_AMDGPU_MACH_R600_RV710, EF_AMDGPU_MACH);
577 BCaseMask(EF_AMDGPU_MACH_R600_RV730, EF_AMDGPU_MACH);
578 BCaseMask(EF_AMDGPU_MACH_R600_RV770, EF_AMDGPU_MACH);
579 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR, EF_AMDGPU_MACH);
580 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS, EF_AMDGPU_MACH);
581 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER, EF_AMDGPU_MACH);
582 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD, EF_AMDGPU_MACH);
583 BCaseMask(EF_AMDGPU_MACH_R600_SUMO, EF_AMDGPU_MACH);
584 BCaseMask(EF_AMDGPU_MACH_R600_BARTS, EF_AMDGPU_MACH);
585 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS, EF_AMDGPU_MACH);
586 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN, EF_AMDGPU_MACH);
587 BCaseMask(EF_AMDGPU_MACH_R600_TURKS, EF_AMDGPU_MACH);
588 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600, EF_AMDGPU_MACH);
589 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601, EF_AMDGPU_MACH);
590 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX602, EF_AMDGPU_MACH);
591 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700, EF_AMDGPU_MACH);
592 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701, EF_AMDGPU_MACH);
593 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702, EF_AMDGPU_MACH);
594 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703, EF_AMDGPU_MACH);
595 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704, EF_AMDGPU_MACH);
596 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX705, EF_AMDGPU_MACH);
597 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801, EF_AMDGPU_MACH);
598 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802, EF_AMDGPU_MACH);
599 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803, EF_AMDGPU_MACH);
600 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX805, EF_AMDGPU_MACH);
601 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810, EF_AMDGPU_MACH);
602 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900, EF_AMDGPU_MACH);
603 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902, EF_AMDGPU_MACH);
604 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904, EF_AMDGPU_MACH);
605 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906, EF_AMDGPU_MACH);
606 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908, EF_AMDGPU_MACH);
607 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909, EF_AMDGPU_MACH);
608 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90A, EF_AMDGPU_MACH);
609 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90C, EF_AMDGPU_MACH);
610 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX940, EF_AMDGPU_MACH);
611 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX941, EF_AMDGPU_MACH);
612 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX942, EF_AMDGPU_MACH);
613 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX950, EF_AMDGPU_MACH);
614 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010, EF_AMDGPU_MACH);
615 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011, EF_AMDGPU_MACH);
616 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012, EF_AMDGPU_MACH);
617 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1013, EF_AMDGPU_MACH);
618 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1030, EF_AMDGPU_MACH);
619 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1031, EF_AMDGPU_MACH);
620 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1032, EF_AMDGPU_MACH);
621 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1033, EF_AMDGPU_MACH);
622 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1034, EF_AMDGPU_MACH);
623 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1035, EF_AMDGPU_MACH);
624 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1036, EF_AMDGPU_MACH);
625 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1100, EF_AMDGPU_MACH);
626 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1101, EF_AMDGPU_MACH);
627 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1102, EF_AMDGPU_MACH);
628 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1103, EF_AMDGPU_MACH);
629 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1150, EF_AMDGPU_MACH);
630 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1151, EF_AMDGPU_MACH);
631 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1152, EF_AMDGPU_MACH);
632 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1153, EF_AMDGPU_MACH);
633 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1200, EF_AMDGPU_MACH);
634 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1201, EF_AMDGPU_MACH);
635 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX9_GENERIC, EF_AMDGPU_MACH);
636 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX9_4_GENERIC, EF_AMDGPU_MACH);
637 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX10_1_GENERIC, EF_AMDGPU_MACH);
638 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX10_3_GENERIC, EF_AMDGPU_MACH);
639 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX11_GENERIC, EF_AMDGPU_MACH);
640 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX12_GENERIC, EF_AMDGPU_MACH);
641 switch (Object->Header.ABIVersion) {
642 default:
643 // ELFOSABI_AMDGPU_PAL, ELFOSABI_AMDGPU_MESA3D support *_V3 flags.
644 [[fallthrough]];
646 BCase(EF_AMDGPU_FEATURE_XNACK_V3);
647 BCase(EF_AMDGPU_FEATURE_SRAMECC_V3);
648 break;
650 for (unsigned K = ELF::EF_AMDGPU_GENERIC_VERSION_MIN;
652 std::string Key = "EF_AMDGPU_GENERIC_VERSION_V" + std::to_string(K);
653 IO.maskedBitSetCase(Value, Key.c_str(),
656 }
657 [[fallthrough]];
660 BCaseMask(EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4,
661 EF_AMDGPU_FEATURE_XNACK_V4);
662 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ANY_V4,
663 EF_AMDGPU_FEATURE_XNACK_V4);
664 BCaseMask(EF_AMDGPU_FEATURE_XNACK_OFF_V4,
665 EF_AMDGPU_FEATURE_XNACK_V4);
666 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ON_V4,
667 EF_AMDGPU_FEATURE_XNACK_V4);
668 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4,
669 EF_AMDGPU_FEATURE_SRAMECC_V4);
670 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ANY_V4,
671 EF_AMDGPU_FEATURE_SRAMECC_V4);
672 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_OFF_V4,
673 EF_AMDGPU_FEATURE_SRAMECC_V4);
674 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ON_V4,
675 EF_AMDGPU_FEATURE_SRAMECC_V4);
676 break;
677 }
678 break;
679 default:
680 break;
681 }
682#undef BCase
683#undef BCaseMask
684}
685
686void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
687 IO &IO, ELFYAML::ELF_SHT &Value) {
688 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
689 assert(Object && "The IO context is not initialized");
690#define ECase(X) IO.enumCase(Value, #X, ELF::X)
691 ECase(SHT_NULL);
692 ECase(SHT_PROGBITS);
693 ECase(SHT_SYMTAB);
694 // FIXME: Issue a diagnostic with this information.
695 ECase(SHT_STRTAB);
696 ECase(SHT_RELA);
697 ECase(SHT_HASH);
698 ECase(SHT_DYNAMIC);
699 ECase(SHT_NOTE);
700 ECase(SHT_NOBITS);
701 ECase(SHT_REL);
702 ECase(SHT_SHLIB);
703 ECase(SHT_DYNSYM);
704 ECase(SHT_INIT_ARRAY);
705 ECase(SHT_FINI_ARRAY);
706 ECase(SHT_PREINIT_ARRAY);
707 ECase(SHT_GROUP);
708 ECase(SHT_SYMTAB_SHNDX);
709 ECase(SHT_RELR);
710 ECase(SHT_CREL);
711 ECase(SHT_ANDROID_REL);
712 ECase(SHT_ANDROID_RELA);
713 ECase(SHT_ANDROID_RELR);
714 ECase(SHT_LLVM_ODRTAB);
715 ECase(SHT_LLVM_LINKER_OPTIONS);
716 ECase(SHT_LLVM_CALL_GRAPH_PROFILE);
717 ECase(SHT_LLVM_ADDRSIG);
718 ECase(SHT_LLVM_DEPENDENT_LIBRARIES);
719 ECase(SHT_LLVM_SYMPART);
720 ECase(SHT_LLVM_PART_EHDR);
721 ECase(SHT_LLVM_PART_PHDR);
722 ECase(SHT_LLVM_BB_ADDR_MAP_V0);
723 ECase(SHT_LLVM_BB_ADDR_MAP);
724 ECase(SHT_LLVM_OFFLOADING);
725 ECase(SHT_LLVM_LTO);
726 ECase(SHT_GNU_ATTRIBUTES);
727 ECase(SHT_GNU_HASH);
728 ECase(SHT_GNU_verdef);
729 ECase(SHT_GNU_verneed);
730 ECase(SHT_GNU_versym);
731 switch (Object->getMachine()) {
732 case ELF::EM_ARM:
733 ECase(SHT_ARM_EXIDX);
734 ECase(SHT_ARM_PREEMPTMAP);
735 ECase(SHT_ARM_ATTRIBUTES);
736 ECase(SHT_ARM_DEBUGOVERLAY);
737 ECase(SHT_ARM_OVERLAYSECTION);
738 break;
739 case ELF::EM_HEXAGON:
740 ECase(SHT_HEX_ORDERED);
741 ECase(SHT_HEXAGON_ATTRIBUTES);
742 break;
743 case ELF::EM_X86_64:
744 ECase(SHT_X86_64_UNWIND);
745 break;
746 case ELF::EM_MIPS:
747 ECase(SHT_MIPS_REGINFO);
748 ECase(SHT_MIPS_OPTIONS);
749 ECase(SHT_MIPS_DWARF);
750 ECase(SHT_MIPS_ABIFLAGS);
751 break;
752 case ELF::EM_RISCV:
753 ECase(SHT_RISCV_ATTRIBUTES);
754 break;
755 case ELF::EM_MSP430:
756 ECase(SHT_MSP430_ATTRIBUTES);
757 break;
758 case ELF::EM_AARCH64:
759 ECase(SHT_AARCH64_AUTH_RELR);
760 ECase(SHT_AARCH64_MEMTAG_GLOBALS_STATIC);
761 ECase(SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC);
762 break;
763 default:
764 // Nothing to do.
765 break;
766 }
767#undef ECase
768 IO.enumFallback<Hex32>(Value);
769}
770
771void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO,
772 ELFYAML::ELF_PF &Value) {
773#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
774 BCase(PF_X);
775 BCase(PF_W);
776 BCase(PF_R);
777}
778
779void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
780 ELFYAML::ELF_SHF &Value) {
781 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
782#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
783 BCase(SHF_WRITE);
784 BCase(SHF_ALLOC);
785 BCase(SHF_EXCLUDE);
786 BCase(SHF_EXECINSTR);
787 BCase(SHF_MERGE);
788 BCase(SHF_STRINGS);
789 BCase(SHF_INFO_LINK);
790 BCase(SHF_LINK_ORDER);
791 BCase(SHF_OS_NONCONFORMING);
792 BCase(SHF_GROUP);
793 BCase(SHF_TLS);
794 BCase(SHF_COMPRESSED);
795 switch (Object->getOSAbi()) {
797 BCase(SHF_SUNW_NODISCARD);
798 break;
799 default:
800 BCase(SHF_GNU_RETAIN);
801 break;
802 }
803 switch (Object->getMachine()) {
804 case ELF::EM_ARM:
805 BCase(SHF_ARM_PURECODE);
806 break;
807 case ELF::EM_HEXAGON:
808 BCase(SHF_HEX_GPREL);
809 break;
810 case ELF::EM_MIPS:
811 BCase(SHF_MIPS_NODUPES);
812 BCase(SHF_MIPS_NAMES);
813 BCase(SHF_MIPS_LOCAL);
814 BCase(SHF_MIPS_NOSTRIP);
815 BCase(SHF_MIPS_GPREL);
816 BCase(SHF_MIPS_MERGE);
817 BCase(SHF_MIPS_ADDR);
818 BCase(SHF_MIPS_STRING);
819 break;
820 case ELF::EM_X86_64:
821 BCase(SHF_X86_64_LARGE);
822 break;
823 default:
824 // Nothing to do.
825 break;
826 }
827#undef BCase
828}
829
830void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
831 IO &IO, ELFYAML::ELF_SHN &Value) {
832 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
833 assert(Object && "The IO context is not initialized");
834#define ECase(X) IO.enumCase(Value, #X, ELF::X)
835 ECase(SHN_UNDEF);
836 ECase(SHN_LORESERVE);
837 ECase(SHN_LOPROC);
838 ECase(SHN_HIPROC);
839 ECase(SHN_LOOS);
840 ECase(SHN_HIOS);
841 ECase(SHN_ABS);
842 ECase(SHN_COMMON);
843 ECase(SHN_XINDEX);
844 ECase(SHN_HIRESERVE);
845 ECase(SHN_AMDGPU_LDS);
846
847 if (!IO.outputting() || Object->getMachine() == ELF::EM_MIPS) {
848 ECase(SHN_MIPS_ACOMMON);
849 ECase(SHN_MIPS_TEXT);
850 ECase(SHN_MIPS_DATA);
851 ECase(SHN_MIPS_SCOMMON);
852 ECase(SHN_MIPS_SUNDEFINED);
853 }
854
855 ECase(SHN_HEXAGON_SCOMMON);
856 ECase(SHN_HEXAGON_SCOMMON_1);
857 ECase(SHN_HEXAGON_SCOMMON_2);
858 ECase(SHN_HEXAGON_SCOMMON_4);
859 ECase(SHN_HEXAGON_SCOMMON_8);
860#undef ECase
861 IO.enumFallback<Hex16>(Value);
862}
863
864void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration(
865 IO &IO, ELFYAML::ELF_STB &Value) {
866#define ECase(X) IO.enumCase(Value, #X, ELF::X)
867 ECase(STB_LOCAL);
868 ECase(STB_GLOBAL);
869 ECase(STB_WEAK);
870 ECase(STB_GNU_UNIQUE);
871#undef ECase
872 IO.enumFallback<Hex8>(Value);
873}
874
875void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
876 IO &IO, ELFYAML::ELF_STT &Value) {
877#define ECase(X) IO.enumCase(Value, #X, ELF::X)
878 ECase(STT_NOTYPE);
879 ECase(STT_OBJECT);
880 ECase(STT_FUNC);
881 ECase(STT_SECTION);
882 ECase(STT_FILE);
883 ECase(STT_COMMON);
884 ECase(STT_TLS);
885 ECase(STT_GNU_IFUNC);
886#undef ECase
887 IO.enumFallback<Hex8>(Value);
888}
889
890
891void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration(
892 IO &IO, ELFYAML::ELF_RSS &Value) {
893#define ECase(X) IO.enumCase(Value, #X, ELF::X)
894 ECase(RSS_UNDEF);
895 ECase(RSS_GP);
896 ECase(RSS_GP0);
897 ECase(RSS_LOC);
898#undef ECase
899}
900
901void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
902 IO &IO, ELFYAML::ELF_REL &Value) {
903 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
904 assert(Object && "The IO context is not initialized");
905#define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
906 switch (Object->getMachine()) {
907 case ELF::EM_X86_64:
908#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
909 break;
910 case ELF::EM_MIPS:
911#include "llvm/BinaryFormat/ELFRelocs/Mips.def"
912 break;
913 case ELF::EM_HEXAGON:
914#include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
915 break;
916 case ELF::EM_386:
917 case ELF::EM_IAMCU:
918#include "llvm/BinaryFormat/ELFRelocs/i386.def"
919 break;
920 case ELF::EM_AARCH64:
921#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
922 break;
923 case ELF::EM_ARM:
924#include "llvm/BinaryFormat/ELFRelocs/ARM.def"
925 break;
926 case ELF::EM_ARC:
927#include "llvm/BinaryFormat/ELFRelocs/ARC.def"
928 break;
929 case ELF::EM_RISCV:
930#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
931 break;
932 case ELF::EM_LANAI:
933#include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
934 break;
935 case ELF::EM_AMDGPU:
936#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
937 break;
938 case ELF::EM_BPF:
939#include "llvm/BinaryFormat/ELFRelocs/BPF.def"
940 break;
941 case ELF::EM_VE:
942#include "llvm/BinaryFormat/ELFRelocs/VE.def"
943 break;
944 case ELF::EM_CSKY:
945#include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
946 break;
947 case ELF::EM_PPC:
948#include "llvm/BinaryFormat/ELFRelocs/PowerPC.def"
949 break;
950 case ELF::EM_PPC64:
951#include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
952 break;
953 case ELF::EM_68K:
954#include "llvm/BinaryFormat/ELFRelocs/M68k.def"
955 break;
957#include "llvm/BinaryFormat/ELFRelocs/LoongArch.def"
958 break;
959 case ELF::EM_XTENSA:
960#include "llvm/BinaryFormat/ELFRelocs/Xtensa.def"
961 break;
962 default:
963 // Nothing to do.
964 break;
965 }
966#undef ELF_RELOC
967 IO.enumFallback<Hex32>(Value);
968}
969
970void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
971 IO &IO, ELFYAML::ELF_DYNTAG &Value) {
972 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
973 assert(Object && "The IO context is not initialized");
974
975// Disable architecture specific tags by default. We might enable them below.
976#define AARCH64_DYNAMIC_TAG(name, value)
977#define MIPS_DYNAMIC_TAG(name, value)
978#define HEXAGON_DYNAMIC_TAG(name, value)
979#define PPC_DYNAMIC_TAG(name, value)
980#define PPC64_DYNAMIC_TAG(name, value)
981// Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
982#define DYNAMIC_TAG_MARKER(name, value)
983
984#define STRINGIFY(X) (#X)
985#define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
986 switch (Object->getMachine()) {
987 case ELF::EM_AARCH64:
988#undef AARCH64_DYNAMIC_TAG
989#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
990#include "llvm/BinaryFormat/DynamicTags.def"
991#undef AARCH64_DYNAMIC_TAG
992#define AARCH64_DYNAMIC_TAG(name, value)
993 break;
994 case ELF::EM_MIPS:
995#undef MIPS_DYNAMIC_TAG
996#define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
997#include "llvm/BinaryFormat/DynamicTags.def"
998#undef MIPS_DYNAMIC_TAG
999#define MIPS_DYNAMIC_TAG(name, value)
1000 break;
1001 case ELF::EM_HEXAGON:
1002#undef HEXAGON_DYNAMIC_TAG
1003#define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1004#include "llvm/BinaryFormat/DynamicTags.def"
1005#undef HEXAGON_DYNAMIC_TAG
1006#define HEXAGON_DYNAMIC_TAG(name, value)
1007 break;
1008 case ELF::EM_PPC:
1009#undef PPC_DYNAMIC_TAG
1010#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1011#include "llvm/BinaryFormat/DynamicTags.def"
1012#undef PPC_DYNAMIC_TAG
1013#define PPC_DYNAMIC_TAG(name, value)
1014 break;
1015 case ELF::EM_PPC64:
1016#undef PPC64_DYNAMIC_TAG
1017#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1018#include "llvm/BinaryFormat/DynamicTags.def"
1019#undef PPC64_DYNAMIC_TAG
1020#define PPC64_DYNAMIC_TAG(name, value)
1021 break;
1022 case ELF::EM_RISCV:
1023#undef RISCV_DYNAMIC_TAG
1024#define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1025#include "llvm/BinaryFormat/DynamicTags.def"
1026#undef RISCV_DYNAMIC_TAG
1027#define RISCV_DYNAMIC_TAG(name, value)
1028 break;
1029 default:
1030#include "llvm/BinaryFormat/DynamicTags.def"
1031 break;
1032 }
1033#undef AARCH64_DYNAMIC_TAG
1034#undef MIPS_DYNAMIC_TAG
1035#undef HEXAGON_DYNAMIC_TAG
1036#undef PPC_DYNAMIC_TAG
1037#undef PPC64_DYNAMIC_TAG
1038#undef DYNAMIC_TAG_MARKER
1039#undef STRINGIFY
1040#undef DYNAMIC_TAG
1041
1042 IO.enumFallback<Hex64>(Value);
1043}
1044
1045void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration(
1046 IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
1047#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1048 ECase(REG_NONE);
1049 ECase(REG_32);
1050 ECase(REG_64);
1051 ECase(REG_128);
1052#undef ECase
1053}
1054
1055void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration(
1056 IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
1057#define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
1058 ECase(FP_ANY);
1059 ECase(FP_DOUBLE);
1060 ECase(FP_SINGLE);
1061 ECase(FP_SOFT);
1062 ECase(FP_OLD_64);
1063 ECase(FP_XX);
1064 ECase(FP_64);
1065 ECase(FP_64A);
1066#undef ECase
1067}
1068
1069void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration(
1070 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
1071#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1072 ECase(EXT_NONE);
1073 ECase(EXT_XLR);
1074 ECase(EXT_OCTEON2);
1075 ECase(EXT_OCTEONP);
1076 ECase(EXT_LOONGSON_3A);
1077 ECase(EXT_OCTEON);
1078 ECase(EXT_5900);
1079 ECase(EXT_4650);
1080 ECase(EXT_4010);
1081 ECase(EXT_4100);
1082 ECase(EXT_3900);
1083 ECase(EXT_10000);
1084 ECase(EXT_SB1);
1085 ECase(EXT_4111);
1086 ECase(EXT_4120);
1087 ECase(EXT_5400);
1088 ECase(EXT_5500);
1089 ECase(EXT_LOONGSON_2E);
1090 ECase(EXT_LOONGSON_2F);
1091 ECase(EXT_OCTEON3);
1092#undef ECase
1093}
1094
1095void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration(
1096 IO &IO, ELFYAML::MIPS_ISA &Value) {
1097 IO.enumCase(Value, "MIPS1", 1);
1098 IO.enumCase(Value, "MIPS2", 2);
1099 IO.enumCase(Value, "MIPS3", 3);
1100 IO.enumCase(Value, "MIPS4", 4);
1101 IO.enumCase(Value, "MIPS5", 5);
1102 IO.enumCase(Value, "MIPS32", 32);
1103 IO.enumCase(Value, "MIPS64", 64);
1104 IO.enumFallback<Hex32>(Value);
1105}
1106
1107void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset(
1108 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
1109#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
1110 BCase(DSP);
1111 BCase(DSPR2);
1112 BCase(EVA);
1113 BCase(MCU);
1114 BCase(MDMX);
1115 BCase(MIPS3D);
1116 BCase(MT);
1117 BCase(SMARTMIPS);
1118 BCase(VIRT);
1119 BCase(MSA);
1120 BCase(MIPS16);
1121 BCase(MICROMIPS);
1122 BCase(XPA);
1123 BCase(CRC);
1124 BCase(GINV);
1125#undef BCase
1126}
1127
1128void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset(
1129 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
1130#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
1131 BCase(ODDSPREG);
1132#undef BCase
1133}
1134
1135void MappingTraits<ELFYAML::SectionHeader>::mapping(
1136 IO &IO, ELFYAML::SectionHeader &SHdr) {
1137 IO.mapRequired("Name", SHdr.Name);
1138}
1139
1140void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
1141 ELFYAML::FileHeader &FileHdr) {
1142 IO.mapRequired("Class", FileHdr.Class);
1143 IO.mapRequired("Data", FileHdr.Data);
1144 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
1145 IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0));
1146 IO.mapRequired("Type", FileHdr.Type);
1147 IO.mapOptional("Machine", FileHdr.Machine);
1148 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
1149 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
1150 IO.mapOptional("SectionHeaderStringTable", FileHdr.SectionHeaderStringTable);
1151
1152 // obj2yaml does not dump these fields.
1153 assert(!IO.outputting() ||
1154 (!FileHdr.EPhOff && !FileHdr.EPhEntSize && !FileHdr.EPhNum));
1155 IO.mapOptional("EPhOff", FileHdr.EPhOff);
1156 IO.mapOptional("EPhEntSize", FileHdr.EPhEntSize);
1157 IO.mapOptional("EPhNum", FileHdr.EPhNum);
1158 IO.mapOptional("EShEntSize", FileHdr.EShEntSize);
1159 IO.mapOptional("EShOff", FileHdr.EShOff);
1160 IO.mapOptional("EShNum", FileHdr.EShNum);
1161 IO.mapOptional("EShStrNdx", FileHdr.EShStrNdx);
1162}
1163
1164void MappingTraits<ELFYAML::ProgramHeader>::mapping(
1165 IO &IO, ELFYAML::ProgramHeader &Phdr) {
1166 IO.mapRequired("Type", Phdr.Type);
1167 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
1168 IO.mapOptional("FirstSec", Phdr.FirstSec);
1169 IO.mapOptional("LastSec", Phdr.LastSec);
1170 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
1171 IO.mapOptional("PAddr", Phdr.PAddr, Phdr.VAddr);
1172 IO.mapOptional("Align", Phdr.Align);
1173 IO.mapOptional("FileSize", Phdr.FileSize);
1174 IO.mapOptional("MemSize", Phdr.MemSize);
1175 IO.mapOptional("Offset", Phdr.Offset);
1176}
1177
1178std::string MappingTraits<ELFYAML::ProgramHeader>::validate(
1179 IO &IO, ELFYAML::ProgramHeader &FileHdr) {
1180 if (!FileHdr.FirstSec && FileHdr.LastSec)
1181 return "the \"LastSec\" key can't be used without the \"FirstSec\" key";
1182 if (FileHdr.FirstSec && !FileHdr.LastSec)
1183 return "the \"FirstSec\" key can't be used without the \"LastSec\" key";
1184 return "";
1185}
1186
1187LLVM_YAML_STRONG_TYPEDEF(StringRef, StOtherPiece)
1188
1189template <> struct ScalarTraits<StOtherPiece> {
1190 static void output(const StOtherPiece &Val, void *, raw_ostream &Out) {
1191 Out << Val;
1192 }
1193 static StringRef input(StringRef Scalar, void *, StOtherPiece &Val) {
1194 Val = Scalar;
1195 return {};
1196 }
1197 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1198};
1199template <> struct SequenceElementTraits<StOtherPiece> {
1200 static const bool flow = true;
1201};
1202
1203template <> struct ScalarTraits<ELFYAML::YAMLFlowString> {
1204 static void output(const ELFYAML::YAMLFlowString &Val, void *,
1205 raw_ostream &Out) {
1206 Out << Val;
1207 }
1208 static StringRef input(StringRef Scalar, void *,
1209 ELFYAML::YAMLFlowString &Val) {
1210 Val = Scalar;
1211 return {};
1212 }
1213 static QuotingType mustQuote(StringRef S) {
1214 return ScalarTraits<StringRef>::mustQuote(S);
1215 }
1216};
1217template <> struct SequenceElementTraits<ELFYAML::YAMLFlowString> {
1218 static const bool flow = true;
1219};
1220
1221namespace {
1222
1223struct NormalizedOther {
1224 NormalizedOther(IO &IO) : YamlIO(IO) {}
1225 NormalizedOther(IO &IO, std::optional<uint8_t> Original) : YamlIO(IO) {
1226 assert(Original && "This constructor is only used for outputting YAML and "
1227 "assumes a non-empty Original");
1228 std::vector<StOtherPiece> Ret;
1229 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext());
1230 for (std::pair<StringRef, uint8_t> &P :
1231 getFlags(Object->getMachine()).takeVector()) {
1232 uint8_t FlagValue = P.second;
1233 if ((*Original & FlagValue) != FlagValue)
1234 continue;
1235 *Original &= ~FlagValue;
1236 Ret.push_back({P.first});
1237 }
1238
1239 if (*Original != 0) {
1240 UnknownFlagsHolder = std::to_string(*Original);
1241 Ret.push_back({UnknownFlagsHolder});
1242 }
1243
1244 if (!Ret.empty())
1245 Other = std::move(Ret);
1246 }
1247
1248 uint8_t toValue(StringRef Name) {
1249 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext());
1250 MapVector<StringRef, uint8_t> Flags = getFlags(Object->getMachine());
1251
1252 auto It = Flags.find(Name);
1253 if (It != Flags.end())
1254 return It->second;
1255
1256 uint8_t Val;
1257 if (to_integer(Name, Val))
1258 return Val;
1259
1260 YamlIO.setError("an unknown value is used for symbol's 'Other' field: " +
1261 Name);
1262 return 0;
1263 }
1264
1265 std::optional<uint8_t> denormalize(IO &) {
1266 if (!Other)
1267 return std::nullopt;
1268 uint8_t Ret = 0;
1269 for (StOtherPiece &Val : *Other)
1270 Ret |= toValue(Val);
1271 return Ret;
1272 }
1273
1274 // st_other field is used to encode symbol visibility and platform-dependent
1275 // flags and values. This method returns a name to value map that is used for
1276 // parsing and encoding this field.
1277 MapVector<StringRef, uint8_t> getFlags(unsigned EMachine) {
1279 // STV_* values are just enumeration values. We add them in a reversed order
1280 // because when we convert the st_other to named constants when printing
1281 // YAML we want to use a maximum number of bits on each step:
1282 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
1283 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
1284 Map["STV_PROTECTED"] = ELF::STV_PROTECTED;
1285 Map["STV_HIDDEN"] = ELF::STV_HIDDEN;
1286 Map["STV_INTERNAL"] = ELF::STV_INTERNAL;
1287 // STV_DEFAULT is used to represent the default visibility and has a value
1288 // 0. We want to be able to read it from YAML documents, but there is no
1289 // reason to print it.
1290 if (!YamlIO.outputting())
1291 Map["STV_DEFAULT"] = ELF::STV_DEFAULT;
1292
1293 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
1294 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
1295 // consumed first when we print the output, because we do not want to print
1296 // any other flags that have the same bits instead.
1297 if (EMachine == ELF::EM_MIPS) {
1298 Map["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16;
1299 Map["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS;
1300 Map["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC;
1301 Map["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT;
1302 Map["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL;
1303 }
1304
1305 if (EMachine == ELF::EM_AARCH64)
1306 Map["STO_AARCH64_VARIANT_PCS"] = ELF::STO_AARCH64_VARIANT_PCS;
1307 if (EMachine == ELF::EM_RISCV)
1308 Map["STO_RISCV_VARIANT_CC"] = ELF::STO_RISCV_VARIANT_CC;
1309 return Map;
1310 }
1311
1313 std::optional<std::vector<StOtherPiece>> Other;
1315};
1316
1317} // end anonymous namespace
1318
1319void ScalarTraits<ELFYAML::YAMLIntUInt>::output(const ELFYAML::YAMLIntUInt &Val,
1320 void *Ctx, raw_ostream &Out) {
1321 Out << Val;
1322}
1323
1324StringRef ScalarTraits<ELFYAML::YAMLIntUInt>::input(StringRef Scalar, void *Ctx,
1325 ELFYAML::YAMLIntUInt &Val) {
1326 const bool Is64 = static_cast<ELFYAML::Object *>(Ctx)->Header.Class ==
1327 ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
1328 StringRef ErrMsg = "invalid number";
1329 // We do not accept negative hex numbers because their meaning is ambiguous.
1330 // For example, would -0xfffffffff mean 1 or INT32_MIN?
1331 if (Scalar.empty() || Scalar.starts_with("-0x"))
1332 return ErrMsg;
1333
1334 if (Scalar.starts_with("-")) {
1335 const int64_t MinVal = Is64 ? INT64_MIN : INT32_MIN;
1336 long long Int;
1337 if (getAsSignedInteger(Scalar, /*Radix=*/0, Int) || (Int < MinVal))
1338 return ErrMsg;
1339 Val = Int;
1340 return "";
1341 }
1342
1343 const uint64_t MaxVal = Is64 ? UINT64_MAX : UINT32_MAX;
1344 unsigned long long UInt;
1345 if (getAsUnsignedInteger(Scalar, /*Radix=*/0, UInt) || (UInt > MaxVal))
1346 return ErrMsg;
1347 Val = UInt;
1348 return "";
1349}
1350
1351void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
1352 IO.mapOptional("Name", Symbol.Name, StringRef());
1353 IO.mapOptional("StName", Symbol.StName);
1354 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
1355 IO.mapOptional("Section", Symbol.Section);
1356 IO.mapOptional("Index", Symbol.Index);
1357 IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));
1358 IO.mapOptional("Value", Symbol.Value);
1359 IO.mapOptional("Size", Symbol.Size);
1360
1361 // Symbol's Other field is a bit special. It is usually a field that
1362 // represents st_other and holds the symbol visibility. However, on some
1363 // platforms, it can contain bit fields and regular values, or even sometimes
1364 // a crazy mix of them (see comments for NormalizedOther). Because of this, we
1365 // need special handling.
1366 MappingNormalization<NormalizedOther, std::optional<uint8_t>> Keys(
1367 IO, Symbol.Other);
1368 IO.mapOptional("Other", Keys->Other);
1369}
1370
1371std::string MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
1372 ELFYAML::Symbol &Symbol) {
1373 if (Symbol.Index && Symbol.Section)
1374 return "Index and Section cannot both be specified for Symbol";
1375 return "";
1376}
1377
1378static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
1379 IO.mapOptional("Name", Section.Name, StringRef());
1380 IO.mapRequired("Type", Section.Type);
1381 IO.mapOptional("Flags", Section.Flags);
1382 IO.mapOptional("Address", Section.Address);
1383 IO.mapOptional("Link", Section.Link);
1384 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
1385 IO.mapOptional("EntSize", Section.EntSize);
1386 IO.mapOptional("Offset", Section.Offset);
1387
1388 IO.mapOptional("Content", Section.Content);
1389 IO.mapOptional("Size", Section.Size);
1390
1391 // obj2yaml does not dump these fields. They are expected to be empty when we
1392 // are producing YAML, because yaml2obj sets appropriate values for them
1393 // automatically when they are not explicitly defined.
1394 assert(!IO.outputting() ||
1395 (!Section.ShOffset && !Section.ShSize && !Section.ShName &&
1396 !Section.ShFlags && !Section.ShType && !Section.ShAddrAlign));
1397 IO.mapOptional("ShAddrAlign", Section.ShAddrAlign);
1398 IO.mapOptional("ShName", Section.ShName);
1399 IO.mapOptional("ShOffset", Section.ShOffset);
1400 IO.mapOptional("ShSize", Section.ShSize);
1401 IO.mapOptional("ShFlags", Section.ShFlags);
1402 IO.mapOptional("ShType", Section.ShType);
1403}
1404
1405static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) {
1406 commonSectionMapping(IO, Section);
1407 IO.mapOptional("Entries", Section.Entries);
1408}
1409
1410static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
1411 commonSectionMapping(IO, Section);
1412
1413 // We also support reading a content as array of bytes using the ContentArray
1414 // key. obj2yaml never prints this field.
1415 assert(!IO.outputting() || !Section.ContentBuf);
1416 IO.mapOptional("ContentArray", Section.ContentBuf);
1417 if (Section.ContentBuf) {
1418 if (Section.Content)
1419 IO.setError("Content and ContentArray can't be used together");
1420 Section.Content = yaml::BinaryRef(*Section.ContentBuf);
1421 }
1422
1423 IO.mapOptional("Info", Section.Info);
1424}
1425
1426static void sectionMapping(IO &IO, ELFYAML::BBAddrMapSection &Section) {
1427 commonSectionMapping(IO, Section);
1428 IO.mapOptional("Content", Section.Content);
1429 IO.mapOptional("Entries", Section.Entries);
1430 IO.mapOptional("PGOAnalyses", Section.PGOAnalyses);
1431}
1432
1433static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) {
1434 commonSectionMapping(IO, Section);
1435 IO.mapOptional("Entries", Section.Entries);
1436}
1437
1438static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) {
1439 commonSectionMapping(IO, Section);
1440 IO.mapOptional("Bucket", Section.Bucket);
1441 IO.mapOptional("Chain", Section.Chain);
1442
1443 // obj2yaml does not dump these fields. They can be used to override nchain
1444 // and nbucket values for creating broken sections.
1445 assert(!IO.outputting() || (!Section.NBucket && !Section.NChain));
1446 IO.mapOptional("NChain", Section.NChain);
1447 IO.mapOptional("NBucket", Section.NBucket);
1448}
1449
1450static void sectionMapping(IO &IO, ELFYAML::NoteSection &Section) {
1451 commonSectionMapping(IO, Section);
1452 IO.mapOptional("Notes", Section.Notes);
1453}
1454
1455
1456static void sectionMapping(IO &IO, ELFYAML::GnuHashSection &Section) {
1457 commonSectionMapping(IO, Section);
1458 IO.mapOptional("Header", Section.Header);
1459 IO.mapOptional("BloomFilter", Section.BloomFilter);
1460 IO.mapOptional("HashBuckets", Section.HashBuckets);
1461 IO.mapOptional("HashValues", Section.HashValues);
1462}
1463static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
1464 commonSectionMapping(IO, Section);
1465}
1466
1467static void sectionMapping(IO &IO, ELFYAML::VerdefSection &Section) {
1468 commonSectionMapping(IO, Section);
1469 IO.mapOptional("Info", Section.Info);
1470 IO.mapOptional("Entries", Section.Entries);
1471}
1472
1473static void sectionMapping(IO &IO, ELFYAML::SymverSection &Section) {
1474 commonSectionMapping(IO, Section);
1475 IO.mapOptional("Entries", Section.Entries);
1476}
1477
1478static void sectionMapping(IO &IO, ELFYAML::VerneedSection &Section) {
1479 commonSectionMapping(IO, Section);
1480 IO.mapOptional("Info", Section.Info);
1481 IO.mapOptional("Dependencies", Section.VerneedV);
1482}
1483
1484static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
1485 commonSectionMapping(IO, Section);
1486 IO.mapOptional("Info", Section.RelocatableSec, StringRef());
1487 IO.mapOptional("Relocations", Section.Relocations);
1488}
1489
1490static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) {
1491 commonSectionMapping(IO, Section);
1492 IO.mapOptional("Entries", Section.Entries);
1493}
1494
1495static void groupSectionMapping(IO &IO, ELFYAML::GroupSection &Group) {
1496 commonSectionMapping(IO, Group);
1497 IO.mapOptional("Info", Group.Signature);
1498 IO.mapOptional("Members", Group.Members);
1499}
1500
1501static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) {
1502 commonSectionMapping(IO, Section);
1503 IO.mapOptional("Entries", Section.Entries);
1504}
1505
1506static void sectionMapping(IO &IO, ELFYAML::AddrsigSection &Section) {
1507 commonSectionMapping(IO, Section);
1508 IO.mapOptional("Symbols", Section.Symbols);
1509}
1510
1511static void fillMapping(IO &IO, ELFYAML::Fill &Fill) {
1512 IO.mapOptional("Name", Fill.Name, StringRef());
1513 IO.mapOptional("Pattern", Fill.Pattern);
1514 IO.mapOptional("Offset", Fill.Offset);
1515 IO.mapRequired("Size", Fill.Size);
1516}
1517
1518static void sectionHeaderTableMapping(IO &IO,
1520 IO.mapOptional("Offset", SHT.Offset);
1521 IO.mapOptional("Sections", SHT.Sections);
1522 IO.mapOptional("Excluded", SHT.Excluded);
1523 IO.mapOptional("NoHeaders", SHT.NoHeaders);
1524}
1525
1526static void sectionMapping(IO &IO, ELFYAML::LinkerOptionsSection &Section) {
1527 commonSectionMapping(IO, Section);
1528 IO.mapOptional("Options", Section.Options);
1529}
1530
1531static void sectionMapping(IO &IO,
1533 commonSectionMapping(IO, Section);
1534 IO.mapOptional("Libraries", Section.Libs);
1535}
1536
1538 commonSectionMapping(IO, Section);
1539 IO.mapOptional("Entries", Section.Entries);
1540}
1541
1542void MappingTraits<ELFYAML::SectionOrType>::mapping(
1543 IO &IO, ELFYAML::SectionOrType &sectionOrType) {
1544 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
1545}
1546
1547static void sectionMapping(IO &IO, ELFYAML::ARMIndexTableSection &Section) {
1548 commonSectionMapping(IO, Section);
1549 IO.mapOptional("Entries", Section.Entries);
1550}
1551
1552static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) {
1553 commonSectionMapping(IO, Section);
1554 IO.mapOptional("Version", Section.Version, Hex16(0));
1555 IO.mapRequired("ISA", Section.ISALevel);
1556 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
1557 IO.mapOptional("ISAExtension", Section.ISAExtension,
1558 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
1559 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
1560 IO.mapOptional("FpABI", Section.FpABI,
1561 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
1562 IO.mapOptional("GPRSize", Section.GPRSize,
1563 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1564 IO.mapOptional("CPR1Size", Section.CPR1Size,
1565 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1566 IO.mapOptional("CPR2Size", Section.CPR2Size,
1567 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1568 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
1569 IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
1570}
1571
1572static StringRef getStringValue(IO &IO, const char *Key) {
1573 StringRef Val;
1574 IO.mapRequired(Key, Val);
1575 return Val;
1576}
1577
1578static void setStringValue(IO &IO, const char *Key, StringRef Val) {
1579 IO.mapRequired(Key, Val);
1580}
1581
1582static bool isInteger(StringRef Val) {
1583 APInt Tmp;
1584 return !Val.getAsInteger(0, Tmp);
1585}
1586
1587void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
1588 IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) {
1589 ELFYAML::ELF_SHT Type;
1590 StringRef TypeStr;
1591 if (IO.outputting()) {
1592 if (auto *S = dyn_cast<ELFYAML::Section>(Section.get()))
1593 Type = S->Type;
1594 else if (auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(Section.get()))
1595 TypeStr = SHT->TypeStr;
1596 } else {
1597 // When the Type string does not have a "SHT_" prefix, we know it is not a
1598 // description of a regular ELF output section.
1599 TypeStr = getStringValue(IO, "Type");
1600 if (TypeStr.starts_with("SHT_") || isInteger(TypeStr))
1601 IO.mapRequired("Type", Type);
1602 }
1603
1604 if (TypeStr == "Fill") {
1605 assert(!IO.outputting()); // We don't dump fills currently.
1606 Section.reset(new ELFYAML::Fill());
1607 fillMapping(IO, *cast<ELFYAML::Fill>(Section.get()));
1608 return;
1609 }
1610
1611 if (TypeStr == ELFYAML::SectionHeaderTable::TypeStr) {
1612 if (IO.outputting())
1613 setStringValue(IO, "Type", TypeStr);
1614 else
1615 Section.reset(new ELFYAML::SectionHeaderTable(/*IsImplicit=*/false));
1616
1618 IO, *cast<ELFYAML::SectionHeaderTable>(Section.get()));
1619 return;
1620 }
1621
1622 const auto &Obj = *static_cast<ELFYAML::Object *>(IO.getContext());
1623 if (Obj.getMachine() == ELF::EM_MIPS && Type == ELF::SHT_MIPS_ABIFLAGS) {
1624 if (!IO.outputting())
1625 Section.reset(new ELFYAML::MipsABIFlags());
1626 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
1627 return;
1628 }
1629
1630 if (Obj.getMachine() == ELF::EM_ARM && Type == ELF::SHT_ARM_EXIDX) {
1631 if (!IO.outputting())
1632 Section.reset(new ELFYAML::ARMIndexTableSection());
1633 sectionMapping(IO, *cast<ELFYAML::ARMIndexTableSection>(Section.get()));
1634 return;
1635 }
1636
1637 switch (Type) {
1638 case ELF::SHT_DYNAMIC:
1639 if (!IO.outputting())
1640 Section.reset(new ELFYAML::DynamicSection());
1641 sectionMapping(IO, *cast<ELFYAML::DynamicSection>(Section.get()));
1642 break;
1643 case ELF::SHT_REL:
1644 case ELF::SHT_RELA:
1645 case ELF::SHT_CREL:
1646 if (!IO.outputting())
1647 Section.reset(new ELFYAML::RelocationSection());
1648 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
1649 break;
1650 case ELF::SHT_RELR:
1651 if (!IO.outputting())
1652 Section.reset(new ELFYAML::RelrSection());
1653 sectionMapping(IO, *cast<ELFYAML::RelrSection>(Section.get()));
1654 break;
1655 case ELF::SHT_GROUP:
1656 if (!IO.outputting())
1657 Section.reset(new ELFYAML::GroupSection());
1658 groupSectionMapping(IO, *cast<ELFYAML::GroupSection>(Section.get()));
1659 break;
1660 case ELF::SHT_NOBITS:
1661 if (!IO.outputting())
1662 Section.reset(new ELFYAML::NoBitsSection());
1663 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
1664 break;
1665 case ELF::SHT_HASH:
1666 if (!IO.outputting())
1667 Section.reset(new ELFYAML::HashSection());
1668 sectionMapping(IO, *cast<ELFYAML::HashSection>(Section.get()));
1669 break;
1670 case ELF::SHT_NOTE:
1671 if (!IO.outputting())
1672 Section.reset(new ELFYAML::NoteSection());
1673 sectionMapping(IO, *cast<ELFYAML::NoteSection>(Section.get()));
1674 break;
1675 case ELF::SHT_GNU_HASH:
1676 if (!IO.outputting())
1677 Section.reset(new ELFYAML::GnuHashSection());
1678 sectionMapping(IO, *cast<ELFYAML::GnuHashSection>(Section.get()));
1679 break;
1681 if (!IO.outputting())
1682 Section.reset(new ELFYAML::VerdefSection());
1683 sectionMapping(IO, *cast<ELFYAML::VerdefSection>(Section.get()));
1684 break;
1686 if (!IO.outputting())
1687 Section.reset(new ELFYAML::SymverSection());
1688 sectionMapping(IO, *cast<ELFYAML::SymverSection>(Section.get()));
1689 break;
1691 if (!IO.outputting())
1692 Section.reset(new ELFYAML::VerneedSection());
1693 sectionMapping(IO, *cast<ELFYAML::VerneedSection>(Section.get()));
1694 break;
1696 if (!IO.outputting())
1697 Section.reset(new ELFYAML::SymtabShndxSection());
1698 sectionMapping(IO, *cast<ELFYAML::SymtabShndxSection>(Section.get()));
1699 break;
1701 if (!IO.outputting())
1702 Section.reset(new ELFYAML::AddrsigSection());
1703 sectionMapping(IO, *cast<ELFYAML::AddrsigSection>(Section.get()));
1704 break;
1706 if (!IO.outputting())
1707 Section.reset(new ELFYAML::LinkerOptionsSection());
1708 sectionMapping(IO, *cast<ELFYAML::LinkerOptionsSection>(Section.get()));
1709 break;
1711 if (!IO.outputting())
1712 Section.reset(new ELFYAML::DependentLibrariesSection());
1713 sectionMapping(IO,
1714 *cast<ELFYAML::DependentLibrariesSection>(Section.get()));
1715 break;
1717 if (!IO.outputting())
1718 Section.reset(new ELFYAML::CallGraphProfileSection());
1719 sectionMapping(IO, *cast<ELFYAML::CallGraphProfileSection>(Section.get()));
1720 break;
1722 if (!IO.outputting())
1723 Section.reset(new ELFYAML::BBAddrMapSection());
1724 sectionMapping(IO, *cast<ELFYAML::BBAddrMapSection>(Section.get()));
1725 break;
1726 default:
1727 if (!IO.outputting()) {
1728 StringRef Name;
1729 IO.mapOptional("Name", Name, StringRef());
1731
1733 Section = std::make_unique<ELFYAML::StackSizesSection>();
1734 else
1735 Section = std::make_unique<ELFYAML::RawContentSection>();
1736 }
1737
1738 if (auto S = dyn_cast<ELFYAML::RawContentSection>(Section.get()))
1739 sectionMapping(IO, *S);
1740 else
1741 sectionMapping(IO, *cast<ELFYAML::StackSizesSection>(Section.get()));
1742 }
1743}
1744
1745std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
1746 IO &io, std::unique_ptr<ELFYAML::Chunk> &C) {
1747 if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) {
1748 if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size)
1749 return "\"Size\" can't be 0 when \"Pattern\" is not empty";
1750 return "";
1751 }
1752
1753 if (const auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(C.get())) {
1754 if (SHT->NoHeaders && (SHT->Sections || SHT->Excluded || SHT->Offset))
1755 return "NoHeaders can't be used together with Offset/Sections/Excluded";
1756 return "";
1757 }
1758
1759 const ELFYAML::Section &Sec = *cast<ELFYAML::Section>(C.get());
1760 if (Sec.Size && Sec.Content &&
1761 (uint64_t)(*Sec.Size) < Sec.Content->binary_size())
1762 return "Section size must be greater than or equal to the content size";
1763
1764 auto BuildErrPrefix = [](ArrayRef<std::pair<StringRef, bool>> EntV) {
1765 std::string Msg;
1766 for (size_t I = 0, E = EntV.size(); I != E; ++I) {
1767 StringRef Name = EntV[I].first;
1768 if (I == 0) {
1769 Msg = "\"" + Name.str() + "\"";
1770 continue;
1771 }
1772 if (I != EntV.size() - 1)
1773 Msg += ", \"" + Name.str() + "\"";
1774 else
1775 Msg += " and \"" + Name.str() + "\"";
1776 }
1777 return Msg;
1778 };
1779
1780 std::vector<std::pair<StringRef, bool>> Entries = Sec.getEntries();
1781 const size_t NumUsedEntries = llvm::count_if(
1782 Entries, [](const std::pair<StringRef, bool> &P) { return P.second; });
1783
1784 if ((Sec.Size || Sec.Content) && NumUsedEntries > 0)
1785 return BuildErrPrefix(Entries) +
1786 " cannot be used with \"Content\" or \"Size\"";
1787
1788 if (NumUsedEntries > 0 && Entries.size() != NumUsedEntries)
1789 return BuildErrPrefix(Entries) + " must be used together";
1790
1791 if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) {
1792 if (RawSection->Flags && RawSection->ShFlags)
1793 return "ShFlags and Flags cannot be used together";
1794 return "";
1795 }
1796
1797 if (const auto *NB = dyn_cast<ELFYAML::NoBitsSection>(C.get())) {
1798 if (NB->Content)
1799 return "SHT_NOBITS section cannot have \"Content\"";
1800 return "";
1801 }
1802
1803 if (const auto *MF = dyn_cast<ELFYAML::MipsABIFlags>(C.get())) {
1804 if (MF->Content)
1805 return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS "
1806 "sections";
1807 if (MF->Size)
1808 return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections";
1809 return "";
1810 }
1811
1812 return "";
1813}
1814
1815namespace {
1816
1817struct NormalizedMips64RelType {
1818 NormalizedMips64RelType(IO &)
1819 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1820 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1821 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1822 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
1823 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
1824 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
1825 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
1826
1827 ELFYAML::ELF_REL denormalize(IO &) {
1828 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
1829 return Res;
1830 }
1831
1832 ELFYAML::ELF_REL Type;
1833 ELFYAML::ELF_REL Type2;
1834 ELFYAML::ELF_REL Type3;
1835 ELFYAML::ELF_RSS SpecSym;
1836};
1837
1838} // end anonymous namespace
1839
1840void MappingTraits<ELFYAML::StackSizeEntry>::mapping(
1841 IO &IO, ELFYAML::StackSizeEntry &E) {
1842 assert(IO.getContext() && "The IO context is not initialized");
1843 IO.mapOptional("Address", E.Address, Hex64(0));
1844 IO.mapRequired("Size", E.Size);
1845}
1846
1847void MappingTraits<ELFYAML::BBAddrMapEntry>::mapping(
1848 IO &IO, ELFYAML::BBAddrMapEntry &E) {
1849 assert(IO.getContext() && "The IO context is not initialized");
1850 IO.mapRequired("Version", E.Version);
1851 IO.mapOptional("Feature", E.Feature, Hex8(0));
1852 IO.mapOptional("NumBBRanges", E.NumBBRanges);
1853 IO.mapOptional("BBRanges", E.BBRanges);
1854}
1855
1856void MappingTraits<ELFYAML::BBAddrMapEntry::BBRangeEntry>::mapping(
1857 IO &IO, ELFYAML::BBAddrMapEntry::BBRangeEntry &E) {
1858 IO.mapOptional("BaseAddress", E.BaseAddress, Hex64(0));
1859 IO.mapOptional("NumBlocks", E.NumBlocks);
1860 IO.mapOptional("BBEntries", E.BBEntries);
1861}
1862
1863void MappingTraits<ELFYAML::BBAddrMapEntry::BBEntry>::mapping(
1864 IO &IO, ELFYAML::BBAddrMapEntry::BBEntry &E) {
1865 assert(IO.getContext() && "The IO context is not initialized");
1866 IO.mapOptional("ID", E.ID);
1867 IO.mapRequired("AddressOffset", E.AddressOffset);
1868 IO.mapRequired("Size", E.Size);
1869 IO.mapRequired("Metadata", E.Metadata);
1870}
1871
1872void MappingTraits<ELFYAML::PGOAnalysisMapEntry>::mapping(
1873 IO &IO, ELFYAML::PGOAnalysisMapEntry &E) {
1874 assert(IO.getContext() && "The IO context is not initialized");
1875 IO.mapOptional("FuncEntryCount", E.FuncEntryCount);
1876 IO.mapOptional("PGOBBEntries", E.PGOBBEntries);
1877}
1878
1879void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry>::mapping(
1880 IO &IO, ELFYAML::PGOAnalysisMapEntry::PGOBBEntry &E) {
1881 assert(IO.getContext() && "The IO context is not initialized");
1882 IO.mapOptional("BBFreq", E.BBFreq);
1883 IO.mapOptional("Successors", E.Successors);
1884}
1885
1886void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry>::
1887 mapping(IO &IO,
1888 ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry &E) {
1889 assert(IO.getContext() && "The IO context is not initialized");
1890 IO.mapRequired("ID", E.ID);
1891 IO.mapRequired("BrProb", E.BrProb);
1892}
1893
1894void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO,
1895 ELFYAML::GnuHashHeader &E) {
1896 assert(IO.getContext() && "The IO context is not initialized");
1897 IO.mapOptional("NBuckets", E.NBuckets);
1898 IO.mapRequired("SymNdx", E.SymNdx);
1899 IO.mapOptional("MaskWords", E.MaskWords);
1900 IO.mapRequired("Shift2", E.Shift2);
1901}
1902
1903void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO,
1904 ELFYAML::DynamicEntry &Rel) {
1905 assert(IO.getContext() && "The IO context is not initialized");
1906
1907 IO.mapRequired("Tag", Rel.Tag);
1908 IO.mapRequired("Value", Rel.Val);
1909}
1910
1911void MappingTraits<ELFYAML::NoteEntry>::mapping(IO &IO, ELFYAML::NoteEntry &N) {
1912 assert(IO.getContext() && "The IO context is not initialized");
1913
1914 IO.mapOptional("Name", N.Name);
1915 IO.mapOptional("Desc", N.Desc);
1916 IO.mapRequired("Type", N.Type);
1917}
1918
1919void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO,
1920 ELFYAML::VerdefEntry &E) {
1921 assert(IO.getContext() && "The IO context is not initialized");
1922
1923 IO.mapOptional("Version", E.Version);
1924 IO.mapOptional("Flags", E.Flags);
1925 IO.mapOptional("VersionNdx", E.VersionNdx);
1926 IO.mapOptional("Hash", E.Hash);
1927 IO.mapOptional("VDAux", E.VDAux);
1928 IO.mapRequired("Names", E.VerNames);
1929}
1930
1931void MappingTraits<ELFYAML::VerneedEntry>::mapping(IO &IO,
1932 ELFYAML::VerneedEntry &E) {
1933 assert(IO.getContext() && "The IO context is not initialized");
1934
1935 IO.mapRequired("Version", E.Version);
1936 IO.mapRequired("File", E.File);
1937 IO.mapRequired("Entries", E.AuxV);
1938}
1939
1940void MappingTraits<ELFYAML::VernauxEntry>::mapping(IO &IO,
1941 ELFYAML::VernauxEntry &E) {
1942 assert(IO.getContext() && "The IO context is not initialized");
1943
1944 IO.mapRequired("Name", E.Name);
1945 IO.mapRequired("Hash", E.Hash);
1946 IO.mapRequired("Flags", E.Flags);
1947 IO.mapRequired("Other", E.Other);
1948}
1949
1950void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
1951 ELFYAML::Relocation &Rel) {
1952 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
1953 assert(Object && "The IO context is not initialized");
1954
1955 IO.mapOptional("Offset", Rel.Offset, (Hex64)0);
1956 IO.mapOptional("Symbol", Rel.Symbol);
1957
1958 if (Object->getMachine() == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
1959 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
1960 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
1961 IO, Rel.Type);
1962 IO.mapRequired("Type", Key->Type);
1963 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
1964 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
1965 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
1966 } else
1967 IO.mapRequired("Type", Rel.Type);
1968
1969 IO.mapOptional("Addend", Rel.Addend, (ELFYAML::YAMLIntUInt)0);
1970}
1971
1972void MappingTraits<ELFYAML::ARMIndexTableEntry>::mapping(
1973 IO &IO, ELFYAML::ARMIndexTableEntry &E) {
1974 assert(IO.getContext() && "The IO context is not initialized");
1975 IO.mapRequired("Offset", E.Offset);
1976
1977 StringRef CantUnwind = "EXIDX_CANTUNWIND";
1978 if (IO.outputting() && (uint32_t)E.Value == ARM::EHABI::EXIDX_CANTUNWIND)
1979 IO.mapRequired("Value", CantUnwind);
1980 else if (!IO.outputting() && getStringValue(IO, "Value") == CantUnwind)
1982 else
1983 IO.mapRequired("Value", E.Value);
1984}
1985
1986void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
1987 assert(!IO.getContext() && "The IO context is initialized already");
1988 IO.setContext(&Object);
1989 IO.mapTag("!ELF", true);
1990 IO.mapRequired("FileHeader", Object.Header);
1991 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
1992 IO.mapOptional("Sections", Object.Chunks);
1993 IO.mapOptional("Symbols", Object.Symbols);
1994 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
1995 IO.mapOptional("DWARF", Object.DWARF);
1996 if (Object.DWARF) {
1997 Object.DWARF->IsLittleEndian =
1998 Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
1999 Object.DWARF->Is64BitAddrSize =
2000 Object.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
2001 }
2002 IO.setContext(nullptr);
2003}
2004
2005void MappingTraits<ELFYAML::LinkerOption>::mapping(IO &IO,
2006 ELFYAML::LinkerOption &Opt) {
2007 assert(IO.getContext() && "The IO context is not initialized");
2008 IO.mapRequired("Name", Opt.Key);
2009 IO.mapRequired("Value", Opt.Value);
2010}
2011
2012void MappingTraits<ELFYAML::CallGraphEntryWeight>::mapping(
2013 IO &IO, ELFYAML::CallGraphEntryWeight &E) {
2014 assert(IO.getContext() && "The IO context is not initialized");
2015 IO.mapRequired("Weight", E.Weight);
2016}
2017
2018LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
2022LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
2023
2024} // end namespace yaml
2025
2026} // end namespace llvm
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define BCase(X)
Definition: COFFYAML.cpp:267
std::string Name
std::string UnknownFlagsHolder
Definition: ELFYAML.cpp:1314
ELFYAML::ELF_RSS SpecSym
Definition: ELFYAML.cpp:1835
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:1834
#define BCaseMask(X, M)
IO & YamlIO
Definition: ELFYAML.cpp:1312
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:1833
std::optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1313
This file declares classes for handling the YAML representation of ELF.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file implements a map that provides insertion order iteration.
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:26
#define ECase(X)
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
Class for arbitrary precision integers.
Definition: APInt.h:78
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:470
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:265
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Type(LLVMContext &C, TypeID tid)
Definition: Type.h:93
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
#define UINT64_MAX
Definition: DataTypes.h:77
#define INT64_MIN
Definition: DataTypes.h:74
Key
PAL metadata keys.
@ EXIDX_CANTUNWIND
Special entry for the function never unwind.
Definition: ARMEHABI.h:35
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
StringRef dropUniqueSuffix(StringRef S)
Definition: ELFEmitter.cpp:699
@ STO_AARCH64_VARIANT_PCS
Definition: ELF.h:433
@ ELFOSABI_SOLARIS
Definition: ELF.h:348
@ STO_MIPS_PIC
Definition: ELF.h:590
@ STO_MIPS_OPTIONAL
Definition: ELF.h:588
@ STO_MIPS_MICROMIPS
Definition: ELF.h:591
@ STO_MIPS_MIPS16
Definition: ELF.h:592
@ STO_MIPS_PLT
Definition: ELF.h:589
@ ELFCLASS64
Definition: ELF.h:330
@ EM_MSP430
Definition: ELF.h:223
@ EM_PPC64
Definition: ELF.h:150
@ EM_CSKY
Definition: ELF.h:322
@ EM_SPARC32PLUS
Definition: ELF.h:147
@ EM_NONE
Definition: ELF.h:134
@ EM_68K
Definition: ELF.h:138
@ EM_386
Definition: ELF.h:137
@ EM_LOONGARCH
Definition: ELF.h:323
@ EM_BPF
Definition: ELF.h:320
@ EM_PPC
Definition: ELF.h:149
@ EM_X86_64
Definition: ELF.h:179
@ EM_HEXAGON
Definition: ELF.h:258
@ EM_LANAI
Definition: ELF.h:319
@ EM_MIPS
Definition: ELF.h:142
@ EM_ARC
Definition: ELF.h:162
@ EM_SPARCV9
Definition: ELF.h:160
@ EM_AARCH64
Definition: ELF.h:281
@ EM_XTENSA
Definition: ELF.h:212
@ EM_RISCV
Definition: ELF.h:318
@ EM_ARM
Definition: ELF.h:157
@ EM_VE
Definition: ELF.h:321
@ EM_IAMCU
Definition: ELF.h:140
@ EM_AMDGPU
Definition: ELF.h:317
@ EM_AVR
Definition: ELF.h:200
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition: ELF.h:1121
@ SHT_GROUP
Definition: ELF.h:1104
@ SHT_LLVM_LINKER_OPTIONS
Definition: ELF.h:1118
@ SHT_REL
Definition: ELF.h:1098
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition: ELF.h:1129
@ SHT_NOBITS
Definition: ELF.h:1097
@ SHT_GNU_verneed
Definition: ELF.h:1140
@ SHT_RELR
Definition: ELF.h:1108
@ SHT_GNU_verdef
Definition: ELF.h:1139
@ SHT_CREL
Definition: ELF.h:1111
@ SHT_DYNAMIC
Definition: ELF.h:1095
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:1105
@ SHT_LLVM_ADDRSIG
Definition: ELF.h:1119
@ SHT_ARM_EXIDX
Definition: ELF.h:1146
@ SHT_LLVM_BB_ADDR_MAP
Definition: ELF.h:1130
@ SHT_GNU_HASH
Definition: ELF.h:1138
@ SHT_RELA
Definition: ELF.h:1093
@ SHT_NOTE
Definition: ELF.h:1096
@ SHT_MIPS_ABIFLAGS
Definition: ELF.h:1167
@ SHT_GNU_versym
Definition: ELF.h:1141
@ SHT_HASH
Definition: ELF.h:1094
@ EF_AMDGPU_GENERIC_VERSION_MAX
Definition: ELF.h:884
@ EF_AMDGPU_GENERIC_VERSION_OFFSET
Definition: ELF.h:882
@ EF_AMDGPU_GENERIC_VERSION_MIN
Definition: ELF.h:883
@ EF_AMDGPU_GENERIC_VERSION
Definition: ELF.h:881
@ ELFABIVERSION_AMDGPU_HSA_V4
Definition: ELF.h:379
@ ELFABIVERSION_AMDGPU_HSA_V5
Definition: ELF.h:380
@ ELFABIVERSION_AMDGPU_HSA_V3
Definition: ELF.h:378
@ ELFABIVERSION_AMDGPU_HSA_V6
Definition: ELF.h:381
@ STO_RISCV_VARIANT_CC
Definition: ELF.h:692
@ ELFDATA2LSB
Definition: ELF.h:336
@ RSS_UNDEF
Definition: ELF.h:1382
@ STV_INTERNAL
Definition: ELF.h:1372
@ STV_HIDDEN
Definition: ELF.h:1373
@ STV_PROTECTED
Definition: ELF.h:1374
@ STV_DEFAULT
Definition: ELF.h:1371
@ Val_GNU_MIPS_ABI_FP_ANY
Definition: MipsABIFlags.h:85
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:53
static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section)
Definition: ELFYAML.cpp:1405
static void groupSectionMapping(IO &IO, ELFYAML::GroupSection &Group)
Definition: ELFYAML.cpp:1495
static StringRef getStringValue(IO &IO, const char *Key)
Definition: ELFYAML.cpp:1572
static void sectionHeaderTableMapping(IO &IO, ELFYAML::SectionHeaderTable &SHT)
Definition: ELFYAML.cpp:1518
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section)
Definition: ELFYAML.cpp:1378
static bool isInteger(StringRef Val)
Definition: ELFYAML.cpp:1582
static void fillMapping(IO &IO, ELFYAML::Fill &Fill)
Definition: ELFYAML.cpp:1511
static void setStringValue(IO &IO, const char *Key, StringRef Val)
Definition: ELFYAML.cpp:1578
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result)
Definition: StringRef.cpp:498
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition: STLExtras.h:1945
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
Definition: StringRef.cpp:488
#define N
StringRef Name
Definition: ELFYAML.h:240
std::optional< llvm::yaml::Hex64 > Offset
Definition: ELFYAML.h:241
ELF_ELFOSABI OSABI
Definition: ELFYAML.h:116
std::optional< ELF_EM > Machine
Definition: ELFYAML.h:119
llvm::yaml::Hex64 Size
Definition: ELFYAML.h:311
std::optional< yaml::BinaryRef > Pattern
Definition: ELFYAML.h:310
std::optional< std::vector< SectionOrType > > Members
Definition: ELFYAML.h:605
std::optional< StringRef > Signature
Definition: ELFYAML.h:606
unsigned getMachine() const
Definition: ELFYAML.cpp:35
FileHeader Header
Definition: ELFYAML.h:724
ELF_ELFOSABI getOSAbi() const
Definition: ELFYAML.cpp:33
std::optional< std::vector< SectionHeader > > Excluded
Definition: ELFYAML.h:327
static constexpr StringRef TypeStr
Definition: ELFYAML.h:340
std::optional< bool > NoHeaders
Definition: ELFYAML.h:328
std::optional< std::vector< SectionHeader > > Sections
Definition: ELFYAML.h:326
static bool nameMatches(StringRef Name)
Definition: ELFYAML.h:371
static StringRef input(StringRef Scalar, void *, ELFYAML::YAMLFlowString &Val)
Definition: ELFYAML.cpp:1208
static void output(const ELFYAML::YAMLFlowString &Val, void *, raw_ostream &Out)
Definition: ELFYAML.cpp:1204
static QuotingType mustQuote(StringRef S)
Definition: ELFYAML.cpp:1213
static StringRef input(StringRef Scalar, void *, StOtherPiece &Val)
Definition: ELFYAML.cpp:1193
static QuotingType mustQuote(StringRef)
Definition: ELFYAML.cpp:1197
static void output(const StOtherPiece &Val, void *, raw_ostream &Out)
Definition: ELFYAML.cpp:1190