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_MACH_V75, EF_HEXAGON_MACH);
500 BCaseMask(EF_HEXAGON_ISA_V2, EF_HEXAGON_ISA);
501 BCaseMask(EF_HEXAGON_ISA_V3, EF_HEXAGON_ISA);
502 BCaseMask(EF_HEXAGON_ISA_V4, EF_HEXAGON_ISA);
503 BCaseMask(EF_HEXAGON_ISA_V5, EF_HEXAGON_ISA);
504 BCaseMask(EF_HEXAGON_ISA_V55, EF_HEXAGON_ISA);
505 BCaseMask(EF_HEXAGON_ISA_V60, EF_HEXAGON_ISA);
506 BCaseMask(EF_HEXAGON_ISA_V62, EF_HEXAGON_ISA);
507 BCaseMask(EF_HEXAGON_ISA_V65, EF_HEXAGON_ISA);
508 BCaseMask(EF_HEXAGON_ISA_V66, EF_HEXAGON_ISA);
509 BCaseMask(EF_HEXAGON_ISA_V67, EF_HEXAGON_ISA);
510 BCaseMask(EF_HEXAGON_ISA_V68, EF_HEXAGON_ISA);
511 BCaseMask(EF_HEXAGON_ISA_V69, EF_HEXAGON_ISA);
512 BCaseMask(EF_HEXAGON_ISA_V71, EF_HEXAGON_ISA);
513 BCaseMask(EF_HEXAGON_ISA_V73, EF_HEXAGON_ISA);
514 BCaseMask(EF_HEXAGON_ISA_V75, EF_HEXAGON_ISA);
515 break;
516 case ELF::EM_AVR:
517 BCaseMask(EF_AVR_ARCH_AVR1, EF_AVR_ARCH_MASK);
518 BCaseMask(EF_AVR_ARCH_AVR2, EF_AVR_ARCH_MASK);
519 BCaseMask(EF_AVR_ARCH_AVR25, EF_AVR_ARCH_MASK);
520 BCaseMask(EF_AVR_ARCH_AVR3, EF_AVR_ARCH_MASK);
521 BCaseMask(EF_AVR_ARCH_AVR31, EF_AVR_ARCH_MASK);
522 BCaseMask(EF_AVR_ARCH_AVR35, EF_AVR_ARCH_MASK);
523 BCaseMask(EF_AVR_ARCH_AVR4, EF_AVR_ARCH_MASK);
524 BCaseMask(EF_AVR_ARCH_AVR5, EF_AVR_ARCH_MASK);
525 BCaseMask(EF_AVR_ARCH_AVR51, EF_AVR_ARCH_MASK);
526 BCaseMask(EF_AVR_ARCH_AVR6, EF_AVR_ARCH_MASK);
527 BCaseMask(EF_AVR_ARCH_AVRTINY, EF_AVR_ARCH_MASK);
528 BCaseMask(EF_AVR_ARCH_XMEGA1, EF_AVR_ARCH_MASK);
529 BCaseMask(EF_AVR_ARCH_XMEGA2, EF_AVR_ARCH_MASK);
530 BCaseMask(EF_AVR_ARCH_XMEGA3, EF_AVR_ARCH_MASK);
531 BCaseMask(EF_AVR_ARCH_XMEGA4, EF_AVR_ARCH_MASK);
532 BCaseMask(EF_AVR_ARCH_XMEGA5, EF_AVR_ARCH_MASK);
533 BCaseMask(EF_AVR_ARCH_XMEGA6, EF_AVR_ARCH_MASK);
534 BCaseMask(EF_AVR_ARCH_XMEGA7, EF_AVR_ARCH_MASK);
535 BCase(EF_AVR_LINKRELAX_PREPARED);
536 break;
538 BCaseMask(EF_LOONGARCH_ABI_SOFT_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK);
539 BCaseMask(EF_LOONGARCH_ABI_SINGLE_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK);
540 BCaseMask(EF_LOONGARCH_ABI_DOUBLE_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK);
541 BCaseMask(EF_LOONGARCH_OBJABI_V0, EF_LOONGARCH_OBJABI_MASK);
542 BCaseMask(EF_LOONGARCH_OBJABI_V1, EF_LOONGARCH_OBJABI_MASK);
543 break;
544 case ELF::EM_RISCV:
545 BCase(EF_RISCV_RVC);
546 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT, EF_RISCV_FLOAT_ABI);
547 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE, EF_RISCV_FLOAT_ABI);
548 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_FLOAT_ABI);
549 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD, EF_RISCV_FLOAT_ABI);
550 BCase(EF_RISCV_RVE);
551 BCase(EF_RISCV_TSO);
552 break;
554 BCase(EF_SPARC_32PLUS);
555 BCase(EF_SPARC_SUN_US1);
556 BCase(EF_SPARC_SUN_US3);
557 BCase(EF_SPARC_HAL_R1);
558 break;
559 case ELF::EM_SPARCV9:
560 BCase(EF_SPARC_SUN_US1);
561 BCase(EF_SPARC_SUN_US3);
562 BCase(EF_SPARC_HAL_R1);
563 BCaseMask(EF_SPARCV9_RMO, EF_SPARCV9_MM);
564 BCaseMask(EF_SPARCV9_PSO, EF_SPARCV9_MM);
565 BCaseMask(EF_SPARCV9_TSO, EF_SPARCV9_MM);
566 break;
567 case ELF::EM_XTENSA:
568 BCase(EF_XTENSA_XT_INSN);
569 BCaseMask(EF_XTENSA_MACH_NONE, EF_XTENSA_MACH);
570 BCase(EF_XTENSA_XT_LIT);
571 break;
572 case ELF::EM_AMDGPU:
573 BCaseMask(EF_AMDGPU_MACH_NONE, EF_AMDGPU_MACH);
574 BCaseMask(EF_AMDGPU_MACH_R600_R600, EF_AMDGPU_MACH);
575 BCaseMask(EF_AMDGPU_MACH_R600_R630, EF_AMDGPU_MACH);
576 BCaseMask(EF_AMDGPU_MACH_R600_RS880, EF_AMDGPU_MACH);
577 BCaseMask(EF_AMDGPU_MACH_R600_RV670, EF_AMDGPU_MACH);
578 BCaseMask(EF_AMDGPU_MACH_R600_RV710, EF_AMDGPU_MACH);
579 BCaseMask(EF_AMDGPU_MACH_R600_RV730, EF_AMDGPU_MACH);
580 BCaseMask(EF_AMDGPU_MACH_R600_RV770, EF_AMDGPU_MACH);
581 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR, EF_AMDGPU_MACH);
582 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS, EF_AMDGPU_MACH);
583 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER, EF_AMDGPU_MACH);
584 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD, EF_AMDGPU_MACH);
585 BCaseMask(EF_AMDGPU_MACH_R600_SUMO, EF_AMDGPU_MACH);
586 BCaseMask(EF_AMDGPU_MACH_R600_BARTS, EF_AMDGPU_MACH);
587 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS, EF_AMDGPU_MACH);
588 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN, EF_AMDGPU_MACH);
589 BCaseMask(EF_AMDGPU_MACH_R600_TURKS, EF_AMDGPU_MACH);
590 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600, EF_AMDGPU_MACH);
591 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601, EF_AMDGPU_MACH);
592 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX602, EF_AMDGPU_MACH);
593 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700, EF_AMDGPU_MACH);
594 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701, EF_AMDGPU_MACH);
595 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702, EF_AMDGPU_MACH);
596 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703, EF_AMDGPU_MACH);
597 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704, EF_AMDGPU_MACH);
598 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX705, EF_AMDGPU_MACH);
599 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801, EF_AMDGPU_MACH);
600 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802, EF_AMDGPU_MACH);
601 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803, EF_AMDGPU_MACH);
602 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX805, EF_AMDGPU_MACH);
603 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810, EF_AMDGPU_MACH);
604 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900, EF_AMDGPU_MACH);
605 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902, EF_AMDGPU_MACH);
606 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904, EF_AMDGPU_MACH);
607 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906, EF_AMDGPU_MACH);
608 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908, EF_AMDGPU_MACH);
609 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909, EF_AMDGPU_MACH);
610 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90A, EF_AMDGPU_MACH);
611 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX90C, EF_AMDGPU_MACH);
612 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX940, EF_AMDGPU_MACH);
613 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX941, EF_AMDGPU_MACH);
614 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX942, EF_AMDGPU_MACH);
615 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX950, EF_AMDGPU_MACH);
616 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010, EF_AMDGPU_MACH);
617 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011, EF_AMDGPU_MACH);
618 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012, EF_AMDGPU_MACH);
619 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1013, EF_AMDGPU_MACH);
620 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1030, EF_AMDGPU_MACH);
621 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1031, EF_AMDGPU_MACH);
622 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1032, EF_AMDGPU_MACH);
623 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1033, EF_AMDGPU_MACH);
624 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1034, EF_AMDGPU_MACH);
625 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1035, EF_AMDGPU_MACH);
626 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1036, EF_AMDGPU_MACH);
627 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1100, EF_AMDGPU_MACH);
628 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1101, EF_AMDGPU_MACH);
629 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1102, EF_AMDGPU_MACH);
630 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1103, EF_AMDGPU_MACH);
631 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1150, EF_AMDGPU_MACH);
632 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1151, EF_AMDGPU_MACH);
633 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1152, EF_AMDGPU_MACH);
634 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1153, EF_AMDGPU_MACH);
635 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1200, EF_AMDGPU_MACH);
636 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1201, EF_AMDGPU_MACH);
637 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX9_GENERIC, EF_AMDGPU_MACH);
638 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX9_4_GENERIC, EF_AMDGPU_MACH);
639 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX10_1_GENERIC, EF_AMDGPU_MACH);
640 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX10_3_GENERIC, EF_AMDGPU_MACH);
641 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX11_GENERIC, EF_AMDGPU_MACH);
642 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX12_GENERIC, EF_AMDGPU_MACH);
643 switch (Object->Header.ABIVersion) {
644 default:
645 // ELFOSABI_AMDGPU_PAL, ELFOSABI_AMDGPU_MESA3D support *_V3 flags.
646 [[fallthrough]];
648 BCase(EF_AMDGPU_FEATURE_XNACK_V3);
649 BCase(EF_AMDGPU_FEATURE_SRAMECC_V3);
650 break;
652 for (unsigned K = ELF::EF_AMDGPU_GENERIC_VERSION_MIN;
654 std::string Key = "EF_AMDGPU_GENERIC_VERSION_V" + std::to_string(K);
655 IO.maskedBitSetCase(Value, Key.c_str(),
658 }
659 [[fallthrough]];
662 BCaseMask(EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4,
663 EF_AMDGPU_FEATURE_XNACK_V4);
664 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ANY_V4,
665 EF_AMDGPU_FEATURE_XNACK_V4);
666 BCaseMask(EF_AMDGPU_FEATURE_XNACK_OFF_V4,
667 EF_AMDGPU_FEATURE_XNACK_V4);
668 BCaseMask(EF_AMDGPU_FEATURE_XNACK_ON_V4,
669 EF_AMDGPU_FEATURE_XNACK_V4);
670 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4,
671 EF_AMDGPU_FEATURE_SRAMECC_V4);
672 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ANY_V4,
673 EF_AMDGPU_FEATURE_SRAMECC_V4);
674 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_OFF_V4,
675 EF_AMDGPU_FEATURE_SRAMECC_V4);
676 BCaseMask(EF_AMDGPU_FEATURE_SRAMECC_ON_V4,
677 EF_AMDGPU_FEATURE_SRAMECC_V4);
678 break;
679 }
680 break;
681 default:
682 break;
683 }
684#undef BCase
685#undef BCaseMask
686}
687
688void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
689 IO &IO, ELFYAML::ELF_SHT &Value) {
690 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
691 assert(Object && "The IO context is not initialized");
692#define ECase(X) IO.enumCase(Value, #X, ELF::X)
693 ECase(SHT_NULL);
694 ECase(SHT_PROGBITS);
695 ECase(SHT_SYMTAB);
696 // FIXME: Issue a diagnostic with this information.
697 ECase(SHT_STRTAB);
698 ECase(SHT_RELA);
699 ECase(SHT_HASH);
700 ECase(SHT_DYNAMIC);
701 ECase(SHT_NOTE);
702 ECase(SHT_NOBITS);
703 ECase(SHT_REL);
704 ECase(SHT_SHLIB);
705 ECase(SHT_DYNSYM);
706 ECase(SHT_INIT_ARRAY);
707 ECase(SHT_FINI_ARRAY);
708 ECase(SHT_PREINIT_ARRAY);
709 ECase(SHT_GROUP);
710 ECase(SHT_SYMTAB_SHNDX);
711 ECase(SHT_RELR);
712 ECase(SHT_CREL);
713 ECase(SHT_ANDROID_REL);
714 ECase(SHT_ANDROID_RELA);
715 ECase(SHT_ANDROID_RELR);
716 ECase(SHT_LLVM_ODRTAB);
717 ECase(SHT_LLVM_LINKER_OPTIONS);
718 ECase(SHT_LLVM_CALL_GRAPH_PROFILE);
719 ECase(SHT_LLVM_ADDRSIG);
720 ECase(SHT_LLVM_DEPENDENT_LIBRARIES);
721 ECase(SHT_LLVM_SYMPART);
722 ECase(SHT_LLVM_PART_EHDR);
723 ECase(SHT_LLVM_PART_PHDR);
724 ECase(SHT_LLVM_BB_ADDR_MAP_V0);
725 ECase(SHT_LLVM_BB_ADDR_MAP);
726 ECase(SHT_LLVM_OFFLOADING);
727 ECase(SHT_LLVM_LTO);
728 ECase(SHT_GNU_ATTRIBUTES);
729 ECase(SHT_GNU_HASH);
730 ECase(SHT_GNU_verdef);
731 ECase(SHT_GNU_verneed);
732 ECase(SHT_GNU_versym);
733 switch (Object->getMachine()) {
734 case ELF::EM_ARM:
735 ECase(SHT_ARM_EXIDX);
736 ECase(SHT_ARM_PREEMPTMAP);
737 ECase(SHT_ARM_ATTRIBUTES);
738 ECase(SHT_ARM_DEBUGOVERLAY);
739 ECase(SHT_ARM_OVERLAYSECTION);
740 break;
741 case ELF::EM_HEXAGON:
742 ECase(SHT_HEX_ORDERED);
743 ECase(SHT_HEXAGON_ATTRIBUTES);
744 break;
745 case ELF::EM_X86_64:
746 ECase(SHT_X86_64_UNWIND);
747 break;
748 case ELF::EM_MIPS:
749 ECase(SHT_MIPS_REGINFO);
750 ECase(SHT_MIPS_OPTIONS);
751 ECase(SHT_MIPS_DWARF);
752 ECase(SHT_MIPS_ABIFLAGS);
753 break;
754 case ELF::EM_RISCV:
755 ECase(SHT_RISCV_ATTRIBUTES);
756 break;
757 case ELF::EM_MSP430:
758 ECase(SHT_MSP430_ATTRIBUTES);
759 break;
760 case ELF::EM_AARCH64:
761 ECase(SHT_AARCH64_AUTH_RELR);
762 ECase(SHT_AARCH64_MEMTAG_GLOBALS_STATIC);
763 ECase(SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC);
764 break;
765 default:
766 // Nothing to do.
767 break;
768 }
769#undef ECase
770 IO.enumFallback<Hex32>(Value);
771}
772
773void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO,
774 ELFYAML::ELF_PF &Value) {
775#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
776 BCase(PF_X);
777 BCase(PF_W);
778 BCase(PF_R);
779}
780
781void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
782 ELFYAML::ELF_SHF &Value) {
783 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
784#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
785 BCase(SHF_WRITE);
786 BCase(SHF_ALLOC);
787 BCase(SHF_EXCLUDE);
788 BCase(SHF_EXECINSTR);
789 BCase(SHF_MERGE);
790 BCase(SHF_STRINGS);
791 BCase(SHF_INFO_LINK);
792 BCase(SHF_LINK_ORDER);
793 BCase(SHF_OS_NONCONFORMING);
794 BCase(SHF_GROUP);
795 BCase(SHF_TLS);
796 BCase(SHF_COMPRESSED);
797 switch (Object->getOSAbi()) {
799 BCase(SHF_SUNW_NODISCARD);
800 break;
801 default:
802 BCase(SHF_GNU_RETAIN);
803 break;
804 }
805 switch (Object->getMachine()) {
806 case ELF::EM_ARM:
807 BCase(SHF_ARM_PURECODE);
808 break;
809 case ELF::EM_HEXAGON:
810 BCase(SHF_HEX_GPREL);
811 break;
812 case ELF::EM_MIPS:
813 BCase(SHF_MIPS_NODUPES);
814 BCase(SHF_MIPS_NAMES);
815 BCase(SHF_MIPS_LOCAL);
816 BCase(SHF_MIPS_NOSTRIP);
817 BCase(SHF_MIPS_GPREL);
818 BCase(SHF_MIPS_MERGE);
819 BCase(SHF_MIPS_ADDR);
820 BCase(SHF_MIPS_STRING);
821 break;
822 case ELF::EM_X86_64:
823 BCase(SHF_X86_64_LARGE);
824 break;
825 default:
826 // Nothing to do.
827 break;
828 }
829#undef BCase
830}
831
832void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
833 IO &IO, ELFYAML::ELF_SHN &Value) {
834 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
835 assert(Object && "The IO context is not initialized");
836#define ECase(X) IO.enumCase(Value, #X, ELF::X)
837 ECase(SHN_UNDEF);
838 ECase(SHN_LORESERVE);
839 ECase(SHN_LOPROC);
840 ECase(SHN_HIPROC);
841 ECase(SHN_LOOS);
842 ECase(SHN_HIOS);
843 ECase(SHN_ABS);
844 ECase(SHN_COMMON);
845 ECase(SHN_XINDEX);
846 ECase(SHN_HIRESERVE);
847 ECase(SHN_AMDGPU_LDS);
848
849 if (!IO.outputting() || Object->getMachine() == ELF::EM_MIPS) {
850 ECase(SHN_MIPS_ACOMMON);
851 ECase(SHN_MIPS_TEXT);
852 ECase(SHN_MIPS_DATA);
853 ECase(SHN_MIPS_SCOMMON);
854 ECase(SHN_MIPS_SUNDEFINED);
855 }
856
857 ECase(SHN_HEXAGON_SCOMMON);
858 ECase(SHN_HEXAGON_SCOMMON_1);
859 ECase(SHN_HEXAGON_SCOMMON_2);
860 ECase(SHN_HEXAGON_SCOMMON_4);
861 ECase(SHN_HEXAGON_SCOMMON_8);
862#undef ECase
863 IO.enumFallback<Hex16>(Value);
864}
865
866void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration(
867 IO &IO, ELFYAML::ELF_STB &Value) {
868#define ECase(X) IO.enumCase(Value, #X, ELF::X)
869 ECase(STB_LOCAL);
870 ECase(STB_GLOBAL);
871 ECase(STB_WEAK);
872 ECase(STB_GNU_UNIQUE);
873#undef ECase
874 IO.enumFallback<Hex8>(Value);
875}
876
877void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
878 IO &IO, ELFYAML::ELF_STT &Value) {
879#define ECase(X) IO.enumCase(Value, #X, ELF::X)
880 ECase(STT_NOTYPE);
881 ECase(STT_OBJECT);
882 ECase(STT_FUNC);
883 ECase(STT_SECTION);
884 ECase(STT_FILE);
885 ECase(STT_COMMON);
886 ECase(STT_TLS);
887 ECase(STT_GNU_IFUNC);
888#undef ECase
889 IO.enumFallback<Hex8>(Value);
890}
891
892
893void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration(
894 IO &IO, ELFYAML::ELF_RSS &Value) {
895#define ECase(X) IO.enumCase(Value, #X, ELF::X)
896 ECase(RSS_UNDEF);
897 ECase(RSS_GP);
898 ECase(RSS_GP0);
899 ECase(RSS_LOC);
900#undef ECase
901}
902
903void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
904 IO &IO, ELFYAML::ELF_REL &Value) {
905 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
906 assert(Object && "The IO context is not initialized");
907#define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
908 switch (Object->getMachine()) {
909 case ELF::EM_X86_64:
910#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
911 break;
912 case ELF::EM_MIPS:
913#include "llvm/BinaryFormat/ELFRelocs/Mips.def"
914 break;
915 case ELF::EM_HEXAGON:
916#include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
917 break;
918 case ELF::EM_386:
919 case ELF::EM_IAMCU:
920#include "llvm/BinaryFormat/ELFRelocs/i386.def"
921 break;
922 case ELF::EM_AARCH64:
923#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
924 break;
925 case ELF::EM_ARM:
926#include "llvm/BinaryFormat/ELFRelocs/ARM.def"
927 break;
928 case ELF::EM_ARC:
929#include "llvm/BinaryFormat/ELFRelocs/ARC.def"
930 break;
931 case ELF::EM_RISCV:
932#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
933 break;
934 case ELF::EM_LANAI:
935#include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
936 break;
937 case ELF::EM_AMDGPU:
938#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
939 break;
940 case ELF::EM_BPF:
941#include "llvm/BinaryFormat/ELFRelocs/BPF.def"
942 break;
943 case ELF::EM_VE:
944#include "llvm/BinaryFormat/ELFRelocs/VE.def"
945 break;
946 case ELF::EM_CSKY:
947#include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
948 break;
949 case ELF::EM_PPC:
950#include "llvm/BinaryFormat/ELFRelocs/PowerPC.def"
951 break;
952 case ELF::EM_PPC64:
953#include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
954 break;
955 case ELF::EM_68K:
956#include "llvm/BinaryFormat/ELFRelocs/M68k.def"
957 break;
959#include "llvm/BinaryFormat/ELFRelocs/LoongArch.def"
960 break;
961 case ELF::EM_XTENSA:
962#include "llvm/BinaryFormat/ELFRelocs/Xtensa.def"
963 break;
964 default:
965 // Nothing to do.
966 break;
967 }
968#undef ELF_RELOC
969 IO.enumFallback<Hex32>(Value);
970}
971
972void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
973 IO &IO, ELFYAML::ELF_DYNTAG &Value) {
974 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
975 assert(Object && "The IO context is not initialized");
976
977// Disable architecture specific tags by default. We might enable them below.
978#define AARCH64_DYNAMIC_TAG(name, value)
979#define MIPS_DYNAMIC_TAG(name, value)
980#define HEXAGON_DYNAMIC_TAG(name, value)
981#define PPC_DYNAMIC_TAG(name, value)
982#define PPC64_DYNAMIC_TAG(name, value)
983// Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
984#define DYNAMIC_TAG_MARKER(name, value)
985
986#define STRINGIFY(X) (#X)
987#define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
988 switch (Object->getMachine()) {
989 case ELF::EM_AARCH64:
990#undef AARCH64_DYNAMIC_TAG
991#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
992#include "llvm/BinaryFormat/DynamicTags.def"
993#undef AARCH64_DYNAMIC_TAG
994#define AARCH64_DYNAMIC_TAG(name, value)
995 break;
996 case ELF::EM_MIPS:
997#undef MIPS_DYNAMIC_TAG
998#define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
999#include "llvm/BinaryFormat/DynamicTags.def"
1000#undef MIPS_DYNAMIC_TAG
1001#define MIPS_DYNAMIC_TAG(name, value)
1002 break;
1003 case ELF::EM_HEXAGON:
1004#undef HEXAGON_DYNAMIC_TAG
1005#define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1006#include "llvm/BinaryFormat/DynamicTags.def"
1007#undef HEXAGON_DYNAMIC_TAG
1008#define HEXAGON_DYNAMIC_TAG(name, value)
1009 break;
1010 case ELF::EM_PPC:
1011#undef PPC_DYNAMIC_TAG
1012#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1013#include "llvm/BinaryFormat/DynamicTags.def"
1014#undef PPC_DYNAMIC_TAG
1015#define PPC_DYNAMIC_TAG(name, value)
1016 break;
1017 case ELF::EM_PPC64:
1018#undef PPC64_DYNAMIC_TAG
1019#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1020#include "llvm/BinaryFormat/DynamicTags.def"
1021#undef PPC64_DYNAMIC_TAG
1022#define PPC64_DYNAMIC_TAG(name, value)
1023 break;
1024 case ELF::EM_RISCV:
1025#undef RISCV_DYNAMIC_TAG
1026#define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
1027#include "llvm/BinaryFormat/DynamicTags.def"
1028#undef RISCV_DYNAMIC_TAG
1029#define RISCV_DYNAMIC_TAG(name, value)
1030 break;
1031 default:
1032#include "llvm/BinaryFormat/DynamicTags.def"
1033 break;
1034 }
1035#undef AARCH64_DYNAMIC_TAG
1036#undef MIPS_DYNAMIC_TAG
1037#undef HEXAGON_DYNAMIC_TAG
1038#undef PPC_DYNAMIC_TAG
1039#undef PPC64_DYNAMIC_TAG
1040#undef DYNAMIC_TAG_MARKER
1041#undef STRINGIFY
1042#undef DYNAMIC_TAG
1043
1044 IO.enumFallback<Hex64>(Value);
1045}
1046
1047void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration(
1048 IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
1049#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1050 ECase(REG_NONE);
1051 ECase(REG_32);
1052 ECase(REG_64);
1053 ECase(REG_128);
1054#undef ECase
1055}
1056
1057void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration(
1058 IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
1059#define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
1060 ECase(FP_ANY);
1061 ECase(FP_DOUBLE);
1062 ECase(FP_SINGLE);
1063 ECase(FP_SOFT);
1064 ECase(FP_OLD_64);
1065 ECase(FP_XX);
1066 ECase(FP_64);
1067 ECase(FP_64A);
1068#undef ECase
1069}
1070
1071void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration(
1072 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
1073#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
1074 ECase(EXT_NONE);
1075 ECase(EXT_XLR);
1076 ECase(EXT_OCTEON2);
1077 ECase(EXT_OCTEONP);
1078 ECase(EXT_LOONGSON_3A);
1079 ECase(EXT_OCTEON);
1080 ECase(EXT_5900);
1081 ECase(EXT_4650);
1082 ECase(EXT_4010);
1083 ECase(EXT_4100);
1084 ECase(EXT_3900);
1085 ECase(EXT_10000);
1086 ECase(EXT_SB1);
1087 ECase(EXT_4111);
1088 ECase(EXT_4120);
1089 ECase(EXT_5400);
1090 ECase(EXT_5500);
1091 ECase(EXT_LOONGSON_2E);
1092 ECase(EXT_LOONGSON_2F);
1093 ECase(EXT_OCTEON3);
1094#undef ECase
1095}
1096
1097void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration(
1098 IO &IO, ELFYAML::MIPS_ISA &Value) {
1099 IO.enumCase(Value, "MIPS1", 1);
1100 IO.enumCase(Value, "MIPS2", 2);
1101 IO.enumCase(Value, "MIPS3", 3);
1102 IO.enumCase(Value, "MIPS4", 4);
1103 IO.enumCase(Value, "MIPS5", 5);
1104 IO.enumCase(Value, "MIPS32", 32);
1105 IO.enumCase(Value, "MIPS64", 64);
1106 IO.enumFallback<Hex32>(Value);
1107}
1108
1109void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset(
1110 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
1111#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
1112 BCase(DSP);
1113 BCase(DSPR2);
1114 BCase(EVA);
1115 BCase(MCU);
1116 BCase(MDMX);
1117 BCase(MIPS3D);
1118 BCase(MT);
1119 BCase(SMARTMIPS);
1120 BCase(VIRT);
1121 BCase(MSA);
1122 BCase(MIPS16);
1123 BCase(MICROMIPS);
1124 BCase(XPA);
1125 BCase(CRC);
1126 BCase(GINV);
1127#undef BCase
1128}
1129
1130void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset(
1131 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
1132#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
1133 BCase(ODDSPREG);
1134#undef BCase
1135}
1136
1137void MappingTraits<ELFYAML::SectionHeader>::mapping(
1138 IO &IO, ELFYAML::SectionHeader &SHdr) {
1139 IO.mapRequired("Name", SHdr.Name);
1140}
1141
1142void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
1143 ELFYAML::FileHeader &FileHdr) {
1144 IO.mapRequired("Class", FileHdr.Class);
1145 IO.mapRequired("Data", FileHdr.Data);
1146 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
1147 IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0));
1148 IO.mapRequired("Type", FileHdr.Type);
1149 IO.mapOptional("Machine", FileHdr.Machine);
1150 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
1151 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
1152 IO.mapOptional("SectionHeaderStringTable", FileHdr.SectionHeaderStringTable);
1153
1154 // obj2yaml does not dump these fields.
1155 assert(!IO.outputting() ||
1156 (!FileHdr.EPhOff && !FileHdr.EPhEntSize && !FileHdr.EPhNum));
1157 IO.mapOptional("EPhOff", FileHdr.EPhOff);
1158 IO.mapOptional("EPhEntSize", FileHdr.EPhEntSize);
1159 IO.mapOptional("EPhNum", FileHdr.EPhNum);
1160 IO.mapOptional("EShEntSize", FileHdr.EShEntSize);
1161 IO.mapOptional("EShOff", FileHdr.EShOff);
1162 IO.mapOptional("EShNum", FileHdr.EShNum);
1163 IO.mapOptional("EShStrNdx", FileHdr.EShStrNdx);
1164}
1165
1166void MappingTraits<ELFYAML::ProgramHeader>::mapping(
1167 IO &IO, ELFYAML::ProgramHeader &Phdr) {
1168 IO.mapRequired("Type", Phdr.Type);
1169 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
1170 IO.mapOptional("FirstSec", Phdr.FirstSec);
1171 IO.mapOptional("LastSec", Phdr.LastSec);
1172 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
1173 IO.mapOptional("PAddr", Phdr.PAddr, Phdr.VAddr);
1174 IO.mapOptional("Align", Phdr.Align);
1175 IO.mapOptional("FileSize", Phdr.FileSize);
1176 IO.mapOptional("MemSize", Phdr.MemSize);
1177 IO.mapOptional("Offset", Phdr.Offset);
1178}
1179
1180std::string MappingTraits<ELFYAML::ProgramHeader>::validate(
1181 IO &IO, ELFYAML::ProgramHeader &FileHdr) {
1182 if (!FileHdr.FirstSec && FileHdr.LastSec)
1183 return "the \"LastSec\" key can't be used without the \"FirstSec\" key";
1184 if (FileHdr.FirstSec && !FileHdr.LastSec)
1185 return "the \"FirstSec\" key can't be used without the \"LastSec\" key";
1186 return "";
1187}
1188
1189LLVM_YAML_STRONG_TYPEDEF(StringRef, StOtherPiece)
1190
1191template <> struct ScalarTraits<StOtherPiece> {
1192 static void output(const StOtherPiece &Val, void *, raw_ostream &Out) {
1193 Out << Val;
1194 }
1195 static StringRef input(StringRef Scalar, void *, StOtherPiece &Val) {
1196 Val = Scalar;
1197 return {};
1198 }
1199 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1200};
1201template <> struct SequenceElementTraits<StOtherPiece> {
1202 static const bool flow = true;
1203};
1204
1205template <> struct ScalarTraits<ELFYAML::YAMLFlowString> {
1206 static void output(const ELFYAML::YAMLFlowString &Val, void *,
1207 raw_ostream &Out) {
1208 Out << Val;
1209 }
1210 static StringRef input(StringRef Scalar, void *,
1211 ELFYAML::YAMLFlowString &Val) {
1212 Val = Scalar;
1213 return {};
1214 }
1215 static QuotingType mustQuote(StringRef S) {
1216 return ScalarTraits<StringRef>::mustQuote(S);
1217 }
1218};
1219template <> struct SequenceElementTraits<ELFYAML::YAMLFlowString> {
1220 static const bool flow = true;
1221};
1222
1223namespace {
1224
1225struct NormalizedOther {
1226 NormalizedOther(IO &IO) : YamlIO(IO) {}
1227 NormalizedOther(IO &IO, std::optional<uint8_t> Original) : YamlIO(IO) {
1228 assert(Original && "This constructor is only used for outputting YAML and "
1229 "assumes a non-empty Original");
1230 std::vector<StOtherPiece> Ret;
1231 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext());
1232 for (std::pair<StringRef, uint8_t> &P :
1233 getFlags(Object->getMachine()).takeVector()) {
1234 uint8_t FlagValue = P.second;
1235 if ((*Original & FlagValue) != FlagValue)
1236 continue;
1237 *Original &= ~FlagValue;
1238 Ret.push_back({P.first});
1239 }
1240
1241 if (*Original != 0) {
1242 UnknownFlagsHolder = std::to_string(*Original);
1243 Ret.push_back({UnknownFlagsHolder});
1244 }
1245
1246 if (!Ret.empty())
1247 Other = std::move(Ret);
1248 }
1249
1250 uint8_t toValue(StringRef Name) {
1251 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext());
1252 MapVector<StringRef, uint8_t> Flags = getFlags(Object->getMachine());
1253
1254 auto It = Flags.find(Name);
1255 if (It != Flags.end())
1256 return It->second;
1257
1258 uint8_t Val;
1259 if (to_integer(Name, Val))
1260 return Val;
1261
1262 YamlIO.setError("an unknown value is used for symbol's 'Other' field: " +
1263 Name);
1264 return 0;
1265 }
1266
1267 std::optional<uint8_t> denormalize(IO &) {
1268 if (!Other)
1269 return std::nullopt;
1270 uint8_t Ret = 0;
1271 for (StOtherPiece &Val : *Other)
1272 Ret |= toValue(Val);
1273 return Ret;
1274 }
1275
1276 // st_other field is used to encode symbol visibility and platform-dependent
1277 // flags and values. This method returns a name to value map that is used for
1278 // parsing and encoding this field.
1279 MapVector<StringRef, uint8_t> getFlags(unsigned EMachine) {
1281 // STV_* values are just enumeration values. We add them in a reversed order
1282 // because when we convert the st_other to named constants when printing
1283 // YAML we want to use a maximum number of bits on each step:
1284 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
1285 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
1286 Map["STV_PROTECTED"] = ELF::STV_PROTECTED;
1287 Map["STV_HIDDEN"] = ELF::STV_HIDDEN;
1288 Map["STV_INTERNAL"] = ELF::STV_INTERNAL;
1289 // STV_DEFAULT is used to represent the default visibility and has a value
1290 // 0. We want to be able to read it from YAML documents, but there is no
1291 // reason to print it.
1292 if (!YamlIO.outputting())
1293 Map["STV_DEFAULT"] = ELF::STV_DEFAULT;
1294
1295 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
1296 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
1297 // consumed first when we print the output, because we do not want to print
1298 // any other flags that have the same bits instead.
1299 if (EMachine == ELF::EM_MIPS) {
1300 Map["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16;
1301 Map["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS;
1302 Map["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC;
1303 Map["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT;
1304 Map["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL;
1305 }
1306
1307 if (EMachine == ELF::EM_AARCH64)
1308 Map["STO_AARCH64_VARIANT_PCS"] = ELF::STO_AARCH64_VARIANT_PCS;
1309 if (EMachine == ELF::EM_RISCV)
1310 Map["STO_RISCV_VARIANT_CC"] = ELF::STO_RISCV_VARIANT_CC;
1311 return Map;
1312 }
1313
1315 std::optional<std::vector<StOtherPiece>> Other;
1317};
1318
1319} // end anonymous namespace
1320
1321void ScalarTraits<ELFYAML::YAMLIntUInt>::output(const ELFYAML::YAMLIntUInt &Val,
1322 void *Ctx, raw_ostream &Out) {
1323 Out << Val;
1324}
1325
1326StringRef ScalarTraits<ELFYAML::YAMLIntUInt>::input(StringRef Scalar, void *Ctx,
1327 ELFYAML::YAMLIntUInt &Val) {
1328 const bool Is64 = static_cast<ELFYAML::Object *>(Ctx)->Header.Class ==
1329 ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
1330 StringRef ErrMsg = "invalid number";
1331 // We do not accept negative hex numbers because their meaning is ambiguous.
1332 // For example, would -0xfffffffff mean 1 or INT32_MIN?
1333 if (Scalar.empty() || Scalar.starts_with("-0x"))
1334 return ErrMsg;
1335
1336 if (Scalar.starts_with("-")) {
1337 const int64_t MinVal = Is64 ? INT64_MIN : INT32_MIN;
1338 long long Int;
1339 if (getAsSignedInteger(Scalar, /*Radix=*/0, Int) || (Int < MinVal))
1340 return ErrMsg;
1341 Val = Int;
1342 return "";
1343 }
1344
1345 const uint64_t MaxVal = Is64 ? UINT64_MAX : UINT32_MAX;
1346 unsigned long long UInt;
1347 if (getAsUnsignedInteger(Scalar, /*Radix=*/0, UInt) || (UInt > MaxVal))
1348 return ErrMsg;
1349 Val = UInt;
1350 return "";
1351}
1352
1353void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
1354 IO.mapOptional("Name", Symbol.Name, StringRef());
1355 IO.mapOptional("StName", Symbol.StName);
1356 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
1357 IO.mapOptional("Section", Symbol.Section);
1358 IO.mapOptional("Index", Symbol.Index);
1359 IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));
1360 IO.mapOptional("Value", Symbol.Value);
1361 IO.mapOptional("Size", Symbol.Size);
1362
1363 // Symbol's Other field is a bit special. It is usually a field that
1364 // represents st_other and holds the symbol visibility. However, on some
1365 // platforms, it can contain bit fields and regular values, or even sometimes
1366 // a crazy mix of them (see comments for NormalizedOther). Because of this, we
1367 // need special handling.
1368 MappingNormalization<NormalizedOther, std::optional<uint8_t>> Keys(
1369 IO, Symbol.Other);
1370 IO.mapOptional("Other", Keys->Other);
1371}
1372
1373std::string MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
1374 ELFYAML::Symbol &Symbol) {
1375 if (Symbol.Index && Symbol.Section)
1376 return "Index and Section cannot both be specified for Symbol";
1377 return "";
1378}
1379
1380static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
1381 IO.mapOptional("Name", Section.Name, StringRef());
1382 IO.mapRequired("Type", Section.Type);
1383 IO.mapOptional("Flags", Section.Flags);
1384 IO.mapOptional("Address", Section.Address);
1385 IO.mapOptional("Link", Section.Link);
1386 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
1387 IO.mapOptional("EntSize", Section.EntSize);
1388 IO.mapOptional("Offset", Section.Offset);
1389
1390 IO.mapOptional("Content", Section.Content);
1391 IO.mapOptional("Size", Section.Size);
1392
1393 // obj2yaml does not dump these fields. They are expected to be empty when we
1394 // are producing YAML, because yaml2obj sets appropriate values for them
1395 // automatically when they are not explicitly defined.
1396 assert(!IO.outputting() ||
1397 (!Section.ShOffset && !Section.ShSize && !Section.ShName &&
1398 !Section.ShFlags && !Section.ShType && !Section.ShAddrAlign));
1399 IO.mapOptional("ShAddrAlign", Section.ShAddrAlign);
1400 IO.mapOptional("ShName", Section.ShName);
1401 IO.mapOptional("ShOffset", Section.ShOffset);
1402 IO.mapOptional("ShSize", Section.ShSize);
1403 IO.mapOptional("ShFlags", Section.ShFlags);
1404 IO.mapOptional("ShType", Section.ShType);
1405}
1406
1407static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) {
1408 commonSectionMapping(IO, Section);
1409 IO.mapOptional("Entries", Section.Entries);
1410}
1411
1412static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
1413 commonSectionMapping(IO, Section);
1414
1415 // We also support reading a content as array of bytes using the ContentArray
1416 // key. obj2yaml never prints this field.
1417 assert(!IO.outputting() || !Section.ContentBuf);
1418 IO.mapOptional("ContentArray", Section.ContentBuf);
1419 if (Section.ContentBuf) {
1420 if (Section.Content)
1421 IO.setError("Content and ContentArray can't be used together");
1422 Section.Content = yaml::BinaryRef(*Section.ContentBuf);
1423 }
1424
1425 IO.mapOptional("Info", Section.Info);
1426}
1427
1428static void sectionMapping(IO &IO, ELFYAML::BBAddrMapSection &Section) {
1429 commonSectionMapping(IO, Section);
1430 IO.mapOptional("Content", Section.Content);
1431 IO.mapOptional("Entries", Section.Entries);
1432 IO.mapOptional("PGOAnalyses", Section.PGOAnalyses);
1433}
1434
1435static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) {
1436 commonSectionMapping(IO, Section);
1437 IO.mapOptional("Entries", Section.Entries);
1438}
1439
1440static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) {
1441 commonSectionMapping(IO, Section);
1442 IO.mapOptional("Bucket", Section.Bucket);
1443 IO.mapOptional("Chain", Section.Chain);
1444
1445 // obj2yaml does not dump these fields. They can be used to override nchain
1446 // and nbucket values for creating broken sections.
1447 assert(!IO.outputting() || (!Section.NBucket && !Section.NChain));
1448 IO.mapOptional("NChain", Section.NChain);
1449 IO.mapOptional("NBucket", Section.NBucket);
1450}
1451
1452static void sectionMapping(IO &IO, ELFYAML::NoteSection &Section) {
1453 commonSectionMapping(IO, Section);
1454 IO.mapOptional("Notes", Section.Notes);
1455}
1456
1457
1458static void sectionMapping(IO &IO, ELFYAML::GnuHashSection &Section) {
1459 commonSectionMapping(IO, Section);
1460 IO.mapOptional("Header", Section.Header);
1461 IO.mapOptional("BloomFilter", Section.BloomFilter);
1462 IO.mapOptional("HashBuckets", Section.HashBuckets);
1463 IO.mapOptional("HashValues", Section.HashValues);
1464}
1465static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
1466 commonSectionMapping(IO, Section);
1467}
1468
1469static void sectionMapping(IO &IO, ELFYAML::VerdefSection &Section) {
1470 commonSectionMapping(IO, Section);
1471 IO.mapOptional("Info", Section.Info);
1472 IO.mapOptional("Entries", Section.Entries);
1473}
1474
1475static void sectionMapping(IO &IO, ELFYAML::SymverSection &Section) {
1476 commonSectionMapping(IO, Section);
1477 IO.mapOptional("Entries", Section.Entries);
1478}
1479
1480static void sectionMapping(IO &IO, ELFYAML::VerneedSection &Section) {
1481 commonSectionMapping(IO, Section);
1482 IO.mapOptional("Info", Section.Info);
1483 IO.mapOptional("Dependencies", Section.VerneedV);
1484}
1485
1486static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
1487 commonSectionMapping(IO, Section);
1488 IO.mapOptional("Info", Section.RelocatableSec, StringRef());
1489 IO.mapOptional("Relocations", Section.Relocations);
1490}
1491
1492static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) {
1493 commonSectionMapping(IO, Section);
1494 IO.mapOptional("Entries", Section.Entries);
1495}
1496
1497static void groupSectionMapping(IO &IO, ELFYAML::GroupSection &Group) {
1498 commonSectionMapping(IO, Group);
1499 IO.mapOptional("Info", Group.Signature);
1500 IO.mapOptional("Members", Group.Members);
1501}
1502
1503static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) {
1504 commonSectionMapping(IO, Section);
1505 IO.mapOptional("Entries", Section.Entries);
1506}
1507
1508static void sectionMapping(IO &IO, ELFYAML::AddrsigSection &Section) {
1509 commonSectionMapping(IO, Section);
1510 IO.mapOptional("Symbols", Section.Symbols);
1511}
1512
1513static void fillMapping(IO &IO, ELFYAML::Fill &Fill) {
1514 IO.mapOptional("Name", Fill.Name, StringRef());
1515 IO.mapOptional("Pattern", Fill.Pattern);
1516 IO.mapOptional("Offset", Fill.Offset);
1517 IO.mapRequired("Size", Fill.Size);
1518}
1519
1520static void sectionHeaderTableMapping(IO &IO,
1522 IO.mapOptional("Offset", SHT.Offset);
1523 IO.mapOptional("Sections", SHT.Sections);
1524 IO.mapOptional("Excluded", SHT.Excluded);
1525 IO.mapOptional("NoHeaders", SHT.NoHeaders);
1526}
1527
1528static void sectionMapping(IO &IO, ELFYAML::LinkerOptionsSection &Section) {
1529 commonSectionMapping(IO, Section);
1530 IO.mapOptional("Options", Section.Options);
1531}
1532
1533static void sectionMapping(IO &IO,
1535 commonSectionMapping(IO, Section);
1536 IO.mapOptional("Libraries", Section.Libs);
1537}
1538
1540 commonSectionMapping(IO, Section);
1541 IO.mapOptional("Entries", Section.Entries);
1542}
1543
1544void MappingTraits<ELFYAML::SectionOrType>::mapping(
1545 IO &IO, ELFYAML::SectionOrType &sectionOrType) {
1546 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
1547}
1548
1549static void sectionMapping(IO &IO, ELFYAML::ARMIndexTableSection &Section) {
1550 commonSectionMapping(IO, Section);
1551 IO.mapOptional("Entries", Section.Entries);
1552}
1553
1554static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) {
1555 commonSectionMapping(IO, Section);
1556 IO.mapOptional("Version", Section.Version, Hex16(0));
1557 IO.mapRequired("ISA", Section.ISALevel);
1558 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
1559 IO.mapOptional("ISAExtension", Section.ISAExtension,
1560 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
1561 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
1562 IO.mapOptional("FpABI", Section.FpABI,
1563 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
1564 IO.mapOptional("GPRSize", Section.GPRSize,
1565 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1566 IO.mapOptional("CPR1Size", Section.CPR1Size,
1567 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1568 IO.mapOptional("CPR2Size", Section.CPR2Size,
1569 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1570 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
1571 IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
1572}
1573
1574static StringRef getStringValue(IO &IO, const char *Key) {
1575 StringRef Val;
1576 IO.mapRequired(Key, Val);
1577 return Val;
1578}
1579
1580static void setStringValue(IO &IO, const char *Key, StringRef Val) {
1581 IO.mapRequired(Key, Val);
1582}
1583
1584static bool isInteger(StringRef Val) {
1585 APInt Tmp;
1586 return !Val.getAsInteger(0, Tmp);
1587}
1588
1589void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
1590 IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) {
1591 ELFYAML::ELF_SHT Type;
1592 StringRef TypeStr;
1593 if (IO.outputting()) {
1594 if (auto *S = dyn_cast<ELFYAML::Section>(Section.get()))
1595 Type = S->Type;
1596 else if (auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(Section.get()))
1597 TypeStr = SHT->TypeStr;
1598 } else {
1599 // When the Type string does not have a "SHT_" prefix, we know it is not a
1600 // description of a regular ELF output section.
1601 TypeStr = getStringValue(IO, "Type");
1602 if (TypeStr.starts_with("SHT_") || isInteger(TypeStr))
1603 IO.mapRequired("Type", Type);
1604 }
1605
1606 if (TypeStr == "Fill") {
1607 assert(!IO.outputting()); // We don't dump fills currently.
1608 Section.reset(new ELFYAML::Fill());
1609 fillMapping(IO, *cast<ELFYAML::Fill>(Section.get()));
1610 return;
1611 }
1612
1613 if (TypeStr == ELFYAML::SectionHeaderTable::TypeStr) {
1614 if (IO.outputting())
1615 setStringValue(IO, "Type", TypeStr);
1616 else
1617 Section.reset(new ELFYAML::SectionHeaderTable(/*IsImplicit=*/false));
1618
1620 IO, *cast<ELFYAML::SectionHeaderTable>(Section.get()));
1621 return;
1622 }
1623
1624 const auto &Obj = *static_cast<ELFYAML::Object *>(IO.getContext());
1625 if (Obj.getMachine() == ELF::EM_MIPS && Type == ELF::SHT_MIPS_ABIFLAGS) {
1626 if (!IO.outputting())
1627 Section.reset(new ELFYAML::MipsABIFlags());
1628 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
1629 return;
1630 }
1631
1632 if (Obj.getMachine() == ELF::EM_ARM && Type == ELF::SHT_ARM_EXIDX) {
1633 if (!IO.outputting())
1634 Section.reset(new ELFYAML::ARMIndexTableSection());
1635 sectionMapping(IO, *cast<ELFYAML::ARMIndexTableSection>(Section.get()));
1636 return;
1637 }
1638
1639 switch (Type) {
1640 case ELF::SHT_DYNAMIC:
1641 if (!IO.outputting())
1642 Section.reset(new ELFYAML::DynamicSection());
1643 sectionMapping(IO, *cast<ELFYAML::DynamicSection>(Section.get()));
1644 break;
1645 case ELF::SHT_REL:
1646 case ELF::SHT_RELA:
1647 case ELF::SHT_CREL:
1648 if (!IO.outputting())
1649 Section.reset(new ELFYAML::RelocationSection());
1650 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
1651 break;
1652 case ELF::SHT_RELR:
1653 if (!IO.outputting())
1654 Section.reset(new ELFYAML::RelrSection());
1655 sectionMapping(IO, *cast<ELFYAML::RelrSection>(Section.get()));
1656 break;
1657 case ELF::SHT_GROUP:
1658 if (!IO.outputting())
1659 Section.reset(new ELFYAML::GroupSection());
1660 groupSectionMapping(IO, *cast<ELFYAML::GroupSection>(Section.get()));
1661 break;
1662 case ELF::SHT_NOBITS:
1663 if (!IO.outputting())
1664 Section.reset(new ELFYAML::NoBitsSection());
1665 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
1666 break;
1667 case ELF::SHT_HASH:
1668 if (!IO.outputting())
1669 Section.reset(new ELFYAML::HashSection());
1670 sectionMapping(IO, *cast<ELFYAML::HashSection>(Section.get()));
1671 break;
1672 case ELF::SHT_NOTE:
1673 if (!IO.outputting())
1674 Section.reset(new ELFYAML::NoteSection());
1675 sectionMapping(IO, *cast<ELFYAML::NoteSection>(Section.get()));
1676 break;
1677 case ELF::SHT_GNU_HASH:
1678 if (!IO.outputting())
1679 Section.reset(new ELFYAML::GnuHashSection());
1680 sectionMapping(IO, *cast<ELFYAML::GnuHashSection>(Section.get()));
1681 break;
1683 if (!IO.outputting())
1684 Section.reset(new ELFYAML::VerdefSection());
1685 sectionMapping(IO, *cast<ELFYAML::VerdefSection>(Section.get()));
1686 break;
1688 if (!IO.outputting())
1689 Section.reset(new ELFYAML::SymverSection());
1690 sectionMapping(IO, *cast<ELFYAML::SymverSection>(Section.get()));
1691 break;
1693 if (!IO.outputting())
1694 Section.reset(new ELFYAML::VerneedSection());
1695 sectionMapping(IO, *cast<ELFYAML::VerneedSection>(Section.get()));
1696 break;
1698 if (!IO.outputting())
1699 Section.reset(new ELFYAML::SymtabShndxSection());
1700 sectionMapping(IO, *cast<ELFYAML::SymtabShndxSection>(Section.get()));
1701 break;
1703 if (!IO.outputting())
1704 Section.reset(new ELFYAML::AddrsigSection());
1705 sectionMapping(IO, *cast<ELFYAML::AddrsigSection>(Section.get()));
1706 break;
1708 if (!IO.outputting())
1709 Section.reset(new ELFYAML::LinkerOptionsSection());
1710 sectionMapping(IO, *cast<ELFYAML::LinkerOptionsSection>(Section.get()));
1711 break;
1713 if (!IO.outputting())
1714 Section.reset(new ELFYAML::DependentLibrariesSection());
1715 sectionMapping(IO,
1716 *cast<ELFYAML::DependentLibrariesSection>(Section.get()));
1717 break;
1719 if (!IO.outputting())
1720 Section.reset(new ELFYAML::CallGraphProfileSection());
1721 sectionMapping(IO, *cast<ELFYAML::CallGraphProfileSection>(Section.get()));
1722 break;
1724 if (!IO.outputting())
1725 Section.reset(new ELFYAML::BBAddrMapSection());
1726 sectionMapping(IO, *cast<ELFYAML::BBAddrMapSection>(Section.get()));
1727 break;
1728 default:
1729 if (!IO.outputting()) {
1730 StringRef Name;
1731 IO.mapOptional("Name", Name, StringRef());
1733
1735 Section = std::make_unique<ELFYAML::StackSizesSection>();
1736 else
1737 Section = std::make_unique<ELFYAML::RawContentSection>();
1738 }
1739
1740 if (auto S = dyn_cast<ELFYAML::RawContentSection>(Section.get()))
1741 sectionMapping(IO, *S);
1742 else
1743 sectionMapping(IO, *cast<ELFYAML::StackSizesSection>(Section.get()));
1744 }
1745}
1746
1747std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
1748 IO &io, std::unique_ptr<ELFYAML::Chunk> &C) {
1749 if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) {
1750 if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size)
1751 return "\"Size\" can't be 0 when \"Pattern\" is not empty";
1752 return "";
1753 }
1754
1755 if (const auto *SHT = dyn_cast<ELFYAML::SectionHeaderTable>(C.get())) {
1756 if (SHT->NoHeaders && (SHT->Sections || SHT->Excluded || SHT->Offset))
1757 return "NoHeaders can't be used together with Offset/Sections/Excluded";
1758 return "";
1759 }
1760
1761 const ELFYAML::Section &Sec = *cast<ELFYAML::Section>(C.get());
1762 if (Sec.Size && Sec.Content &&
1763 (uint64_t)(*Sec.Size) < Sec.Content->binary_size())
1764 return "Section size must be greater than or equal to the content size";
1765
1766 auto BuildErrPrefix = [](ArrayRef<std::pair<StringRef, bool>> EntV) {
1767 std::string Msg;
1768 for (size_t I = 0, E = EntV.size(); I != E; ++I) {
1769 StringRef Name = EntV[I].first;
1770 if (I == 0) {
1771 Msg = "\"" + Name.str() + "\"";
1772 continue;
1773 }
1774 if (I != EntV.size() - 1)
1775 Msg += ", \"" + Name.str() + "\"";
1776 else
1777 Msg += " and \"" + Name.str() + "\"";
1778 }
1779 return Msg;
1780 };
1781
1782 std::vector<std::pair<StringRef, bool>> Entries = Sec.getEntries();
1783 const size_t NumUsedEntries = llvm::count_if(
1784 Entries, [](const std::pair<StringRef, bool> &P) { return P.second; });
1785
1786 if ((Sec.Size || Sec.Content) && NumUsedEntries > 0)
1787 return BuildErrPrefix(Entries) +
1788 " cannot be used with \"Content\" or \"Size\"";
1789
1790 if (NumUsedEntries > 0 && Entries.size() != NumUsedEntries)
1791 return BuildErrPrefix(Entries) + " must be used together";
1792
1793 if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) {
1794 if (RawSection->Flags && RawSection->ShFlags)
1795 return "ShFlags and Flags cannot be used together";
1796 return "";
1797 }
1798
1799 if (const auto *NB = dyn_cast<ELFYAML::NoBitsSection>(C.get())) {
1800 if (NB->Content)
1801 return "SHT_NOBITS section cannot have \"Content\"";
1802 return "";
1803 }
1804
1805 if (const auto *MF = dyn_cast<ELFYAML::MipsABIFlags>(C.get())) {
1806 if (MF->Content)
1807 return "\"Content\" key is not implemented for SHT_MIPS_ABIFLAGS "
1808 "sections";
1809 if (MF->Size)
1810 return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections";
1811 return "";
1812 }
1813
1814 return "";
1815}
1816
1817namespace {
1818
1819struct NormalizedMips64RelType {
1820 NormalizedMips64RelType(IO &)
1821 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1822 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1823 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1824 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
1825 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
1826 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
1827 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
1828
1829 ELFYAML::ELF_REL denormalize(IO &) {
1830 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
1831 return Res;
1832 }
1833
1834 ELFYAML::ELF_REL Type;
1835 ELFYAML::ELF_REL Type2;
1836 ELFYAML::ELF_REL Type3;
1837 ELFYAML::ELF_RSS SpecSym;
1838};
1839
1840} // end anonymous namespace
1841
1842void MappingTraits<ELFYAML::StackSizeEntry>::mapping(
1843 IO &IO, ELFYAML::StackSizeEntry &E) {
1844 assert(IO.getContext() && "The IO context is not initialized");
1845 IO.mapOptional("Address", E.Address, Hex64(0));
1846 IO.mapRequired("Size", E.Size);
1847}
1848
1849void MappingTraits<ELFYAML::BBAddrMapEntry>::mapping(
1850 IO &IO, ELFYAML::BBAddrMapEntry &E) {
1851 assert(IO.getContext() && "The IO context is not initialized");
1852 IO.mapRequired("Version", E.Version);
1853 IO.mapOptional("Feature", E.Feature, Hex8(0));
1854 IO.mapOptional("NumBBRanges", E.NumBBRanges);
1855 IO.mapOptional("BBRanges", E.BBRanges);
1856}
1857
1858void MappingTraits<ELFYAML::BBAddrMapEntry::BBRangeEntry>::mapping(
1859 IO &IO, ELFYAML::BBAddrMapEntry::BBRangeEntry &E) {
1860 IO.mapOptional("BaseAddress", E.BaseAddress, Hex64(0));
1861 IO.mapOptional("NumBlocks", E.NumBlocks);
1862 IO.mapOptional("BBEntries", E.BBEntries);
1863}
1864
1865void MappingTraits<ELFYAML::BBAddrMapEntry::BBEntry>::mapping(
1866 IO &IO, ELFYAML::BBAddrMapEntry::BBEntry &E) {
1867 assert(IO.getContext() && "The IO context is not initialized");
1868 IO.mapOptional("ID", E.ID);
1869 IO.mapRequired("AddressOffset", E.AddressOffset);
1870 IO.mapRequired("Size", E.Size);
1871 IO.mapRequired("Metadata", E.Metadata);
1872}
1873
1874void MappingTraits<ELFYAML::PGOAnalysisMapEntry>::mapping(
1875 IO &IO, ELFYAML::PGOAnalysisMapEntry &E) {
1876 assert(IO.getContext() && "The IO context is not initialized");
1877 IO.mapOptional("FuncEntryCount", E.FuncEntryCount);
1878 IO.mapOptional("PGOBBEntries", E.PGOBBEntries);
1879}
1880
1881void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry>::mapping(
1882 IO &IO, ELFYAML::PGOAnalysisMapEntry::PGOBBEntry &E) {
1883 assert(IO.getContext() && "The IO context is not initialized");
1884 IO.mapOptional("BBFreq", E.BBFreq);
1885 IO.mapOptional("Successors", E.Successors);
1886}
1887
1888void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry>::
1889 mapping(IO &IO,
1890 ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry &E) {
1891 assert(IO.getContext() && "The IO context is not initialized");
1892 IO.mapRequired("ID", E.ID);
1893 IO.mapRequired("BrProb", E.BrProb);
1894}
1895
1896void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO,
1897 ELFYAML::GnuHashHeader &E) {
1898 assert(IO.getContext() && "The IO context is not initialized");
1899 IO.mapOptional("NBuckets", E.NBuckets);
1900 IO.mapRequired("SymNdx", E.SymNdx);
1901 IO.mapOptional("MaskWords", E.MaskWords);
1902 IO.mapRequired("Shift2", E.Shift2);
1903}
1904
1905void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO,
1906 ELFYAML::DynamicEntry &Rel) {
1907 assert(IO.getContext() && "The IO context is not initialized");
1908
1909 IO.mapRequired("Tag", Rel.Tag);
1910 IO.mapRequired("Value", Rel.Val);
1911}
1912
1913void MappingTraits<ELFYAML::NoteEntry>::mapping(IO &IO, ELFYAML::NoteEntry &N) {
1914 assert(IO.getContext() && "The IO context is not initialized");
1915
1916 IO.mapOptional("Name", N.Name);
1917 IO.mapOptional("Desc", N.Desc);
1918 IO.mapRequired("Type", N.Type);
1919}
1920
1921void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO,
1922 ELFYAML::VerdefEntry &E) {
1923 assert(IO.getContext() && "The IO context is not initialized");
1924
1925 IO.mapOptional("Version", E.Version);
1926 IO.mapOptional("Flags", E.Flags);
1927 IO.mapOptional("VersionNdx", E.VersionNdx);
1928 IO.mapOptional("Hash", E.Hash);
1929 IO.mapOptional("VDAux", E.VDAux);
1930 IO.mapRequired("Names", E.VerNames);
1931}
1932
1933void MappingTraits<ELFYAML::VerneedEntry>::mapping(IO &IO,
1934 ELFYAML::VerneedEntry &E) {
1935 assert(IO.getContext() && "The IO context is not initialized");
1936
1937 IO.mapRequired("Version", E.Version);
1938 IO.mapRequired("File", E.File);
1939 IO.mapRequired("Entries", E.AuxV);
1940}
1941
1942void MappingTraits<ELFYAML::VernauxEntry>::mapping(IO &IO,
1943 ELFYAML::VernauxEntry &E) {
1944 assert(IO.getContext() && "The IO context is not initialized");
1945
1946 IO.mapRequired("Name", E.Name);
1947 IO.mapRequired("Hash", E.Hash);
1948 IO.mapRequired("Flags", E.Flags);
1949 IO.mapRequired("Other", E.Other);
1950}
1951
1952void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
1953 ELFYAML::Relocation &Rel) {
1954 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
1955 assert(Object && "The IO context is not initialized");
1956
1957 IO.mapOptional("Offset", Rel.Offset, (Hex64)0);
1958 IO.mapOptional("Symbol", Rel.Symbol);
1959
1960 if (Object->getMachine() == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
1961 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
1962 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
1963 IO, Rel.Type);
1964 IO.mapRequired("Type", Key->Type);
1965 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
1966 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
1967 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
1968 } else
1969 IO.mapRequired("Type", Rel.Type);
1970
1971 IO.mapOptional("Addend", Rel.Addend, (ELFYAML::YAMLIntUInt)0);
1972}
1973
1974void MappingTraits<ELFYAML::ARMIndexTableEntry>::mapping(
1975 IO &IO, ELFYAML::ARMIndexTableEntry &E) {
1976 assert(IO.getContext() && "The IO context is not initialized");
1977 IO.mapRequired("Offset", E.Offset);
1978
1979 StringRef CantUnwind = "EXIDX_CANTUNWIND";
1980 if (IO.outputting() && (uint32_t)E.Value == ARM::EHABI::EXIDX_CANTUNWIND)
1981 IO.mapRequired("Value", CantUnwind);
1982 else if (!IO.outputting() && getStringValue(IO, "Value") == CantUnwind)
1984 else
1985 IO.mapRequired("Value", E.Value);
1986}
1987
1988void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
1989 assert(!IO.getContext() && "The IO context is initialized already");
1990 IO.setContext(&Object);
1991 IO.mapTag("!ELF", true);
1992 IO.mapRequired("FileHeader", Object.Header);
1993 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
1994 IO.mapOptional("Sections", Object.Chunks);
1995 IO.mapOptional("Symbols", Object.Symbols);
1996 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
1997 IO.mapOptional("DWARF", Object.DWARF);
1998 if (Object.DWARF) {
1999 Object.DWARF->IsLittleEndian =
2000 Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
2001 Object.DWARF->Is64BitAddrSize =
2002 Object.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
2003 }
2004 IO.setContext(nullptr);
2005}
2006
2007void MappingTraits<ELFYAML::LinkerOption>::mapping(IO &IO,
2008 ELFYAML::LinkerOption &Opt) {
2009 assert(IO.getContext() && "The IO context is not initialized");
2010 IO.mapRequired("Name", Opt.Key);
2011 IO.mapRequired("Value", Opt.Value);
2012}
2013
2014void MappingTraits<ELFYAML::CallGraphEntryWeight>::mapping(
2015 IO &IO, ELFYAML::CallGraphEntryWeight &E) {
2016 assert(IO.getContext() && "The IO context is not initialized");
2017 IO.mapRequired("Weight", E.Weight);
2018}
2019
2020LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
2024LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
2025
2026} // end namespace yaml
2027
2028} // 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:1316
ELFYAML::ELF_RSS SpecSym
Definition: ELFYAML.cpp:1837
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:1836
#define BCaseMask(X, M)
IO & YamlIO
Definition: ELFYAML.cpp:1314
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:1835
std::optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1315
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:435
@ ELFOSABI_SOLARIS
Definition: ELF.h:350
@ STO_MIPS_PIC
Definition: ELF.h:592
@ STO_MIPS_OPTIONAL
Definition: ELF.h:590
@ STO_MIPS_MICROMIPS
Definition: ELF.h:593
@ STO_MIPS_MIPS16
Definition: ELF.h:594
@ STO_MIPS_PLT
Definition: ELF.h:591
@ ELFCLASS64
Definition: ELF.h:332
@ EM_MSP430
Definition: ELF.h:225
@ EM_PPC64
Definition: ELF.h:152
@ EM_CSKY
Definition: ELF.h:324
@ EM_SPARC32PLUS
Definition: ELF.h:149
@ EM_NONE
Definition: ELF.h:136
@ EM_68K
Definition: ELF.h:140
@ EM_386
Definition: ELF.h:139
@ EM_LOONGARCH
Definition: ELF.h:325
@ EM_BPF
Definition: ELF.h:322
@ EM_PPC
Definition: ELF.h:151
@ EM_X86_64
Definition: ELF.h:181
@ EM_HEXAGON
Definition: ELF.h:260
@ EM_LANAI
Definition: ELF.h:321
@ EM_MIPS
Definition: ELF.h:144
@ EM_ARC
Definition: ELF.h:164
@ EM_SPARCV9
Definition: ELF.h:162
@ EM_AARCH64
Definition: ELF.h:283
@ EM_XTENSA
Definition: ELF.h:214
@ EM_RISCV
Definition: ELF.h:320
@ EM_ARM
Definition: ELF.h:159
@ EM_VE
Definition: ELF.h:323
@ EM_IAMCU
Definition: ELF.h:142
@ EM_AMDGPU
Definition: ELF.h:319
@ EM_AVR
Definition: ELF.h:202
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition: ELF.h:1126
@ SHT_GROUP
Definition: ELF.h:1109
@ SHT_LLVM_LINKER_OPTIONS
Definition: ELF.h:1123
@ SHT_REL
Definition: ELF.h:1103
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition: ELF.h:1134
@ SHT_NOBITS
Definition: ELF.h:1102
@ SHT_GNU_verneed
Definition: ELF.h:1145
@ SHT_RELR
Definition: ELF.h:1113
@ SHT_GNU_verdef
Definition: ELF.h:1144
@ SHT_CREL
Definition: ELF.h:1116
@ SHT_DYNAMIC
Definition: ELF.h:1100
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:1110
@ SHT_LLVM_ADDRSIG
Definition: ELF.h:1124
@ SHT_ARM_EXIDX
Definition: ELF.h:1151
@ SHT_LLVM_BB_ADDR_MAP
Definition: ELF.h:1135
@ SHT_GNU_HASH
Definition: ELF.h:1143
@ SHT_RELA
Definition: ELF.h:1098
@ SHT_NOTE
Definition: ELF.h:1101
@ SHT_MIPS_ABIFLAGS
Definition: ELF.h:1172
@ SHT_GNU_versym
Definition: ELF.h:1146
@ SHT_HASH
Definition: ELF.h:1099
@ EF_AMDGPU_GENERIC_VERSION_MAX
Definition: ELF.h:889
@ EF_AMDGPU_GENERIC_VERSION_OFFSET
Definition: ELF.h:887
@ EF_AMDGPU_GENERIC_VERSION_MIN
Definition: ELF.h:888
@ EF_AMDGPU_GENERIC_VERSION
Definition: ELF.h:886
@ ELFABIVERSION_AMDGPU_HSA_V4
Definition: ELF.h:381
@ ELFABIVERSION_AMDGPU_HSA_V5
Definition: ELF.h:382
@ ELFABIVERSION_AMDGPU_HSA_V3
Definition: ELF.h:380
@ ELFABIVERSION_AMDGPU_HSA_V6
Definition: ELF.h:383
@ STO_RISCV_VARIANT_CC
Definition: ELF.h:697
@ ELFDATA2LSB
Definition: ELF.h:338
@ RSS_UNDEF
Definition: ELF.h:1387
@ STV_INTERNAL
Definition: ELF.h:1377
@ STV_HIDDEN
Definition: ELF.h:1378
@ STV_PROTECTED
Definition: ELF.h:1379
@ STV_DEFAULT
Definition: ELF.h:1376
@ 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:1407
static void groupSectionMapping(IO &IO, ELFYAML::GroupSection &Group)
Definition: ELFYAML.cpp:1497
static StringRef getStringValue(IO &IO, const char *Key)
Definition: ELFYAML.cpp:1574
static void sectionHeaderTableMapping(IO &IO, ELFYAML::SectionHeaderTable &SHT)
Definition: ELFYAML.cpp:1520
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section)
Definition: ELFYAML.cpp:1380
static bool isInteger(StringRef Val)
Definition: ELFYAML.cpp:1584
static void fillMapping(IO &IO, ELFYAML::Fill &Fill)
Definition: ELFYAML.cpp:1513
static void setStringValue(IO &IO, const char *Key, StringRef Val)
Definition: ELFYAML.cpp:1580
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:1210
static void output(const ELFYAML::YAMLFlowString &Val, void *, raw_ostream &Out)
Definition: ELFYAML.cpp:1206
static QuotingType mustQuote(StringRef S)
Definition: ELFYAML.cpp:1215
static StringRef input(StringRef Scalar, void *, StOtherPiece &Val)
Definition: ELFYAML.cpp:1195
static QuotingType mustQuote(StringRef)
Definition: ELFYAML.cpp:1199
static void output(const StOtherPiece &Val, void *, raw_ostream &Out)
Definition: ELFYAML.cpp:1192