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