1 //===--- ARMAttributeParser.cpp - ARM Attribute Information Printer -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/Support/ARMAttributeParser.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/StringExtras.h"
13 #include "llvm/Support/LEB128.h"
14 #include "llvm/Support/ScopedPrinter.h"
15
16 using namespace llvm;
17 using namespace llvm::ARMBuildAttrs;
18
19
20 static const EnumEntry<unsigned> TagNames[] = {
21 { "Tag_File", ARMBuildAttrs::File },
22 { "Tag_Section", ARMBuildAttrs::Section },
23 { "Tag_Symbol", ARMBuildAttrs::Symbol },
24 };
25
26 namespace llvm {
27 #define ATTRIBUTE_HANDLER(Attr_) \
28 { ARMBuildAttrs::Attr_, &ARMAttributeParser::Attr_ }
29
30 const ARMAttributeParser::DisplayHandler
31 ARMAttributeParser::DisplayRoutines[] = {
32 { ARMBuildAttrs::CPU_raw_name, &ARMAttributeParser::StringAttribute, },
33 { ARMBuildAttrs::CPU_name, &ARMAttributeParser::StringAttribute },
34 ATTRIBUTE_HANDLER(CPU_arch),
35 ATTRIBUTE_HANDLER(CPU_arch_profile),
36 ATTRIBUTE_HANDLER(ARM_ISA_use),
37 ATTRIBUTE_HANDLER(THUMB_ISA_use),
38 ATTRIBUTE_HANDLER(FP_arch),
39 ATTRIBUTE_HANDLER(WMMX_arch),
40 ATTRIBUTE_HANDLER(Advanced_SIMD_arch),
41 ATTRIBUTE_HANDLER(PCS_config),
42 ATTRIBUTE_HANDLER(ABI_PCS_R9_use),
43 ATTRIBUTE_HANDLER(ABI_PCS_RW_data),
44 ATTRIBUTE_HANDLER(ABI_PCS_RO_data),
45 ATTRIBUTE_HANDLER(ABI_PCS_GOT_use),
46 ATTRIBUTE_HANDLER(ABI_PCS_wchar_t),
47 ATTRIBUTE_HANDLER(ABI_FP_rounding),
48 ATTRIBUTE_HANDLER(ABI_FP_denormal),
49 ATTRIBUTE_HANDLER(ABI_FP_exceptions),
50 ATTRIBUTE_HANDLER(ABI_FP_user_exceptions),
51 ATTRIBUTE_HANDLER(ABI_FP_number_model),
52 ATTRIBUTE_HANDLER(ABI_align_needed),
53 ATTRIBUTE_HANDLER(ABI_align_preserved),
54 ATTRIBUTE_HANDLER(ABI_enum_size),
55 ATTRIBUTE_HANDLER(ABI_HardFP_use),
56 ATTRIBUTE_HANDLER(ABI_VFP_args),
57 ATTRIBUTE_HANDLER(ABI_WMMX_args),
58 ATTRIBUTE_HANDLER(ABI_optimization_goals),
59 ATTRIBUTE_HANDLER(ABI_FP_optimization_goals),
60 ATTRIBUTE_HANDLER(compatibility),
61 ATTRIBUTE_HANDLER(CPU_unaligned_access),
62 ATTRIBUTE_HANDLER(FP_HP_extension),
63 ATTRIBUTE_HANDLER(ABI_FP_16bit_format),
64 ATTRIBUTE_HANDLER(MPextension_use),
65 ATTRIBUTE_HANDLER(DIV_use),
66 ATTRIBUTE_HANDLER(DSP_extension),
67 ATTRIBUTE_HANDLER(T2EE_use),
68 ATTRIBUTE_HANDLER(Virtualization_use),
69 ATTRIBUTE_HANDLER(nodefaults)
70 };
71
72 #undef ATTRIBUTE_HANDLER
73
ParseInteger(const uint8_t * Data,uint32_t & Offset)74 uint64_t ARMAttributeParser::ParseInteger(const uint8_t *Data,
75 uint32_t &Offset) {
76 unsigned Length;
77 uint64_t Value = decodeULEB128(Data + Offset, &Length);
78 Offset = Offset + Length;
79 return Value;
80 }
81
ParseString(const uint8_t * Data,uint32_t & Offset)82 StringRef ARMAttributeParser::ParseString(const uint8_t *Data,
83 uint32_t &Offset) {
84 const char *String = reinterpret_cast<const char*>(Data + Offset);
85 size_t Length = std::strlen(String);
86 Offset = Offset + Length + 1;
87 return StringRef(String, Length);
88 }
89
IntegerAttribute(AttrType Tag,const uint8_t * Data,uint32_t & Offset)90 void ARMAttributeParser::IntegerAttribute(AttrType Tag, const uint8_t *Data,
91 uint32_t &Offset) {
92
93 uint64_t Value = ParseInteger(Data, Offset);
94 Attributes.insert(std::make_pair(Tag, Value));
95
96 if (SW)
97 SW->printNumber(ARMBuildAttrs::AttrTypeAsString(Tag), Value);
98 }
99
StringAttribute(AttrType Tag,const uint8_t * Data,uint32_t & Offset)100 void ARMAttributeParser::StringAttribute(AttrType Tag, const uint8_t *Data,
101 uint32_t &Offset) {
102 StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false);
103 StringRef ValueDesc = ParseString(Data, Offset);
104
105 if (SW) {
106 DictScope AS(*SW, "Attribute");
107 SW->printNumber("Tag", Tag);
108 if (!TagName.empty())
109 SW->printString("TagName", TagName);
110 SW->printString("Value", ValueDesc);
111 }
112 }
113
PrintAttribute(unsigned Tag,unsigned Value,StringRef ValueDesc)114 void ARMAttributeParser::PrintAttribute(unsigned Tag, unsigned Value,
115 StringRef ValueDesc) {
116 Attributes.insert(std::make_pair(Tag, Value));
117
118 if (SW) {
119 StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag,
120 /*TagPrefix*/false);
121 DictScope AS(*SW, "Attribute");
122 SW->printNumber("Tag", Tag);
123 SW->printNumber("Value", Value);
124 if (!TagName.empty())
125 SW->printString("TagName", TagName);
126 if (!ValueDesc.empty())
127 SW->printString("Description", ValueDesc);
128 }
129 }
130
CPU_arch(AttrType Tag,const uint8_t * Data,uint32_t & Offset)131 void ARMAttributeParser::CPU_arch(AttrType Tag, const uint8_t *Data,
132 uint32_t &Offset) {
133 static const char *const Strings[] = {
134 "Pre-v4", "ARM v4", "ARM v4T", "ARM v5T", "ARM v5TE", "ARM v5TEJ", "ARM v6",
135 "ARM v6KZ", "ARM v6T2", "ARM v6K", "ARM v7", "ARM v6-M", "ARM v6S-M",
136 "ARM v7E-M", "ARM v8"
137 };
138
139 uint64_t Value = ParseInteger(Data, Offset);
140 StringRef ValueDesc =
141 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
142 PrintAttribute(Tag, Value, ValueDesc);
143 }
144
CPU_arch_profile(AttrType Tag,const uint8_t * Data,uint32_t & Offset)145 void ARMAttributeParser::CPU_arch_profile(AttrType Tag, const uint8_t *Data,
146 uint32_t &Offset) {
147 uint64_t Encoded = ParseInteger(Data, Offset);
148
149 StringRef Profile;
150 switch (Encoded) {
151 default: Profile = "Unknown"; break;
152 case 'A': Profile = "Application"; break;
153 case 'R': Profile = "Real-time"; break;
154 case 'M': Profile = "Microcontroller"; break;
155 case 'S': Profile = "Classic"; break;
156 case 0: Profile = "None"; break;
157 }
158
159 PrintAttribute(Tag, Encoded, Profile);
160 }
161
ARM_ISA_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)162 void ARMAttributeParser::ARM_ISA_use(AttrType Tag, const uint8_t *Data,
163 uint32_t &Offset) {
164 static const char *const Strings[] = { "Not Permitted", "Permitted" };
165
166 uint64_t Value = ParseInteger(Data, Offset);
167 StringRef ValueDesc =
168 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
169 PrintAttribute(Tag, Value, ValueDesc);
170 }
171
THUMB_ISA_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)172 void ARMAttributeParser::THUMB_ISA_use(AttrType Tag, const uint8_t *Data,
173 uint32_t &Offset) {
174 static const char *const Strings[] = { "Not Permitted", "Thumb-1", "Thumb-2" };
175
176 uint64_t Value = ParseInteger(Data, Offset);
177 StringRef ValueDesc =
178 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
179 PrintAttribute(Tag, Value, ValueDesc);
180 }
181
FP_arch(AttrType Tag,const uint8_t * Data,uint32_t & Offset)182 void ARMAttributeParser::FP_arch(AttrType Tag, const uint8_t *Data,
183 uint32_t &Offset) {
184 static const char *const Strings[] = {
185 "Not Permitted", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4",
186 "VFPv4-D16", "ARMv8-a FP", "ARMv8-a FP-D16"
187 };
188
189 uint64_t Value = ParseInteger(Data, Offset);
190 StringRef ValueDesc =
191 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
192 PrintAttribute(Tag, Value, ValueDesc);
193 }
194
WMMX_arch(AttrType Tag,const uint8_t * Data,uint32_t & Offset)195 void ARMAttributeParser::WMMX_arch(AttrType Tag, const uint8_t *Data,
196 uint32_t &Offset) {
197 static const char *const Strings[] = { "Not Permitted", "WMMXv1", "WMMXv2" };
198
199 uint64_t Value = ParseInteger(Data, Offset);
200 StringRef ValueDesc =
201 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
202 PrintAttribute(Tag, Value, ValueDesc);
203 }
204
Advanced_SIMD_arch(AttrType Tag,const uint8_t * Data,uint32_t & Offset)205 void ARMAttributeParser::Advanced_SIMD_arch(AttrType Tag, const uint8_t *Data,
206 uint32_t &Offset) {
207 static const char *const Strings[] = {
208 "Not Permitted", "NEONv1", "NEONv2+FMA", "ARMv8-a NEON", "ARMv8.1-a NEON"
209 };
210
211 uint64_t Value = ParseInteger(Data, Offset);
212 StringRef ValueDesc =
213 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
214 PrintAttribute(Tag, Value, ValueDesc);
215 }
216
PCS_config(AttrType Tag,const uint8_t * Data,uint32_t & Offset)217 void ARMAttributeParser::PCS_config(AttrType Tag, const uint8_t *Data,
218 uint32_t &Offset) {
219 static const char *const Strings[] = {
220 "None", "Bare Platform", "Linux Application", "Linux DSO", "Palm OS 2004",
221 "Reserved (Palm OS)", "Symbian OS 2004", "Reserved (Symbian OS)"
222 };
223
224 uint64_t Value = ParseInteger(Data, Offset);
225 StringRef ValueDesc =
226 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
227 PrintAttribute(Tag, Value, ValueDesc);
228 }
229
ABI_PCS_R9_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)230 void ARMAttributeParser::ABI_PCS_R9_use(AttrType Tag, const uint8_t *Data,
231 uint32_t &Offset) {
232 static const char *const Strings[] = { "v6", "Static Base", "TLS", "Unused" };
233
234 uint64_t Value = ParseInteger(Data, Offset);
235 StringRef ValueDesc =
236 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
237 PrintAttribute(Tag, Value, ValueDesc);
238 }
239
ABI_PCS_RW_data(AttrType Tag,const uint8_t * Data,uint32_t & Offset)240 void ARMAttributeParser::ABI_PCS_RW_data(AttrType Tag, const uint8_t *Data,
241 uint32_t &Offset) {
242 static const char *const Strings[] = {
243 "Absolute", "PC-relative", "SB-relative", "Not Permitted"
244 };
245
246 uint64_t Value = ParseInteger(Data, Offset);
247 StringRef ValueDesc =
248 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
249 PrintAttribute(Tag, Value, ValueDesc);
250 }
251
ABI_PCS_RO_data(AttrType Tag,const uint8_t * Data,uint32_t & Offset)252 void ARMAttributeParser::ABI_PCS_RO_data(AttrType Tag, const uint8_t *Data,
253 uint32_t &Offset) {
254 static const char *const Strings[] = {
255 "Absolute", "PC-relative", "Not Permitted"
256 };
257
258 uint64_t Value = ParseInteger(Data, Offset);
259 StringRef ValueDesc =
260 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
261 PrintAttribute(Tag, Value, ValueDesc);
262 }
263
ABI_PCS_GOT_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)264 void ARMAttributeParser::ABI_PCS_GOT_use(AttrType Tag, const uint8_t *Data,
265 uint32_t &Offset) {
266 static const char *const Strings[] = {
267 "Not Permitted", "Direct", "GOT-Indirect"
268 };
269
270 uint64_t Value = ParseInteger(Data, Offset);
271 StringRef ValueDesc =
272 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
273 PrintAttribute(Tag, Value, ValueDesc);
274 }
275
ABI_PCS_wchar_t(AttrType Tag,const uint8_t * Data,uint32_t & Offset)276 void ARMAttributeParser::ABI_PCS_wchar_t(AttrType Tag, const uint8_t *Data,
277 uint32_t &Offset) {
278 static const char *const Strings[] = {
279 "Not Permitted", "Unknown", "2-byte", "Unknown", "4-byte"
280 };
281
282 uint64_t Value = ParseInteger(Data, Offset);
283 StringRef ValueDesc =
284 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
285 PrintAttribute(Tag, Value, ValueDesc);
286 }
287
ABI_FP_rounding(AttrType Tag,const uint8_t * Data,uint32_t & Offset)288 void ARMAttributeParser::ABI_FP_rounding(AttrType Tag, const uint8_t *Data,
289 uint32_t &Offset) {
290 static const char *const Strings[] = { "IEEE-754", "Runtime" };
291
292 uint64_t Value = ParseInteger(Data, Offset);
293 StringRef ValueDesc =
294 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
295 PrintAttribute(Tag, Value, ValueDesc);
296 }
297
ABI_FP_denormal(AttrType Tag,const uint8_t * Data,uint32_t & Offset)298 void ARMAttributeParser::ABI_FP_denormal(AttrType Tag, const uint8_t *Data,
299 uint32_t &Offset) {
300 static const char *const Strings[] = {
301 "Unsupported", "IEEE-754", "Sign Only"
302 };
303
304 uint64_t Value = ParseInteger(Data, Offset);
305 StringRef ValueDesc =
306 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
307 PrintAttribute(Tag, Value, ValueDesc);
308 }
309
ABI_FP_exceptions(AttrType Tag,const uint8_t * Data,uint32_t & Offset)310 void ARMAttributeParser::ABI_FP_exceptions(AttrType Tag, const uint8_t *Data,
311 uint32_t &Offset) {
312 static const char *const Strings[] = { "Not Permitted", "IEEE-754" };
313
314 uint64_t Value = ParseInteger(Data, Offset);
315 StringRef ValueDesc =
316 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
317 PrintAttribute(Tag, Value, ValueDesc);
318 }
319
ABI_FP_user_exceptions(AttrType Tag,const uint8_t * Data,uint32_t & Offset)320 void ARMAttributeParser::ABI_FP_user_exceptions(AttrType Tag,
321 const uint8_t *Data,
322 uint32_t &Offset) {
323 static const char *const Strings[] = { "Not Permitted", "IEEE-754" };
324
325 uint64_t Value = ParseInteger(Data, Offset);
326 StringRef ValueDesc =
327 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
328 PrintAttribute(Tag, Value, ValueDesc);
329 }
330
ABI_FP_number_model(AttrType Tag,const uint8_t * Data,uint32_t & Offset)331 void ARMAttributeParser::ABI_FP_number_model(AttrType Tag, const uint8_t *Data,
332 uint32_t &Offset) {
333 static const char *const Strings[] = {
334 "Not Permitted", "Finite Only", "RTABI", "IEEE-754"
335 };
336
337 uint64_t Value = ParseInteger(Data, Offset);
338 StringRef ValueDesc =
339 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
340 PrintAttribute(Tag, Value, ValueDesc);
341 }
342
ABI_align_needed(AttrType Tag,const uint8_t * Data,uint32_t & Offset)343 void ARMAttributeParser::ABI_align_needed(AttrType Tag, const uint8_t *Data,
344 uint32_t &Offset) {
345 static const char *const Strings[] = {
346 "Not Permitted", "8-byte alignment", "4-byte alignment", "Reserved"
347 };
348
349 uint64_t Value = ParseInteger(Data, Offset);
350
351 std::string Description;
352 if (Value < array_lengthof(Strings))
353 Description = std::string(Strings[Value]);
354 else if (Value <= 12)
355 Description = std::string("8-byte alignment, ") + utostr(1ULL << Value)
356 + std::string("-byte extended alignment");
357 else
358 Description = "Invalid";
359
360 PrintAttribute(Tag, Value, Description);
361 }
362
ABI_align_preserved(AttrType Tag,const uint8_t * Data,uint32_t & Offset)363 void ARMAttributeParser::ABI_align_preserved(AttrType Tag, const uint8_t *Data,
364 uint32_t &Offset) {
365 static const char *const Strings[] = {
366 "Not Required", "8-byte data alignment", "8-byte data and code alignment",
367 "Reserved"
368 };
369
370 uint64_t Value = ParseInteger(Data, Offset);
371
372 std::string Description;
373 if (Value < array_lengthof(Strings))
374 Description = std::string(Strings[Value]);
375 else if (Value <= 12)
376 Description = std::string("8-byte stack alignment, ") +
377 utostr(1ULL << Value) + std::string("-byte data alignment");
378 else
379 Description = "Invalid";
380
381 PrintAttribute(Tag, Value, Description);
382 }
383
ABI_enum_size(AttrType Tag,const uint8_t * Data,uint32_t & Offset)384 void ARMAttributeParser::ABI_enum_size(AttrType Tag, const uint8_t *Data,
385 uint32_t &Offset) {
386 static const char *const Strings[] = {
387 "Not Permitted", "Packed", "Int32", "External Int32"
388 };
389
390 uint64_t Value = ParseInteger(Data, Offset);
391 StringRef ValueDesc =
392 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
393 PrintAttribute(Tag, Value, ValueDesc);
394 }
395
ABI_HardFP_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)396 void ARMAttributeParser::ABI_HardFP_use(AttrType Tag, const uint8_t *Data,
397 uint32_t &Offset) {
398 static const char *const Strings[] = {
399 "Tag_FP_arch", "Single-Precision", "Reserved", "Tag_FP_arch (deprecated)"
400 };
401
402 uint64_t Value = ParseInteger(Data, Offset);
403 StringRef ValueDesc =
404 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
405 PrintAttribute(Tag, Value, ValueDesc);
406 }
407
ABI_VFP_args(AttrType Tag,const uint8_t * Data,uint32_t & Offset)408 void ARMAttributeParser::ABI_VFP_args(AttrType Tag, const uint8_t *Data,
409 uint32_t &Offset) {
410 static const char *const Strings[] = {
411 "AAPCS", "AAPCS VFP", "Custom", "Not Permitted"
412 };
413
414 uint64_t Value = ParseInteger(Data, Offset);
415 StringRef ValueDesc =
416 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
417 PrintAttribute(Tag, Value, ValueDesc);
418 }
419
ABI_WMMX_args(AttrType Tag,const uint8_t * Data,uint32_t & Offset)420 void ARMAttributeParser::ABI_WMMX_args(AttrType Tag, const uint8_t *Data,
421 uint32_t &Offset) {
422 static const char *const Strings[] = { "AAPCS", "iWMMX", "Custom" };
423
424 uint64_t Value = ParseInteger(Data, Offset);
425 StringRef ValueDesc =
426 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
427 PrintAttribute(Tag, Value, ValueDesc);
428 }
429
ABI_optimization_goals(AttrType Tag,const uint8_t * Data,uint32_t & Offset)430 void ARMAttributeParser::ABI_optimization_goals(AttrType Tag,
431 const uint8_t *Data,
432 uint32_t &Offset) {
433 static const char *const Strings[] = {
434 "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Debugging",
435 "Best Debugging"
436 };
437
438 uint64_t Value = ParseInteger(Data, Offset);
439 StringRef ValueDesc =
440 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
441 PrintAttribute(Tag, Value, ValueDesc);
442 }
443
ABI_FP_optimization_goals(AttrType Tag,const uint8_t * Data,uint32_t & Offset)444 void ARMAttributeParser::ABI_FP_optimization_goals(AttrType Tag,
445 const uint8_t *Data,
446 uint32_t &Offset) {
447 static const char *const Strings[] = {
448 "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Accuracy",
449 "Best Accuracy"
450 };
451
452 uint64_t Value = ParseInteger(Data, Offset);
453 StringRef ValueDesc =
454 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
455 PrintAttribute(Tag, Value, ValueDesc);
456 }
457
compatibility(AttrType Tag,const uint8_t * Data,uint32_t & Offset)458 void ARMAttributeParser::compatibility(AttrType Tag, const uint8_t *Data,
459 uint32_t &Offset) {
460 uint64_t Integer = ParseInteger(Data, Offset);
461 StringRef String = ParseString(Data, Offset);
462
463 if (SW) {
464 DictScope AS(*SW, "Attribute");
465 SW->printNumber("Tag", Tag);
466 SW->startLine() << "Value: " << Integer << ", " << String << '\n';
467 SW->printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false));
468 switch (Integer) {
469 case 0:
470 SW->printString("Description", StringRef("No Specific Requirements"));
471 break;
472 case 1:
473 SW->printString("Description", StringRef("AEABI Conformant"));
474 break;
475 default:
476 SW->printString("Description", StringRef("AEABI Non-Conformant"));
477 break;
478 }
479 }
480 }
481
CPU_unaligned_access(AttrType Tag,const uint8_t * Data,uint32_t & Offset)482 void ARMAttributeParser::CPU_unaligned_access(AttrType Tag, const uint8_t *Data,
483 uint32_t &Offset) {
484 static const char *const Strings[] = { "Not Permitted", "v6-style" };
485
486 uint64_t Value = ParseInteger(Data, Offset);
487 StringRef ValueDesc =
488 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
489 PrintAttribute(Tag, Value, ValueDesc);
490 }
491
FP_HP_extension(AttrType Tag,const uint8_t * Data,uint32_t & Offset)492 void ARMAttributeParser::FP_HP_extension(AttrType Tag, const uint8_t *Data,
493 uint32_t &Offset) {
494 static const char *const Strings[] = { "If Available", "Permitted" };
495
496 uint64_t Value = ParseInteger(Data, Offset);
497 StringRef ValueDesc =
498 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
499 PrintAttribute(Tag, Value, ValueDesc);
500 }
501
ABI_FP_16bit_format(AttrType Tag,const uint8_t * Data,uint32_t & Offset)502 void ARMAttributeParser::ABI_FP_16bit_format(AttrType Tag, const uint8_t *Data,
503 uint32_t &Offset) {
504 static const char *const Strings[] = { "Not Permitted", "IEEE-754", "VFPv3" };
505
506 uint64_t Value = ParseInteger(Data, Offset);
507 StringRef ValueDesc =
508 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
509 PrintAttribute(Tag, Value, ValueDesc);
510 }
511
MPextension_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)512 void ARMAttributeParser::MPextension_use(AttrType Tag, const uint8_t *Data,
513 uint32_t &Offset) {
514 static const char *const Strings[] = { "Not Permitted", "Permitted" };
515
516 uint64_t Value = ParseInteger(Data, Offset);
517 StringRef ValueDesc =
518 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
519 PrintAttribute(Tag, Value, ValueDesc);
520 }
521
DIV_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)522 void ARMAttributeParser::DIV_use(AttrType Tag, const uint8_t *Data,
523 uint32_t &Offset) {
524 static const char *const Strings[] = {
525 "If Available", "Not Permitted", "Permitted"
526 };
527
528 uint64_t Value = ParseInteger(Data, Offset);
529 StringRef ValueDesc =
530 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
531 PrintAttribute(Tag, Value, ValueDesc);
532 }
533
DSP_extension(AttrType Tag,const uint8_t * Data,uint32_t & Offset)534 void ARMAttributeParser::DSP_extension(AttrType Tag, const uint8_t *Data,
535 uint32_t &Offset) {
536 static const char *const Strings[] = { "Not Permitted", "Permitted" };
537
538 uint64_t Value = ParseInteger(Data, Offset);
539 StringRef ValueDesc =
540 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
541 PrintAttribute(Tag, Value, ValueDesc);
542 }
543
T2EE_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)544 void ARMAttributeParser::T2EE_use(AttrType Tag, const uint8_t *Data,
545 uint32_t &Offset) {
546 static const char *const Strings[] = { "Not Permitted", "Permitted" };
547
548 uint64_t Value = ParseInteger(Data, Offset);
549 StringRef ValueDesc =
550 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
551 PrintAttribute(Tag, Value, ValueDesc);
552 }
553
Virtualization_use(AttrType Tag,const uint8_t * Data,uint32_t & Offset)554 void ARMAttributeParser::Virtualization_use(AttrType Tag, const uint8_t *Data,
555 uint32_t &Offset) {
556 static const char *const Strings[] = {
557 "Not Permitted", "TrustZone", "Virtualization Extensions",
558 "TrustZone + Virtualization Extensions"
559 };
560
561 uint64_t Value = ParseInteger(Data, Offset);
562 StringRef ValueDesc =
563 (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
564 PrintAttribute(Tag, Value, ValueDesc);
565 }
566
nodefaults(AttrType Tag,const uint8_t * Data,uint32_t & Offset)567 void ARMAttributeParser::nodefaults(AttrType Tag, const uint8_t *Data,
568 uint32_t &Offset) {
569 uint64_t Value = ParseInteger(Data, Offset);
570 PrintAttribute(Tag, Value, "Unspecified Tags UNDEFINED");
571 }
572
ParseIndexList(const uint8_t * Data,uint32_t & Offset,SmallVectorImpl<uint8_t> & IndexList)573 void ARMAttributeParser::ParseIndexList(const uint8_t *Data, uint32_t &Offset,
574 SmallVectorImpl<uint8_t> &IndexList) {
575 for (;;) {
576 unsigned Length;
577 uint64_t Value = decodeULEB128(Data + Offset, &Length);
578 Offset = Offset + Length;
579 if (Value == 0)
580 break;
581 IndexList.push_back(Value);
582 }
583 }
584
ParseAttributeList(const uint8_t * Data,uint32_t & Offset,uint32_t Length)585 void ARMAttributeParser::ParseAttributeList(const uint8_t *Data,
586 uint32_t &Offset, uint32_t Length) {
587 while (Offset < Length) {
588 unsigned Length;
589 uint64_t Tag = decodeULEB128(Data + Offset, &Length);
590 Offset += Length;
591
592 bool Handled = false;
593 for (unsigned AHI = 0, AHE = array_lengthof(DisplayRoutines);
594 AHI != AHE && !Handled; ++AHI) {
595 if (uint64_t(DisplayRoutines[AHI].Attribute) == Tag) {
596 (this->*DisplayRoutines[AHI].Routine)(ARMBuildAttrs::AttrType(Tag),
597 Data, Offset);
598 Handled = true;
599 break;
600 }
601 }
602 if (!Handled) {
603 if (Tag < 32) {
604 errs() << "unhandled AEABI Tag " << Tag
605 << " (" << ARMBuildAttrs::AttrTypeAsString(Tag) << ")\n";
606 continue;
607 }
608
609 if (Tag % 2 == 0)
610 IntegerAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset);
611 else
612 StringAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset);
613 }
614 }
615 }
616
ParseSubsection(const uint8_t * Data,uint32_t Length)617 void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) {
618 uint32_t Offset = sizeof(uint32_t); /* SectionLength */
619
620 const char *VendorName = reinterpret_cast<const char*>(Data + Offset);
621 size_t VendorNameLength = std::strlen(VendorName);
622 Offset = Offset + VendorNameLength + 1;
623
624 if (SW) {
625 SW->printNumber("SectionLength", Length);
626 SW->printString("Vendor", StringRef(VendorName, VendorNameLength));
627 }
628
629 if (StringRef(VendorName, VendorNameLength).lower() != "aeabi") {
630 return;
631 }
632
633 while (Offset < Length) {
634 /// Tag_File | Tag_Section | Tag_Symbol uleb128:byte-size
635 uint8_t Tag = Data[Offset];
636 Offset = Offset + sizeof(Tag);
637
638 uint32_t Size =
639 *reinterpret_cast<const support::ulittle32_t*>(Data + Offset);
640 Offset = Offset + sizeof(Size);
641
642 if (SW) {
643 SW->printEnum("Tag", Tag, makeArrayRef(TagNames));
644 SW->printNumber("Size", Size);
645 }
646
647 if (Size > Length) {
648 errs() << "subsection length greater than section length\n";
649 return;
650 }
651
652 StringRef ScopeName, IndexName;
653 SmallVector<uint8_t, 8> Indicies;
654 switch (Tag) {
655 case ARMBuildAttrs::File:
656 ScopeName = "FileAttributes";
657 break;
658 case ARMBuildAttrs::Section:
659 ScopeName = "SectionAttributes";
660 IndexName = "Sections";
661 ParseIndexList(Data, Offset, Indicies);
662 break;
663 case ARMBuildAttrs::Symbol:
664 ScopeName = "SymbolAttributes";
665 IndexName = "Symbols";
666 ParseIndexList(Data, Offset, Indicies);
667 break;
668 default:
669 errs() << "unrecognised tag: 0x" << Twine::utohexstr(Tag) << '\n';
670 return;
671 }
672
673 if (SW) {
674 DictScope ASS(*SW, ScopeName);
675 if (!Indicies.empty())
676 SW->printList(IndexName, Indicies);
677 ParseAttributeList(Data, Offset, Length);
678 } else {
679 ParseAttributeList(Data, Offset, Length);
680 }
681 }
682 }
683
Parse(ArrayRef<uint8_t> Section,bool isLittle)684 void ARMAttributeParser::Parse(ArrayRef<uint8_t> Section, bool isLittle) {
685 size_t Offset = 1;
686 unsigned SectionNumber = 0;
687
688 while (Offset < Section.size()) {
689 uint32_t SectionLength = isLittle ?
690 support::endian::read32le(Section.data() + Offset) :
691 support::endian::read32be(Section.data() + Offset);
692
693 if (SW) {
694 SW->startLine() << "Section " << ++SectionNumber << " {\n";
695 SW->indent();
696 }
697
698 ParseSubsection(Section.data() + Offset, SectionLength);
699 Offset = Offset + SectionLength;
700
701 if (SW) {
702 SW->unindent();
703 SW->startLine() << "}\n";
704 }
705 }
706 }
707 }
708