Skip to content

Commit e2f6f2c

Browse files
committed
[AArch64][Build Attributes] Improve functionality and fix bugs
- Improve testing - Allow Tag_PAuth_Platform and Tag_PAuth_Schema assembly with any unsigned, not only 0 or 1 - Do not allow unknown tags to be strings - Remove assertion when value exists - Print and parse known string tags as a number + comment (e.g. .aeabi_attribute 0, 1 @ Tag_Feature_BTI)
1 parent 3019e49 commit e2f6f2c

22 files changed

+250
-170
lines changed

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

Lines changed: 27 additions & 14 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) {
@@ -7948,7 +7947,12 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
79487947
}
79497948
}
79507949
Parser.Lex();
7951-
// Parsing finished, check for trailing tokens.
7950+
7951+
// Parsing finished, hereafter only accept comments; otherwise no trailing
7952+
// tokens.
7953+
if (Parser.getTok().is(llvm::AsmToken::At)) {
7954+
Parser.parseStringToEndOfStatement();
7955+
}
79527956
if (Parser.getTok().isNot(llvm::AsmToken::EndOfStatement)) {
79537957
Error(Parser.getTok().getLoc(), "unexpected token for AArch64 build "
79547958
"attributes subsection header directive");
@@ -7986,14 +7990,22 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
79867990

79877991
StringRef TagStr = "";
79887992
unsigned Tag;
7989-
if (Parser.getTok().is(AsmToken::Identifier)) {
7993+
if (Parser.getTok().is(AsmToken::Integer)) {
7994+
Tag = getTok().getIntVal();
7995+
} else if (Parser.getTok().is(AsmToken::Identifier)) {
79907996
TagStr = Parser.getTok().getIdentifier();
79917997
switch (ActiveSubsectionID) {
79927998
default:
7999+
// Should not happen
79938000
assert(0 && "Subsection name error");
79948001
break;
79958002
case AArch64BuildAttrs::VENDOR_UNKNOWN:
7996-
// Private subsection, accept any tag.
8003+
// Tag was provided as an unrecognized string instead of an unsigned
8004+
// integer
8005+
Error(Parser.getTok().getLoc(), "unrecognized Tag: '" + TagStr +
8006+
"' \nExcept for public subsections, "
8007+
"tags have to be an unsigned int.");
8008+
return true;
79978009
break;
79988010
case AArch64BuildAttrs::AEABI_PAUTHABI:
79998011
Tag = AArch64BuildAttrs::getPauthABITagsID(TagStr);
@@ -8014,8 +8026,6 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
80148026
}
80158027
break;
80168028
}
8017-
} else if (Parser.getTok().is(AsmToken::Integer)) {
8018-
Tag = getTok().getIntVal();
80198029
} else {
80208030
Error(Parser.getTok().getLoc(), "AArch64 build attributes tag not found");
80218031
return true;
@@ -8059,10 +8069,9 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
80598069
Error(Parser.getTok().getLoc(), "AArch64 build attributes value not found");
80608070
return true;
80618071
}
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
8072+
// Check for possible unaccepted values for known tags
8073+
// (AEABI_FEATURE_AND_BITS)
8074+
if (ActiveSubsectionID == AArch64BuildAttrs::AEABI_FEATURE_AND_BITS) {
80668075
if (0 != ValueInt && 1 != ValueInt) {
80678076
Error(Parser.getTok().getLoc(),
80688077
"unknown AArch64 build attributes Value for Tag '" + TagStr +
@@ -8071,7 +8080,12 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
80718080
}
80728081
}
80738082
Parser.Lex();
8074-
// Parsing finished, check for trailing tokens.
8083+
8084+
// Parsing finished, hereafter only accept comments; otherwise no trailing
8085+
// tokens.
8086+
if (Parser.getTok().is(llvm::AsmToken::At)) {
8087+
Parser.parseStringToEndOfStatement();
8088+
}
80758089
if (Parser.getTok().isNot(llvm::AsmToken::EndOfStatement)) {
80768090
Error(Parser.getTok().getLoc(),
80778091
"unexpected token for AArch64 build attributes tag and value "
@@ -8083,7 +8097,6 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
80838097
getTargetStreamer().emitAttribute(ActiveSubsectionName, Tag, ValueInt, "",
80848098
false);
80858099
}
8086-
80878100
if ("" != ValueStr) {
80888101
getTargetStreamer().emitAttribute(ActiveSubsectionName, Tag, unsigned(-1),
80898102
ValueStr, false);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer {
191191
case AArch64BuildAttrs::TAG_FEATURE_BTI:
192192
case AArch64BuildAttrs::TAG_FEATURE_GCS:
193193
case AArch64BuildAttrs::TAG_FEATURE_PAC:
194-
OS << "\t.aeabi_attribute" << "\t"
195-
<< AArch64BuildAttrs::getFeatureAndBitsTagsStr(Tag) << ", " << Value;
194+
OS << "\t.aeabi_attribute" << "\t" << Tag << ", " << Value << "\t@ "
195+
<< AArch64BuildAttrs::getFeatureAndBitsTagsStr(Tag);
196196
AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "",
197197
Override);
198198
break;
@@ -210,8 +210,8 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer {
210210
break;
211211
case AArch64BuildAttrs::TAG_PAUTH_PLATFORM:
212212
case AArch64BuildAttrs::TAG_PAUTH_SCHEMA:
213-
OS << "\t.aeabi_attribute" << "\t"
214-
<< AArch64BuildAttrs::getPauthABITagsStr(Tag) << ", " << Value;
213+
OS << "\t.aeabi_attribute" << "\t" << Tag << ", " << Value << "\t@ "
214+
<< AArch64BuildAttrs::getPauthABITagsStr(Tag);
215215
AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "",
216216
Override);
217217
break;

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 is permited.
227+
return;
232228
}
233229
}
234230
}

llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
33

44
; ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
5-
; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 1
6-
; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 1
7-
; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 1
5+
; ASM-NEXT: .aeabi_attribute 0, 1 @ Tag_Feature_BTI
6+
; ASM-NEXT: .aeabi_attribute 1, 1 @ Tag_Feature_PAC
7+
; ASM-NEXT: .aeabi_attribute 2, 1 @ Tag_Feature_GCS
88

99
; ELF: Hex dump of section '.ARM.attributes':
1010
; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu

llvm/test/CodeGen/AArch64/aarch64-build-attributes-bti.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
33

44
; ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
5-
; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 1
6-
; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 0
7-
; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 0
5+
; ASM-NEXT: .aeabi_attribute 0, 1 @ Tag_Feature_BTI
6+
; ASM-NEXT: .aeabi_attribute 1, 0 @ Tag_Feature_PAC
7+
; ASM-NEXT: .aeabi_attribute 2, 0 @ Tag_Feature_GCS
88

99
; ELF: Hex dump of section '.ARM.attributes':
1010
; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu

llvm/test/CodeGen/AArch64/aarch64-build-attributes-gcs.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
33

44
; ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
5-
; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 0
6-
; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 0
7-
; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 1
5+
; ASM-NEXT: .aeabi_attribute 0, 0 @ Tag_Feature_BTI
6+
; ASM-NEXT: .aeabi_attribute 1, 0 @ Tag_Feature_PAC
7+
; ASM-NEXT: .aeabi_attribute 2, 1 @ Tag_Feature_GCS
88

99
; ELF: Hex dump of section '.ARM.attributes':
1010
; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu

llvm/test/CodeGen/AArch64/aarch64-build-attributes-pac.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF
33

44
; ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
5-
; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 0
6-
; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 1
7-
; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 0
5+
; ASM-NEXT: .aeabi_attribute 0, 0 @ Tag_Feature_BTI
6+
; ASM-NEXT: .aeabi_attribute 1, 1 @ Tag_Feature_PAC
7+
; ASM-NEXT: .aeabi_attribute 2, 0 @ Tag_Feature_GCS
88

99
; ELF: Hex dump of section '.ARM.attributes':
1010
; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu

llvm/test/CodeGen/AArch64/aarch64-build-attributes-pauthabi.ll

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

44
; ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128
5-
; ASM-NEXT: .aeabi_attribute Tag_PAuth_Platform, 2
6-
; ASM-NEXT: .aeabi_attribute Tag_PAuth_Schema, 31
5+
; ASM-NEXT: .aeabi_attribute 1, 2 @ Tag_PAuth_Platform
6+
; ASM-NEXT: .aeabi_attribute 2, 31 @ Tag_PAuth_Schema
77

88
; ELF: Hex dump of section '.ARM.attributes':
99
; ELF-NEXT: 0x00000000 41190000 00616561 62695f70 61757468 A....aeabi_pauth
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 aeabi_pauthabi, required, uleb128
5+
// ASM: .aeabi_attribute 1, 7 @ Tag_PAuth_Platform
6+
// ASM: .aeabi_attribute 2, 777 @ Tag_PAuth_Schema
7+
// ASM: .aeabi_attribute 2, 777 @ Tag_PAuth_Schema
8+
// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
9+
// ASM: .aeabi_attribute 0, 1 @ Tag_Feature_BTI
10+
// ASM: .aeabi_attribute 1, 1 @ Tag_Feature_PAC
11+
// ASM: .aeabi_attribute 2, 1 @ Tag_Feature_GCS
12+
// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128
13+
// ASM: .aeabi_attribute 1, 7 @ Tag_PAuth_Platform
14+
// ASM: .aeabi_attribute 2, 777 @ Tag_PAuth_Schema
15+
// ASM: .aeabi_attribute 2, 777 @ Tag_PAuth_Schema
16+
// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
17+
// ASM: .aeabi_attribute 0, 1 @ Tag_Feature_BTI
18+
// ASM: .aeabi_attribute 1, 1 @ Tag_Feature_PAC
19+
// ASM: .aeabi_attribute 2, 1 @ Tag_Feature_GCS
20+
21+
// ELF: Hex dump of section '.ARM.attributes':
22+
// ELF: 0x00000000 411a0000 00616561 62695f70 61757468 A....aeabi_pauth
23+
// ELF: 0x00000010 61626900 00000107 02890623 00000061 abi........#...a
24+
// ELF: 0x00000020 65616269 5f666561 74757265 5f616e64 eabi_feature_and
25+
// ELF: 0x00000030 5f626974 73000100 00010101 0201 _bits.........
26+
27+
28+
.aeabi_subsection aeabi_pauthabi, required, uleb128 @ test header comment
29+
.aeabi_attribute Tag_PAuth_Platform, 7
30+
.aeabi_attribute Tag_PAuth_Schema, 777
31+
.aeabi_attribute Tag_PAuth_Schema, 777
32+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
33+
.aeabi_attribute Tag_Feature_BTI, 1
34+
.aeabi_attribute Tag_Feature_PAC, 1
35+
.aeabi_attribute Tag_Feature_GCS, 1
36+
.aeabi_subsection aeabi_pauthabi, required, uleb128
37+
.aeabi_attribute 1, 7 @ Tag_PAuth_Platform
38+
.aeabi_attribute 2, 777 @ Tag_PAuth_Schema
39+
.aeabi_attribute 2, 777 @ Tag_PAuth_Schema
40+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
41+
.aeabi_attribute 0, 1 @ Tag_Feature_BTI
42+
.aeabi_attribute 1, 1 @ Tag_Feature_PAC
43+
.aeabi_attribute 2, 1 @ Tag_Feature_GCS

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
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_feature_and_bits, optional, uleb128
5-
// ASM: .aeabi_attribute Tag_Feature_BTI, 1
6-
// ASM: .aeabi_attribute Tag_Feature_PAC, 0
7-
// ASM: .aeabi_attribute Tag_Feature_GCS, 0
5+
// ASM: .aeabi_attribute 0, 1 @ Tag_Feature_BTI
6+
// ASM: .aeabi_attribute 1, 0 @ Tag_Feature_PAC
7+
// ASM: .aeabi_attribute 2, 0 @ Tag_Feature_GCS
88

99
// ELF: Hex dump of section '.ARM.attributes':
1010
// ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu

0 commit comments

Comments
 (0)