Skip to content

Commit 460e9a8

Browse files
authored
[LLVM][AArch64] Build attributes: Support switching to a defined subsection by name only (llvm#154159)
The AArch64 build attribute specification now allows switching to an already-defined subsection using its name alone, without repeating the optionality and type parameters. This patch updates the parser to support that behavior. Spec reference: https://github.com/ARM-software/abi-aa/pull/230/files
1 parent 5ae749b commit 460e9a8

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7909,9 +7909,11 @@ bool AArch64AsmParser::parseDirectiveSEHSavePReg(SMLoc L) {
79097909
}
79107910

79117911
bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
7912-
// Expecting 3 AsmToken::Identifier after '.aeabi_subsection', a name and 2
7913-
// parameters, e.g.: .aeabi_subsection (1)aeabi_feature_and_bits, (2)optional,
7914-
// (3)uleb128 separated by 2 commas.
7912+
// Handle parsing of .aeabi_subsection directives
7913+
// - On first declaration of a subsection, expect exactly three identifiers
7914+
// after `.aeabi_subsection`: the subsection name and two parameters.
7915+
// - When switching to an existing subsection, it is valid to provide only
7916+
// the subsection name, or the name together with the two parameters.
79157917
MCAsmParser &Parser = getParser();
79167918

79177919
// Consume the name (subsection name)
@@ -7925,16 +7927,38 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
79257927
return true;
79267928
}
79277929
Parser.Lex();
7928-
// consume a comma
7930+
7931+
std::unique_ptr<MCELFStreamer::AttributeSubSection> SubsectionExists =
7932+
getTargetStreamer().getAttributesSubsectionByName(SubsectionName);
7933+
// Check whether only the subsection name was provided.
7934+
// If so, the user is trying to switch to a subsection that should have been
7935+
// declared before.
7936+
if (Parser.getTok().is(llvm::AsmToken::EndOfStatement)) {
7937+
if (SubsectionExists) {
7938+
getTargetStreamer().emitAttributesSubsection(
7939+
SubsectionName,
7940+
static_cast<AArch64BuildAttributes::SubsectionOptional>(
7941+
SubsectionExists->IsOptional),
7942+
static_cast<AArch64BuildAttributes::SubsectionType>(
7943+
SubsectionExists->ParameterType));
7944+
return false;
7945+
}
7946+
// If subsection does not exists, report error.
7947+
else {
7948+
Error(Parser.getTok().getLoc(),
7949+
"Could not switch to subsection '" + SubsectionName +
7950+
"' using subsection name, subsection has not been defined");
7951+
return true;
7952+
}
7953+
}
7954+
7955+
// Otherwise, expecting 2 more parameters: consume a comma
79297956
// parseComma() return *false* on success, and call Lex(), no need to call
79307957
// Lex() again.
79317958
if (Parser.parseComma()) {
79327959
return true;
79337960
}
79347961

7935-
std::unique_ptr<MCELFStreamer::AttributeSubSection> SubsectionExists =
7936-
getTargetStreamer().getAttributesSubsectionByName(SubsectionName);
7937-
79387962
// Consume the first parameter (optionality parameter)
79397963
AArch64BuildAttributes::SubsectionOptional IsOptional;
79407964
// options: optional/required
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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_subsection aeabi_feature_and_bits, optional, uleb128
6+
// ASM: .aeabi_attribute 0, 1 // Tag_Feature_BTI
7+
// ASM: .aeabi_attribute 2, 1 // Tag_PAuth_Schema
8+
// ASM: .aeabi_attribute 1, 1 // Tag_PAuth_Platform
9+
// ASM: .aeabi_attribute 2, 1 // Tag_Feature_GCS
10+
// ASM: .aeabi_attribute 1, 0 // Tag_Feature_PAC
11+
// ASM: .aeabi_attribute 7, 1
12+
// ASM: .aeabi_attribute 7, 0
13+
14+
// ELF: Hex dump of section '.ARM.attributes':
15+
// ELF-NEXT: 0x00000000 411b0000 00616561 62695f70 61757468 A....aeabi_pauth
16+
// ELF-NEXT: 0x00000010 61626900 00000201 01010700 25000000 abi.........%...
17+
// ELF-NEXT: 0x00000020 61656162 695f6665 61747572 655f616e aeabi_feature_an
18+
// ELF-NEXT: 0x00000030 645f6269 74730001 00000102 01010007 d_bits..........
19+
// ELF-NEXT: 0x00000040 01
20+
21+
22+
.aeabi_subsection aeabi_pauthabi, required, uleb128
23+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
24+
.aeabi_attribute Tag_Feature_BTI, 1
25+
.aeabi_subsection aeabi_feature_and_bits
26+
.aeabi_subsection aeabi_pauthabi
27+
.aeabi_attribute Tag_PAuth_Schema, 1
28+
.aeabi_subsection aeabi_pauthabi
29+
.aeabi_attribute Tag_PAuth_Platform, 1
30+
.aeabi_subsection aeabi_pauthabi
31+
.aeabi_subsection aeabi_feature_and_bits
32+
.aeabi_attribute Tag_Feature_GCS, 1
33+
.aeabi_subsection aeabi_pauthabi
34+
.aeabi_subsection aeabi_feature_and_bits
35+
.aeabi_attribute Tag_Feature_PAC, 0
36+
.aeabi_subsection aeabi_feature_and_bits
37+
.aeabi_attribute 7, 1
38+
.aeabi_subsection aeabi_pauthabi
39+
.aeabi_attribute 7, 0

0 commit comments

Comments
 (0)