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