llvm.org GIT mirror llvm / aa96763
[ARM] Create objdump subtarget from build attrs Enable an ELFObjectFile to read the its arm build attributes to produce a target triple with a specific ARM architecture. llvm-objdump now uses this functionality to automatically produce a more accurate target. Differential Revision: https://reviews.llvm.org/D28769 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292366 91177308-0d34-0410-b5e6-96231b3b80d8 Sam Parker 3 years ago
19 changed file(s) with 694 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
2525 #include "llvm/Object/Error.h"
2626 #include "llvm/Object/ObjectFile.h"
2727 #include "llvm/Object/SymbolicFile.h"
28 #include "llvm/Support/ARMAttributeParser.h"
2829 #include "llvm/Support/Casting.h"
2930 #include "llvm/Support/ELF.h"
3031 #include "llvm/Support/Endian.h"
7172 static inline bool classof(const Binary *v) { return v->isELF(); }
7273
7374 SubtargetFeatures getFeatures() const override;
75
76 void setARMSubArch(Triple &TheTriple) const override;
7477 };
7578
7679 class ELFSectionRef : public SectionRef {
352355
353356 std::error_code getPlatformFlags(unsigned &Result) const override {
354357 Result = EF.getHeader()->e_flags;
358 return std::error_code();
359 }
360
361 std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override {
362 auto SectionsOrErr = EF.sections();
363 if (!SectionsOrErr)
364 return errorToErrorCode(SectionsOrErr.takeError());
365
366 for (const Elf_Shdr &Sec : *SectionsOrErr) {
367 if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) {
368 auto ErrorOrContents = EF.getSectionContents(&Sec);
369 if (!ErrorOrContents)
370 return errorToErrorCode(ErrorOrContents.takeError());
371
372 auto Contents = ErrorOrContents.get();
373 if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1)
374 return std::error_code();
375
376 Attributes.Parse(Contents, ELFT::TargetEndianness == support::little);
377 break;
378 }
379 }
355380 return std::error_code();
356381 }
357382
2323 #include
2424
2525 namespace llvm {
26 class ARMAttributeParser;
27
2628 namespace object {
2729
2830 class ObjectFile;
264266 virtual StringRef getFileFormatName() const = 0;
265267 virtual /* Triple::ArchType */ unsigned getArch() const = 0;
266268 virtual SubtargetFeatures getFeatures() const = 0;
269 virtual void setARMSubArch(Triple &TheTriple) const { }
267270
268271 /// Returns platform-specific object flags, if any.
269272 virtual std::error_code getPlatformFlags(unsigned &Result) const {
270273 Result = 0;
271274 return object_error::invalid_file_type;
272275 }
276
277 virtual std::error_code
278 getBuildAttributes(ARMAttributeParser &Attributes) const {
279 return std::error_code();
280 }
273281
274282 /// True if this is a relocatable object (.o/.obj).
275283 virtual bool isRelocatableObject() const = 0;
1212 #include "ARMBuildAttributes.h"
1313 #include "ScopedPrinter.h"
1414
15 #include
16
1517 namespace llvm {
1618 class StringRef;
1719
1820 class ARMAttributeParser {
19 ScopedPrinter &SW;
21 ScopedPrinter *SW;
22
23 std::map Attributes;
2024
2125 struct DisplayHandler {
2226 ARMBuildAttrs::AttrType Attribute;
114118 SmallVectorImpl &IndexList);
115119 void ParseSubsection(const uint8_t *Data, uint32_t Length);
116120 public:
117 ARMAttributeParser(ScopedPrinter &SW) : SW(SW) {}
121 ARMAttributeParser(ScopedPrinter *SW) : SW(SW) {}
118122
119 void Parse(ArrayRef Section);
123 ARMAttributeParser() : SW(nullptr) { }
124
125 void Parse(ArrayRef Section, bool isLittle);
126
127 bool hasAttribute(unsigned Tag) const {
128 return Attributes.count(Tag);
129 }
130
131 unsigned getAttributeValue(unsigned Tag) const {
132 return Attributes.find(Tag)->second;
133 }
120134 };
121135
122136 }
175175 WCharWidth2Bytes = 2, // sizeof(wchar_t) == 2
176176 WCharWidth4Bytes = 4, // sizeof(wchar_t) == 4
177177
178 // Tag_ABI_align_needed, (=24), uleb128
179 Align8Byte = 1,
180 Align4Byte = 2,
181 AlignReserved = 3,
182
183 // Tag_ABI_align_needed, (=25), uleb128
184 AlignNotPreserved = 0,
185 AlignPreserve8Byte = 1,
186 AlignPreserveAll = 2,
187
178188 // Tag_ABI_FP_denormal, (=20), uleb128
179189 PositiveZero = 0,
180190 IEEEDenormals = 1,
181191 PreserveFPSign = 2, // sign when flushed-to-zero is preserved
182192
183193 // Tag_ABI_FP_number_model, (=23), uleb128
194 AllowIEEENormal = 1,
184195 AllowRTABI = 2, // numbers, infinities, and one quiet NaN (see [RTABI])
185 AllowIEE754 = 3, // this code to use all the IEEE 754-defined FP encodings
196 AllowIEEE754 = 3, // this code to use all the IEEE 754-defined FP encodings
186197
187198 // Tag_ABI_enum_size, (=26), uleb128
188199 EnumProhibited = 0, // The user prohibited the use of enums when building
207218
208219 // Tag_FP_16bit_format, (=38), uleb128
209220 FP16FormatIEEE = 1,
221 FP16VFP3 = 2,
210222
211223 // Tag_MPextension_use, (=42), uleb128
212224 AllowMP = 1, // Allow use of MP extensions
121121 }
122122 }
123123
124 // FIXME Encode from a tablegen description or target parser.
125 void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
126 if (TheTriple.getSubArch() != Triple::NoSubArch)
127 return;
128
129 ARMAttributeParser Attributes;
130 std::error_code EC = getBuildAttributes(Attributes);
131 if (EC)
132 return;
133
134 std::string Triple;
135 // Default to ARM, but use the triple if it's been set.
136 if (TheTriple.getArch() == Triple::thumb ||
137 TheTriple.getArch() == Triple::thumbeb)
138 Triple = "thumb";
139 else
140 Triple = "arm";
141
142 if (Attributes.hasAttribute(ARMBuildAttrs::CPU_arch)) {
143 switch(Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch)) {
144 case ARMBuildAttrs::v4:
145 Triple += "v4";
146 break;
147 case ARMBuildAttrs::v4T:
148 Triple += "v4t";
149 break;
150 case ARMBuildAttrs::v5T:
151 Triple += "v5t";
152 break;
153 case ARMBuildAttrs::v5TE:
154 Triple += "v5te";
155 break;
156 case ARMBuildAttrs::v5TEJ:
157 Triple += "v5tej";
158 break;
159 case ARMBuildAttrs::v6:
160 Triple += "v6";
161 break;
162 case ARMBuildAttrs::v6KZ:
163 Triple += "v6kz";
164 break;
165 case ARMBuildAttrs::v6T2:
166 Triple += "v6t2";
167 break;
168 case ARMBuildAttrs::v6K:
169 Triple += "v6k";
170 break;
171 case ARMBuildAttrs::v7:
172 Triple += "v7";
173 break;
174 case ARMBuildAttrs::v6_M:
175 Triple += "v6m";
176 break;
177 case ARMBuildAttrs::v6S_M:
178 Triple += "v6sm";
179 break;
180 case ARMBuildAttrs::v7E_M:
181 Triple += "v7em";
182 break;
183 }
184 }
185 if (!isLittleEndian())
186 Triple += "eb";
187
188 TheTriple.setArchName(Triple);
189 }
190
124191 } // end namespace llvm
8888
8989 void ARMAttributeParser::IntegerAttribute(AttrType Tag, const uint8_t *Data,
9090 uint32_t &Offset) {
91 SW.printNumber(ARMBuildAttrs::AttrTypeAsString(Tag),
92 ParseInteger(Data, Offset));
91
92 uint64_t Value = ParseInteger(Data, Offset);
93 Attributes.insert(std::make_pair(Tag, Value));
94
95 if (SW)
96 SW->printNumber(ARMBuildAttrs::AttrTypeAsString(Tag), Value);
9397 }
9498
9599 void ARMAttributeParser::StringAttribute(AttrType Tag, const uint8_t *Data,
96100 uint32_t &Offset) {
97101 StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false);
98
99 DictScope AS(SW, "Attribute");
100 SW.printNumber("Tag", Tag);
101 if (!TagName.empty())
102 SW.printString("TagName", TagName);
103 SW.printString("Value", ParseString(Data, Offset));
102 StringRef ValueDesc = ParseString(Data, Offset);
103
104 if (SW) {
105 DictScope AS(*SW, "Attribute");
106 SW->printNumber("Tag", Tag);
107 if (!TagName.empty())
108 SW->printString("TagName", TagName);
109 SW->printString("Value", ValueDesc);
110 }
104111 }
105112
106113 void ARMAttributeParser::PrintAttribute(unsigned Tag, unsigned Value,
107114 StringRef ValueDesc) {
108 StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false);
109
110 DictScope AS(SW, "Attribute");
111 SW.printNumber("Tag", Tag);
112 SW.printNumber("Value", Value);
113 if (!TagName.empty())
114 SW.printString("TagName", TagName);
115 if (!ValueDesc.empty())
116 SW.printString("Description", ValueDesc);
115 Attributes.insert(std::make_pair(Tag, Value));
116
117 if (SW) {
118 StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag,
119 /*TagPrefix*/false);
120 DictScope AS(*SW, "Attribute");
121 SW->printNumber("Tag", Tag);
122 SW->printNumber("Value", Value);
123 if (!TagName.empty())
124 SW->printString("TagName", TagName);
125 if (!ValueDesc.empty())
126 SW->printString("Description", ValueDesc);
127 }
117128 }
118129
119130 void ARMAttributeParser::CPU_arch(AttrType Tag, const uint8_t *Data,
448459 uint64_t Integer = ParseInteger(Data, Offset);
449460 StringRef String = ParseString(Data, Offset);
450461
451 DictScope AS(SW, "Attribute");
452 SW.printNumber("Tag", Tag);
453 SW.startLine() << "Value: " << Integer << ", " << String << '\n';
454 SW.printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false));
455 switch (Integer) {
456 case 0:
457 SW.printString("Description", StringRef("No Specific Requirements"));
458 break;
459 case 1:
460 SW.printString("Description", StringRef("AEABI Conformant"));
461 break;
462 default:
463 SW.printString("Description", StringRef("AEABI Non-Conformant"));
464 break;
462 if (SW) {
463 DictScope AS(*SW, "Attribute");
464 SW->printNumber("Tag", Tag);
465 SW->startLine() << "Value: " << Integer << ", " << String << '\n';
466 SW->printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false));
467 switch (Integer) {
468 case 0:
469 SW->printString("Description", StringRef("No Specific Requirements"));
470 break;
471 case 1:
472 SW->printString("Description", StringRef("AEABI Conformant"));
473 break;
474 default:
475 SW->printString("Description", StringRef("AEABI Non-Conformant"));
476 break;
477 }
465478 }
466479 }
467480
603616 void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) {
604617 uint32_t Offset = sizeof(uint32_t); /* SectionLength */
605618
606 SW.printNumber("SectionLength", Length);
607
608619 const char *VendorName = reinterpret_cast(Data + Offset);
609620 size_t VendorNameLength = std::strlen(VendorName);
610 SW.printString("Vendor", StringRef(VendorName, VendorNameLength));
611621 Offset = Offset + VendorNameLength + 1;
612622
613 if (StringRef(VendorName, VendorNameLength).lower() != "aeabi")
623 if (SW) {
624 SW->printNumber("SectionLength", Length);
625 SW->printString("Vendor", StringRef(VendorName, VendorNameLength));
626 }
627
628 if (StringRef(VendorName, VendorNameLength).lower() != "aeabi") {
614629 return;
630 }
615631
616632 while (Offset < Length) {
617633 /// Tag_File | Tag_Section | Tag_Symbol uleb128:byte-size
618634 uint8_t Tag = Data[Offset];
619 SW.printEnum("Tag", Tag, makeArrayRef(TagNames));
620635 Offset = Offset + sizeof(Tag);
621636
622637 uint32_t Size =
623638 *reinterpret_cast(Data + Offset);
624 SW.printNumber("Size", Size);
625639 Offset = Offset + sizeof(Size);
640
641 if (SW) {
642 SW->printEnum("Tag", Tag, makeArrayRef(TagNames));
643 SW->printNumber("Size", Size);
644 }
626645
627646 if (Size > Length) {
628647 errs() << "subsection length greater than section length\n";
650669 return;
651670 }
652671
653 DictScope ASS(SW, ScopeName);
654
655 if (!Indicies.empty())
656 SW.printList(IndexName, Indicies);
657
658 ParseAttributeList(Data, Offset, Length);
659 }
660 }
661
662 void ARMAttributeParser::Parse(ArrayRef Section) {
672 if (SW) {
673 DictScope ASS(*SW, ScopeName);
674 if (!Indicies.empty())
675 SW->printList(IndexName, Indicies);
676 ParseAttributeList(Data, Offset, Length);
677 } else {
678 ParseAttributeList(Data, Offset, Length);
679 }
680 }
681 }
682
683 void ARMAttributeParser::Parse(ArrayRef Section, bool isLittle) {
663684 size_t Offset = 1;
664685 unsigned SectionNumber = 0;
665686
666687 while (Offset < Section.size()) {
667 uint32_t SectionLength =
668 *reinterpret_cast(Section.data() + Offset);
669
670 SW.startLine() << "Section " << ++SectionNumber << " {\n";
671 SW.indent();
688 uint32_t SectionLength = isLittle ?
689 support::endian::read32le(Section.data() + Offset) :
690 support::endian::read32be(Section.data() + Offset);
691
692 if (SW) {
693 SW->startLine() << "Section " << ++SectionNumber << " {\n";
694 SW->indent();
695 }
672696
673697 ParseSubsection(Section.data() + Offset, SectionLength);
674698 Offset = Offset + SectionLength;
675699
676 SW.unindent();
677 SW.startLine() << "}\n";
678 }
679 }
680 }
681
700 if (SW) {
701 SW->unindent();
702 SW->startLine() << "}\n";
703 }
704 }
705 }
706 }
707
840840 ARMBuildAttrs::Allowed);
841841 else
842842 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
843 ARMBuildAttrs::AllowIEE754);
843 ARMBuildAttrs::AllowIEEE754);
844844
845845 if (STI.allowsUnalignedMem())
846846 ATS.emitAttribute(ARMBuildAttrs::CPU_unaligned_access,
0 @ RUN: llvm-mc < %s -triple armv5t-elf -filetype=obj | llvm-objdump -triple=arm -d - | FileCheck %s
1
2 .arch armv5t
3
4 clz:
5 clz r0, r1
6
7 @ CHECK-LABEL: clz
8 @ CHECK: 11 0f 6f e1
9
0 @ RUN: llvm-mc < %s -triple armv5te-elf -filetype=obj | llvm-objdump -triple=arm -d - | FileCheck %s
1
2 .arch armv5te
3
4 strd:
5 strd r0, r1, [r2, +r3]
6
7 @ CHECK-LABEL strd
8 @ CHECK: f3 00 82 e1 strd r0, r1, [r2, r3]
9
0 @ RUN: llvm-mc < %s -triple armv5tej-elf -filetype=obj | llvm-objdump -triple=arm -d - | FileCheck %s
1
2 bxj:
3 bxj r0
4
5 @ CHECK-LABEL: bxj
6 @ CHECK: 20 ff 2f e1 bxj r0
0 @ RUN: llvm-mc < %s -triple armv6-elf -filetype=obj | llvm-objdump -triple=arm -d - | FileCheck %s
1
2 .arch armv6
3
4 umaal:
5 umaal r0, r1, r2, r3
6
7 @ CHECK-LABEL:umaal
8 @ CHECK: 92 03 41 e0 umaal r0, r1, r2, r3
0 @ RUN: llvm-mc < %s -triple armv6k-elf -filetype=obj | llvm-objdump -triple=arm -d - | FileCheck %s
1
2 .arch armv6k
3
4 clrex:
5 clrex
6
7 @ CHECK-LABEL: clrex
8 @ CHECK: 1f f0 7f f5 clrex
0 @ RUN: llvm-mc < %s -triple armv6m-elf -filetype=obj | llvm-objdump -triple=thumb -d - | FileCheck %s
1
2 .arch armv6m
3
4 dmb:
5 dmb
6
7 @ CHECK-LABEL: dmb
8 @ CHECK: bf f3 5f 8f dmb sy
0 @ RUN: llvm-mc < %s -triple armv6t2-elf -filetype=obj | llvm-objdump -triple=thumb -d - | FileCheck %s
1
2 .arch armv6t2
3
4 .thumb
5 umaalt2:
6 umaal r0, r1, r2, r3
7
8 @ CHECK-LABEL: umaalt2
9 @ CHECK: e2 fb 63 01 umaal r0, r1, r2, r3
0 @ RUN: llvm-mc < %s -triple armv7m-elf -filetype=obj | llvm-objdump -triple=thumb -d - | FileCheck %s
1
2 .arch armv7m
3
4 umlal:
5 umlal r0, r1, r2, r3
6
7 @ CHECK-LABEL: umlal
8 @ CHECK: e2 fb 03 01 umlal r0, r1, r2, r3
9
356356 llvm::Triple TheTriple("unknown-unknown-unknown");
357357 if (TripleName.empty()) {
358358 if (Obj) {
359 TheTriple.setArch(Triple::ArchType(Obj->getArch()));
359 auto Arch = Obj->getArch();
360 TheTriple.setArch(Triple::ArchType(Arch));
361
362 // For ARM targets, try to use the build attributes to build determine
363 // the build target. Target features are also added, but later during
364 // disassembly.
365 if (Arch == Triple::arm || Arch == Triple::armeb) {
366 Obj->setARMSubArch(TheTriple);
367 }
368
360369 // TheTriple defaults to ELF, and COFF doesn't have an environment:
361370 // the best we can do here is indicate that it is mach-o.
362371 if (Obj->isMachO())
368377 TheTriple.setTriple("thumbv7-windows");
369378 }
370379 }
371 } else
380 } else {
372381 TheTriple.setTriple(Triple::normalize(TripleName));
382 // Use the triple, but also try to combine with ARM build attributes.
383 if (Obj) {
384 auto Arch = Obj->getArch();
385 if (Arch == Triple::arm || Arch == Triple::armeb) {
386 Obj->setARMSubArch(TheTriple);
387 }
388 }
389 }
373390
374391 // Get the target specific parser.
375392 std::string Error;
18911891 if (Contents.size() == 1)
18921892 continue;
18931893
1894 ARMAttributeParser(W).Parse(Contents);
1894 ARMAttributeParser(&W).Parse(Contents, true);
18951895 }
18961896 }
18971897 }
0 #include "llvm/Support/ARMBuildAttributes.h"
1 #include "llvm/Support/ARMAttributeParser.h"
2 #include "llvm/Support/LEB128.h"
3 #include "gtest/gtest.h"
4 #include
5
6 using namespace llvm;
7
8 struct AttributeSection {
9 unsigned Tag;
10 unsigned Value;
11
12 AttributeSection(unsigned tag, unsigned value) : Tag(tag), Value(value) { }
13
14 void write(raw_ostream &OS) {
15 OS.flush();
16 // length = length + "aeabi\0" + TagFile + ByteSize + Tag + Value;
17 // length = 17 bytes
18
19 OS << 'A' << (uint8_t)17 << (uint8_t)0 << (uint8_t)0 << (uint8_t)0;
20 OS << "aeabi" << '\0';
21 OS << (uint8_t)1 << (uint8_t)7 << (uint8_t)0 << (uint8_t)0 << (uint8_t)0;
22 OS << (uint8_t)Tag << (uint8_t)Value;
23
24 }
25 };
26
27 bool testBuildAttr(unsigned Tag, unsigned Value,
28 unsigned ExpectedTag, unsigned ExpectedValue) {
29 std::string buffer;
30 raw_string_ostream OS(buffer);
31 AttributeSection Section(Tag, Value);
32 Section.write(OS);
33 ArrayRef Bytes((uint8_t*)OS.str().c_str(), OS.str().size());
34
35 ARMAttributeParser Parser;
36 Parser.Parse(Bytes, true);
37
38 return (Parser.hasAttribute(ExpectedTag) &&
39 Parser.getAttributeValue(ExpectedTag) == ExpectedValue);
40 }
41
42 bool testTagString(unsigned Tag, const char *name) {
43 return ARMBuildAttrs::AttrTypeAsString(Tag).str() == name;
44 }
45
46 TEST(CPUArchBuildAttr, testBuildAttr) {
47 EXPECT_TRUE(testTagString(6, "Tag_CPU_arch"));
48
49 EXPECT_TRUE(testBuildAttr(6, 0, ARMBuildAttrs::CPU_arch,
50 ARMBuildAttrs::Pre_v4));
51 EXPECT_TRUE(testBuildAttr(6, 1, ARMBuildAttrs::CPU_arch,
52 ARMBuildAttrs::v4));
53 EXPECT_TRUE(testBuildAttr(6, 2, ARMBuildAttrs::CPU_arch,
54 ARMBuildAttrs::v4T));
55 EXPECT_TRUE(testBuildAttr(6, 3, ARMBuildAttrs::CPU_arch,
56 ARMBuildAttrs::v5T));
57 EXPECT_TRUE(testBuildAttr(6, 4, ARMBuildAttrs::CPU_arch,
58 ARMBuildAttrs::v5TE));
59 EXPECT_TRUE(testBuildAttr(6, 5, ARMBuildAttrs::CPU_arch,
60 ARMBuildAttrs::v5TEJ));
61 EXPECT_TRUE(testBuildAttr(6, 6, ARMBuildAttrs::CPU_arch,
62 ARMBuildAttrs::v6));
63 EXPECT_TRUE(testBuildAttr(6, 7, ARMBuildAttrs::CPU_arch,
64 ARMBuildAttrs::v6KZ));
65 EXPECT_TRUE(testBuildAttr(6, 8, ARMBuildAttrs::CPU_arch,
66 ARMBuildAttrs::v6T2));
67 EXPECT_TRUE(testBuildAttr(6, 9, ARMBuildAttrs::CPU_arch,
68 ARMBuildAttrs::v6K));
69 EXPECT_TRUE(testBuildAttr(6, 10, ARMBuildAttrs::CPU_arch,
70 ARMBuildAttrs::v7));
71 EXPECT_TRUE(testBuildAttr(6, 11, ARMBuildAttrs::CPU_arch,
72 ARMBuildAttrs::v6_M));
73 EXPECT_TRUE(testBuildAttr(6, 12, ARMBuildAttrs::CPU_arch,
74 ARMBuildAttrs::v6S_M));
75 EXPECT_TRUE(testBuildAttr(6, 13, ARMBuildAttrs::CPU_arch,
76 ARMBuildAttrs::v7E_M));
77 }
78
79 TEST(CPUArchProfileBuildAttr, testBuildAttr) {
80 EXPECT_TRUE(testTagString(7, "Tag_CPU_arch_profile"));
81 EXPECT_TRUE(testBuildAttr(7, 'A', ARMBuildAttrs::CPU_arch_profile,
82 ARMBuildAttrs::ApplicationProfile));
83 EXPECT_TRUE(testBuildAttr(7, 'R', ARMBuildAttrs::CPU_arch_profile,
84 ARMBuildAttrs::RealTimeProfile));
85 EXPECT_TRUE(testBuildAttr(7, 'M', ARMBuildAttrs::CPU_arch_profile,
86 ARMBuildAttrs::MicroControllerProfile));
87 EXPECT_TRUE(testBuildAttr(7, 'S', ARMBuildAttrs::CPU_arch_profile,
88 ARMBuildAttrs::SystemProfile));
89 }
90
91 TEST(ARMISABuildAttr, testBuildAttr) {
92 EXPECT_TRUE(testTagString(8, "Tag_ARM_ISA_use"));
93 EXPECT_TRUE(testBuildAttr(8, 0, ARMBuildAttrs::ARM_ISA_use,
94 ARMBuildAttrs::Not_Allowed));
95 EXPECT_TRUE(testBuildAttr(8, 1, ARMBuildAttrs::ARM_ISA_use,
96 ARMBuildAttrs::Allowed));
97 }
98
99 TEST(ThumbISABuildAttr, testBuildAttr) {
100 EXPECT_TRUE(testTagString(9, "Tag_THUMB_ISA_use"));
101 EXPECT_TRUE(testBuildAttr(9, 0, ARMBuildAttrs::THUMB_ISA_use,
102 ARMBuildAttrs::Not_Allowed));
103 EXPECT_TRUE(testBuildAttr(9, 1, ARMBuildAttrs::THUMB_ISA_use,
104 ARMBuildAttrs::Allowed));
105 }
106
107 TEST(FPArchBuildAttr, testBuildAttr) {
108 EXPECT_TRUE(testTagString(10, "Tag_FP_arch"));
109 EXPECT_TRUE(testBuildAttr(10, 0, ARMBuildAttrs::FP_arch,
110 ARMBuildAttrs::Not_Allowed));
111 EXPECT_TRUE(testBuildAttr(10, 1, ARMBuildAttrs::FP_arch,
112 ARMBuildAttrs::Allowed));
113 EXPECT_TRUE(testBuildAttr(10, 2, ARMBuildAttrs::FP_arch,
114 ARMBuildAttrs::AllowFPv2));
115 EXPECT_TRUE(testBuildAttr(10, 3, ARMBuildAttrs::FP_arch,
116 ARMBuildAttrs::AllowFPv3A));
117 EXPECT_TRUE(testBuildAttr(10, 4, ARMBuildAttrs::FP_arch,
118 ARMBuildAttrs::AllowFPv3B));
119 EXPECT_TRUE(testBuildAttr(10, 5, ARMBuildAttrs::FP_arch,
120 ARMBuildAttrs::AllowFPv4A));
121 EXPECT_TRUE(testBuildAttr(10, 6, ARMBuildAttrs::FP_arch,
122 ARMBuildAttrs::AllowFPv4B));
123 EXPECT_TRUE(testBuildAttr(10, 7, ARMBuildAttrs::FP_arch,
124 ARMBuildAttrs::AllowFPARMv8A));
125 EXPECT_TRUE(testBuildAttr(10, 8, ARMBuildAttrs::FP_arch,
126 ARMBuildAttrs::AllowFPARMv8B));
127 }
128
129 TEST(WMMXBuildAttr, testBuildAttr) {
130 EXPECT_TRUE(testTagString(11, "Tag_WMMX_arch"));
131 EXPECT_TRUE(testBuildAttr(11, 0, ARMBuildAttrs::WMMX_arch,
132 ARMBuildAttrs::Not_Allowed));
133 EXPECT_TRUE(testBuildAttr(11, 1, ARMBuildAttrs::WMMX_arch,
134 ARMBuildAttrs::AllowWMMXv1));
135 EXPECT_TRUE(testBuildAttr(11, 2, ARMBuildAttrs::WMMX_arch,
136 ARMBuildAttrs::AllowWMMXv2));
137 }
138
139 TEST(SIMDBuildAttr, testBuildAttr) {
140 EXPECT_TRUE(testTagString(12, "Tag_Advanced_SIMD_arch"));
141 EXPECT_TRUE(testBuildAttr(12, 0, ARMBuildAttrs::Advanced_SIMD_arch,
142 ARMBuildAttrs::Not_Allowed));
143 EXPECT_TRUE(testBuildAttr(12, 1, ARMBuildAttrs::Advanced_SIMD_arch,
144 ARMBuildAttrs::AllowNeon));
145 EXPECT_TRUE(testBuildAttr(12, 2, ARMBuildAttrs::Advanced_SIMD_arch,
146 ARMBuildAttrs::AllowNeon2));
147 EXPECT_TRUE(testBuildAttr(12, 3, ARMBuildAttrs::Advanced_SIMD_arch,
148 ARMBuildAttrs::AllowNeonARMv8));
149 EXPECT_TRUE(testBuildAttr(12, 4, ARMBuildAttrs::Advanced_SIMD_arch,
150 ARMBuildAttrs::AllowNeonARMv8_1a));
151 }
152
153 TEST(FPHPBuildAttr, testBuildAttr) {
154 EXPECT_TRUE(testTagString(36, "Tag_FP_HP_extension"));
155 EXPECT_TRUE(testBuildAttr(36, 0, ARMBuildAttrs::FP_HP_extension,
156 ARMBuildAttrs::Not_Allowed));
157 EXPECT_TRUE(testBuildAttr(36, 1, ARMBuildAttrs::FP_HP_extension,
158 ARMBuildAttrs::AllowHPFP));
159 }
160
161 TEST(CPUAlignBuildAttr, testBuildAttr) {
162 EXPECT_TRUE(testTagString(34, "Tag_CPU_unaligned_access"));
163 EXPECT_TRUE(testBuildAttr(34, 0, ARMBuildAttrs::CPU_unaligned_access,
164 ARMBuildAttrs::Not_Allowed));
165 EXPECT_TRUE(testBuildAttr(34, 1, ARMBuildAttrs::CPU_unaligned_access,
166 ARMBuildAttrs::Allowed));
167 }
168
169 TEST(T2EEBuildAttr, testBuildAttr) {
170 EXPECT_TRUE(testTagString(66, "Tag_T2EE_use"));
171 EXPECT_TRUE(testBuildAttr(66, 0, ARMBuildAttrs::T2EE_use,
172 ARMBuildAttrs::Not_Allowed));
173 EXPECT_TRUE(testBuildAttr(66, 1, ARMBuildAttrs::T2EE_use,
174 ARMBuildAttrs::Allowed));
175 }
176
177 TEST(VirtualizationBuildAttr, testBuildAttr) {
178 EXPECT_TRUE(testTagString(68, "Tag_Virtualization_use"));
179 EXPECT_TRUE(testBuildAttr(68, 0, ARMBuildAttrs::Virtualization_use,
180 ARMBuildAttrs::Not_Allowed));
181 EXPECT_TRUE(testBuildAttr(68, 1, ARMBuildAttrs::Virtualization_use,
182 ARMBuildAttrs::AllowTZ));
183 EXPECT_TRUE(testBuildAttr(68, 2, ARMBuildAttrs::Virtualization_use,
184 ARMBuildAttrs::AllowVirtualization));
185 EXPECT_TRUE(testBuildAttr(68, 3, ARMBuildAttrs::Virtualization_use,
186 ARMBuildAttrs::AllowTZVirtualization));
187 }
188
189 TEST(MPBuildAttr, testBuildAttr) {
190 EXPECT_TRUE(testTagString(42, "Tag_MPextension_use"));
191 EXPECT_TRUE(testBuildAttr(42, 0, ARMBuildAttrs::MPextension_use,
192 ARMBuildAttrs::Not_Allowed));
193 EXPECT_TRUE(testBuildAttr(42, 1, ARMBuildAttrs::MPextension_use,
194 ARMBuildAttrs::AllowMP));
195 }
196
197 TEST(DivBuildAttr, testBuildAttr) {
198 EXPECT_TRUE(testTagString(44, "Tag_DIV_use"));
199 EXPECT_TRUE(testBuildAttr(44, 0, ARMBuildAttrs::DIV_use,
200 ARMBuildAttrs::AllowDIVIfExists));
201 EXPECT_TRUE(testBuildAttr(44, 1, ARMBuildAttrs::DIV_use,
202 ARMBuildAttrs::DisallowDIV));
203 EXPECT_TRUE(testBuildAttr(44, 2, ARMBuildAttrs::DIV_use,
204 ARMBuildAttrs::AllowDIVExt));
205 }
206
207 TEST(PCS_ConfigBuildAttr, testBuildAttr) {
208 EXPECT_TRUE(testTagString(13, "Tag_PCS_config"));
209 EXPECT_TRUE(testBuildAttr(13, 0, ARMBuildAttrs::PCS_config, 0));
210 EXPECT_TRUE(testBuildAttr(13, 1, ARMBuildAttrs::PCS_config, 1));
211 EXPECT_TRUE(testBuildAttr(13, 2, ARMBuildAttrs::PCS_config, 2));
212 EXPECT_TRUE(testBuildAttr(13, 3, ARMBuildAttrs::PCS_config, 3));
213 EXPECT_TRUE(testBuildAttr(13, 4, ARMBuildAttrs::PCS_config, 4));
214 EXPECT_TRUE(testBuildAttr(13, 5, ARMBuildAttrs::PCS_config, 5));
215 EXPECT_TRUE(testBuildAttr(13, 6, ARMBuildAttrs::PCS_config, 6));
216 EXPECT_TRUE(testBuildAttr(13, 7, ARMBuildAttrs::PCS_config, 7));
217 }
218
219 TEST(PCS_R9BuildAttr, testBuildAttr) {
220 EXPECT_TRUE(testTagString(14, "Tag_ABI_PCS_R9_use"));
221 EXPECT_TRUE(testBuildAttr(14, 0, ARMBuildAttrs::ABI_PCS_R9_use,
222 ARMBuildAttrs::R9IsGPR));
223 EXPECT_TRUE(testBuildAttr(14, 1, ARMBuildAttrs::ABI_PCS_R9_use,
224 ARMBuildAttrs::R9IsSB));
225 EXPECT_TRUE(testBuildAttr(14, 2, ARMBuildAttrs::ABI_PCS_R9_use,
226 ARMBuildAttrs::R9IsTLSPointer));
227 EXPECT_TRUE(testBuildAttr(14, 3, ARMBuildAttrs::ABI_PCS_R9_use,
228 ARMBuildAttrs::R9Reserved));
229 }
230
231 TEST(PCS_RWBuildAttr, testBuildAttr) {
232 EXPECT_TRUE(testTagString(15, "Tag_ABI_PCS_RW_data"));
233 EXPECT_TRUE(testBuildAttr(15, 0, ARMBuildAttrs::ABI_PCS_RW_data,
234 ARMBuildAttrs::Not_Allowed));
235 EXPECT_TRUE(testBuildAttr(15, 1, ARMBuildAttrs::ABI_PCS_RW_data,
236 ARMBuildAttrs::AddressRWPCRel));
237 EXPECT_TRUE(testBuildAttr(15, 2, ARMBuildAttrs::ABI_PCS_RW_data,
238 ARMBuildAttrs::AddressRWSBRel));
239 EXPECT_TRUE(testBuildAttr(15, 3, ARMBuildAttrs::ABI_PCS_RW_data,
240 ARMBuildAttrs::AddressRWNone));
241 }
242
243 TEST(PCS_ROBuildAttr, testBuildAttr) {
244 EXPECT_TRUE(testTagString(16, "Tag_ABI_PCS_RO_data"));
245 EXPECT_TRUE(testBuildAttr(16, 0, ARMBuildAttrs::ABI_PCS_RO_data,
246 ARMBuildAttrs::Not_Allowed));
247 EXPECT_TRUE(testBuildAttr(16, 1, ARMBuildAttrs::ABI_PCS_RO_data,
248 ARMBuildAttrs::AddressROPCRel));
249 EXPECT_TRUE(testBuildAttr(16, 2, ARMBuildAttrs::ABI_PCS_RO_data,
250 ARMBuildAttrs::AddressRONone));
251 }
252
253 TEST(PCS_GOTBuildAttr, testBuildAttr) {
254 EXPECT_TRUE(testTagString(17, "Tag_ABI_PCS_GOT_use"));
255 EXPECT_TRUE(testBuildAttr(17, 0, ARMBuildAttrs::ABI_PCS_GOT_use,
256 ARMBuildAttrs::Not_Allowed));
257 EXPECT_TRUE(testBuildAttr(17, 1, ARMBuildAttrs::ABI_PCS_GOT_use,
258 ARMBuildAttrs::AddressDirect));
259 EXPECT_TRUE(testBuildAttr(17, 2, ARMBuildAttrs::ABI_PCS_GOT_use,
260 ARMBuildAttrs::AddressGOT));
261 }
262
263 TEST(PCS_WCharBuildAttr, testBuildAttr) {
264 EXPECT_TRUE(testTagString(18, "Tag_ABI_PCS_wchar_t"));
265 EXPECT_TRUE(testBuildAttr(18, 0, ARMBuildAttrs::ABI_PCS_wchar_t,
266 ARMBuildAttrs::WCharProhibited));
267 EXPECT_TRUE(testBuildAttr(18, 2, ARMBuildAttrs::ABI_PCS_wchar_t,
268 ARMBuildAttrs::WCharWidth2Bytes));
269 EXPECT_TRUE(testBuildAttr(18, 4, ARMBuildAttrs::ABI_PCS_wchar_t,
270 ARMBuildAttrs::WCharWidth4Bytes));
271 }
272
273 TEST(EnumSizeBuildAttr, testBuildAttr) {
274 EXPECT_TRUE(testTagString(26, "Tag_ABI_enum_size"));
275 EXPECT_TRUE(testBuildAttr(26, 0, ARMBuildAttrs::ABI_enum_size,
276 ARMBuildAttrs::EnumProhibited));
277 EXPECT_TRUE(testBuildAttr(26, 1, ARMBuildAttrs::ABI_enum_size,
278 ARMBuildAttrs::EnumSmallest));
279 EXPECT_TRUE(testBuildAttr(26, 2, ARMBuildAttrs::ABI_enum_size,
280 ARMBuildAttrs::Enum32Bit));
281 EXPECT_TRUE(testBuildAttr(26, 3, ARMBuildAttrs::ABI_enum_size,
282 ARMBuildAttrs::Enum32BitABI));
283 }
284
285 TEST(AlignNeededBuildAttr, testBuildAttr) {
286 EXPECT_TRUE(testTagString(24, "Tag_ABI_align_needed"));
287 EXPECT_TRUE(testBuildAttr(24, 0, ARMBuildAttrs::ABI_align_needed,
288 ARMBuildAttrs::Not_Allowed));
289 EXPECT_TRUE(testBuildAttr(24, 1, ARMBuildAttrs::ABI_align_needed,
290 ARMBuildAttrs::Align8Byte));
291 EXPECT_TRUE(testBuildAttr(24, 2, ARMBuildAttrs::ABI_align_needed,
292 ARMBuildAttrs::Align4Byte));
293 EXPECT_TRUE(testBuildAttr(24, 3, ARMBuildAttrs::ABI_align_needed,
294 ARMBuildAttrs::AlignReserved));
295 }
296
297 TEST(AlignPreservedBuildAttr, testBuildAttr) {
298 EXPECT_TRUE(testTagString(25, "Tag_ABI_align_preserved"));
299 EXPECT_TRUE(testBuildAttr(25, 0, ARMBuildAttrs::ABI_align_preserved,
300 ARMBuildAttrs::AlignNotPreserved));
301 EXPECT_TRUE(testBuildAttr(25, 1, ARMBuildAttrs::ABI_align_preserved,
302 ARMBuildAttrs::AlignPreserve8Byte));
303 EXPECT_TRUE(testBuildAttr(25, 2, ARMBuildAttrs::ABI_align_preserved,
304 ARMBuildAttrs::AlignPreserveAll));
305 EXPECT_TRUE(testBuildAttr(25, 3, ARMBuildAttrs::ABI_align_preserved,
306 ARMBuildAttrs::AlignReserved));
307 }
308
309 TEST(FPRoundingBuildAttr, testBuildAttr) {
310 EXPECT_TRUE(testTagString(19, "Tag_ABI_FP_rounding"));
311 EXPECT_TRUE(testBuildAttr(19, 0, ARMBuildAttrs::ABI_FP_rounding, 0));
312 EXPECT_TRUE(testBuildAttr(19, 1, ARMBuildAttrs::ABI_FP_rounding, 1));
313 }
314
315 TEST(FPDenormalBuildAttr, testBuildAttr) {
316 EXPECT_TRUE(testTagString(20, "Tag_ABI_FP_denormal"));
317 EXPECT_TRUE(testBuildAttr(20, 0, ARMBuildAttrs::ABI_FP_denormal,
318 ARMBuildAttrs::PositiveZero));
319 EXPECT_TRUE(testBuildAttr(20, 1, ARMBuildAttrs::ABI_FP_denormal,
320 ARMBuildAttrs::IEEEDenormals));
321 EXPECT_TRUE(testBuildAttr(20, 2, ARMBuildAttrs::ABI_FP_denormal,
322 ARMBuildAttrs::PreserveFPSign));
323 }
324
325 TEST(FPExceptionsBuildAttr, testBuildAttr) {
326 EXPECT_TRUE(testTagString(21, "Tag_ABI_FP_exceptions"));
327 EXPECT_TRUE(testBuildAttr(21, 0, ARMBuildAttrs::ABI_FP_exceptions, 0));
328 EXPECT_TRUE(testBuildAttr(21, 1, ARMBuildAttrs::ABI_FP_exceptions, 1));
329 }
330
331 TEST(FPUserExceptionsBuildAttr, testBuildAttr) {
332 EXPECT_TRUE(testTagString(22, "Tag_ABI_FP_user_exceptions"));
333 EXPECT_TRUE(testBuildAttr(22, 0, ARMBuildAttrs::ABI_FP_user_exceptions, 0));
334 EXPECT_TRUE(testBuildAttr(22, 1, ARMBuildAttrs::ABI_FP_user_exceptions, 1));
335 }
336
337 TEST(FPNumberModelBuildAttr, testBuildAttr) {
338 EXPECT_TRUE(testTagString(23, "Tag_ABI_FP_number_model"));
339 EXPECT_TRUE(testBuildAttr(23, 0, ARMBuildAttrs::ABI_FP_number_model,
340 ARMBuildAttrs::Not_Allowed));
341 EXPECT_TRUE(testBuildAttr(23, 1, ARMBuildAttrs::ABI_FP_number_model,
342 ARMBuildAttrs::AllowIEEENormal));
343 EXPECT_TRUE(testBuildAttr(23, 2, ARMBuildAttrs::ABI_FP_number_model,
344 ARMBuildAttrs::AllowRTABI));
345 EXPECT_TRUE(testBuildAttr(23, 3, ARMBuildAttrs::ABI_FP_number_model,
346 ARMBuildAttrs::AllowIEEE754));
347 }
348
349 TEST(FP16BuildAttr, testBuildAttr) {
350 EXPECT_TRUE(testTagString(38, "Tag_ABI_FP_16bit_format"));
351 EXPECT_TRUE(testBuildAttr(38, 0, ARMBuildAttrs::ABI_FP_16bit_format,
352 ARMBuildAttrs::Not_Allowed));
353 EXPECT_TRUE(testBuildAttr(38, 1, ARMBuildAttrs::ABI_FP_16bit_format,
354 ARMBuildAttrs::FP16FormatIEEE));
355 EXPECT_TRUE(testBuildAttr(38, 2, ARMBuildAttrs::ABI_FP_16bit_format,
356 ARMBuildAttrs::FP16VFP3));
357 }
358
359 TEST(HardFPBuildAttr, testBuildAttr) {
360 EXPECT_TRUE(testTagString(27, "Tag_ABI_HardFP_use"));
361 EXPECT_TRUE(testBuildAttr(27, 0, ARMBuildAttrs::ABI_HardFP_use,
362 ARMBuildAttrs::HardFPImplied));
363 EXPECT_TRUE(testBuildAttr(27, 1, ARMBuildAttrs::ABI_HardFP_use,
364 ARMBuildAttrs::HardFPSinglePrecision));
365 EXPECT_TRUE(testBuildAttr(27, 2, ARMBuildAttrs::ABI_HardFP_use, 2));
366 }
367
368 TEST(VFPArgsBuildAttr, testBuildAttr) {
369 EXPECT_TRUE(testTagString(28, "Tag_ABI_VFP_args"));
370 EXPECT_TRUE(testBuildAttr(28, 0, ARMBuildAttrs::ABI_VFP_args,
371 ARMBuildAttrs::BaseAAPCS));
372 EXPECT_TRUE(testBuildAttr(28, 1, ARMBuildAttrs::ABI_VFP_args,
373 ARMBuildAttrs::HardFPAAPCS));
374 EXPECT_TRUE(testBuildAttr(28, 2, ARMBuildAttrs::ABI_VFP_args, 2));
375 EXPECT_TRUE(testBuildAttr(28, 3, ARMBuildAttrs::ABI_VFP_args, 3));
376 }
377
378 TEST(WMMXArgsBuildAttr, testBuildAttr) {
379 EXPECT_TRUE(testTagString(29, "Tag_ABI_WMMX_args"));
380 EXPECT_TRUE(testBuildAttr(29, 0, ARMBuildAttrs::ABI_WMMX_args, 0));
381 EXPECT_TRUE(testBuildAttr(29, 1, ARMBuildAttrs::ABI_WMMX_args, 1));
382 EXPECT_TRUE(testBuildAttr(29, 2, ARMBuildAttrs::ABI_WMMX_args, 2));
383 }
44 add_llvm_unittest(SupportTests
55 AlignOfTest.cpp
66 AllocatorTest.cpp
7 ARMAttributeParser.cpp
78 ArrayRecyclerTest.cpp
89 BlockFrequencyTest.cpp
910 BranchProbabilityTest.cpp