Clang] Fix expansion of response files in -Wp after integrated-cc1 change
[llvm-project.git] / llvm / lib / ObjectYAML / ELFYAML.cpp
blob2de6aaa78b0c6453aeb60f3e2b5264ca7da95984
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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ObjectYAML/ELFYAML.h"
14 #include "llvm/ADT/MapVector.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/BinaryFormat/ELF.h"
17 #include "llvm/Support/Casting.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/MipsABIFlags.h"
20 #include "llvm/Support/YAMLTraits.h"
21 #include "llvm/Support/WithColor.h"
22 #include <cassert>
23 #include <cstdint>
25 namespace llvm {
27 ELFYAML::Chunk::~Chunk() = default;
29 namespace yaml {
31 void ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(
32 IO &IO, ELFYAML::ELF_ET &Value) {
33 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
34 ECase(ET_NONE);
35 ECase(ET_REL);
36 ECase(ET_EXEC);
37 ECase(ET_DYN);
38 ECase(ET_CORE);
39 #undef ECase
40 IO.enumFallback<Hex16>(Value);
43 void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration(
44 IO &IO, ELFYAML::ELF_PT &Value) {
45 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
46 ECase(PT_NULL);
47 ECase(PT_LOAD);
48 ECase(PT_DYNAMIC);
49 ECase(PT_INTERP);
50 ECase(PT_NOTE);
51 ECase(PT_SHLIB);
52 ECase(PT_PHDR);
53 ECase(PT_TLS);
54 ECase(PT_GNU_EH_FRAME);
55 ECase(PT_GNU_STACK);
56 ECase(PT_GNU_RELRO);
57 ECase(PT_GNU_PROPERTY);
58 #undef ECase
59 IO.enumFallback<Hex32>(Value);
62 void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(
63 IO &IO, ELFYAML::ELF_EM &Value) {
64 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
65 ECase(EM_NONE);
66 ECase(EM_M32);
67 ECase(EM_SPARC);
68 ECase(EM_386);
69 ECase(EM_68K);
70 ECase(EM_88K);
71 ECase(EM_IAMCU);
72 ECase(EM_860);
73 ECase(EM_MIPS);
74 ECase(EM_S370);
75 ECase(EM_MIPS_RS3_LE);
76 ECase(EM_PARISC);
77 ECase(EM_VPP500);
78 ECase(EM_SPARC32PLUS);
79 ECase(EM_960);
80 ECase(EM_PPC);
81 ECase(EM_PPC64);
82 ECase(EM_S390);
83 ECase(EM_SPU);
84 ECase(EM_V800);
85 ECase(EM_FR20);
86 ECase(EM_RH32);
87 ECase(EM_RCE);
88 ECase(EM_ARM);
89 ECase(EM_ALPHA);
90 ECase(EM_SH);
91 ECase(EM_SPARCV9);
92 ECase(EM_TRICORE);
93 ECase(EM_ARC);
94 ECase(EM_H8_300);
95 ECase(EM_H8_300H);
96 ECase(EM_H8S);
97 ECase(EM_H8_500);
98 ECase(EM_IA_64);
99 ECase(EM_MIPS_X);
100 ECase(EM_COLDFIRE);
101 ECase(EM_68HC12);
102 ECase(EM_MMA);
103 ECase(EM_PCP);
104 ECase(EM_NCPU);
105 ECase(EM_NDR1);
106 ECase(EM_STARCORE);
107 ECase(EM_ME16);
108 ECase(EM_ST100);
109 ECase(EM_TINYJ);
110 ECase(EM_X86_64);
111 ECase(EM_PDSP);
112 ECase(EM_PDP10);
113 ECase(EM_PDP11);
114 ECase(EM_FX66);
115 ECase(EM_ST9PLUS);
116 ECase(EM_ST7);
117 ECase(EM_68HC16);
118 ECase(EM_68HC11);
119 ECase(EM_68HC08);
120 ECase(EM_68HC05);
121 ECase(EM_SVX);
122 ECase(EM_ST19);
123 ECase(EM_VAX);
124 ECase(EM_CRIS);
125 ECase(EM_JAVELIN);
126 ECase(EM_FIREPATH);
127 ECase(EM_ZSP);
128 ECase(EM_MMIX);
129 ECase(EM_HUANY);
130 ECase(EM_PRISM);
131 ECase(EM_AVR);
132 ECase(EM_FR30);
133 ECase(EM_D10V);
134 ECase(EM_D30V);
135 ECase(EM_V850);
136 ECase(EM_M32R);
137 ECase(EM_MN10300);
138 ECase(EM_MN10200);
139 ECase(EM_PJ);
140 ECase(EM_OPENRISC);
141 ECase(EM_ARC_COMPACT);
142 ECase(EM_XTENSA);
143 ECase(EM_VIDEOCORE);
144 ECase(EM_TMM_GPP);
145 ECase(EM_NS32K);
146 ECase(EM_TPC);
147 ECase(EM_SNP1K);
148 ECase(EM_ST200);
149 ECase(EM_IP2K);
150 ECase(EM_MAX);
151 ECase(EM_CR);
152 ECase(EM_F2MC16);
153 ECase(EM_MSP430);
154 ECase(EM_BLACKFIN);
155 ECase(EM_SE_C33);
156 ECase(EM_SEP);
157 ECase(EM_ARCA);
158 ECase(EM_UNICORE);
159 ECase(EM_EXCESS);
160 ECase(EM_DXP);
161 ECase(EM_ALTERA_NIOS2);
162 ECase(EM_CRX);
163 ECase(EM_XGATE);
164 ECase(EM_C166);
165 ECase(EM_M16C);
166 ECase(EM_DSPIC30F);
167 ECase(EM_CE);
168 ECase(EM_M32C);
169 ECase(EM_TSK3000);
170 ECase(EM_RS08);
171 ECase(EM_SHARC);
172 ECase(EM_ECOG2);
173 ECase(EM_SCORE7);
174 ECase(EM_DSP24);
175 ECase(EM_VIDEOCORE3);
176 ECase(EM_LATTICEMICO32);
177 ECase(EM_SE_C17);
178 ECase(EM_TI_C6000);
179 ECase(EM_TI_C2000);
180 ECase(EM_TI_C5500);
181 ECase(EM_MMDSP_PLUS);
182 ECase(EM_CYPRESS_M8C);
183 ECase(EM_R32C);
184 ECase(EM_TRIMEDIA);
185 ECase(EM_HEXAGON);
186 ECase(EM_8051);
187 ECase(EM_STXP7X);
188 ECase(EM_NDS32);
189 ECase(EM_ECOG1);
190 ECase(EM_ECOG1X);
191 ECase(EM_MAXQ30);
192 ECase(EM_XIMO16);
193 ECase(EM_MANIK);
194 ECase(EM_CRAYNV2);
195 ECase(EM_RX);
196 ECase(EM_METAG);
197 ECase(EM_MCST_ELBRUS);
198 ECase(EM_ECOG16);
199 ECase(EM_CR16);
200 ECase(EM_ETPU);
201 ECase(EM_SLE9X);
202 ECase(EM_L10M);
203 ECase(EM_K10M);
204 ECase(EM_AARCH64);
205 ECase(EM_AVR32);
206 ECase(EM_STM8);
207 ECase(EM_TILE64);
208 ECase(EM_TILEPRO);
209 ECase(EM_CUDA);
210 ECase(EM_TILEGX);
211 ECase(EM_CLOUDSHIELD);
212 ECase(EM_COREA_1ST);
213 ECase(EM_COREA_2ND);
214 ECase(EM_ARC_COMPACT2);
215 ECase(EM_OPEN8);
216 ECase(EM_RL78);
217 ECase(EM_VIDEOCORE5);
218 ECase(EM_78KOR);
219 ECase(EM_56800EX);
220 ECase(EM_AMDGPU);
221 ECase(EM_RISCV);
222 ECase(EM_LANAI);
223 ECase(EM_BPF);
224 #undef ECase
225 IO.enumFallback<Hex16>(Value);
228 void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration(
229 IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
230 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
231 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
232 // here.
233 ECase(ELFCLASS32);
234 ECase(ELFCLASS64);
235 #undef ECase
238 void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
239 IO &IO, ELFYAML::ELF_ELFDATA &Value) {
240 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
241 // ELFDATANONE is an invalid data encoding, but we accept it because
242 // we want to be able to produce invalid binaries for the tests.
243 ECase(ELFDATANONE);
244 ECase(ELFDATA2LSB);
245 ECase(ELFDATA2MSB);
246 #undef ECase
249 void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
250 IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
251 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
252 ECase(ELFOSABI_NONE);
253 ECase(ELFOSABI_HPUX);
254 ECase(ELFOSABI_NETBSD);
255 ECase(ELFOSABI_GNU);
256 ECase(ELFOSABI_LINUX);
257 ECase(ELFOSABI_HURD);
258 ECase(ELFOSABI_SOLARIS);
259 ECase(ELFOSABI_AIX);
260 ECase(ELFOSABI_IRIX);
261 ECase(ELFOSABI_FREEBSD);
262 ECase(ELFOSABI_TRU64);
263 ECase(ELFOSABI_MODESTO);
264 ECase(ELFOSABI_OPENBSD);
265 ECase(ELFOSABI_OPENVMS);
266 ECase(ELFOSABI_NSK);
267 ECase(ELFOSABI_AROS);
268 ECase(ELFOSABI_FENIXOS);
269 ECase(ELFOSABI_CLOUDABI);
270 ECase(ELFOSABI_AMDGPU_HSA);
271 ECase(ELFOSABI_AMDGPU_PAL);
272 ECase(ELFOSABI_AMDGPU_MESA3D);
273 ECase(ELFOSABI_ARM);
274 ECase(ELFOSABI_C6000_ELFABI);
275 ECase(ELFOSABI_C6000_LINUX);
276 ECase(ELFOSABI_STANDALONE);
277 #undef ECase
278 IO.enumFallback<Hex8>(Value);
281 void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
282 ELFYAML::ELF_EF &Value) {
283 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
284 assert(Object && "The IO context is not initialized");
285 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
286 #define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
287 switch (Object->Header.Machine) {
288 case ELF::EM_ARM:
289 BCase(EF_ARM_SOFT_FLOAT);
290 BCase(EF_ARM_VFP_FLOAT);
291 BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK);
292 BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK);
293 BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK);
294 BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK);
295 BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK);
296 BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK);
297 break;
298 case ELF::EM_MIPS:
299 BCase(EF_MIPS_NOREORDER);
300 BCase(EF_MIPS_PIC);
301 BCase(EF_MIPS_CPIC);
302 BCase(EF_MIPS_ABI2);
303 BCase(EF_MIPS_32BITMODE);
304 BCase(EF_MIPS_FP64);
305 BCase(EF_MIPS_NAN2008);
306 BCase(EF_MIPS_MICROMIPS);
307 BCase(EF_MIPS_ARCH_ASE_M16);
308 BCase(EF_MIPS_ARCH_ASE_MDMX);
309 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI);
310 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI);
311 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI);
312 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI);
313 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH);
314 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH);
315 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH);
316 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH);
317 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH);
318 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH);
319 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH);
320 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH);
321 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH);
322 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH);
323 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH);
324 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH);
325 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH);
326 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH);
327 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH);
328 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH);
329 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH);
330 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH);
331 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH);
332 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH);
333 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH);
334 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH);
335 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH);
336 BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH);
337 BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH);
338 BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH);
339 BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH);
340 BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH);
341 BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH);
342 break;
343 case ELF::EM_HEXAGON:
344 BCase(EF_HEXAGON_MACH_V2);
345 BCase(EF_HEXAGON_MACH_V3);
346 BCase(EF_HEXAGON_MACH_V4);
347 BCase(EF_HEXAGON_MACH_V5);
348 BCase(EF_HEXAGON_MACH_V55);
349 BCase(EF_HEXAGON_MACH_V60);
350 BCase(EF_HEXAGON_MACH_V62);
351 BCase(EF_HEXAGON_MACH_V65);
352 BCase(EF_HEXAGON_MACH_V66);
353 BCase(EF_HEXAGON_MACH_V67);
354 BCase(EF_HEXAGON_MACH_V67T);
355 BCase(EF_HEXAGON_ISA_V2);
356 BCase(EF_HEXAGON_ISA_V3);
357 BCase(EF_HEXAGON_ISA_V4);
358 BCase(EF_HEXAGON_ISA_V5);
359 BCase(EF_HEXAGON_ISA_V55);
360 BCase(EF_HEXAGON_ISA_V60);
361 BCase(EF_HEXAGON_ISA_V62);
362 BCase(EF_HEXAGON_ISA_V65);
363 BCase(EF_HEXAGON_ISA_V66);
364 BCase(EF_HEXAGON_ISA_V67);
365 break;
366 case ELF::EM_AVR:
367 BCase(EF_AVR_ARCH_AVR1);
368 BCase(EF_AVR_ARCH_AVR2);
369 BCase(EF_AVR_ARCH_AVR25);
370 BCase(EF_AVR_ARCH_AVR3);
371 BCase(EF_AVR_ARCH_AVR31);
372 BCase(EF_AVR_ARCH_AVR35);
373 BCase(EF_AVR_ARCH_AVR4);
374 BCase(EF_AVR_ARCH_AVR51);
375 BCase(EF_AVR_ARCH_AVR6);
376 BCase(EF_AVR_ARCH_AVRTINY);
377 BCase(EF_AVR_ARCH_XMEGA1);
378 BCase(EF_AVR_ARCH_XMEGA2);
379 BCase(EF_AVR_ARCH_XMEGA3);
380 BCase(EF_AVR_ARCH_XMEGA4);
381 BCase(EF_AVR_ARCH_XMEGA5);
382 BCase(EF_AVR_ARCH_XMEGA6);
383 BCase(EF_AVR_ARCH_XMEGA7);
384 break;
385 case ELF::EM_RISCV:
386 BCase(EF_RISCV_RVC);
387 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT, EF_RISCV_FLOAT_ABI);
388 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE, EF_RISCV_FLOAT_ABI);
389 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_FLOAT_ABI);
390 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD, EF_RISCV_FLOAT_ABI);
391 BCase(EF_RISCV_RVE);
392 break;
393 case ELF::EM_AMDGPU:
394 BCaseMask(EF_AMDGPU_MACH_NONE, EF_AMDGPU_MACH);
395 BCaseMask(EF_AMDGPU_MACH_R600_R600, EF_AMDGPU_MACH);
396 BCaseMask(EF_AMDGPU_MACH_R600_R630, EF_AMDGPU_MACH);
397 BCaseMask(EF_AMDGPU_MACH_R600_RS880, EF_AMDGPU_MACH);
398 BCaseMask(EF_AMDGPU_MACH_R600_RV670, EF_AMDGPU_MACH);
399 BCaseMask(EF_AMDGPU_MACH_R600_RV710, EF_AMDGPU_MACH);
400 BCaseMask(EF_AMDGPU_MACH_R600_RV730, EF_AMDGPU_MACH);
401 BCaseMask(EF_AMDGPU_MACH_R600_RV770, EF_AMDGPU_MACH);
402 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR, EF_AMDGPU_MACH);
403 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS, EF_AMDGPU_MACH);
404 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER, EF_AMDGPU_MACH);
405 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD, EF_AMDGPU_MACH);
406 BCaseMask(EF_AMDGPU_MACH_R600_SUMO, EF_AMDGPU_MACH);
407 BCaseMask(EF_AMDGPU_MACH_R600_BARTS, EF_AMDGPU_MACH);
408 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS, EF_AMDGPU_MACH);
409 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN, EF_AMDGPU_MACH);
410 BCaseMask(EF_AMDGPU_MACH_R600_TURKS, EF_AMDGPU_MACH);
411 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600, EF_AMDGPU_MACH);
412 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601, EF_AMDGPU_MACH);
413 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700, EF_AMDGPU_MACH);
414 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701, EF_AMDGPU_MACH);
415 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702, EF_AMDGPU_MACH);
416 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703, EF_AMDGPU_MACH);
417 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704, EF_AMDGPU_MACH);
418 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801, EF_AMDGPU_MACH);
419 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802, EF_AMDGPU_MACH);
420 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803, EF_AMDGPU_MACH);
421 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810, EF_AMDGPU_MACH);
422 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900, EF_AMDGPU_MACH);
423 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902, EF_AMDGPU_MACH);
424 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904, EF_AMDGPU_MACH);
425 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906, EF_AMDGPU_MACH);
426 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX908, EF_AMDGPU_MACH);
427 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909, EF_AMDGPU_MACH);
428 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1010, EF_AMDGPU_MACH);
429 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1011, EF_AMDGPU_MACH);
430 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX1012, EF_AMDGPU_MACH);
431 BCase(EF_AMDGPU_XNACK);
432 BCase(EF_AMDGPU_SRAM_ECC);
433 break;
434 case ELF::EM_X86_64:
435 break;
436 default:
437 llvm_unreachable("Unsupported architecture");
439 #undef BCase
440 #undef BCaseMask
443 void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
444 IO &IO, ELFYAML::ELF_SHT &Value) {
445 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
446 assert(Object && "The IO context is not initialized");
447 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
448 ECase(SHT_NULL);
449 ECase(SHT_PROGBITS);
450 ECase(SHT_SYMTAB);
451 // FIXME: Issue a diagnostic with this information.
452 ECase(SHT_STRTAB);
453 ECase(SHT_RELA);
454 ECase(SHT_HASH);
455 ECase(SHT_DYNAMIC);
456 ECase(SHT_NOTE);
457 ECase(SHT_NOBITS);
458 ECase(SHT_REL);
459 ECase(SHT_SHLIB);
460 ECase(SHT_DYNSYM);
461 ECase(SHT_INIT_ARRAY);
462 ECase(SHT_FINI_ARRAY);
463 ECase(SHT_PREINIT_ARRAY);
464 ECase(SHT_GROUP);
465 ECase(SHT_SYMTAB_SHNDX);
466 ECase(SHT_RELR);
467 ECase(SHT_ANDROID_REL);
468 ECase(SHT_ANDROID_RELA);
469 ECase(SHT_ANDROID_RELR);
470 ECase(SHT_LLVM_ODRTAB);
471 ECase(SHT_LLVM_LINKER_OPTIONS);
472 ECase(SHT_LLVM_CALL_GRAPH_PROFILE);
473 ECase(SHT_LLVM_ADDRSIG);
474 ECase(SHT_LLVM_DEPENDENT_LIBRARIES);
475 ECase(SHT_LLVM_SYMPART);
476 ECase(SHT_LLVM_PART_EHDR);
477 ECase(SHT_LLVM_PART_PHDR);
478 ECase(SHT_GNU_ATTRIBUTES);
479 ECase(SHT_GNU_HASH);
480 ECase(SHT_GNU_verdef);
481 ECase(SHT_GNU_verneed);
482 ECase(SHT_GNU_versym);
483 switch (Object->Header.Machine) {
484 case ELF::EM_ARM:
485 ECase(SHT_ARM_EXIDX);
486 ECase(SHT_ARM_PREEMPTMAP);
487 ECase(SHT_ARM_ATTRIBUTES);
488 ECase(SHT_ARM_DEBUGOVERLAY);
489 ECase(SHT_ARM_OVERLAYSECTION);
490 break;
491 case ELF::EM_HEXAGON:
492 ECase(SHT_HEX_ORDERED);
493 break;
494 case ELF::EM_X86_64:
495 ECase(SHT_X86_64_UNWIND);
496 break;
497 case ELF::EM_MIPS:
498 ECase(SHT_MIPS_REGINFO);
499 ECase(SHT_MIPS_OPTIONS);
500 ECase(SHT_MIPS_DWARF);
501 ECase(SHT_MIPS_ABIFLAGS);
502 break;
503 default:
504 // Nothing to do.
505 break;
507 #undef ECase
508 IO.enumFallback<Hex32>(Value);
511 void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO,
512 ELFYAML::ELF_PF &Value) {
513 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
514 BCase(PF_X);
515 BCase(PF_W);
516 BCase(PF_R);
519 void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
520 ELFYAML::ELF_SHF &Value) {
521 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
522 #define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
523 BCase(SHF_WRITE);
524 BCase(SHF_ALLOC);
525 BCase(SHF_EXCLUDE);
526 BCase(SHF_EXECINSTR);
527 BCase(SHF_MERGE);
528 BCase(SHF_STRINGS);
529 BCase(SHF_INFO_LINK);
530 BCase(SHF_LINK_ORDER);
531 BCase(SHF_OS_NONCONFORMING);
532 BCase(SHF_GROUP);
533 BCase(SHF_TLS);
534 BCase(SHF_COMPRESSED);
535 switch (Object->Header.Machine) {
536 case ELF::EM_ARM:
537 BCase(SHF_ARM_PURECODE);
538 break;
539 case ELF::EM_HEXAGON:
540 BCase(SHF_HEX_GPREL);
541 break;
542 case ELF::EM_MIPS:
543 BCase(SHF_MIPS_NODUPES);
544 BCase(SHF_MIPS_NAMES);
545 BCase(SHF_MIPS_LOCAL);
546 BCase(SHF_MIPS_NOSTRIP);
547 BCase(SHF_MIPS_GPREL);
548 BCase(SHF_MIPS_MERGE);
549 BCase(SHF_MIPS_ADDR);
550 BCase(SHF_MIPS_STRING);
551 break;
552 case ELF::EM_X86_64:
553 BCase(SHF_X86_64_LARGE);
554 break;
555 default:
556 // Nothing to do.
557 break;
559 #undef BCase
562 void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
563 IO &IO, ELFYAML::ELF_SHN &Value) {
564 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
565 ECase(SHN_UNDEF);
566 ECase(SHN_LORESERVE);
567 ECase(SHN_LOPROC);
568 ECase(SHN_HIPROC);
569 ECase(SHN_LOOS);
570 ECase(SHN_HIOS);
571 ECase(SHN_ABS);
572 ECase(SHN_COMMON);
573 ECase(SHN_XINDEX);
574 ECase(SHN_HIRESERVE);
575 ECase(SHN_AMDGPU_LDS);
576 ECase(SHN_HEXAGON_SCOMMON);
577 ECase(SHN_HEXAGON_SCOMMON_1);
578 ECase(SHN_HEXAGON_SCOMMON_2);
579 ECase(SHN_HEXAGON_SCOMMON_4);
580 ECase(SHN_HEXAGON_SCOMMON_8);
581 #undef ECase
582 IO.enumFallback<Hex16>(Value);
585 void ScalarEnumerationTraits<ELFYAML::ELF_STB>::enumeration(
586 IO &IO, ELFYAML::ELF_STB &Value) {
587 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
588 ECase(STB_LOCAL);
589 ECase(STB_GLOBAL);
590 ECase(STB_WEAK);
591 ECase(STB_GNU_UNIQUE);
592 #undef ECase
593 IO.enumFallback<Hex8>(Value);
596 void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
597 IO &IO, ELFYAML::ELF_STT &Value) {
598 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
599 ECase(STT_NOTYPE);
600 ECase(STT_OBJECT);
601 ECase(STT_FUNC);
602 ECase(STT_SECTION);
603 ECase(STT_FILE);
604 ECase(STT_COMMON);
605 ECase(STT_TLS);
606 ECase(STT_GNU_IFUNC);
607 #undef ECase
608 IO.enumFallback<Hex8>(Value);
612 void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration(
613 IO &IO, ELFYAML::ELF_RSS &Value) {
614 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
615 ECase(RSS_UNDEF);
616 ECase(RSS_GP);
617 ECase(RSS_GP0);
618 ECase(RSS_LOC);
619 #undef ECase
622 void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
623 IO &IO, ELFYAML::ELF_REL &Value) {
624 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
625 assert(Object && "The IO context is not initialized");
626 #define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
627 switch (Object->Header.Machine) {
628 case ELF::EM_X86_64:
629 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
630 break;
631 case ELF::EM_MIPS:
632 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
633 break;
634 case ELF::EM_HEXAGON:
635 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
636 break;
637 case ELF::EM_386:
638 case ELF::EM_IAMCU:
639 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
640 break;
641 case ELF::EM_AARCH64:
642 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
643 break;
644 case ELF::EM_ARM:
645 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
646 break;
647 case ELF::EM_ARC:
648 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
649 break;
650 case ELF::EM_RISCV:
651 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
652 break;
653 case ELF::EM_LANAI:
654 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
655 break;
656 case ELF::EM_AMDGPU:
657 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
658 break;
659 case ELF::EM_BPF:
660 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
661 break;
662 case ELF::EM_PPC64:
663 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
664 break;
665 default:
666 // Nothing to do.
667 break;
669 #undef ELF_RELOC
670 IO.enumFallback<Hex32>(Value);
673 void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
674 IO &IO, ELFYAML::ELF_DYNTAG &Value) {
675 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
676 assert(Object && "The IO context is not initialized");
678 // Disable architecture specific tags by default. We might enable them below.
679 #define AARCH64_DYNAMIC_TAG(name, value)
680 #define MIPS_DYNAMIC_TAG(name, value)
681 #define HEXAGON_DYNAMIC_TAG(name, value)
682 #define PPC_DYNAMIC_TAG(name, value)
683 #define PPC64_DYNAMIC_TAG(name, value)
684 // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
685 #define DYNAMIC_TAG_MARKER(name, value)
687 #define STRINGIFY(X) (#X)
688 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
689 switch (Object->Header.Machine) {
690 case ELF::EM_AARCH64:
691 #undef AARCH64_DYNAMIC_TAG
692 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
693 #include "llvm/BinaryFormat/DynamicTags.def"
694 #undef AARCH64_DYNAMIC_TAG
695 #define AARCH64_DYNAMIC_TAG(name, value)
696 break;
697 case ELF::EM_MIPS:
698 #undef MIPS_DYNAMIC_TAG
699 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
700 #include "llvm/BinaryFormat/DynamicTags.def"
701 #undef MIPS_DYNAMIC_TAG
702 #define MIPS_DYNAMIC_TAG(name, value)
703 break;
704 case ELF::EM_HEXAGON:
705 #undef HEXAGON_DYNAMIC_TAG
706 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
707 #include "llvm/BinaryFormat/DynamicTags.def"
708 #undef HEXAGON_DYNAMIC_TAG
709 #define HEXAGON_DYNAMIC_TAG(name, value)
710 break;
711 case ELF::EM_PPC:
712 #undef PPC_DYNAMIC_TAG
713 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
714 #include "llvm/BinaryFormat/DynamicTags.def"
715 #undef PPC_DYNAMIC_TAG
716 #define PPC_DYNAMIC_TAG(name, value)
717 break;
718 case ELF::EM_PPC64:
719 #undef PPC64_DYNAMIC_TAG
720 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
721 #include "llvm/BinaryFormat/DynamicTags.def"
722 #undef PPC64_DYNAMIC_TAG
723 #define PPC64_DYNAMIC_TAG(name, value)
724 break;
725 default:
726 #include "llvm/BinaryFormat/DynamicTags.def"
727 break;
729 #undef AARCH64_DYNAMIC_TAG
730 #undef MIPS_DYNAMIC_TAG
731 #undef HEXAGON_DYNAMIC_TAG
732 #undef PPC_DYNAMIC_TAG
733 #undef PPC64_DYNAMIC_TAG
734 #undef DYNAMIC_TAG_MARKER
735 #undef STRINGIFY
736 #undef DYNAMIC_TAG
738 IO.enumFallback<Hex64>(Value);
741 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration(
742 IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
743 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
744 ECase(REG_NONE);
745 ECase(REG_32);
746 ECase(REG_64);
747 ECase(REG_128);
748 #undef ECase
751 void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration(
752 IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
753 #define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
754 ECase(FP_ANY);
755 ECase(FP_DOUBLE);
756 ECase(FP_SINGLE);
757 ECase(FP_SOFT);
758 ECase(FP_OLD_64);
759 ECase(FP_XX);
760 ECase(FP_64);
761 ECase(FP_64A);
762 #undef ECase
765 void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration(
766 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
767 #define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
768 ECase(EXT_NONE);
769 ECase(EXT_XLR);
770 ECase(EXT_OCTEON2);
771 ECase(EXT_OCTEONP);
772 ECase(EXT_LOONGSON_3A);
773 ECase(EXT_OCTEON);
774 ECase(EXT_5900);
775 ECase(EXT_4650);
776 ECase(EXT_4010);
777 ECase(EXT_4100);
778 ECase(EXT_3900);
779 ECase(EXT_10000);
780 ECase(EXT_SB1);
781 ECase(EXT_4111);
782 ECase(EXT_4120);
783 ECase(EXT_5400);
784 ECase(EXT_5500);
785 ECase(EXT_LOONGSON_2E);
786 ECase(EXT_LOONGSON_2F);
787 ECase(EXT_OCTEON3);
788 #undef ECase
791 void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration(
792 IO &IO, ELFYAML::MIPS_ISA &Value) {
793 IO.enumCase(Value, "MIPS1", 1);
794 IO.enumCase(Value, "MIPS2", 2);
795 IO.enumCase(Value, "MIPS3", 3);
796 IO.enumCase(Value, "MIPS4", 4);
797 IO.enumCase(Value, "MIPS5", 5);
798 IO.enumCase(Value, "MIPS32", 32);
799 IO.enumCase(Value, "MIPS64", 64);
802 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset(
803 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
804 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
805 BCase(DSP);
806 BCase(DSPR2);
807 BCase(EVA);
808 BCase(MCU);
809 BCase(MDMX);
810 BCase(MIPS3D);
811 BCase(MT);
812 BCase(SMARTMIPS);
813 BCase(VIRT);
814 BCase(MSA);
815 BCase(MIPS16);
816 BCase(MICROMIPS);
817 BCase(XPA);
818 #undef BCase
821 void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset(
822 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
823 #define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
824 BCase(ODDSPREG);
825 #undef BCase
828 void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
829 ELFYAML::FileHeader &FileHdr) {
830 IO.mapRequired("Class", FileHdr.Class);
831 IO.mapRequired("Data", FileHdr.Data);
832 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
833 IO.mapOptional("ABIVersion", FileHdr.ABIVersion, Hex8(0));
834 IO.mapRequired("Type", FileHdr.Type);
835 IO.mapRequired("Machine", FileHdr.Machine);
836 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
837 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
839 IO.mapOptional("SHEntSize", FileHdr.SHEntSize);
840 IO.mapOptional("SHOff", FileHdr.SHOff);
841 IO.mapOptional("SHNum", FileHdr.SHNum);
842 IO.mapOptional("SHStrNdx", FileHdr.SHStrNdx);
845 void MappingTraits<ELFYAML::ProgramHeader>::mapping(
846 IO &IO, ELFYAML::ProgramHeader &Phdr) {
847 IO.mapRequired("Type", Phdr.Type);
848 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
849 IO.mapOptional("Sections", Phdr.Sections);
850 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
851 IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
852 IO.mapOptional("Align", Phdr.Align);
853 IO.mapOptional("FileSize", Phdr.FileSize);
854 IO.mapOptional("MemSize", Phdr.MemSize);
855 IO.mapOptional("Offset", Phdr.Offset);
858 LLVM_YAML_STRONG_TYPEDEF(StringRef, StOtherPiece)
860 template <> struct ScalarTraits<StOtherPiece> {
861 static void output(const StOtherPiece &Val, void *, raw_ostream &Out) {
862 Out << Val;
864 static StringRef input(StringRef Scalar, void *, StOtherPiece &Val) {
865 Val = Scalar;
866 return {};
868 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
870 template <> struct SequenceElementTraits<StOtherPiece> {
871 static const bool flow = true;
874 template <> struct ScalarTraits<ELFYAML::YAMLFlowString> {
875 static void output(const ELFYAML::YAMLFlowString &Val, void *,
876 raw_ostream &Out) {
877 Out << Val;
879 static StringRef input(StringRef Scalar, void *,
880 ELFYAML::YAMLFlowString &Val) {
881 Val = Scalar;
882 return {};
884 static QuotingType mustQuote(StringRef S) {
885 return ScalarTraits<StringRef>::mustQuote(S);
888 template <> struct SequenceElementTraits<ELFYAML::YAMLFlowString> {
889 static const bool flow = true;
892 namespace {
894 struct NormalizedOther {
895 NormalizedOther(IO &IO) : YamlIO(IO) {}
896 NormalizedOther(IO &IO, Optional<uint8_t> Original) : YamlIO(IO) {
897 assert(Original && "This constructor is only used for outputting YAML and "
898 "assumes a non-empty Original");
899 std::vector<StOtherPiece> Ret;
900 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext());
901 for (std::pair<StringRef, uint8_t> &P :
902 getFlags(Object->Header.Machine).takeVector()) {
903 uint8_t FlagValue = P.second;
904 if ((*Original & FlagValue) != FlagValue)
905 continue;
906 *Original &= ~FlagValue;
907 Ret.push_back({P.first});
910 if (*Original != 0) {
911 UnknownFlagsHolder = std::to_string(*Original);
912 Ret.push_back({UnknownFlagsHolder});
915 if (!Ret.empty())
916 Other = std::move(Ret);
919 uint8_t toValue(StringRef Name) {
920 const auto *Object = static_cast<ELFYAML::Object *>(YamlIO.getContext());
921 MapVector<StringRef, uint8_t> Flags = getFlags(Object->Header.Machine);
923 auto It = Flags.find(Name);
924 if (It != Flags.end())
925 return It->second;
927 uint8_t Val;
928 if (to_integer(Name, Val))
929 return Val;
931 YamlIO.setError("an unknown value is used for symbol's 'Other' field: " +
932 Name);
933 return 0;
936 Optional<uint8_t> denormalize(IO &) {
937 if (!Other)
938 return None;
939 uint8_t Ret = 0;
940 for (StOtherPiece &Val : *Other)
941 Ret |= toValue(Val);
942 return Ret;
945 // st_other field is used to encode symbol visibility and platform-dependent
946 // flags and values. This method returns a name to value map that is used for
947 // parsing and encoding this field.
948 MapVector<StringRef, uint8_t> getFlags(unsigned EMachine) {
949 MapVector<StringRef, uint8_t> Map;
950 // STV_* values are just enumeration values. We add them in a reversed order
951 // because when we convert the st_other to named constants when printing
952 // YAML we want to use a maximum number of bits on each step:
953 // when we have st_other == 3, we want to print it as STV_PROTECTED (3), but
954 // not as STV_HIDDEN (2) + STV_INTERNAL (1).
955 Map["STV_PROTECTED"] = ELF::STV_PROTECTED;
956 Map["STV_HIDDEN"] = ELF::STV_HIDDEN;
957 Map["STV_INTERNAL"] = ELF::STV_INTERNAL;
958 // STV_DEFAULT is used to represent the default visibility and has a value
959 // 0. We want to be able to read it from YAML documents, but there is no
960 // reason to print it.
961 if (!YamlIO.outputting())
962 Map["STV_DEFAULT"] = ELF::STV_DEFAULT;
964 // MIPS is not consistent. All of the STO_MIPS_* values are bit flags,
965 // except STO_MIPS_MIPS16 which overlaps them. It should be checked and
966 // consumed first when we print the output, because we do not want to print
967 // any other flags that have the same bits instead.
968 if (EMachine == ELF::EM_MIPS) {
969 Map["STO_MIPS_MIPS16"] = ELF::STO_MIPS_MIPS16;
970 Map["STO_MIPS_MICROMIPS"] = ELF::STO_MIPS_MICROMIPS;
971 Map["STO_MIPS_PIC"] = ELF::STO_MIPS_PIC;
972 Map["STO_MIPS_PLT"] = ELF::STO_MIPS_PLT;
973 Map["STO_MIPS_OPTIONAL"] = ELF::STO_MIPS_OPTIONAL;
975 return Map;
978 IO &YamlIO;
979 Optional<std::vector<StOtherPiece>> Other;
980 std::string UnknownFlagsHolder;
983 } // end anonymous namespace
985 void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
986 IO.mapOptional("Name", Symbol.Name, StringRef());
987 IO.mapOptional("NameIndex", Symbol.NameIndex);
988 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
989 IO.mapOptional("Section", Symbol.Section, StringRef());
990 IO.mapOptional("Index", Symbol.Index);
991 IO.mapOptional("Binding", Symbol.Binding, ELFYAML::ELF_STB(0));
992 IO.mapOptional("Value", Symbol.Value, Hex64(0));
993 IO.mapOptional("Size", Symbol.Size, Hex64(0));
995 // Symbol's Other field is a bit special. It is usually a field that
996 // represents st_other and holds the symbol visibility. However, on some
997 // platforms, it can contain bit fields and regular values, or even sometimes a
998 // crazy mix of them (see comments for NormalizedOther). Because of this, we
999 // need special handling.
1000 MappingNormalization<NormalizedOther, Optional<uint8_t>> Keys(IO,
1001 Symbol.Other);
1002 IO.mapOptional("Other", Keys->Other);
1005 StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
1006 ELFYAML::Symbol &Symbol) {
1007 if (Symbol.Index && Symbol.Section.data())
1008 return "Index and Section cannot both be specified for Symbol";
1009 if (Symbol.NameIndex && !Symbol.Name.empty())
1010 return "Name and NameIndex cannot both be specified for Symbol";
1011 return StringRef();
1014 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
1015 IO.mapOptional("Name", Section.Name, StringRef());
1016 IO.mapRequired("Type", Section.Type);
1017 IO.mapOptional("Flags", Section.Flags);
1018 IO.mapOptional("Address", Section.Address, Hex64(0));
1019 IO.mapOptional("Link", Section.Link, StringRef());
1020 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
1021 IO.mapOptional("EntSize", Section.EntSize);
1023 // obj2yaml does not dump these fields. They are expected to be empty when we
1024 // are producing YAML, because yaml2obj sets appropriate values for them
1025 // automatically when they are not explicitly defined.
1026 assert(!IO.outputting() ||
1027 (!Section.ShOffset.hasValue() && !Section.ShSize.hasValue() &&
1028 !Section.ShName.hasValue() && !Section.ShFlags.hasValue()));
1029 IO.mapOptional("ShName", Section.ShName);
1030 IO.mapOptional("ShOffset", Section.ShOffset);
1031 IO.mapOptional("ShSize", Section.ShSize);
1032 IO.mapOptional("ShFlags", Section.ShFlags);
1035 static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) {
1036 commonSectionMapping(IO, Section);
1037 IO.mapOptional("Entries", Section.Entries);
1038 IO.mapOptional("Content", Section.Content);
1041 static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
1042 commonSectionMapping(IO, Section);
1043 IO.mapOptional("Content", Section.Content);
1044 IO.mapOptional("Size", Section.Size);
1045 IO.mapOptional("Info", Section.Info);
1048 static void sectionMapping(IO &IO, ELFYAML::StackSizesSection &Section) {
1049 commonSectionMapping(IO, Section);
1050 IO.mapOptional("Content", Section.Content);
1051 IO.mapOptional("Size", Section.Size);
1052 IO.mapOptional("Entries", Section.Entries);
1055 static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) {
1056 commonSectionMapping(IO, Section);
1057 IO.mapOptional("Content", Section.Content);
1058 IO.mapOptional("Bucket", Section.Bucket);
1059 IO.mapOptional("Chain", Section.Chain);
1060 IO.mapOptional("Size", Section.Size);
1063 static void sectionMapping(IO &IO, ELFYAML::NoteSection &Section) {
1064 commonSectionMapping(IO, Section);
1065 IO.mapOptional("Content", Section.Content);
1066 IO.mapOptional("Size", Section.Size);
1067 IO.mapOptional("Notes", Section.Notes);
1071 static void sectionMapping(IO &IO, ELFYAML::GnuHashSection &Section) {
1072 commonSectionMapping(IO, Section);
1073 IO.mapOptional("Content", Section.Content);
1074 IO.mapOptional("Header", Section.Header);
1075 IO.mapOptional("BloomFilter", Section.BloomFilter);
1076 IO.mapOptional("HashBuckets", Section.HashBuckets);
1077 IO.mapOptional("HashValues", Section.HashValues);
1079 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
1080 commonSectionMapping(IO, Section);
1081 IO.mapOptional("Size", Section.Size, Hex64(0));
1084 static void sectionMapping(IO &IO, ELFYAML::VerdefSection &Section) {
1085 commonSectionMapping(IO, Section);
1086 IO.mapRequired("Info", Section.Info);
1087 IO.mapOptional("Entries", Section.Entries);
1088 IO.mapOptional("Content", Section.Content);
1091 static void sectionMapping(IO &IO, ELFYAML::SymverSection &Section) {
1092 commonSectionMapping(IO, Section);
1093 IO.mapRequired("Entries", Section.Entries);
1096 static void sectionMapping(IO &IO, ELFYAML::VerneedSection &Section) {
1097 commonSectionMapping(IO, Section);
1098 IO.mapRequired("Info", Section.Info);
1099 IO.mapOptional("Dependencies", Section.VerneedV);
1100 IO.mapOptional("Content", Section.Content);
1103 static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
1104 commonSectionMapping(IO, Section);
1105 IO.mapOptional("Info", Section.RelocatableSec, StringRef());
1106 IO.mapOptional("Relocations", Section.Relocations);
1109 static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) {
1110 commonSectionMapping(IO, Section);
1111 IO.mapOptional("Entries", Section.Entries);
1112 IO.mapOptional("Content", Section.Content);
1115 static void groupSectionMapping(IO &IO, ELFYAML::Group &Group) {
1116 commonSectionMapping(IO, Group);
1117 IO.mapOptional("Info", Group.Signature);
1118 IO.mapRequired("Members", Group.Members);
1121 static void sectionMapping(IO &IO, ELFYAML::SymtabShndxSection &Section) {
1122 commonSectionMapping(IO, Section);
1123 IO.mapRequired("Entries", Section.Entries);
1126 static void sectionMapping(IO &IO, ELFYAML::AddrsigSection &Section) {
1127 commonSectionMapping(IO, Section);
1128 IO.mapOptional("Content", Section.Content);
1129 IO.mapOptional("Size", Section.Size);
1130 IO.mapOptional("Symbols", Section.Symbols);
1133 static void fillMapping(IO &IO, ELFYAML::Fill &Fill) {
1134 IO.mapOptional("Name", Fill.Name, StringRef());
1135 IO.mapOptional("Pattern", Fill.Pattern);
1136 IO.mapRequired("Size", Fill.Size);
1139 static void sectionMapping(IO &IO, ELFYAML::LinkerOptionsSection &Section) {
1140 commonSectionMapping(IO, Section);
1141 IO.mapOptional("Options", Section.Options);
1142 IO.mapOptional("Content", Section.Content);
1145 static void sectionMapping(IO &IO,
1146 ELFYAML::DependentLibrariesSection &Section) {
1147 commonSectionMapping(IO, Section);
1148 IO.mapOptional("Libraries", Section.Libs);
1149 IO.mapOptional("Content", Section.Content);
1152 void MappingTraits<ELFYAML::SectionOrType>::mapping(
1153 IO &IO, ELFYAML::SectionOrType &sectionOrType) {
1154 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
1157 void MappingTraits<ELFYAML::SectionName>::mapping(
1158 IO &IO, ELFYAML::SectionName &sectionName) {
1159 IO.mapRequired("Section", sectionName.Section);
1162 static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) {
1163 commonSectionMapping(IO, Section);
1164 IO.mapOptional("Version", Section.Version, Hex16(0));
1165 IO.mapRequired("ISA", Section.ISALevel);
1166 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
1167 IO.mapOptional("ISAExtension", Section.ISAExtension,
1168 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
1169 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
1170 IO.mapOptional("FpABI", Section.FpABI,
1171 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
1172 IO.mapOptional("GPRSize", Section.GPRSize,
1173 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1174 IO.mapOptional("CPR1Size", Section.CPR1Size,
1175 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1176 IO.mapOptional("CPR2Size", Section.CPR2Size,
1177 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
1178 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
1179 IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
1182 void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
1183 IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) {
1184 ELFYAML::ELF_SHT Type;
1185 if (IO.outputting()) {
1186 Type = cast<ELFYAML::Section>(Section.get())->Type;
1187 } else {
1188 // When the Type string does not have a "SHT_" prefix, we know it is not a
1189 // description of a regular ELF output section. Currently, we have one
1190 // special type named "Fill". See comments for Fill.
1191 StringRef StrType;
1192 IO.mapRequired("Type", StrType);
1193 if (StrType == "Fill") {
1194 Section.reset(new ELFYAML::Fill());
1195 fillMapping(IO, *cast<ELFYAML::Fill>(Section.get()));
1196 return;
1199 IO.mapRequired("Type", Type);
1202 switch (Type) {
1203 case ELF::SHT_DYNAMIC:
1204 if (!IO.outputting())
1205 Section.reset(new ELFYAML::DynamicSection());
1206 sectionMapping(IO, *cast<ELFYAML::DynamicSection>(Section.get()));
1207 break;
1208 case ELF::SHT_REL:
1209 case ELF::SHT_RELA:
1210 if (!IO.outputting())
1211 Section.reset(new ELFYAML::RelocationSection());
1212 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
1213 break;
1214 case ELF::SHT_RELR:
1215 if (!IO.outputting())
1216 Section.reset(new ELFYAML::RelrSection());
1217 sectionMapping(IO, *cast<ELFYAML::RelrSection>(Section.get()));
1218 break;
1219 case ELF::SHT_GROUP:
1220 if (!IO.outputting())
1221 Section.reset(new ELFYAML::Group());
1222 groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
1223 break;
1224 case ELF::SHT_NOBITS:
1225 if (!IO.outputting())
1226 Section.reset(new ELFYAML::NoBitsSection());
1227 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
1228 break;
1229 case ELF::SHT_HASH:
1230 if (!IO.outputting())
1231 Section.reset(new ELFYAML::HashSection());
1232 sectionMapping(IO, *cast<ELFYAML::HashSection>(Section.get()));
1233 break;
1234 case ELF::SHT_NOTE:
1235 if (!IO.outputting())
1236 Section.reset(new ELFYAML::NoteSection());
1237 sectionMapping(IO, *cast<ELFYAML::NoteSection>(Section.get()));
1238 break;
1239 case ELF::SHT_GNU_HASH:
1240 if (!IO.outputting())
1241 Section.reset(new ELFYAML::GnuHashSection());
1242 sectionMapping(IO, *cast<ELFYAML::GnuHashSection>(Section.get()));
1243 break;
1244 case ELF::SHT_MIPS_ABIFLAGS:
1245 if (!IO.outputting())
1246 Section.reset(new ELFYAML::MipsABIFlags());
1247 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
1248 break;
1249 case ELF::SHT_GNU_verdef:
1250 if (!IO.outputting())
1251 Section.reset(new ELFYAML::VerdefSection());
1252 sectionMapping(IO, *cast<ELFYAML::VerdefSection>(Section.get()));
1253 break;
1254 case ELF::SHT_GNU_versym:
1255 if (!IO.outputting())
1256 Section.reset(new ELFYAML::SymverSection());
1257 sectionMapping(IO, *cast<ELFYAML::SymverSection>(Section.get()));
1258 break;
1259 case ELF::SHT_GNU_verneed:
1260 if (!IO.outputting())
1261 Section.reset(new ELFYAML::VerneedSection());
1262 sectionMapping(IO, *cast<ELFYAML::VerneedSection>(Section.get()));
1263 break;
1264 case ELF::SHT_SYMTAB_SHNDX:
1265 if (!IO.outputting())
1266 Section.reset(new ELFYAML::SymtabShndxSection());
1267 sectionMapping(IO, *cast<ELFYAML::SymtabShndxSection>(Section.get()));
1268 break;
1269 case ELF::SHT_LLVM_ADDRSIG:
1270 if (!IO.outputting())
1271 Section.reset(new ELFYAML::AddrsigSection());
1272 sectionMapping(IO, *cast<ELFYAML::AddrsigSection>(Section.get()));
1273 break;
1274 case ELF::SHT_LLVM_LINKER_OPTIONS:
1275 if (!IO.outputting())
1276 Section.reset(new ELFYAML::LinkerOptionsSection());
1277 sectionMapping(IO, *cast<ELFYAML::LinkerOptionsSection>(Section.get()));
1278 break;
1279 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES:
1280 if (!IO.outputting())
1281 Section.reset(new ELFYAML::DependentLibrariesSection());
1282 sectionMapping(IO,
1283 *cast<ELFYAML::DependentLibrariesSection>(Section.get()));
1284 break;
1285 default:
1286 if (!IO.outputting()) {
1287 StringRef Name;
1288 IO.mapOptional("Name", Name, StringRef());
1289 Name = ELFYAML::dropUniqueSuffix(Name);
1291 if (ELFYAML::StackSizesSection::nameMatches(Name))
1292 Section = std::make_unique<ELFYAML::StackSizesSection>();
1293 else
1294 Section = std::make_unique<ELFYAML::RawContentSection>();
1297 if (auto S = dyn_cast<ELFYAML::RawContentSection>(Section.get()))
1298 sectionMapping(IO, *S);
1299 else
1300 sectionMapping(IO, *cast<ELFYAML::StackSizesSection>(Section.get()));
1304 StringRef MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
1305 IO &io, std::unique_ptr<ELFYAML::Chunk> &C) {
1306 if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) {
1307 if (RawSection->Size && RawSection->Content &&
1308 (uint64_t)(*RawSection->Size) < RawSection->Content->binary_size())
1309 return "Section size must be greater than or equal to the content size";
1310 if (RawSection->Flags && RawSection->ShFlags)
1311 return "ShFlags and Flags cannot be used together";
1312 return {};
1315 if (const auto *SS = dyn_cast<ELFYAML::StackSizesSection>(C.get())) {
1316 if (!SS->Entries && !SS->Content && !SS->Size)
1317 return ".stack_sizes: one of Content, Entries and Size must be specified";
1319 if (SS->Size && SS->Content &&
1320 (uint64_t)(*SS->Size) < SS->Content->binary_size())
1321 return ".stack_sizes: Size must be greater than or equal to the content "
1322 "size";
1324 // We accept Content, Size or both together when there are no Entries.
1325 if (!SS->Entries)
1326 return {};
1328 if (SS->Size)
1329 return ".stack_sizes: Size and Entries cannot be used together";
1330 if (SS->Content)
1331 return ".stack_sizes: Content and Entries cannot be used together";
1332 return {};
1335 if (const auto *HS = dyn_cast<ELFYAML::HashSection>(C.get())) {
1336 if (!HS->Content && !HS->Bucket && !HS->Chain && !HS->Size)
1337 return "one of \"Content\", \"Size\", \"Bucket\" or \"Chain\" must be "
1338 "specified";
1340 if (HS->Content || HS->Size) {
1341 if (HS->Size && HS->Content &&
1342 (uint64_t)*HS->Size < HS->Content->binary_size())
1343 return "\"Size\" must be greater than or equal to the content "
1344 "size";
1346 if (HS->Bucket)
1347 return "\"Bucket\" cannot be used with \"Content\" or \"Size\"";
1348 if (HS->Chain)
1349 return "\"Chain\" cannot be used with \"Content\" or \"Size\"";
1350 return {};
1353 if ((HS->Bucket && !HS->Chain) || (!HS->Bucket && HS->Chain))
1354 return "\"Bucket\" and \"Chain\" must be used together";
1355 return {};
1358 if (const auto *Sec = dyn_cast<ELFYAML::AddrsigSection>(C.get())) {
1359 if (!Sec->Symbols && !Sec->Content && !Sec->Size)
1360 return "one of \"Content\", \"Size\" or \"Symbols\" must be specified";
1362 if (Sec->Content || Sec->Size) {
1363 if (Sec->Size && Sec->Content &&
1364 (uint64_t)*Sec->Size < Sec->Content->binary_size())
1365 return "\"Size\" must be greater than or equal to the content "
1366 "size";
1368 if (Sec->Symbols)
1369 return "\"Symbols\" cannot be used with \"Content\" or \"Size\"";
1370 return {};
1373 if (!Sec->Symbols)
1374 return {};
1376 for (const ELFYAML::AddrsigSymbol &AS : *Sec->Symbols)
1377 if (AS.Index && AS.Name)
1378 return "\"Index\" and \"Name\" cannot be used together when defining a "
1379 "symbol";
1380 return {};
1383 if (const auto *NS = dyn_cast<ELFYAML::NoteSection>(C.get())) {
1384 if (!NS->Content && !NS->Size && !NS->Notes)
1385 return "one of \"Content\", \"Size\" or \"Notes\" must be "
1386 "specified";
1388 if (!NS->Content && !NS->Size)
1389 return {};
1391 if (NS->Size && NS->Content &&
1392 (uint64_t)*NS->Size < NS->Content->binary_size())
1393 return "\"Size\" must be greater than or equal to the content "
1394 "size";
1396 if (NS->Notes)
1397 return "\"Notes\" cannot be used with \"Content\" or \"Size\"";
1398 return {};
1401 if (const auto *Sec = dyn_cast<ELFYAML::GnuHashSection>(C.get())) {
1402 if (!Sec->Content && !Sec->Header && !Sec->BloomFilter &&
1403 !Sec->HashBuckets && !Sec->HashValues)
1404 return "either \"Content\" or \"Header\", \"BloomFilter\", "
1405 "\"HashBuckets\" and \"HashBuckets\" must be specified";
1407 if (Sec->Header || Sec->BloomFilter || Sec->HashBuckets ||
1408 Sec->HashValues) {
1409 if (!Sec->Header || !Sec->BloomFilter || !Sec->HashBuckets ||
1410 !Sec->HashValues)
1411 return "\"Header\", \"BloomFilter\", "
1412 "\"HashBuckets\" and \"HashValues\" must be used together";
1413 if (Sec->Content)
1414 return "\"Header\", \"BloomFilter\", "
1415 "\"HashBuckets\" and \"HashValues\" can't be used together with "
1416 "\"Content\"";
1417 return {};
1420 // Only Content is specified.
1421 return {};
1424 if (const auto *Sec = dyn_cast<ELFYAML::LinkerOptionsSection>(C.get())) {
1425 if (Sec->Options && Sec->Content)
1426 return "\"Options\" and \"Content\" can't be used together";
1427 return {};
1430 if (const auto *Sec = dyn_cast<ELFYAML::DependentLibrariesSection>(C.get())) {
1431 if (Sec->Libs && Sec->Content)
1432 return "SHT_LLVM_DEPENDENT_LIBRARIES: \"Libraries\" and \"Content\" "
1433 "can't "
1434 "be used together";
1435 return {};
1438 if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) {
1439 if (!F->Pattern)
1440 return {};
1441 if (F->Pattern->binary_size() != 0 && !F->Size)
1442 return "\"Size\" can't be 0 when \"Pattern\" is not empty";
1443 return {};
1446 if (const auto *VD = dyn_cast<ELFYAML::VerdefSection>(C.get())) {
1447 if (VD->Entries && VD->Content)
1448 return "SHT_GNU_verdef: \"Entries\" and \"Content\" can't be used "
1449 "together";
1450 return {};
1453 if (const auto *VD = dyn_cast<ELFYAML::VerneedSection>(C.get())) {
1454 if (VD->VerneedV && VD->Content)
1455 return "SHT_GNU_verneed: \"Dependencies\" and \"Content\" can't be used "
1456 "together";
1457 return {};
1460 if (const auto *RS = dyn_cast<ELFYAML::RelrSection>(C.get())) {
1461 if (RS->Entries && RS->Content)
1462 return "\"Entries\" and \"Content\" can't be used together";
1463 return {};
1466 return {};
1469 namespace {
1471 struct NormalizedMips64RelType {
1472 NormalizedMips64RelType(IO &)
1473 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1474 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1475 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
1476 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
1477 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
1478 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
1479 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
1481 ELFYAML::ELF_REL denormalize(IO &) {
1482 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
1483 return Res;
1486 ELFYAML::ELF_REL Type;
1487 ELFYAML::ELF_REL Type2;
1488 ELFYAML::ELF_REL Type3;
1489 ELFYAML::ELF_RSS SpecSym;
1492 } // end anonymous namespace
1494 void MappingTraits<ELFYAML::StackSizeEntry>::mapping(
1495 IO &IO, ELFYAML::StackSizeEntry &E) {
1496 assert(IO.getContext() && "The IO context is not initialized");
1497 IO.mapOptional("Address", E.Address, Hex64(0));
1498 IO.mapRequired("Size", E.Size);
1501 void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO,
1502 ELFYAML::GnuHashHeader &E) {
1503 assert(IO.getContext() && "The IO context is not initialized");
1504 IO.mapOptional("NBuckets", E.NBuckets);
1505 IO.mapRequired("SymNdx", E.SymNdx);
1506 IO.mapOptional("MaskWords", E.MaskWords);
1507 IO.mapRequired("Shift2", E.Shift2);
1510 void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO,
1511 ELFYAML::DynamicEntry &Rel) {
1512 assert(IO.getContext() && "The IO context is not initialized");
1514 IO.mapRequired("Tag", Rel.Tag);
1515 IO.mapRequired("Value", Rel.Val);
1518 void MappingTraits<ELFYAML::NoteEntry>::mapping(IO &IO, ELFYAML::NoteEntry &N) {
1519 assert(IO.getContext() && "The IO context is not initialized");
1521 IO.mapOptional("Name", N.Name);
1522 IO.mapOptional("Desc", N.Desc);
1523 IO.mapRequired("Type", N.Type);
1526 void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO,
1527 ELFYAML::VerdefEntry &E) {
1528 assert(IO.getContext() && "The IO context is not initialized");
1530 IO.mapRequired("Version", E.Version);
1531 IO.mapRequired("Flags", E.Flags);
1532 IO.mapRequired("VersionNdx", E.VersionNdx);
1533 IO.mapRequired("Hash", E.Hash);
1534 IO.mapRequired("Names", E.VerNames);
1537 void MappingTraits<ELFYAML::VerneedEntry>::mapping(IO &IO,
1538 ELFYAML::VerneedEntry &E) {
1539 assert(IO.getContext() && "The IO context is not initialized");
1541 IO.mapRequired("Version", E.Version);
1542 IO.mapRequired("File", E.File);
1543 IO.mapRequired("Entries", E.AuxV);
1546 void MappingTraits<ELFYAML::VernauxEntry>::mapping(IO &IO,
1547 ELFYAML::VernauxEntry &E) {
1548 assert(IO.getContext() && "The IO context is not initialized");
1550 IO.mapRequired("Name", E.Name);
1551 IO.mapRequired("Hash", E.Hash);
1552 IO.mapRequired("Flags", E.Flags);
1553 IO.mapRequired("Other", E.Other);
1556 void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
1557 ELFYAML::Relocation &Rel) {
1558 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
1559 assert(Object && "The IO context is not initialized");
1561 IO.mapRequired("Offset", Rel.Offset);
1562 IO.mapOptional("Symbol", Rel.Symbol);
1564 if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
1565 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
1566 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
1567 IO, Rel.Type);
1568 IO.mapRequired("Type", Key->Type);
1569 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
1570 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
1571 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
1572 } else
1573 IO.mapRequired("Type", Rel.Type);
1575 IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
1578 void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
1579 assert(!IO.getContext() && "The IO context is initialized already");
1580 IO.setContext(&Object);
1581 IO.mapTag("!ELF", true);
1582 IO.mapRequired("FileHeader", Object.Header);
1583 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
1584 IO.mapOptional("Sections", Object.Chunks);
1585 IO.mapOptional("Symbols", Object.Symbols);
1586 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
1587 IO.setContext(nullptr);
1590 void MappingTraits<ELFYAML::AddrsigSymbol>::mapping(IO &IO, ELFYAML::AddrsigSymbol &Sym) {
1591 assert(IO.getContext() && "The IO context is not initialized");
1592 IO.mapOptional("Name", Sym.Name);
1593 IO.mapOptional("Index", Sym.Index);
1596 void MappingTraits<ELFYAML::LinkerOption>::mapping(IO &IO,
1597 ELFYAML::LinkerOption &Opt) {
1598 assert(IO.getContext() && "The IO context is not initialized");
1599 IO.mapRequired("Name", Opt.Key);
1600 IO.mapRequired("Value", Opt.Value);
1603 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
1604 LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
1605 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)
1606 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)
1607 LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)
1609 } // end namespace yaml
1611 } // end namespace llvm