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