Skip to content

Commit 37d4e35

Browse files
committed
[AArch64][Build Attributes] Improve functionality and fix bugs
- Improve testing - Do not allow unknown tags to be strings - Remove assertion when value exists
1 parent 3019e49 commit 37d4e35

15 files changed

+156
-104
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7870,8 +7870,7 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
78707870
IsOptional = AArch64BuildAttrs::getOptionalID(Optionality);
78717871
if (AArch64BuildAttrs::OPTIONAL_NOT_FOUND == IsOptional) {
78727872
Error(Parser.getTok().getLoc(),
7873-
AArch64BuildAttrs::getSubsectionOptionalUnknownError() + ": " +
7874-
Optionality);
7873+
AArch64BuildAttrs::getSubsectionOptionalUnknownError());
78757874
return true;
78767875
}
78777876
if (SubsectionExists) {
@@ -7919,7 +7918,7 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
79197918
Type = AArch64BuildAttrs::getTypeID(Name);
79207919
if (AArch64BuildAttrs::TYPE_NOT_FOUND == Type) {
79217920
Error(Parser.getTok().getLoc(),
7922-
AArch64BuildAttrs::getSubsectionTypeUnknownError() + ": " + Name);
7921+
AArch64BuildAttrs::getSubsectionTypeUnknownError());
79237922
return true;
79247923
}
79257924
if (SubsectionExists) {
@@ -7986,14 +7985,22 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
79867985

79877986
StringRef TagStr = "";
79887987
unsigned Tag;
7989-
if (Parser.getTok().is(AsmToken::Identifier)) {
7988+
if (Parser.getTok().is(AsmToken::Integer)) {
7989+
Tag = getTok().getIntVal();
7990+
} else if (Parser.getTok().is(AsmToken::Identifier)) {
79907991
TagStr = Parser.getTok().getIdentifier();
79917992
switch (ActiveSubsectionID) {
79927993
default:
7994+
// Should not happen
79937995
assert(0 && "Subsection name error");
79947996
break;
79957997
case AArch64BuildAttrs::VENDOR_UNKNOWN:
7996-
// Private subsection, accept any tag.
7998+
// Tag was provided as an unrecognized string instead of an unsigned
7999+
// integer
8000+
Error(Parser.getTok().getLoc(), "unrecognized Tag: '" + TagStr +
8001+
"' \nExcept for public subsections, "
8002+
"tags have to be an unsigned int.");
8003+
return true;
79978004
break;
79988005
case AArch64BuildAttrs::AEABI_PAUTHABI:
79998006
Tag = AArch64BuildAttrs::getPauthABITagsID(TagStr);
@@ -8014,8 +8021,6 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
80148021
}
80158022
break;
80168023
}
8017-
} else if (Parser.getTok().is(AsmToken::Integer)) {
8018-
Tag = getTok().getIntVal();
80198024
} else {
80208025
Error(Parser.getTok().getLoc(), "AArch64 build attributes tag not found");
80218026
return true;
@@ -8059,10 +8064,9 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
80598064
Error(Parser.getTok().getLoc(), "AArch64 build attributes value not found");
80608065
return true;
80618066
}
8062-
// Check for possible unaccepted values for known tags (AEABI_PAUTHABI,
8063-
// AEABI_FEATURE_AND_BITS)
8064-
if (!(ActiveSubsectionID == AArch64BuildAttrs::VENDOR_UNKNOWN) &&
8065-
TagStr != "") { // TagStr was a recognized string
8067+
// Check for possible unaccepted values for known tags
8068+
// (AEABI_FEATURE_AND_BITS)
8069+
if (ActiveSubsectionID == AArch64BuildAttrs::AEABI_FEATURE_AND_BITS) {
80668070
if (0 != ValueInt && 1 != ValueInt) {
80678071
Error(Parser.getTok().getLoc(),
80688072
"unknown AArch64 build attributes Value for Tag '" + TagStr +
@@ -8083,7 +8087,6 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
80838087
getTargetStreamer().emitAttribute(ActiveSubsectionName, Tag, ValueInt, "",
80848088
false);
80858089
}
8086-
80878090
if ("" != ValueStr) {
80888091
getTargetStreamer().emitAttribute(ActiveSubsectionName, Tag, unsigned(-1),
80898092
ValueStr, false);

llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,9 @@ void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag,
222222
"Can not add AArch64 build attribute: An attribute with "
223223
"the same tag and a different value already exists");
224224
return;
225-
} else {
226-
// Case Item.IntValue == Value, no need to emit twice
227-
assert(0 &&
228-
"AArch64 build attribute: An attribute with the same tag "
229-
"and a same value already exists");
230-
return;
231225
}
226+
// Case Item.IntValue == Value, no need to emit twice
227+
return;
232228
}
233229
}
234230
}

llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s renamed to llvm/test/MC/AArch64/aarch64-build-attributes-asm-aeabi-aeabi-known.s

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
// RUN: llvm-mc -triple=aarch64 -filetype=obj %s -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
33

44
// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128
5-
// ASM: .aeabi_attribute Tag_PAuth_Platform, 1
6-
// ASM: .aeabi_attribute Tag_PAuth_Schema, 1
5+
// ASM: .aeabi_attribute Tag_PAuth_Platform, 7
6+
// ASM: .aeabi_attribute Tag_PAuth_Schema, 777
77
// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
88
// ASM: .aeabi_attribute Tag_Feature_BTI, 1
99
// ASM: .aeabi_attribute Tag_Feature_PAC, 1
1010
// ASM: .aeabi_attribute Tag_Feature_GCS, 1
1111

1212
// ELF: Hex dump of section '.ARM.attributes':
13-
// ELF-NEXT: 0x00000000 41190000 00616561 62695f70 61757468 A....aeabi_pauth
14-
// ELF-NEXT: 0x00000010 61626900 00000101 02012300 00006165 abi.......#...ae
15-
// ELF-NEXT: 0x00000020 6162695f 66656174 7572655f 616e645f abi_feature_and_
16-
// ELF-NEXT: 0x00000030 62697473 00010000 01010102 01
13+
// ELF: 0x00000000 411a0000 00616561 62695f70 61757468 A....aeabi_pauth
14+
// ELF: 0x00000010 61626900 00000107 02890623 00000061 abi........#...a
15+
// ELF: 0x00000020 65616269 5f666561 74757265 5f616e64 eabi_feature_and
16+
// ELF: 0x00000030 5f626974 73000100 00010101 0201 _bits.........
1717

1818

1919
.aeabi_subsection aeabi_pauthabi, required, uleb128
20-
.aeabi_attribute Tag_PAuth_Platform, 1
21-
.aeabi_attribute Tag_PAuth_Schema, 1
20+
.aeabi_attribute Tag_PAuth_Platform, 7
21+
.aeabi_attribute Tag_PAuth_Schema, 777
2222
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
2323
.aeabi_attribute Tag_Feature_BTI, 1
2424
.aeabi_attribute Tag_Feature_PAC, 1

llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s renamed to llvm/test/MC/AArch64/aarch64-build-attributes-asm-aeabi-err-attrs.s

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: not llvm-mc -triple=aarch64 %s 2>&1 | FileCheck --check-prefix=ERR %s
22

3+
// Test logic and type mismatch
34
.aeabi_attribute Tag_Feature_BTI, 1
45
// ERR: error: no active subsection, build attribute can not be added
56
// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, 1
@@ -9,10 +10,6 @@
910
// ERR: error: unknown AArch64 build attribute 'Tag_Feature_BTI' for subsection 'aeabi_pauthabi'
1011
// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, 1
1112

12-
.aeabi_attribute Tag_PAuth_Platform, 4
13-
// ERR: error: unknown AArch64 build attributes Value for Tag 'Tag_PAuth_Platform' options are 0|1
14-
// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, 4
15-
1613
.aeabi_attribute a, 1
1714
// ERR: error: unknown AArch64 build attribute 'a' for subsection 'aeabi_pauthabi'
1815
// ERR-NEXT: .aeabi_attribute a, 1
@@ -25,6 +22,8 @@
2522
// ERR: error: active subsection type is ULEB128 (unsigned), found NTBS (string)
2623
// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, a
2724

25+
26+
// Test syntax errors
2827
.aeabi_attribute Tag_PAuth_Platform,
2928
// ERR: error: AArch64 build attributes value not found
3029
// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform,
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
// RUN: not llvm-mc -triple=aarch64 %s 2>&1 | FileCheck --check-prefix=ERR %s
22

3-
.aeabi_subsection aeabi_pauthabi, optional, uleb128
4-
// ERR: error: aeabi_pauthabi must be marked as required
5-
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, optional, uleb128
6-
7-
.aeabi_subsection aeabi_pauthabi, required, ntbs
8-
// ERR: error: aeabi_pauthabi must be marked as ULEB128
9-
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, ntbs
10-
11-
.aeabi_subsection aeabi_feature_and_bits, required, uleb128
12-
// ERR: error: aeabi_feature_and_bits must be marked as optional
13-
// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, required, uleb128
14-
15-
.aeabi_subsection aeabi_feature_and_bits, optional, ntbs
16-
// ERR: error: aeabi_feature_and_bits must be marked as ULEB128
17-
// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, ntbs
18-
3+
// Test syntax errors
194
.aeabi_subsection 1, required, uleb128
205
// ERR: error: subsection name not found
216
// ERR-NEXT: .aeabi_subsection 1, required, uleb128
@@ -25,11 +10,7 @@
2510
// ERR-NEXT: .aeabi_subsection , required, uleb128
2611

2712
.aeabi_subsection aeabi_pauthabi, a, uleb128
28-
// ERR: error: unknown AArch64 build attributes optionality, expected required|optional: a
29-
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, a, uleb128
30-
31-
.aeabi_subsection aeabi_pauthabi, a, uleb128
32-
// ERR: error: unknown AArch64 build attributes optionality, expected required|optional: a
13+
// ERR: error: unknown AArch64 build attributes optionality, expected required|optional
3314
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, a, uleb128
3415

3516
.aeabi_subsection aeabi_pauthabi, 1, uleb128
@@ -41,7 +22,7 @@
4122
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, ,uleb128
4223

4324
.aeabi_subsection aeabi_pauthabi,uleb128
44-
// ERR: error: unknown AArch64 build attributes optionality, expected required|optional: uleb128
25+
// ERR: error: unknown AArch64 build attributes optionality, expected required|optional
4526
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi,uleb128
4627

4728
.aeabi_subsection aeabi_pauthabi uleb128
@@ -57,5 +38,27 @@
5738
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required,
5839

5940
.aeabi_subsection aeabi_pauthabi, required, a
60-
// ERR: error: unknown AArch64 build attributes type, expected uleb128|ntbs: a
41+
// ERR: error: unknown AArch64 build attributes type, expected uleb128|ntbs
6142
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, a
43+
44+
.aeabi_subsection aeabi_pauthabi, optional, uleb128
45+
// ERR: error: aeabi_pauthabi must be marked as required
46+
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, optional, uleb128
47+
48+
49+
// Test types mismatch
50+
.aeabi_subsection aeabi_pauthabi, optional, uleb128
51+
// ERR: error: aeabi_pauthabi must be marked as required
52+
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, optional, uleb128
53+
54+
.aeabi_subsection aeabi_pauthabi, required, ntbs
55+
// ERR: error: aeabi_pauthabi must be marked as ULEB128
56+
// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, ntbs
57+
58+
.aeabi_subsection aeabi_feature_and_bits, required, uleb128
59+
// ERR: error: aeabi_feature_and_bits must be marked as optional
60+
// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, required, uleb128
61+
62+
.aeabi_subsection aeabi_feature_and_bits, optional, ntbs
63+
// ERR: error: aeabi_feature_and_bits must be marked as ULEB128
64+
// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, ntbs
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: llvm-mc -triple=aarch64 %s -o - | FileCheck %s --check-prefix=ASM
2+
// RUN: llvm-mc -triple=aarch64 -filetype=obj %s -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
3+
4+
// ASM: .aeabi_subsection subsection_a, optional, uleb128
5+
// ASM: .aeabi_subsection aeabi_subsection, optional, ntbs
6+
// ASM: .aeabi_subsection subsection_b, required, uleb128
7+
// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128
8+
// ASM: .aeabi_attribute Tag_PAuth_Platform, 7
9+
// ASM: .aeabi_attribute Tag_PAuth_Schema, 777
10+
// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
11+
// ASM: .aeabi_attribute Tag_Feature_BTI, 1
12+
// ASM: .aeabi_attribute Tag_Feature_PAC, 1
13+
// ASM: .aeabi_attribute Tag_Feature_GCS, 1
14+
// ASM: .aeabi_subsection aeabi_subsection, optional, ntbs
15+
// ASM: .aeabi_attribute 5, "Value"
16+
// ASM: .aeabi_subsection subsection_b, required, uleb128
17+
// ASM: .aeabi_attribute 6, 536
18+
// ASM: .aeabi_subsection subsection_a, optional, uleb128
19+
// ASM: .aeabi_attribute 7, 11
20+
21+
// ELF: Hex dump of section '.ARM.attributes':
22+
// ELF: 0x00000000 41150000 00737562 73656374 696f6e5f A....subsection_
23+
// ELF: 0x00000010 61000100 070b2000 00006165 6162695f a..... ...aeabi_
24+
// ELF: 0x00000020 73756273 65637469 6f6e0001 01052256 subsection...."V
25+
// ELF: 0x00000030 616c7565 22001600 00007375 62736563 alue".....subsec
26+
// ELF: 0x00000040 74696f6e 5f620000 00069804 1a000000 tion_b..........
27+
// ELF: 0x00000050 61656162 695f7061 75746861 62690000 aeabi_pauthabi..
28+
// ELF: 0x00000060 00010702 89062300 00006165 6162695f ......#...aeabi_
29+
// ELF: 0x00000070 66656174 7572655f 616e645f 62697473 feature_and_bits
30+
// ELF: 0x00000080 00010000 01010102 01 .........
31+
32+
33+
.aeabi_subsection subsection_a, optional, uleb128
34+
.aeabi_subsection aeabi_subsection, optional, ntbs
35+
.aeabi_subsection subsection_b, required, uleb128
36+
.aeabi_subsection aeabi_pauthabi, required, uleb128
37+
.aeabi_attribute Tag_PAuth_Platform, 7
38+
.aeabi_attribute Tag_PAuth_Schema, 777
39+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
40+
.aeabi_attribute Tag_Feature_BTI, 1
41+
.aeabi_attribute Tag_Feature_PAC, 1
42+
.aeabi_attribute Tag_Feature_GCS, 1
43+
.aeabi_subsection aeabi_subsection, optional, ntbs
44+
.aeabi_attribute 5, "Value"
45+
.aeabi_subsection subsection_b, required, uleb128
46+
.aeabi_attribute 6, 536
47+
.aeabi_subsection subsection_a, optional, uleb128
48+
.aeabi_attribute 7, 11

0 commit comments

Comments
 (0)