Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7909,9 +7909,11 @@ bool AArch64AsmParser::parseDirectiveSEHSavePReg(SMLoc L) {
}

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

// Consume the name (subsection name)
Expand All @@ -7925,16 +7927,38 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
return true;
}
Parser.Lex();
// consume a comma

std::unique_ptr<MCELFStreamer::AttributeSubSection> SubsectionExists =
getTargetStreamer().getAttributesSubsectionByName(SubsectionName);
// Check whether only the subsection name was provided.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simplify the change by moving the call to SubsectionExists here. This can supply the parameters for emitAttributesSubsection so you wouldn't need to change anything in the AArch64TargetStreamer.

  std::unique_ptr<MCELFStreamer::AttributeSubSection> SubsectionExists =
      getTargetStreamer().getAttributesSubsectionByName(SubsectionName);

  if (Parser.getTok().is(llvm::AsmToken::EndOfStatement)) {
    if (SubsectionExists) {
      getTargetStreamer().emitAttributesSubsection(SubsectionName, SubsectionExists->IsOptional, SubsectionExists->Type);
      return false;
    }
    else {
      Error(Parser.getTok().getLoc(),
            "Could not switch to subsection '" + SubsectionName +
                "' using subsection name, subsection has not been defined");
      return true;
    }
  }
  // Otherwise, expecting 2 more parameters: consume a comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, comment addressed.

// If so, the user is trying to switch to a subsection that should have been
// declared before.
if (Parser.getTok().is(llvm::AsmToken::EndOfStatement)) {
if (SubsectionExists) {
getTargetStreamer().emitAttributesSubsection(
SubsectionName,
static_cast<AArch64BuildAttributes::SubsectionOptional>(
SubsectionExists->IsOptional),
static_cast<AArch64BuildAttributes::SubsectionType>(
SubsectionExists->ParameterType));
return false;
}
// If subsection does not exists, report error.
else {
Error(Parser.getTok().getLoc(),
"Could not switch to subsection '" + SubsectionName +
"' using subsection name, subsection has not been defined");
return true;
}
}

// Otherwise, expecting 2 more parameters: consume a comma
// parseComma() return *false* on success, and call Lex(), no need to call
// Lex() again.
if (Parser.parseComma()) {
return true;
}

std::unique_ptr<MCELFStreamer::AttributeSubSection> SubsectionExists =
getTargetStreamer().getAttributesSubsectionByName(SubsectionName);

// Consume the first parameter (optionality parameter)
AArch64BuildAttributes::SubsectionOptional IsOptional;
// options: optional/required
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: llvm-mc -triple=aarch64 %s -o - | FileCheck %s --check-prefix=ASM
// RUN: llvm-mc -triple=aarch64 -filetype=obj %s -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF

// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128
// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128
// ASM: .aeabi_attribute 0, 1 // Tag_Feature_BTI
// ASM: .aeabi_attribute 2, 1 // Tag_PAuth_Schema
// ASM: .aeabi_attribute 1, 1 // Tag_PAuth_Platform
// ASM: .aeabi_attribute 2, 1 // Tag_Feature_GCS
// ASM: .aeabi_attribute 1, 0 // Tag_Feature_PAC
// ASM: .aeabi_attribute 7, 1
// ASM: .aeabi_attribute 7, 0

// ELF: Hex dump of section '.ARM.attributes':
// ELF-NEXT: 0x00000000 411b0000 00616561 62695f70 61757468 A....aeabi_pauth
// ELF-NEXT: 0x00000010 61626900 00000201 01010700 25000000 abi.........%...
// ELF-NEXT: 0x00000020 61656162 695f6665 61747572 655f616e aeabi_feature_an
// ELF-NEXT: 0x00000030 645f6269 74730001 00000102 01010007 d_bits..........
// ELF-NEXT: 0x00000040 01


.aeabi_subsection aeabi_pauthabi, required, uleb128
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
.aeabi_attribute Tag_Feature_BTI, 1
.aeabi_subsection aeabi_feature_and_bits
.aeabi_subsection aeabi_pauthabi
.aeabi_attribute Tag_PAuth_Schema, 1
.aeabi_subsection aeabi_pauthabi
.aeabi_attribute Tag_PAuth_Platform, 1
.aeabi_subsection aeabi_pauthabi
.aeabi_subsection aeabi_feature_and_bits
.aeabi_attribute Tag_Feature_GCS, 1
.aeabi_subsection aeabi_pauthabi
.aeabi_subsection aeabi_feature_and_bits
.aeabi_attribute Tag_Feature_PAC, 0
.aeabi_subsection aeabi_feature_and_bits
.aeabi_attribute 7, 1
.aeabi_subsection aeabi_pauthabi
.aeabi_attribute 7, 0