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