From a10af4639c827bd44ff25bd60b820186b5bec74f Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Wed, 4 Dec 2024 20:08:20 +0000 Subject: [PATCH 01/21] [LLVM][Clang][AArch64] Implement AArch64 build attributes - Added support for AArch64-specific build attributes. - Print AArch64 build attributes to assembly. - Emit AArch64 build attributes to ELF. Specification: https://github.com/ARM-software/abi-aa/blob/654a64cbac041fc3bff617800998d40b5068f592/buildattr64/buildattr64.rst#aeabi-feature-and-bits-subsection --- llvm/include/llvm/BinaryFormat/ELF.h | 2 + llvm/include/llvm/MC/MCELFStreamer.h | 27 +++- .../include/llvm/Support/ARMBuildAttributes.h | 63 +++++++++ llvm/lib/MC/MCELFStreamer.cpp | 76 +++++++++-- llvm/lib/Support/ARMBuildAttrs.cpp | 59 ++++++++- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 74 ++++++++--- .../MCTargetDesc/AArch64ELFStreamer.cpp | 122 +++++++++++++++++- .../MCTargetDesc/AArch64TargetStreamer.h | 23 +++- .../ARM/MCTargetDesc/ARMELFStreamer.cpp | 116 ++++++++--------- .../MCTargetDesc/HexagonMCTargetDesc.cpp | 2 +- .../RISCV/MCTargetDesc/RISCVELFStreamer.cpp | 6 +- 11 files changed, 472 insertions(+), 98 deletions(-) diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h index fd32a6ec19652..dd64647c5c033 100644 --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -1150,6 +1150,8 @@ enum : unsigned { SHT_ARM_ATTRIBUTES = 0x70000003U, SHT_ARM_DEBUGOVERLAY = 0x70000004U, SHT_ARM_OVERLAYSECTION = 0x70000005U, + // Support for AArch64 build attributes + SHT_AARCH64_ATTRIBUTES = 0x70000003U, // Special aarch64-specific section for MTE support, as described in: // https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#section-types SHT_AARCH64_AUTH_RELR = 0x70000004U, diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 94d14088d0f5d..351c7ddd3b738 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -10,6 +10,7 @@ #define LLVM_MC_MCELFSTREAMER_H #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCObjectStreamer.h" @@ -107,25 +108,41 @@ class MCELFStreamer : public MCObjectStreamer { std::string StringValue; }; + /// ELF object attributes subsection support + struct AttributeSubSection { + // [ NTBS: vendor-name ]* + StringRef Vendor; + // * + unsigned IsMandatory; // SubsectionMandatory::REQUIRED (0), SubsectionMandatory::OPTIONAL (1) + unsigned ParameterType; // SubsectionType::ULEB128 (0), SubsectionType::NTBS (1) + SmallVector Content; + }; + // Attributes that are added and managed entirely by target. SmallVector Contents; void setAttributeItem(unsigned Attribute, unsigned Value, - bool OverwriteExisting); + bool OverwriteExisting, SmallVector &Attributes); void setAttributeItem(unsigned Attribute, StringRef Value, - bool OverwriteExisting); + bool OverwriteExisting, SmallVector &Attributes); void setAttributeItems(unsigned Attribute, unsigned IntValue, - StringRef StringValue, bool OverwriteExisting); + StringRef StringValue, bool OverwriteExisting, SmallVector &Attributes); void emitAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection) { createAttributesSection(Vendor, Section, Type, AttributeSection, Contents); } + void emitAttributesSection(MCSection *&AttributeSection, + const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { + createAttributesSection(AttributeSection, Section, Type, SubSectionVec); + } private: - AttributeItem *getAttributeItem(unsigned Attribute); - size_t calculateContentSize(SmallVector &AttrsVec); + AttributeItem *getAttributeItem(unsigned Attribute, SmallVector &Attributes); + size_t calculateContentSize(SmallVector &AttrsVec) const; void createAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection, SmallVector &AttrsVec); + void createAttributesSection(MCSection *&AttributeSection, const Twine & Section, + unsigned Type, SmallVector &SubSectionVec); // GNU attributes that will get emitted at the end of the asm file. SmallVector GNUAttributes; diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 35f8992ca9329..5e17ccf835190 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -21,10 +21,58 @@ #include "llvm/Support/ELFAttributes.h" namespace llvm { +class StringRef; + namespace ARMBuildAttrs { const TagNameMap &getARMAttributeTags(); +/// AArch64 build attributes vendors (=subsection name) +enum Vendor : unsigned { + AEBI_FEATURE_AND_BITS = 0, + AEBI_PAUTHABI = 1 +}; + +inline StringRef vendorToStr(unsigned Vendor) { + switch(Vendor) { + default: + llvm_unreachable("unknown AArch64 vendor name"); + return ""; + case AEBI_FEATURE_AND_BITS: + return "aeabi-feature-and-bits"; + case AEBI_PAUTHABI: + return "aeabi-pauthabi"; + } +} + +enum SubsectionMandatory : unsigned { + OPTIONAL = 0, + REQUIRED = 1 +}; + +enum SubsectionType : unsigned { + ULEB128 = 0, + NTBS = 1 +}; + +enum FeatureAndBitsTags : unsigned { + Tag_PAuth_Platform = 1, + Tag_PAuth_Schema = 2 +}; + +enum PauthabiTags : unsigned { + Tag_Feature_BTI = 0, + Tag_Feature_PAC = 1, + Tag_Feature_GCS = 2 +}; + +enum PauthabiTagsFlag : unsigned { + Feature_BTI_Flag = 1 << 0, + Feature_PAC_Flag = 1 << 1, + Feature_GCS_Flag = 1 << 2 +}; +/// --- + enum SpecialAttr { // This is for the .cpu asm attr. It translates into one or more // AttrType (below) entries in the .ARM.attributes section in the ELF. @@ -88,6 +136,21 @@ enum AttrType : unsigned { MPextension_use_old = 70 // recoded to MPextension_use (ABI r2.08) }; +enum AVAttr { + AV_cpp_exceptions = 6, + AV_eba = 16 +}; + +StringRef AttrTypeAsString(StringRef Vendor, unsigned Attr, bool HasTagPrefix = true); +StringRef AttrTypeAsString(AttrType Attr, bool HasTagPrefix = true); +StringRef AttrTypeAsString(AVAttr Attr, bool HasTagPrefix = true); +int AttrTypeFromString(StringRef Vendor, StringRef Tag); + +// Magic numbers for .ARM.attributes +enum AttrMagic { + Format_Version = 0x41 +}; + // Legal Values for CPU_arch, (=6), uleb128 enum CPUArch { Pre_v4 = 0, diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 64ab2b2ab58f5..34a7367a18f44 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -636,9 +636,9 @@ void MCELFStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, } void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value, - bool OverwriteExisting) { + bool OverwriteExisting, SmallVector &Attributes) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute)) { + if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::NumericAttribute; @@ -653,9 +653,9 @@ void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value, } void MCELFStreamer::setAttributeItem(unsigned Attribute, StringRef Value, - bool OverwriteExisting) { + bool OverwriteExisting, SmallVector &Attributes) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute)) { + if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::TextAttribute; @@ -671,9 +671,9 @@ void MCELFStreamer::setAttributeItem(unsigned Attribute, StringRef Value, void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue, StringRef StringValue, - bool OverwriteExisting) { + bool OverwriteExisting, SmallVector &Attributes) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute)) { + if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::NumericAndTextAttributes; @@ -689,15 +689,15 @@ void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue, } MCELFStreamer::AttributeItem * -MCELFStreamer::getAttributeItem(unsigned Attribute) { - for (AttributeItem &Item : Contents) +MCELFStreamer::getAttributeItem(unsigned Attribute, SmallVector &Attributes) { + for (AttributeItem &Item : Attributes) if (Item.Tag == Attribute) return &Item; return nullptr; } size_t -MCELFStreamer::calculateContentSize(SmallVector &AttrsVec) { +MCELFStreamer::calculateContentSize(SmallVector &AttrsVec) const { size_t Result = 0; for (const AttributeItem &Item : AttrsVec) { switch (Item.Type) { @@ -783,6 +783,64 @@ void MCELFStreamer::createAttributesSection( AttrsVec.clear(); } +void MCELFStreamer::createAttributesSection(MCSection *&AttributeSection, + const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { +// +// [ NTBS: vendor-name +// +// ]* +// vendor-data expends to: +// * + if (SubSectionVec.size() == 0) { + return; + } + + // Switch section to AttributeSection or get/create the section. + if (AttributeSection) { + switchSection(AttributeSection); + } else { + AttributeSection = getContext().getELFSection(Section, Type, 0); + switchSection(AttributeSection); + + // Format version + emitInt8(0x41); + } + + for (AttributeSubSection &SubSection : SubSectionVec) { + // subsection-length + vendor-name + '\0' + const size_t VendorHeaderSize = 4 + SubSection.Vendor.size() + 1; + // optional + parameter-type + const size_t VendorParameters = 1 + 1; + const size_t ContentsSize = calculateContentSize(SubSection.Content); + + emitInt32(VendorHeaderSize + VendorParameters + ContentsSize); + emitBytes(SubSection.Vendor); + emitInt8(SubSection.IsMandatory); + emitInt8(SubSection.ParameterType); + + for (AttributeItem &Item : SubSection.Content) { + emitULEB128IntValue(Item.Tag); + switch (Item.Type) { + default: + llvm_unreachable("Invalid attribute type"); + case AttributeItem::NumericAttribute: + emitULEB128IntValue(Item.IntValue); + break; + case AttributeItem::TextAttribute: + emitBytes(Item.StringValue); + emitInt8(0); // '\0' + break; + case AttributeItem::NumericAndTextAttributes: + emitULEB128IntValue(Item.IntValue); + emitBytes(Item.StringValue); + emitInt8(0); // '\0' + break; + } + } + } + SubSectionVec.clear(); +} + MCStreamer *llvm::createELFStreamer(MCContext &Context, std::unique_ptr &&MAB, std::unique_ptr &&OW, diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index 815cfc62a4b0e..96d0f312d734c 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -6,11 +6,13 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringRef.h" #include "llvm/Support/ARMBuildAttributes.h" using namespace llvm; -static const TagNameItem tagData[] = { +namespace { +const TagNameItem ARMAttributeTags[] = { {ARMBuildAttrs::File, "Tag_File"}, {ARMBuildAttrs::Section, "Tag_Section"}, {ARMBuildAttrs::Symbol, "Tag_Symbol"}, @@ -67,7 +69,56 @@ static const TagNameItem tagData[] = { {ARMBuildAttrs::ABI_align_preserved, "Tag_ABI_align8_preserved"}, }; -constexpr TagNameMap ARMAttributeTags{tagData}; -const TagNameMap &llvm::ARMBuildAttrs::getARMAttributeTags() { - return ARMAttributeTags; +const TagNameItem AVAttributeTags[] = { + { ARMBuildAttrs::AV_cpp_exceptions, "Tag_AV_cpp_exceptions" }, + { ARMBuildAttrs::AV_eba, "Tag_AV_eba" }, +}; + +template int FromString(T (&Table)[N], StringRef Tag) { + bool HasTagPrefix = Tag.starts_with("Tag_"); + for (unsigned TI = 0; TI < N; ++TI) + if (Table[TI].tagName.drop_front(HasTagPrefix ? 0 : 4) == Tag) + return Table[TI].attr; + return -1; +} + +template +StringRef AsString(T (&Table)[N], A Attr, bool HasTagPrefix) { + for (unsigned TI = 0; TI < N; ++TI) + if (Table[TI].attr == Attr) + return Table[TI].tagName.drop_front(HasTagPrefix ? 0 : 4); + return StringRef(); +} +} + +namespace llvm { +namespace ARMBuildAttrs { +StringRef AttrTypeAsString(StringRef Vendor, unsigned Attr, bool HasTagPrefix) { + if (Vendor.equals_insensitive("aeabi") || Vendor.equals_insensitive("eabi")) + return AsString(ARMAttributeTags, static_cast(Attr), + HasTagPrefix); + else if (Vendor.equals_insensitive("arm")) + return AsString(AVAttributeTags, static_cast(Attr), HasTagPrefix); + return StringRef(); +} + +StringRef AttrTypeAsString(AttrType Attr, bool HasTagPrefix) { + return AsString(ARMAttributeTags, static_cast(Attr), HasTagPrefix); +} + +StringRef AttrTypeAsString(AVAttr Attr, bool HasTagPrefix) { + return AsString(AVAttributeTags, static_cast(Attr), HasTagPrefix); +} + +int AttrTypeFromString(StringRef Vendor, StringRef Tag) { + if (Vendor.equals_insensitive("aeabi") || Vendor.equals_insensitive("eabi")) + return FromString(ARMAttributeTags, Tag); + else if (Vendor.equals_insensitive("arm")) + return FromString(AVAttributeTags, Tag); + return -1; +} + +static constexpr TagNameMap tagNameMap(ARMAttributeTags); +const TagNameMap &getARMAttributeTags() { return tagNameMap; } +} } diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index 4fd6b0d4311a5..f5e6a580fcd6a 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -54,6 +54,7 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" @@ -200,6 +201,9 @@ class AArch64AsmPrinter : public AsmPrinter { /// pseudo instructions. bool lowerPseudoInstExpansion(const MachineInstr *MI, MCInst &Inst); + // Emit Build Attributes + void emitAttributes(unsigned Flags, uint64_t PAuthABIPlatform, uint64_t PAuthABIVersion, AArch64TargetStreamer* TS); + void EmitToStreamer(MCStreamer &S, const MCInst &Inst); void EmitToStreamer(const MCInst &Inst) { EmitToStreamer(*OutStreamer, Inst); @@ -332,36 +336,51 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { if (!TT.isOSBinFormatELF()) return; - // Assemble feature flags that may require creation of a note section. - unsigned Flags = 0; + // For emitting build attributes and .note.gnu.property section + auto *TS = static_cast(OutStreamer->getTargetStreamer()); + // Assemble feature flags that may require creation of build attributes and a note section. + unsigned BAFlags = 0; + unsigned GNUFlags = 0; if (const auto *BTE = mdconst::extract_or_null( - M.getModuleFlag("branch-target-enforcement"))) - if (!BTE->isZero()) - Flags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI; + M.getModuleFlag("branch-target-enforcement"))) { + if (!BTE->isZero()) { + BAFlags |= ARMBuildAttrs::PauthabiTagsFlag::Feature_BTI_Flag; + GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI; + } + } if (const auto *GCS = mdconst::extract_or_null( - M.getModuleFlag("guarded-control-stack"))) - if (!GCS->isZero()) - Flags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_GCS; + M.getModuleFlag("guarded-control-stack"))) { + if (!GCS->isZero()) { + BAFlags |= ARMBuildAttrs::PauthabiTagsFlag::Feature_GCS_Flag; + GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_GCS; + } + } if (const auto *Sign = mdconst::extract_or_null( - M.getModuleFlag("sign-return-address"))) - if (!Sign->isZero()) - Flags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_PAC; + M.getModuleFlag("sign-return-address"))) { + if (!Sign->isZero()) { + BAFlags |= ARMBuildAttrs::PauthabiTagsFlag::Feature_PAC_Flag; + GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_PAC; + } + } uint64_t PAuthABIPlatform = -1; if (const auto *PAP = mdconst::extract_or_null( - M.getModuleFlag("aarch64-elf-pauthabi-platform"))) + M.getModuleFlag("aarch64-elf-pauthabi-platform"))) { PAuthABIPlatform = PAP->getZExtValue(); + } + uint64_t PAuthABIVersion = -1; if (const auto *PAV = mdconst::extract_or_null( - M.getModuleFlag("aarch64-elf-pauthabi-version"))) + M.getModuleFlag("aarch64-elf-pauthabi-version"))) { PAuthABIVersion = PAV->getZExtValue(); + } + // Emit AArch64 Build Attributes + emitAttributes(BAFlags, PAuthABIPlatform, PAuthABIVersion, TS); // Emit a .note.gnu.property section with the flags. - auto *TS = - static_cast(OutStreamer->getTargetStreamer()); - TS->emitNoteSection(Flags, PAuthABIPlatform, PAuthABIVersion); + TS->emitNoteSection(GNUFlags, PAuthABIPlatform, PAuthABIVersion); } void AArch64AsmPrinter::emitFunctionHeaderComment() { @@ -434,6 +453,29 @@ void AArch64AsmPrinter::emitSled(const MachineInstr &MI, SledKind Kind) { recordSled(CurSled, MI, Kind, 2); } +void AArch64AsmPrinter::emitAttributes(unsigned Flags, uint64_t PAuthABIPlatform, uint64_t PAuthABIVersion, AArch64TargetStreamer* TS) { + + PAuthABIPlatform = (PAuthABIPlatform == uint64_t(-1)) ? 0 : PAuthABIPlatform; + PAuthABIVersion = (PAuthABIVersion == uint64_t(-1)) ? 0 : PAuthABIVersion; + + if(PAuthABIPlatform || PAuthABIVersion) { + TS->emitSubsection(ARMBuildAttrs::AEBI_PAUTHABI, 0, 0); + TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, ARMBuildAttrs::Tag_PAuth_Platform, PAuthABIPlatform, false); + TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, ARMBuildAttrs::Tag_PAuth_Schema, PAuthABIVersion, false); + } + + unsigned BTIValue = (Flags & ARMBuildAttrs::Feature_BTI_Flag) ? 1 : 0; + unsigned PACValue = (Flags & ARMBuildAttrs::Feature_PAC_Flag) ? 1 : 0; + unsigned GCSValue = (Flags & ARMBuildAttrs::Feature_GCS_Flag) ? 1 : 0; + + if(BTIValue || PACValue || GCSValue) { + TS->emitSubsection(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, 1, 0); + TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_BTI, BTIValue, false); + TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_PAC, PACValue, false); + TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_GCS, GCSValue, false); + } +} + // Emit the following code for Intrinsic::{xray_customevent,xray_typedevent} // (built-in functions __xray_customevent/__xray_typedevent). // diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 5bae846824548..e57b070313738 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -33,6 +33,7 @@ #include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/MCWinCOFFStreamer.h" +#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/raw_ostream.h" @@ -45,6 +46,8 @@ class AArch64ELFStreamer; class AArch64TargetAsmStreamer : public AArch64TargetStreamer { formatted_raw_ostream &OS; + std::string VendorTag; + bool IsVerboseAsm; void emitInst(uint32_t Inst) override; @@ -148,13 +151,80 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { OS << "\t.seh_save_any_reg_px\tq" << Reg << ", " << Offset << "\n"; } + void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) override { + // AArch64 build attributes for assembly attribute form: + // .aeabi_attribute tag, value + + switch(Vendor) { + default: llvm_unreachable("unknown AArch64 build attributes subsection name"); + + case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: + switch(Tag) { + default: llvm_unreachable("unknown tag for the feature-and-bits subsection"); + case ARMBuildAttrs::Tag_Feature_BTI: + OS << "\t.aeabi_attribute\t" << "Tag_Feature_BTI" << ", " << Value; + break; + case ARMBuildAttrs::Tag_Feature_GCS: + OS << "\t.aeabi_attribute\t" << "Tag_Feature_GCS" << ", " << Value; + break; + case ARMBuildAttrs::Tag_Feature_PAC: + OS << "\t.aeabi_attribute\t" << "Tag_Feature_PAC" << ", " << Value; + break; + } + break; + + case ARMBuildAttrs::AEBI_PAUTHABI: + switch(Tag) { + default: llvm_unreachable("unknown tag for the feature-and-bits subsection"); + case ARMBuildAttrs::Tag_PAuth_Platform: + OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Platform" << ", " << Value; + break; + case ARMBuildAttrs::Tag_PAuth_Schema: + OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Schema" << ", " << Value; + break; + break; + } + } + OS << "\n"; + } + + void emitSubsection(unsigned SubsectionName, unsigned Optional, unsigned ParameterType) override { + // The AArch64 build attributes assembly subsection header format: + // ".aeabi_subsection name, optional, parameter type" + // optional: required (0) optional (1) + // parameter type: uleb128 or ULEB128 (0) ntbs or NTBS (1) + + assert((Optional == 0 || Optional == 1) && "unsupported parameter for Optional"); + assert((ParameterType == 0 || ParameterType == 1) && "unsupported parameter for ParameterType"); + + StringRef OptionalStr = Optional ? "optional" : "required"; + StringRef ParameterStr = ParameterType ? "NTBS" : "ULEB128"; + + switch(SubsectionName) { + default: llvm_unreachable("unknown AArch64 build attributes subsection name"); + + case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: + assert(Optional == 1 && "subsection .aeabi-feature-and-bits should be marked as optional and not as mandatory"); + assert(ParameterType == 0 && "subsection .aeabi-feature-and-bits should be marked as uleb128 and not as ntbs"); + OS << "\t.aeabi_subsection\t" << ".aeabi-feature-and-bits" << ", " << OptionalStr << ", " << ParameterStr; + break; + + case ARMBuildAttrs::AEBI_PAUTHABI: + assert(Optional == 0 && "subsection .aeabi-pauthabi should be marked as mandatory and not as optional"); + assert(ParameterType == 0 && "subsection .aeabi-pauthabi should be marked as uleb128 and not as ntbs"); + OS << "\t.aeabi_subsection\t" << ".aeabi-pauthabi" << ", " << OptionalStr << ", " << ParameterStr; + break; + } + OS << "\n"; + } + public: AArch64TargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); }; AArch64TargetAsmStreamer::AArch64TargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS) - : AArch64TargetStreamer(S), OS(OS) {} + : AArch64TargetStreamer(S), OS(OS), VendorTag("eabi"), IsVerboseAsm(S.isVerboseAsm()) {} void AArch64TargetAsmStreamer::emitInst(uint32_t Inst) { OS << "\t.inst\t0x" << Twine::utohexstr(Inst) << "\n"; @@ -294,6 +364,53 @@ AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() { return static_cast(Streamer); } +void AArch64TargetELFStreamer::emitSubsection(unsigned Vendor, unsigned IsMandatory, unsigned ParameterType) { + StringRef VendorAsStr = ARMBuildAttrs::vendorToStr(Vendor); + + // If exists, return. + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (SubSection.Vendor == VendorAsStr) { + llvm_unreachable("AArch64 build attributes subsection already exists"); + return; + } + } + // else, add the subsection + MCELFStreamer::AttributeSubSection AttSubSection; + AttSubSection.Vendor = VendorAsStr; + AttSubSection.IsMandatory = IsMandatory; + AttSubSection.ParameterType = ParameterType; + AttributeSubSections.push_back(AttSubSection); +} + +void AArch64TargetELFStreamer::emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) { + StringRef VendorAsStr = ARMBuildAttrs::vendorToStr(Vendor); + + if (AttributeSubSections.size() == 0) { + llvm_unreachable("Attribute can not be added unless the required AArch64 build attributes subsection exists"); + return; + } + + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (SubSection.Vendor == VendorAsStr) { + for (MCELFStreamer::AttributeItem &Item : SubSection.Content) { + if (Item.Tag == Tag) { + if (!Override) { + llvm_unreachable("Attribute exists but override is set to false"); + return; + } + } + } + MCELFStreamer::AttributeItem AttItem; + AttItem.Type = AttItem.NumericAttribute; + AttItem.Tag = Tag; + AttItem.IntValue = Value; + SubSection.Content.push_back(AttItem); + return; + } + } + llvm_unreachable("Attribute can not be added unless the required AArch64 build attributes subsection exists"); +} + void AArch64TargetELFStreamer::emitInst(uint32_t Inst) { getStreamer().emitInst(Inst); } @@ -309,6 +426,9 @@ void AArch64TargetELFStreamer::finish() { MCContext &Ctx = S.getContext(); auto &Asm = S.getAssembler(); + S.emitAttributesSection(AttributeSection, ".ARM.attributes", + ELF::SHT_AARCH64_ATTRIBUTES, AttributeSubSections); + // If ImplicitMapSyms is specified, ensure that text sections end with // the A64 state while non-text sections end with the data state. When // sections are combined by the linker, the subsequent section will start with diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index ac441ae3b603f..7d90759cfc6e1 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -9,7 +9,15 @@ #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64TARGETSTREAMER_H #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64TARGETSTREAMER_H +#include "llvm/ADT/StringRef.h" +#include "llvm/IR/Instructions.h" +#include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/Support/ARMBuildAttributes.h" +#include "llvm/TableGen/Record.h" +#include +#include +#include namespace { class AArch64ELFStreamer; @@ -83,20 +91,33 @@ class AArch64TargetStreamer : public MCTargetStreamer { virtual void emitARM64WinCFISaveAnyRegQX(unsigned Reg, int Offset) {} virtual void emitARM64WinCFISaveAnyRegQPX(unsigned Reg, int Offset) {} + /// Build attributes implementation + virtual void emitSubsection(unsigned Vendor, unsigned IsMandatory, unsigned ParameterType) {} + virtual void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) {} + private: std::unique_ptr ConstantPools; }; class AArch64TargetELFStreamer : public AArch64TargetStreamer { private: + StringRef CurrentVendor; AArch64ELFStreamer &getStreamer(); + MCSection *AttributeSection = nullptr; + SmallVector AttributeSubSections; + + /// Build attributes implementation + void emitSubsection(unsigned Vendor, unsigned IsMandatory, unsigned ParameterType) override; + void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) override; + void emitInst(uint32_t Inst) override; void emitDirectiveVariantPCS(MCSymbol *Symbol) override; void finish() override; public: - AArch64TargetELFStreamer(MCStreamer &S) : AArch64TargetStreamer(S) {} + AArch64TargetELFStreamer(MCStreamer &S) + : AArch64TargetStreamer(S), CurrentVendor("aeabi") {} }; class AArch64TargetWinCOFFStreamer : public llvm::AArch64TargetStreamer { diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index c528526382a2b..b6a16de748d9b 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -793,20 +793,20 @@ void ARMTargetELFStreamer::switchVendor(StringRef Vendor) { void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) { getStreamer().setAttributeItem(Attribute, Value, - /* OverwriteExisting= */ true); + /* OverwriteExisting= */ true, getStreamer().Contents); } void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute, StringRef Value) { getStreamer().setAttributeItem(Attribute, Value, - /* OverwriteExisting= */ true); + /* OverwriteExisting= */ true, getStreamer().Contents); } void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) { getStreamer().setAttributeItems(Attribute, IntValue, StringValue, - /* OverwriteExisting= */ true); + /* OverwriteExisting= */ true, getStreamer().Contents); } void ARMTargetELFStreamer::emitArch(ARM::ArchKind Value) { @@ -821,16 +821,16 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { using namespace ARMBuildAttrs; ARMELFStreamer &S = getStreamer(); - S.setAttributeItem(CPU_name, ARM::getCPUAttr(Arch), false); + S.setAttributeItem(CPU_name, ARM::getCPUAttr(Arch), false, getStreamer().Contents); if (EmittedArch == ARM::ArchKind::INVALID) - S.setAttributeItem(CPU_arch, ARM::getArchAttr(Arch), false); + S.setAttributeItem(CPU_arch, ARM::getArchAttr(Arch), false, getStreamer().Contents); else - S.setAttributeItem(CPU_arch, ARM::getArchAttr(EmittedArch), false); + S.setAttributeItem(CPU_arch, ARM::getArchAttr(EmittedArch), false, getStreamer().Contents); switch (Arch) { case ARM::ArchKind::ARMV4: - S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV4T: @@ -838,42 +838,42 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { case ARM::ArchKind::XSCALE: case ARM::ArchKind::ARMV5TE: case ARM::ArchKind::ARMV6: - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, Allowed, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV6T2: - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false,getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV6K: case ARM::ArchKind::ARMV6KZ: - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, Allowed, false); - S.setAttributeItem(Virtualization_use, AllowTZ, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(Virtualization_use, AllowTZ, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV6M: - S.setAttributeItem(THUMB_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV7A: - S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false); - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); + S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV7R: - S.setAttributeItem(CPU_arch_profile, RealTimeProfile, false); - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); + S.setAttributeItem(CPU_arch_profile, RealTimeProfile, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV7EM: case ARM::ArchKind::ARMV7M: - S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); + S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV8A: @@ -893,29 +893,29 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { case ARM::ArchKind::ARMV9_4A: case ARM::ArchKind::ARMV9_5A: case ARM::ArchKind::ARMV9_6A: - S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false); - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); - S.setAttributeItem(MPextension_use, Allowed, false); - S.setAttributeItem(Virtualization_use, AllowTZVirtualization, false); + S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); + S.setAttributeItem(MPextension_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(Virtualization_use, AllowTZVirtualization, false, getStreamer().Contents); break; case ARM::ArchKind::ARMV8MBaseline: case ARM::ArchKind::ARMV8MMainline: - S.setAttributeItem(THUMB_ISA_use, AllowThumbDerived, false); - S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false); + S.setAttributeItem(THUMB_ISA_use, AllowThumbDerived, false, getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, getStreamer().Contents); break; case ARM::ArchKind::IWMMXT: - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, Allowed, false); - S.setAttributeItem(WMMX_arch, AllowWMMXv1, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(WMMX_arch, AllowWMMXv1, false, getStreamer().Contents); break; case ARM::ArchKind::IWMMXT2: - S.setAttributeItem(ARM_ISA_use, Allowed, false); - S.setAttributeItem(THUMB_ISA_use, Allowed, false); - S.setAttributeItem(WMMX_arch, AllowWMMXv2, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(WMMX_arch, AllowWMMXv2, false, getStreamer().Contents); break; default: @@ -933,47 +933,47 @@ void ARMTargetELFStreamer::emitFPUDefaultAttributes() { case ARM::FK_VFP: case ARM::FK_VFPV2: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv2, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_VFPV3: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_VFPV3_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_VFPV3_D16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_VFPV3_D16_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_VFPV3XD: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_VFPV3XD_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_VFPV4: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv4A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; // ABI_HardFP_use is handled in ARMAsmPrinter, so _SP_D16 is treated the same @@ -981,12 +981,12 @@ void ARMTargetELFStreamer::emitFPUDefaultAttributes() { case ARM::FK_FPV4_SP_D16: case ARM::FK_VFPV4_D16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv4B, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_FP_ARMV8: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPARMv8A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; // FPV5_D16 is identical to FP_ARMV8 except for the number of D registers, so @@ -998,39 +998,39 @@ void ARMTargetELFStreamer::emitFPUDefaultAttributes() { case ARM::FK_FP_ARMV8_FULLFP16_SP_D16: case ARM::FK_FP_ARMV8_FULLFP16_D16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPARMv8B, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_NEON: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch, ARMBuildAttrs::AllowNeon, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_NEON_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch, ARMBuildAttrs::AllowNeon, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_NEON_VFPV4: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv4A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch, ARMBuildAttrs::AllowNeon2, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); break; case ARM::FK_NEON_FP_ARMV8: case ARM::FK_CRYPTO_NEON_FP_ARMV8: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPARMv8A, - /* OverwriteExisting= */ false); + /* OverwriteExisting= */ false, getStreamer().Contents); // 'Advanced_SIMD_arch' must be emitted not here, but within // ARMAsmPrinter::emitAttributes(), depending on hasV8Ops() and hasV8_1a() break; diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp index aa86b2df85629..d8a177a90a7a3 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -330,7 +330,7 @@ class HexagonTargetELFStreamer : public HexagonTargetStreamer { void emitAttribute(uint32_t Attribute, uint32_t Value) override { getStreamer().setAttributeItem(Attribute, Value, - /*OverwriteExisting=*/true); + /*OverwriteExisting=*/true, getStreamer().Contents); } }; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp index ea0e9fcde21cf..ae536accb399a 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp @@ -57,19 +57,19 @@ void RISCVTargetELFStreamer::emitDirectiveOptionRelax() {} void RISCVTargetELFStreamer::emitDirectiveOptionNoRelax() {} void RISCVTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) { - getStreamer().setAttributeItem(Attribute, Value, /*OverwriteExisting=*/true); + getStreamer().setAttributeItem(Attribute, Value, /*OverwriteExisting=*/true, getStreamer().Contents); } void RISCVTargetELFStreamer::emitTextAttribute(unsigned Attribute, StringRef String) { - getStreamer().setAttributeItem(Attribute, String, /*OverwriteExisting=*/true); + getStreamer().setAttributeItem(Attribute, String, /*OverwriteExisting=*/true, getStreamer().Contents); } void RISCVTargetELFStreamer::emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) { getStreamer().setAttributeItems(Attribute, IntValue, StringValue, - /*OverwriteExisting=*/true); + /*OverwriteExisting=*/true, getStreamer().Contents); } void RISCVTargetELFStreamer::finishAttributeSection() { From c1c4c469b3e46e8777d3c9ca2d8ada5838e82b6b Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Thu, 5 Dec 2024 10:53:07 +0000 Subject: [PATCH 02/21] Formatting --- llvm/include/llvm/MC/MCELFStreamer.h | 30 +++-- .../include/llvm/Support/ARMBuildAttributes.h | 43 +++---- llvm/lib/MC/MCELFStreamer.cpp | 68 +++++----- llvm/lib/Support/ARMBuildAttrs.cpp | 16 +-- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 34 +++-- .../MCTargetDesc/AArch64ELFStreamer.cpp | 116 ++++++++++-------- .../MCTargetDesc/AArch64TargetStreamer.h | 14 ++- .../ARM/MCTargetDesc/ARMELFStreamer.cpp | 59 ++++++--- .../MCTargetDesc/HexagonMCTargetDesc.cpp | 3 +- .../RISCV/MCTargetDesc/RISCVELFStreamer.cpp | 9 +- 10 files changed, 226 insertions(+), 166 deletions(-) diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 351c7ddd3b738..0e37948d3d2b7 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -113,36 +113,46 @@ class MCELFStreamer : public MCObjectStreamer { // [ NTBS: vendor-name ]* StringRef Vendor; // * - unsigned IsMandatory; // SubsectionMandatory::REQUIRED (0), SubsectionMandatory::OPTIONAL (1) - unsigned ParameterType; // SubsectionType::ULEB128 (0), SubsectionType::NTBS (1) + unsigned IsMandatory; // SubsectionMandatory::REQUIRED (0), + // SubsectionMandatory::OPTIONAL (1) + unsigned + ParameterType; // SubsectionType::ULEB128 (0), SubsectionType::NTBS (1) SmallVector Content; }; // Attributes that are added and managed entirely by target. SmallVector Contents; void setAttributeItem(unsigned Attribute, unsigned Value, - bool OverwriteExisting, SmallVector &Attributes); + bool OverwriteExisting, + SmallVector &Attributes); void setAttributeItem(unsigned Attribute, StringRef Value, - bool OverwriteExisting, SmallVector &Attributes); + bool OverwriteExisting, + SmallVector &Attributes); void setAttributeItems(unsigned Attribute, unsigned IntValue, - StringRef StringValue, bool OverwriteExisting, SmallVector &Attributes); + StringRef StringValue, bool OverwriteExisting, + SmallVector &Attributes); void emitAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection) { createAttributesSection(Vendor, Section, Type, AttributeSection, Contents); } - void emitAttributesSection(MCSection *&AttributeSection, - const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { + void + emitAttributesSection(MCSection *&AttributeSection, const Twine &Section, + unsigned Type, + SmallVector &SubSectionVec) { createAttributesSection(AttributeSection, Section, Type, SubSectionVec); } private: - AttributeItem *getAttributeItem(unsigned Attribute, SmallVector &Attributes); + AttributeItem *getAttributeItem(unsigned Attribute, + SmallVector &Attributes); size_t calculateContentSize(SmallVector &AttrsVec) const; void createAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection, SmallVector &AttrsVec); - void createAttributesSection(MCSection *&AttributeSection, const Twine & Section, - unsigned Type, SmallVector &SubSectionVec); + void + createAttributesSection(MCSection *&AttributeSection, const Twine &Section, + unsigned Type, + SmallVector &SubSectionVec); // GNU attributes that will get emitted at the end of the asm file. SmallVector GNUAttributes; diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 5e17ccf835190..788d72977d6f0 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -28,32 +28,23 @@ namespace ARMBuildAttrs { const TagNameMap &getARMAttributeTags(); /// AArch64 build attributes vendors (=subsection name) -enum Vendor : unsigned { - AEBI_FEATURE_AND_BITS = 0, - AEBI_PAUTHABI = 1 -}; +enum Vendor : unsigned { AEBI_FEATURE_AND_BITS = 0, AEBI_PAUTHABI = 1 }; inline StringRef vendorToStr(unsigned Vendor) { - switch(Vendor) { - default: - llvm_unreachable("unknown AArch64 vendor name"); - return ""; - case AEBI_FEATURE_AND_BITS: - return "aeabi-feature-and-bits"; - case AEBI_PAUTHABI: - return "aeabi-pauthabi"; + switch (Vendor) { + default: + llvm_unreachable("unknown AArch64 vendor name"); + return ""; + case AEBI_FEATURE_AND_BITS: + return "aeabi-feature-and-bits"; + case AEBI_PAUTHABI: + return "aeabi-pauthabi"; } } -enum SubsectionMandatory : unsigned { - OPTIONAL = 0, - REQUIRED = 1 -}; +enum SubsectionMandatory : unsigned { OPTIONAL = 0, REQUIRED = 1 }; -enum SubsectionType : unsigned { - ULEB128 = 0, - NTBS = 1 -}; +enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1 }; enum FeatureAndBitsTags : unsigned { Tag_PAuth_Platform = 1, @@ -136,20 +127,16 @@ enum AttrType : unsigned { MPextension_use_old = 70 // recoded to MPextension_use (ABI r2.08) }; -enum AVAttr { - AV_cpp_exceptions = 6, - AV_eba = 16 -}; +enum AVAttr { AV_cpp_exceptions = 6, AV_eba = 16 }; -StringRef AttrTypeAsString(StringRef Vendor, unsigned Attr, bool HasTagPrefix = true); +StringRef AttrTypeAsString(StringRef Vendor, unsigned Attr, + bool HasTagPrefix = true); StringRef AttrTypeAsString(AttrType Attr, bool HasTagPrefix = true); StringRef AttrTypeAsString(AVAttr Attr, bool HasTagPrefix = true); int AttrTypeFromString(StringRef Vendor, StringRef Tag); // Magic numbers for .ARM.attributes -enum AttrMagic { - Format_Version = 0x41 -}; +enum AttrMagic { Format_Version = 0x41 }; // Legal Values for CPU_arch, (=6), uleb128 enum CPUArch { diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 34a7367a18f44..576d4997a3dea 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -635,8 +635,9 @@ void MCELFStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, llvm_unreachable("ELF doesn't support this directive"); } -void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value, - bool OverwriteExisting, SmallVector &Attributes) { +void MCELFStreamer::setAttributeItem( + unsigned Attribute, unsigned Value, bool OverwriteExisting, + SmallVector &Attributes) { // Look for existing attribute item if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { if (!OverwriteExisting) @@ -652,8 +653,9 @@ void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value, Contents.push_back(Item); } -void MCELFStreamer::setAttributeItem(unsigned Attribute, StringRef Value, - bool OverwriteExisting, SmallVector &Attributes) { +void MCELFStreamer::setAttributeItem( + unsigned Attribute, StringRef Value, bool OverwriteExisting, + SmallVector &Attributes) { // Look for existing attribute item if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { if (!OverwriteExisting) @@ -669,9 +671,9 @@ void MCELFStreamer::setAttributeItem(unsigned Attribute, StringRef Value, Contents.push_back(Item); } -void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue, - StringRef StringValue, - bool OverwriteExisting, SmallVector &Attributes) { +void MCELFStreamer::setAttributeItems( + unsigned Attribute, unsigned IntValue, StringRef StringValue, + bool OverwriteExisting, SmallVector &Attributes) { // Look for existing attribute item if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { if (!OverwriteExisting) @@ -689,15 +691,16 @@ void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue, } MCELFStreamer::AttributeItem * -MCELFStreamer::getAttributeItem(unsigned Attribute, SmallVector &Attributes) { +MCELFStreamer::getAttributeItem(unsigned Attribute, + SmallVector &Attributes) { for (AttributeItem &Item : Attributes) if (Item.Tag == Attribute) return &Item; return nullptr; } -size_t -MCELFStreamer::calculateContentSize(SmallVector &AttrsVec) const { +size_t MCELFStreamer::calculateContentSize( + SmallVector &AttrsVec) const { size_t Result = 0; for (const AttributeItem &Item : AttrsVec) { switch (Item.Type) { @@ -783,14 +786,15 @@ void MCELFStreamer::createAttributesSection( AttrsVec.clear(); } -void MCELFStreamer::createAttributesSection(MCSection *&AttributeSection, - const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { -// -// [ NTBS: vendor-name -// -// ]* -// vendor-data expends to: -// * +void MCELFStreamer::createAttributesSection( + MCSection *&AttributeSection, const Twine &Section, unsigned Type, + SmallVector &SubSectionVec) { + // + // [ NTBS: vendor-name + // + // ]* + // vendor-data expends to: + // * if (SubSectionVec.size() == 0) { return; } @@ -821,20 +825,20 @@ void MCELFStreamer::createAttributesSection(MCSection *&AttributeSection, for (AttributeItem &Item : SubSection.Content) { emitULEB128IntValue(Item.Tag); switch (Item.Type) { - default: - llvm_unreachable("Invalid attribute type"); - case AttributeItem::NumericAttribute: - emitULEB128IntValue(Item.IntValue); - break; - case AttributeItem::TextAttribute: - emitBytes(Item.StringValue); - emitInt8(0); // '\0' - break; - case AttributeItem::NumericAndTextAttributes: - emitULEB128IntValue(Item.IntValue); - emitBytes(Item.StringValue); - emitInt8(0); // '\0' - break; + default: + llvm_unreachable("Invalid attribute type"); + case AttributeItem::NumericAttribute: + emitULEB128IntValue(Item.IntValue); + break; + case AttributeItem::TextAttribute: + emitBytes(Item.StringValue); + emitInt8(0); // '\0' + break; + case AttributeItem::NumericAndTextAttributes: + emitULEB128IntValue(Item.IntValue); + emitBytes(Item.StringValue); + emitInt8(0); // '\0' + break; } } } diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index 96d0f312d734c..457e7d66a7e87 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -70,26 +70,26 @@ const TagNameItem ARMAttributeTags[] = { }; const TagNameItem AVAttributeTags[] = { - { ARMBuildAttrs::AV_cpp_exceptions, "Tag_AV_cpp_exceptions" }, - { ARMBuildAttrs::AV_eba, "Tag_AV_eba" }, + {ARMBuildAttrs::AV_cpp_exceptions, "Tag_AV_cpp_exceptions"}, + {ARMBuildAttrs::AV_eba, "Tag_AV_eba"}, }; -template int FromString(T (&Table)[N], StringRef Tag) { +template int FromString(T (&Table)[N], StringRef Tag) { bool HasTagPrefix = Tag.starts_with("Tag_"); - for (unsigned TI = 0; TI < N; ++TI) + for (unsigned TI = 0; TI < N; ++TI) if (Table[TI].tagName.drop_front(HasTagPrefix ? 0 : 4) == Tag) return Table[TI].attr; return -1; } -template +template StringRef AsString(T (&Table)[N], A Attr, bool HasTagPrefix) { for (unsigned TI = 0; TI < N; ++TI) if (Table[TI].attr == Attr) return Table[TI].tagName.drop_front(HasTagPrefix ? 0 : 4); return StringRef(); } -} +} // namespace namespace llvm { namespace ARMBuildAttrs { @@ -120,5 +120,5 @@ int AttrTypeFromString(StringRef Vendor, StringRef Tag) { static constexpr TagNameMap tagNameMap(ARMAttributeTags); const TagNameMap &getARMAttributeTags() { return tagNameMap; } -} -} +} // namespace ARMBuildAttrs +} // namespace llvm diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index f5e6a580fcd6a..ca60e249e1421 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -202,7 +202,8 @@ class AArch64AsmPrinter : public AsmPrinter { bool lowerPseudoInstExpansion(const MachineInstr *MI, MCInst &Inst); // Emit Build Attributes - void emitAttributes(unsigned Flags, uint64_t PAuthABIPlatform, uint64_t PAuthABIVersion, AArch64TargetStreamer* TS); + void emitAttributes(unsigned Flags, uint64_t PAuthABIPlatform, + uint64_t PAuthABIVersion, AArch64TargetStreamer *TS); void EmitToStreamer(MCStreamer &S, const MCInst &Inst); void EmitToStreamer(const MCInst &Inst) { @@ -337,8 +338,10 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { return; // For emitting build attributes and .note.gnu.property section - auto *TS = static_cast(OutStreamer->getTargetStreamer()); - // Assemble feature flags that may require creation of build attributes and a note section. + auto *TS = + static_cast(OutStreamer->getTargetStreamer()); + // Assemble feature flags that may require creation of build attributes and a + // note section. unsigned BAFlags = 0; unsigned GNUFlags = 0; if (const auto *BTE = mdconst::extract_or_null( @@ -453,26 +456,35 @@ void AArch64AsmPrinter::emitSled(const MachineInstr &MI, SledKind Kind) { recordSled(CurSled, MI, Kind, 2); } -void AArch64AsmPrinter::emitAttributes(unsigned Flags, uint64_t PAuthABIPlatform, uint64_t PAuthABIVersion, AArch64TargetStreamer* TS) { +void AArch64AsmPrinter::emitAttributes(unsigned Flags, + uint64_t PAuthABIPlatform, + uint64_t PAuthABIVersion, + AArch64TargetStreamer *TS) { PAuthABIPlatform = (PAuthABIPlatform == uint64_t(-1)) ? 0 : PAuthABIPlatform; PAuthABIVersion = (PAuthABIVersion == uint64_t(-1)) ? 0 : PAuthABIVersion; - if(PAuthABIPlatform || PAuthABIVersion) { + if (PAuthABIPlatform || PAuthABIVersion) { TS->emitSubsection(ARMBuildAttrs::AEBI_PAUTHABI, 0, 0); - TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, ARMBuildAttrs::Tag_PAuth_Platform, PAuthABIPlatform, false); - TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, ARMBuildAttrs::Tag_PAuth_Schema, PAuthABIVersion, false); + TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, + ARMBuildAttrs::Tag_PAuth_Platform, PAuthABIPlatform, + false); + TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, + ARMBuildAttrs::Tag_PAuth_Schema, PAuthABIVersion, false); } unsigned BTIValue = (Flags & ARMBuildAttrs::Feature_BTI_Flag) ? 1 : 0; unsigned PACValue = (Flags & ARMBuildAttrs::Feature_PAC_Flag) ? 1 : 0; unsigned GCSValue = (Flags & ARMBuildAttrs::Feature_GCS_Flag) ? 1 : 0; - if(BTIValue || PACValue || GCSValue) { + if (BTIValue || PACValue || GCSValue) { TS->emitSubsection(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, 1, 0); - TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_BTI, BTIValue, false); - TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_PAC, PACValue, false); - TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_GCS, GCSValue, false); + TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, + ARMBuildAttrs::Tag_Feature_BTI, BTIValue, false); + TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, + ARMBuildAttrs::Tag_Feature_PAC, PACValue, false); + TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, + ARMBuildAttrs::Tag_Feature_GCS, GCSValue, false); } } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index e57b070313738..cb594785a09d2 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -151,69 +151,83 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { OS << "\t.seh_save_any_reg_px\tq" << Reg << ", " << Offset << "\n"; } - void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) override { + void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, + bool Override) override { // AArch64 build attributes for assembly attribute form: // .aeabi_attribute tag, value - switch(Vendor) { - default: llvm_unreachable("unknown AArch64 build attributes subsection name"); - - case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: - switch(Tag) { - default: llvm_unreachable("unknown tag for the feature-and-bits subsection"); - case ARMBuildAttrs::Tag_Feature_BTI: - OS << "\t.aeabi_attribute\t" << "Tag_Feature_BTI" << ", " << Value; - break; - case ARMBuildAttrs::Tag_Feature_GCS: - OS << "\t.aeabi_attribute\t" << "Tag_Feature_GCS" << ", " << Value; - break; - case ARMBuildAttrs::Tag_Feature_PAC: - OS << "\t.aeabi_attribute\t" << "Tag_Feature_PAC" << ", " << Value; - break; - } + switch (Vendor) { + default: + llvm_unreachable("unknown AArch64 build attributes subsection name"); + + case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: + switch (Tag) { + default: + llvm_unreachable("unknown tag for the feature-and-bits subsection"); + case ARMBuildAttrs::Tag_Feature_BTI: + OS << "\t.aeabi_attribute\t" << "Tag_Feature_BTI" << ", " << Value; + break; + case ARMBuildAttrs::Tag_Feature_GCS: + OS << "\t.aeabi_attribute\t" << "Tag_Feature_GCS" << ", " << Value; + break; + case ARMBuildAttrs::Tag_Feature_PAC: + OS << "\t.aeabi_attribute\t" << "Tag_Feature_PAC" << ", " << Value; break; + } + break; - case ARMBuildAttrs::AEBI_PAUTHABI: - switch(Tag) { - default: llvm_unreachable("unknown tag for the feature-and-bits subsection"); - case ARMBuildAttrs::Tag_PAuth_Platform: - OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Platform" << ", " << Value; - break; - case ARMBuildAttrs::Tag_PAuth_Schema: - OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Schema" << ", " << Value; - break; + case ARMBuildAttrs::AEBI_PAUTHABI: + switch (Tag) { + default: + llvm_unreachable("unknown tag for the feature-and-bits subsection"); + case ARMBuildAttrs::Tag_PAuth_Platform: + OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Platform" << ", " << Value; break; - } + case ARMBuildAttrs::Tag_PAuth_Schema: + OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Schema" << ", " << Value; + break; + break; + } } OS << "\n"; } - void emitSubsection(unsigned SubsectionName, unsigned Optional, unsigned ParameterType) override { + void emitSubsection(unsigned SubsectionName, unsigned Optional, + unsigned ParameterType) override { // The AArch64 build attributes assembly subsection header format: // ".aeabi_subsection name, optional, parameter type" // optional: required (0) optional (1) // parameter type: uleb128 or ULEB128 (0) ntbs or NTBS (1) - assert((Optional == 0 || Optional == 1) && "unsupported parameter for Optional"); - assert((ParameterType == 0 || ParameterType == 1) && "unsupported parameter for ParameterType"); + assert((Optional == 0 || Optional == 1) && + "unsupported parameter for Optional"); + assert((ParameterType == 0 || ParameterType == 1) && + "unsupported parameter for ParameterType"); StringRef OptionalStr = Optional ? "optional" : "required"; StringRef ParameterStr = ParameterType ? "NTBS" : "ULEB128"; - switch(SubsectionName) { - default: llvm_unreachable("unknown AArch64 build attributes subsection name"); - - case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: - assert(Optional == 1 && "subsection .aeabi-feature-and-bits should be marked as optional and not as mandatory"); - assert(ParameterType == 0 && "subsection .aeabi-feature-and-bits should be marked as uleb128 and not as ntbs"); - OS << "\t.aeabi_subsection\t" << ".aeabi-feature-and-bits" << ", " << OptionalStr << ", " << ParameterStr; - break; + switch (SubsectionName) { + default: + llvm_unreachable("unknown AArch64 build attributes subsection name"); + + case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: + assert(Optional == 1 && "subsection .aeabi-feature-and-bits should be " + "marked as optional and not as mandatory"); + assert(ParameterType == 0 && "subsection .aeabi-feature-and-bits should " + "be marked as uleb128 and not as ntbs"); + OS << "\t.aeabi_subsection\t" << ".aeabi-feature-and-bits" << ", " + << OptionalStr << ", " << ParameterStr; + break; - case ARMBuildAttrs::AEBI_PAUTHABI: - assert(Optional == 0 && "subsection .aeabi-pauthabi should be marked as mandatory and not as optional"); - assert(ParameterType == 0 && "subsection .aeabi-pauthabi should be marked as uleb128 and not as ntbs"); - OS << "\t.aeabi_subsection\t" << ".aeabi-pauthabi" << ", " << OptionalStr << ", " << ParameterStr; - break; + case ARMBuildAttrs::AEBI_PAUTHABI: + assert(Optional == 0 && "subsection .aeabi-pauthabi should be marked as " + "mandatory and not as optional"); + assert(ParameterType == 0 && "subsection .aeabi-pauthabi should be " + "marked as uleb128 and not as ntbs"); + OS << "\t.aeabi_subsection\t" << ".aeabi-pauthabi" << ", " << OptionalStr + << ", " << ParameterStr; + break; } OS << "\n"; } @@ -224,7 +238,8 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { AArch64TargetAsmStreamer::AArch64TargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS) - : AArch64TargetStreamer(S), OS(OS), VendorTag("eabi"), IsVerboseAsm(S.isVerboseAsm()) {} + : AArch64TargetStreamer(S), OS(OS), VendorTag("eabi"), + IsVerboseAsm(S.isVerboseAsm()) {} void AArch64TargetAsmStreamer::emitInst(uint32_t Inst) { OS << "\t.inst\t0x" << Twine::utohexstr(Inst) << "\n"; @@ -364,7 +379,9 @@ AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() { return static_cast(Streamer); } -void AArch64TargetELFStreamer::emitSubsection(unsigned Vendor, unsigned IsMandatory, unsigned ParameterType) { +void AArch64TargetELFStreamer::emitSubsection(unsigned Vendor, + unsigned IsMandatory, + unsigned ParameterType) { StringRef VendorAsStr = ARMBuildAttrs::vendorToStr(Vendor); // If exists, return. @@ -382,11 +399,13 @@ void AArch64TargetELFStreamer::emitSubsection(unsigned Vendor, unsigned IsMandat AttributeSubSections.push_back(AttSubSection); } -void AArch64TargetELFStreamer::emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) { +void AArch64TargetELFStreamer::emitAttribute(unsigned Vendor, unsigned Tag, + unsigned Value, bool Override) { StringRef VendorAsStr = ARMBuildAttrs::vendorToStr(Vendor); if (AttributeSubSections.size() == 0) { - llvm_unreachable("Attribute can not be added unless the required AArch64 build attributes subsection exists"); + llvm_unreachable("Attribute can not be added unless the required AArch64 " + "build attributes subsection exists"); return; } @@ -408,7 +427,8 @@ void AArch64TargetELFStreamer::emitAttribute(unsigned Vendor, unsigned Tag, unsi return; } } - llvm_unreachable("Attribute can not be added unless the required AArch64 build attributes subsection exists"); + llvm_unreachable("Attribute can not be added unless the required AArch64 " + "build attributes subsection exists"); } void AArch64TargetELFStreamer::emitInst(uint32_t Inst) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index 7d90759cfc6e1..913754af6f266 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -92,8 +92,10 @@ class AArch64TargetStreamer : public MCTargetStreamer { virtual void emitARM64WinCFISaveAnyRegQPX(unsigned Reg, int Offset) {} /// Build attributes implementation - virtual void emitSubsection(unsigned Vendor, unsigned IsMandatory, unsigned ParameterType) {} - virtual void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) {} + virtual void emitSubsection(unsigned Vendor, unsigned IsMandatory, + unsigned ParameterType) {} + virtual void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, + bool Override) {} private: std::unique_ptr ConstantPools; @@ -108,8 +110,10 @@ class AArch64TargetELFStreamer : public AArch64TargetStreamer { SmallVector AttributeSubSections; /// Build attributes implementation - void emitSubsection(unsigned Vendor, unsigned IsMandatory, unsigned ParameterType) override; - void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) override; + void emitSubsection(unsigned Vendor, unsigned IsMandatory, + unsigned ParameterType) override; + void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, + bool Override) override; void emitInst(uint32_t Inst) override; void emitDirectiveVariantPCS(MCSymbol *Symbol) override; @@ -117,7 +121,7 @@ class AArch64TargetELFStreamer : public AArch64TargetStreamer { public: AArch64TargetELFStreamer(MCStreamer &S) - : AArch64TargetStreamer(S), CurrentVendor("aeabi") {} + : AArch64TargetStreamer(S), CurrentVendor("aeabi") {} }; class AArch64TargetWinCOFFStreamer : public llvm::AArch64TargetStreamer { diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index b6a16de748d9b..8c7fc4e7a1771 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -793,20 +793,23 @@ void ARMTargetELFStreamer::switchVendor(StringRef Vendor) { void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) { getStreamer().setAttributeItem(Attribute, Value, - /* OverwriteExisting= */ true, getStreamer().Contents); + /* OverwriteExisting= */ true, + getStreamer().Contents); } void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute, StringRef Value) { getStreamer().setAttributeItem(Attribute, Value, - /* OverwriteExisting= */ true, getStreamer().Contents); + /* OverwriteExisting= */ true, + getStreamer().Contents); } void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) { getStreamer().setAttributeItems(Attribute, IntValue, StringValue, - /* OverwriteExisting= */ true, getStreamer().Contents); + /* OverwriteExisting= */ true, + getStreamer().Contents); } void ARMTargetELFStreamer::emitArch(ARM::ArchKind Value) { @@ -821,12 +824,15 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { using namespace ARMBuildAttrs; ARMELFStreamer &S = getStreamer(); - S.setAttributeItem(CPU_name, ARM::getCPUAttr(Arch), false, getStreamer().Contents); + S.setAttributeItem(CPU_name, ARM::getCPUAttr(Arch), false, + getStreamer().Contents); if (EmittedArch == ARM::ArchKind::INVALID) - S.setAttributeItem(CPU_arch, ARM::getArchAttr(Arch), false, getStreamer().Contents); + S.setAttributeItem(CPU_arch, ARM::getArchAttr(Arch), false, + getStreamer().Contents); else - S.setAttributeItem(CPU_arch, ARM::getArchAttr(EmittedArch), false, getStreamer().Contents); + S.setAttributeItem(CPU_arch, ARM::getArchAttr(EmittedArch), false, + getStreamer().Contents); switch (Arch) { case ARM::ArchKind::ARMV4: @@ -843,15 +849,17 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { break; case ARM::ArchKind::ARMV6T2: - S.setAttributeItem(ARM_ISA_use, Allowed, false,getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, + getStreamer().Contents); break; case ARM::ArchKind::ARMV6K: case ARM::ArchKind::ARMV6KZ: S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(Virtualization_use, AllowTZ, false, getStreamer().Contents); + S.setAttributeItem(Virtualization_use, AllowTZ, false, + getStreamer().Contents); break; case ARM::ArchKind::ARMV6M: @@ -859,21 +867,27 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { break; case ARM::ArchKind::ARMV7A: - S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, + getStreamer().Contents); S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, + getStreamer().Contents); break; case ARM::ArchKind::ARMV7R: - S.setAttributeItem(CPU_arch_profile, RealTimeProfile, false, getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, RealTimeProfile, false, + getStreamer().Contents); S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, + getStreamer().Contents); break; case ARM::ArchKind::ARMV7EM: case ARM::ArchKind::ARMV7M: - S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, + getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, + getStreamer().Contents); break; case ARM::ArchKind::ARMV8A: @@ -893,17 +907,22 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { case ARM::ArchKind::ARMV9_4A: case ARM::ArchKind::ARMV9_5A: case ARM::ArchKind::ARMV9_6A: - S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, + getStreamer().Contents); S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, + getStreamer().Contents); S.setAttributeItem(MPextension_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(Virtualization_use, AllowTZVirtualization, false, getStreamer().Contents); + S.setAttributeItem(Virtualization_use, AllowTZVirtualization, false, + getStreamer().Contents); break; case ARM::ArchKind::ARMV8MBaseline: case ARM::ArchKind::ARMV8MMainline: - S.setAttributeItem(THUMB_ISA_use, AllowThumbDerived, false, getStreamer().Contents); - S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumbDerived, false, + getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, + getStreamer().Contents); break; case ARM::ArchKind::IWMMXT: diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp index d8a177a90a7a3..4bc205e3f4b6d 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -330,7 +330,8 @@ class HexagonTargetELFStreamer : public HexagonTargetStreamer { void emitAttribute(uint32_t Attribute, uint32_t Value) override { getStreamer().setAttributeItem(Attribute, Value, - /*OverwriteExisting=*/true, getStreamer().Contents); + /*OverwriteExisting=*/true, + getStreamer().Contents); } }; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp index ae536accb399a..b5e2338f379b6 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp @@ -57,19 +57,22 @@ void RISCVTargetELFStreamer::emitDirectiveOptionRelax() {} void RISCVTargetELFStreamer::emitDirectiveOptionNoRelax() {} void RISCVTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) { - getStreamer().setAttributeItem(Attribute, Value, /*OverwriteExisting=*/true, getStreamer().Contents); + getStreamer().setAttributeItem(Attribute, Value, /*OverwriteExisting=*/true, + getStreamer().Contents); } void RISCVTargetELFStreamer::emitTextAttribute(unsigned Attribute, StringRef String) { - getStreamer().setAttributeItem(Attribute, String, /*OverwriteExisting=*/true, getStreamer().Contents); + getStreamer().setAttributeItem(Attribute, String, /*OverwriteExisting=*/true, + getStreamer().Contents); } void RISCVTargetELFStreamer::emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) { getStreamer().setAttributeItems(Attribute, IntValue, StringValue, - /*OverwriteExisting=*/true, getStreamer().Contents); + /*OverwriteExisting=*/true, + getStreamer().Contents); } void RISCVTargetELFStreamer::finishAttributeSection() { From 8bc5b42531321f7ec8337dafa09305b9e5b7a257 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Fri, 6 Dec 2024 13:00:42 +0000 Subject: [PATCH 03/21] Fixing according to some comments: - make use of the enums - s/AEBI/AEABI/ - change function name (createAttributesSection) - remove AVAttribute code --- llvm/include/llvm/MC/MCELFStreamer.h | 17 +++--- .../include/llvm/Support/ARMBuildAttributes.h | 17 +----- llvm/lib/MC/MCELFStreamer.cpp | 2 +- llvm/lib/Support/ARMBuildAttrs.cpp | 59 ++----------------- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 18 +++--- .../MCTargetDesc/AArch64ELFStreamer.cpp | 19 +++--- .../MCTargetDesc/AArch64TargetStreamer.h | 10 ++-- 7 files changed, 43 insertions(+), 99 deletions(-) diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 0e37948d3d2b7..f32e8d323935e 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -13,6 +13,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCObjectStreamer.h" +#include "llvm/Support/ARMBuildAttributes.h" namespace llvm { @@ -113,10 +114,8 @@ class MCELFStreamer : public MCObjectStreamer { // [ NTBS: vendor-name ]* StringRef Vendor; // * - unsigned IsMandatory; // SubsectionMandatory::REQUIRED (0), - // SubsectionMandatory::OPTIONAL (1) - unsigned - ParameterType; // SubsectionType::ULEB128 (0), SubsectionType::NTBS (1) + ARMBuildAttrs::SubsectionMandatory IsMandatory; + ARMBuildAttrs::SubsectionType ParameterType; SmallVector Content; }; @@ -139,7 +138,8 @@ class MCELFStreamer : public MCObjectStreamer { emitAttributesSection(MCSection *&AttributeSection, const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { - createAttributesSection(AttributeSection, Section, Type, SubSectionVec); + createAArch64AttributesSection(AttributeSection, Section, Type, + SubSectionVec); } private: @@ -149,10 +149,9 @@ class MCELFStreamer : public MCObjectStreamer { void createAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection, SmallVector &AttrsVec); - void - createAttributesSection(MCSection *&AttributeSection, const Twine &Section, - unsigned Type, - SmallVector &SubSectionVec); + void createAArch64AttributesSection( + MCSection *&AttributeSection, const Twine &Section, unsigned Type, + SmallVector &SubSectionVec); // GNU attributes that will get emitted at the end of the asm file. SmallVector GNUAttributes; diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 788d72977d6f0..2c940fb20485e 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -28,16 +28,16 @@ namespace ARMBuildAttrs { const TagNameMap &getARMAttributeTags(); /// AArch64 build attributes vendors (=subsection name) -enum Vendor : unsigned { AEBI_FEATURE_AND_BITS = 0, AEBI_PAUTHABI = 1 }; +enum Vendor : unsigned { AEABI_FEATURE_AND_BITS = 0, AEABI_PAUTHABI = 1 }; inline StringRef vendorToStr(unsigned Vendor) { switch (Vendor) { default: llvm_unreachable("unknown AArch64 vendor name"); return ""; - case AEBI_FEATURE_AND_BITS: + case AEABI_FEATURE_AND_BITS: return "aeabi-feature-and-bits"; - case AEBI_PAUTHABI: + case AEABI_PAUTHABI: return "aeabi-pauthabi"; } } @@ -127,17 +127,6 @@ enum AttrType : unsigned { MPextension_use_old = 70 // recoded to MPextension_use (ABI r2.08) }; -enum AVAttr { AV_cpp_exceptions = 6, AV_eba = 16 }; - -StringRef AttrTypeAsString(StringRef Vendor, unsigned Attr, - bool HasTagPrefix = true); -StringRef AttrTypeAsString(AttrType Attr, bool HasTagPrefix = true); -StringRef AttrTypeAsString(AVAttr Attr, bool HasTagPrefix = true); -int AttrTypeFromString(StringRef Vendor, StringRef Tag); - -// Magic numbers for .ARM.attributes -enum AttrMagic { Format_Version = 0x41 }; - // Legal Values for CPU_arch, (=6), uleb128 enum CPUArch { Pre_v4 = 0, diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 576d4997a3dea..0f49d042233f0 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -786,7 +786,7 @@ void MCELFStreamer::createAttributesSection( AttrsVec.clear(); } -void MCELFStreamer::createAttributesSection( +void MCELFStreamer::createAArch64AttributesSection( MCSection *&AttributeSection, const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { // diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index 457e7d66a7e87..815cfc62a4b0e 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -6,13 +6,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/StringRef.h" #include "llvm/Support/ARMBuildAttributes.h" using namespace llvm; -namespace { -const TagNameItem ARMAttributeTags[] = { +static const TagNameItem tagData[] = { {ARMBuildAttrs::File, "Tag_File"}, {ARMBuildAttrs::Section, "Tag_Section"}, {ARMBuildAttrs::Symbol, "Tag_Symbol"}, @@ -69,56 +67,7 @@ const TagNameItem ARMAttributeTags[] = { {ARMBuildAttrs::ABI_align_preserved, "Tag_ABI_align8_preserved"}, }; -const TagNameItem AVAttributeTags[] = { - {ARMBuildAttrs::AV_cpp_exceptions, "Tag_AV_cpp_exceptions"}, - {ARMBuildAttrs::AV_eba, "Tag_AV_eba"}, -}; - -template int FromString(T (&Table)[N], StringRef Tag) { - bool HasTagPrefix = Tag.starts_with("Tag_"); - for (unsigned TI = 0; TI < N; ++TI) - if (Table[TI].tagName.drop_front(HasTagPrefix ? 0 : 4) == Tag) - return Table[TI].attr; - return -1; -} - -template -StringRef AsString(T (&Table)[N], A Attr, bool HasTagPrefix) { - for (unsigned TI = 0; TI < N; ++TI) - if (Table[TI].attr == Attr) - return Table[TI].tagName.drop_front(HasTagPrefix ? 0 : 4); - return StringRef(); +constexpr TagNameMap ARMAttributeTags{tagData}; +const TagNameMap &llvm::ARMBuildAttrs::getARMAttributeTags() { + return ARMAttributeTags; } -} // namespace - -namespace llvm { -namespace ARMBuildAttrs { -StringRef AttrTypeAsString(StringRef Vendor, unsigned Attr, bool HasTagPrefix) { - if (Vendor.equals_insensitive("aeabi") || Vendor.equals_insensitive("eabi")) - return AsString(ARMAttributeTags, static_cast(Attr), - HasTagPrefix); - else if (Vendor.equals_insensitive("arm")) - return AsString(AVAttributeTags, static_cast(Attr), HasTagPrefix); - return StringRef(); -} - -StringRef AttrTypeAsString(AttrType Attr, bool HasTagPrefix) { - return AsString(ARMAttributeTags, static_cast(Attr), HasTagPrefix); -} - -StringRef AttrTypeAsString(AVAttr Attr, bool HasTagPrefix) { - return AsString(AVAttributeTags, static_cast(Attr), HasTagPrefix); -} - -int AttrTypeFromString(StringRef Vendor, StringRef Tag) { - if (Vendor.equals_insensitive("aeabi") || Vendor.equals_insensitive("eabi")) - return FromString(ARMAttributeTags, Tag); - else if (Vendor.equals_insensitive("arm")) - return FromString(AVAttributeTags, Tag); - return -1; -} - -static constexpr TagNameMap tagNameMap(ARMAttributeTags); -const TagNameMap &getARMAttributeTags() { return tagNameMap; } -} // namespace ARMBuildAttrs -} // namespace llvm diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index ca60e249e1421..a12d41e22fb3d 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -465,11 +465,13 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, PAuthABIVersion = (PAuthABIVersion == uint64_t(-1)) ? 0 : PAuthABIVersion; if (PAuthABIPlatform || PAuthABIVersion) { - TS->emitSubsection(ARMBuildAttrs::AEBI_PAUTHABI, 0, 0); - TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, + TS->emitSubsection(ARMBuildAttrs::AEABI_PAUTHABI, + ARMBuildAttrs::SubsectionMandatory::OPTIONAL, + ARMBuildAttrs::SubsectionType::ULEB128); + TS->emitAttribute(ARMBuildAttrs::AEABI_PAUTHABI, ARMBuildAttrs::Tag_PAuth_Platform, PAuthABIPlatform, false); - TS->emitAttribute(ARMBuildAttrs::AEBI_PAUTHABI, + TS->emitAttribute(ARMBuildAttrs::AEABI_PAUTHABI, ARMBuildAttrs::Tag_PAuth_Schema, PAuthABIVersion, false); } @@ -478,12 +480,14 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, unsigned GCSValue = (Flags & ARMBuildAttrs::Feature_GCS_Flag) ? 1 : 0; if (BTIValue || PACValue || GCSValue) { - TS->emitSubsection(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, 1, 0); - TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, + TS->emitSubsection(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, + ARMBuildAttrs::SubsectionMandatory::REQUIRED, + ARMBuildAttrs::SubsectionType::ULEB128); + TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_BTI, BTIValue, false); - TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, + TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_PAC, PACValue, false); - TS->emitAttribute(ARMBuildAttrs::AEBI_FEATURE_AND_BITS, + TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, ARMBuildAttrs::Tag_Feature_GCS, GCSValue, false); } } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index cb594785a09d2..b9c70177436df 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -160,7 +160,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { default: llvm_unreachable("unknown AArch64 build attributes subsection name"); - case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: + case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: switch (Tag) { default: llvm_unreachable("unknown tag for the feature-and-bits subsection"); @@ -176,7 +176,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { } break; - case ARMBuildAttrs::AEBI_PAUTHABI: + case ARMBuildAttrs::AEABI_PAUTHABI: switch (Tag) { default: llvm_unreachable("unknown tag for the feature-and-bits subsection"); @@ -192,8 +192,9 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { OS << "\n"; } - void emitSubsection(unsigned SubsectionName, unsigned Optional, - unsigned ParameterType) override { + void emitSubsection(unsigned SubsectionName, + ARMBuildAttrs::SubsectionMandatory Optional, + ARMBuildAttrs::SubsectionType ParameterType) override { // The AArch64 build attributes assembly subsection header format: // ".aeabi_subsection name, optional, parameter type" // optional: required (0) optional (1) @@ -211,7 +212,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { default: llvm_unreachable("unknown AArch64 build attributes subsection name"); - case ARMBuildAttrs::AEBI_FEATURE_AND_BITS: + case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: assert(Optional == 1 && "subsection .aeabi-feature-and-bits should be " "marked as optional and not as mandatory"); assert(ParameterType == 0 && "subsection .aeabi-feature-and-bits should " @@ -220,7 +221,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { << OptionalStr << ", " << ParameterStr; break; - case ARMBuildAttrs::AEBI_PAUTHABI: + case ARMBuildAttrs::AEABI_PAUTHABI: assert(Optional == 0 && "subsection .aeabi-pauthabi should be marked as " "mandatory and not as optional"); assert(ParameterType == 0 && "subsection .aeabi-pauthabi should be " @@ -379,9 +380,9 @@ AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() { return static_cast(Streamer); } -void AArch64TargetELFStreamer::emitSubsection(unsigned Vendor, - unsigned IsMandatory, - unsigned ParameterType) { +void AArch64TargetELFStreamer::emitSubsection( + unsigned Vendor, ARMBuildAttrs::SubsectionMandatory IsMandatory, + ARMBuildAttrs::SubsectionType ParameterType) { StringRef VendorAsStr = ARMBuildAttrs::vendorToStr(Vendor); // If exists, return. diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index 913754af6f266..1aa207b40a932 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -92,8 +92,9 @@ class AArch64TargetStreamer : public MCTargetStreamer { virtual void emitARM64WinCFISaveAnyRegQPX(unsigned Reg, int Offset) {} /// Build attributes implementation - virtual void emitSubsection(unsigned Vendor, unsigned IsMandatory, - unsigned ParameterType) {} + virtual void emitSubsection(unsigned Vendor, + ARMBuildAttrs::SubsectionMandatory IsMandatory, + ARMBuildAttrs::SubsectionType ParameterType) {} virtual void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) {} @@ -110,8 +111,9 @@ class AArch64TargetELFStreamer : public AArch64TargetStreamer { SmallVector AttributeSubSections; /// Build attributes implementation - void emitSubsection(unsigned Vendor, unsigned IsMandatory, - unsigned ParameterType) override; + void emitSubsection(unsigned Vendor, + ARMBuildAttrs::SubsectionMandatory IsMandatory, + ARMBuildAttrs::SubsectionType ParameterType) override; void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, bool Override) override; From 6e09e352dd559bd54b4000593bfe913d5f78d1fe Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Fri, 6 Dec 2024 16:35:55 +0000 Subject: [PATCH 04/21] Add test files --- ...ld-attributes-aeabi-feature-and-bits-ASM.c | 30 +++++++++++++++++++ ...ld-attributes-aeabi-feature-and-bits-ELF.c | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c create mode 100644 clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c diff --git a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c new file mode 100644 index 0000000000000..2a64274b3f4f1 --- /dev/null +++ b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c @@ -0,0 +1,30 @@ +// Test AArch64 build attributes to assmebly: 'aeabi-feature-and-bits' + +// RUN: %clang --target=aarch64-none-elf -mbranch-protection=bti+pac-ret+gcs -S -o- %s | FileCheck %s -check-prefix=ALL +// RUN: %clang --target=aarch64-none-elf -mbranch-protection=bti -S -o- %s | FileCheck %s -check-prefix=BTI +// RUN: %clang --target=aarch64-none-elf -mbranch-protection=pac-ret -S -o- %s | FileCheck %s -check-prefix=PAC +// RUN: %clang --target=aarch64-none-elf -mbranch-protection=gcs -S -o- %s | FileCheck %s -check-prefix=GCS + +// ALL: .text +// ALL-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// ALL-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 +// ALL-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 +// ALL-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 + +// BTI: .text +// BTI-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// BTI-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 +// BTI-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 +// BTI-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 + +// PAC: .text +// PAC-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// PAC-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 +// PAC-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 +// PAC-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 + +// GCS: .text +// GCS-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// GCS-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 +// GCS-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 +// GCS-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 \ No newline at end of file diff --git a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c new file mode 100644 index 0000000000000..b4191a340128d --- /dev/null +++ b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c @@ -0,0 +1,30 @@ +// Test AArch64 build attributes to ELF: 'aeabi-feature-and-bits' + +// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=bti+pac-ret+gcs %s -o %t +// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=ALL +// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=bti %s -o %t +// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=BTI +// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=pac-ret %s -o %t +// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=PAC +// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=gcs %s -o %t +// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=GCS + +// ALL: Hex dump of section '.ARM.attributes': +// ALL-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu +// ALL-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000101 re-and-bits..... +// ALL-NEXT: 0x00000020 010201 + +// BTI: Hex dump of section '.ARM.attributes': +// BTI-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu +// BTI-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000101 re-and-bits..... +// BTI-NEXT: 0x00000020 000200 + +// PAC: Hex dump of section '.ARM.attributes': +// PAC-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu +// PAC-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000001 re-and-bits..... +// PAC-NEXT: 0x00000020 010200 + +// GCS: Hex dump of section '.ARM.attributes': +// GCS-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu +// GCS-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000001 re-and-bits..... +// GCS-NEXT: 0x00000020 000201 \ No newline at end of file From 3450b3503c1db65fd88ea09d6d08dfb8864a177b Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Tue, 17 Dec 2024 12:20:12 +0000 Subject: [PATCH 05/21] Add Asm parsing Add some fixes --- ...ld-attributes-aeabi-feature-and-bits-ASM.c | 10 +- ...ld-attributes-aeabi-feature-and-bits-ELF.c | 26 +-- llvm/include/llvm/MC/MCELFStreamer.h | 8 +- .../include/llvm/Support/ARMBuildAttributes.h | 77 +++++--- llvm/lib/MC/MCELFStreamer.cpp | 12 +- llvm/lib/Support/ARMBuildAttrs.cpp | 133 +++++++++++++ llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 24 +-- .../AArch64/AsmParser/AArch64AsmParser.cpp | 183 +++++++++++++++++- .../MCTargetDesc/AArch64ELFStreamer.cpp | 148 ++++++++------ .../MCTargetDesc/AArch64TargetStreamer.h | 25 ++- 10 files changed, 502 insertions(+), 144 deletions(-) diff --git a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c index 2a64274b3f4f1..a2c3229b3d86d 100644 --- a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c +++ b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c @@ -1,4 +1,4 @@ -// Test AArch64 build attributes to assmebly: 'aeabi-feature-and-bits' +// Test AArch64 build attributes to assmebly: 'aeabi_feature_and_bits' // RUN: %clang --target=aarch64-none-elf -mbranch-protection=bti+pac-ret+gcs -S -o- %s | FileCheck %s -check-prefix=ALL // RUN: %clang --target=aarch64-none-elf -mbranch-protection=bti -S -o- %s | FileCheck %s -check-prefix=BTI @@ -6,25 +6,25 @@ // RUN: %clang --target=aarch64-none-elf -mbranch-protection=gcs -S -o- %s | FileCheck %s -check-prefix=GCS // ALL: .text -// ALL-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// ALL-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 // ALL-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 // ALL-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 // ALL-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 // BTI: .text -// BTI-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// BTI-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 // BTI-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 // BTI-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 // BTI-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 // PAC: .text -// PAC-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// PAC-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 // PAC-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 // PAC-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 // PAC-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 // GCS: .text -// GCS-NEXT: .aeabi_subsection .aeabi-feature-and-bits, optional, ULEB128 +// GCS-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 // GCS-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 // GCS-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 // GCS-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 \ No newline at end of file diff --git a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c index b4191a340128d..64cd4f9e99589 100644 --- a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c +++ b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c @@ -1,4 +1,4 @@ -// Test AArch64 build attributes to ELF: 'aeabi-feature-and-bits' +// Test AArch64 build attributes to ELF: 'aeabi_feature_and_bits' // RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=bti+pac-ret+gcs %s -o %t // RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=ALL @@ -10,21 +10,21 @@ // RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=GCS // ALL: Hex dump of section '.ARM.attributes': -// ALL-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu -// ALL-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000101 re-and-bits..... -// ALL-NEXT: 0x00000020 010201 +// ALL-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +// ALL-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits..... +// ALL-NEXT: 0x00000020 01010201 // BTI: Hex dump of section '.ARM.attributes': -// BTI-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu -// BTI-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000101 re-and-bits..... -// BTI-NEXT: 0x00000020 000200 +// BTI-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +// BTI-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits..... +// BTI-NEXT: 0x00000020 01000200 // PAC: Hex dump of section '.ARM.attributes': -// PAC-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu -// PAC-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000001 re-and-bits..... -// PAC-NEXT: 0x00000020 010200 +// PAC-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +// PAC-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... +// PAC-NEXT: 0x00000020 01010200 // GCS: Hex dump of section '.ARM.attributes': -// GCS-NEXT: 0x00000000 41230000 00616561 62692d66 65617475 A#...aeabi-featu -// GCS-NEXT: 0x00000010 72652d61 6e642d62 69747301 00000001 re-and-bits..... -// GCS-NEXT: 0x00000020 000201 \ No newline at end of file +// GCS-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +// GCS-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... +// GCS-NEXT: 0x00000020 01000201 \ No newline at end of file diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index f32e8d323935e..80742e8c52fc3 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -98,7 +98,7 @@ class MCELFStreamer : public MCObjectStreamer { // This structure holds all attributes, accounting for their string / // numeric value, so we can later emit them in declaration order, keeping // all in the same vector. - enum { + enum Types { HiddenAttribute = 0, NumericAttribute, TextAttribute, @@ -107,14 +107,16 @@ class MCELFStreamer : public MCObjectStreamer { unsigned Tag; unsigned IntValue; std::string StringValue; + AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV) : Type(Ty), Tag(Tg), IntValue(IV), StringValue(SV) {} }; /// ELF object attributes subsection support struct AttributeSubSection { + bool IsActive; // Indicates whether the section is the active section, required for assembly parsing // [ NTBS: vendor-name ]* - StringRef Vendor; + StringRef VendorName; // * - ARMBuildAttrs::SubsectionMandatory IsMandatory; + ARMBuildAttrs::SubsectionOptional IsOptional; ARMBuildAttrs::SubsectionType ParameterType; SmallVector Content; }; diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 2c940fb20485e..2cb5f72d92733 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -19,50 +19,65 @@ #define LLVM_SUPPORT_ARMBUILDATTRIBUTES_H #include "llvm/Support/ELFAttributes.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/TableGen/Record.h" namespace llvm { class StringRef; namespace ARMBuildAttrs { - -const TagNameMap &getARMAttributeTags(); - -/// AArch64 build attributes vendors (=subsection name) -enum Vendor : unsigned { AEABI_FEATURE_AND_BITS = 0, AEABI_PAUTHABI = 1 }; - -inline StringRef vendorToStr(unsigned Vendor) { - switch (Vendor) { - default: - llvm_unreachable("unknown AArch64 vendor name"); - return ""; - case AEABI_FEATURE_AND_BITS: - return "aeabi-feature-and-bits"; - case AEABI_PAUTHABI: - return "aeabi-pauthabi"; - } -} - -enum SubsectionMandatory : unsigned { OPTIONAL = 0, REQUIRED = 1 }; - -enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1 }; - -enum FeatureAndBitsTags : unsigned { - Tag_PAuth_Platform = 1, - Tag_PAuth_Schema = 2 +// AArch64 build attributes +StringRef getSubsectionTag(); +StringRef getAttrTag(); + +/// AArch64 build attributes vendors IDs (a.k.a subsection name) +enum VendorID : unsigned { AEABI_FEATURE_AND_BITS = 0, AEABI_PAUTHABI = 1, VENDOR_NOT_FOUND = 404 }; +static const StringRef VendorName[] = { "aeabi_feature_and_bits", "aeabi_pauthabi" }; +StringRef getVendorName(unsigned const Vendor); +VendorID getVendorID(StringRef const Vendor); +StringRef getSubsectionUnknownError(); + +enum SubsectionOptional : unsigned { REQUIRED = 0, OPTIONAL = 1, OPTIONAL_NOT_FOUND = 404 }; +static const StringRef OptionalStr[] = { "required", "optional"}; +StringRef getOptionalStr(unsigned Optional); +SubsectionOptional getOptionalID(StringRef Optional); +StringRef getSubsectionOptionalUnknownError(); + +enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1, TYPE_NOT_FOUND = 404 }; +static const StringRef TypeStr[] = { "uleb128", "ntbs" }; +StringRef getTypeStr(unsigned Type); +SubsectionType getTypeID(StringRef Type); +StringRef getSubsectionTypeUnknownError(); + +enum PauthABITags : unsigned { + TAG_PAUTH_PLATFORM = 1, + TAG_PAUTH_SCHEMA = 2, + PAUTHABI_TAG_NOT_FOUND = 404 }; +static const StringRef PauthABITagsStr[] = { "Tag_PAuth_Platform", "Tag_PAuth_Schema"}; +StringRef getPauthABITagsStr(unsigned PauthABITag); +PauthABITags getPauthABITagsID(StringRef PauthABITag); +StringRef getPauthabiTagError(); -enum PauthabiTags : unsigned { - Tag_Feature_BTI = 0, - Tag_Feature_PAC = 1, - Tag_Feature_GCS = 2 +enum FeatureAndBitsTags : unsigned { + TAG_FEATURE_BTI = 0, + TAG_FEATURE_PAC = 1, + TAG_FEATURE_GCS = 2, + FEATURE_AND_BITS_TAG_NOT_FOUND = 404 }; +static const StringRef FeatureAndBitsTagsStr[] = { "Tag_Feature_BTI", "Tag_Feature_PAC", "Tag_Feature_GCS"}; +StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag); +FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag); +StringRef getFeatureAndBitsTagError(); -enum PauthabiTagsFlag : unsigned { +enum FeatureAndBitsFlag : unsigned { Feature_BTI_Flag = 1 << 0, Feature_PAC_Flag = 1 << 1, Feature_GCS_Flag = 1 << 2 }; -/// --- +///--- AArch64 build attributes + +const TagNameMap &getARMAttributeTags(); enum SpecialAttr { // This is for the .cpu asm attr. It translates into one or more diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 0f49d042233f0..b8cb24f3bdf21 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -795,7 +795,7 @@ void MCELFStreamer::createAArch64AttributesSection( // ]* // vendor-data expends to: // * - if (SubSectionVec.size() == 0) { + if (0 == SubSectionVec.size()) { return; } @@ -812,21 +812,23 @@ void MCELFStreamer::createAArch64AttributesSection( for (AttributeSubSection &SubSection : SubSectionVec) { // subsection-length + vendor-name + '\0' - const size_t VendorHeaderSize = 4 + SubSection.Vendor.size() + 1; + const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1; // optional + parameter-type const size_t VendorParameters = 1 + 1; const size_t ContentsSize = calculateContentSize(SubSection.Content); emitInt32(VendorHeaderSize + VendorParameters + ContentsSize); - emitBytes(SubSection.Vendor); - emitInt8(SubSection.IsMandatory); + emitBytes(SubSection.VendorName); + emitInt8(0); // '\0' + emitInt8(SubSection.IsOptional); emitInt8(SubSection.ParameterType); for (AttributeItem &Item : SubSection.Content) { emitULEB128IntValue(Item.Tag); switch (Item.Type) { default: - llvm_unreachable("Invalid attribute type"); + assert(0 && "Invalid attribute type"); + break; case AttributeItem::NumericAttribute: emitULEB128IntValue(Item.IntValue); break; diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index 815cfc62a4b0e..eb4ee5f6d15e0 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -8,6 +8,139 @@ #include "llvm/Support/ARMBuildAttributes.h" + +namespace llvm { + class StringRef; + namespace ARMBuildAttrs { + // AArch64 build attributes + StringRef getSubsectionTag() { return "aeabi_subsection"; } + StringRef getAttrTag() { return "aeabi_attribute"; } + + StringRef getVendorName(unsigned Vendor) { + switch (Vendor) { + case AEABI_FEATURE_AND_BITS: + return VendorName[AEABI_FEATURE_AND_BITS]; + case AEABI_PAUTHABI: + return VendorName[AEABI_PAUTHABI]; + case VENDOR_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown AArch64 vendor"); + return ""; + } + } + VendorID getVendorID(StringRef Vendor) { + if(Vendor == VendorName[AEABI_FEATURE_AND_BITS]) { + return AEABI_FEATURE_AND_BITS; + } + if(Vendor == VendorName[AEABI_PAUTHABI]) { + return AEABI_PAUTHABI; + } + assert(0 && "unknown AArch64 vendor"); + return VENDOR_NOT_FOUND; + } + StringRef getSubsectionUnknownError() { return "unknown AArch64 build attributes subsection"; } + + StringRef getOptionalStr(unsigned Optional) { + switch (Optional) { + case REQUIRED: + return OptionalStr[REQUIRED]; + case OPTIONAL: + return OptionalStr[OPTIONAL]; + case OPTIONAL_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown AArch64 Optional option"); + return ""; + } + } + SubsectionOptional getOptionalID(StringRef Optional) { + if(Optional == OptionalStr[REQUIRED]) + return REQUIRED; + if(Optional == OptionalStr[OPTIONAL]) + return OPTIONAL; + assert(0 && "unknown AArch64 Optional option"); + return OPTIONAL_NOT_FOUND; + } + StringRef getSubsectionOptionalUnknownError() { return "unknown AArch64 build attributes optionality, expecting required|optional"; } + + StringRef getTypeStr(unsigned Type) { + switch (Type) { + case ULEB128: + return TypeStr[ULEB128]; + case NTBS: + return TypeStr[NTBS]; + case TYPE_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown AArch64 subsection type"); + return ""; + } + } + SubsectionType getTypeID(StringRef Type) { + if(Type == TypeStr[ULEB128] || Type == (TypeStr[ULEB128].upper())) + return ULEB128; + if(Type == TypeStr[NTBS]|| Type == (TypeStr[NTBS].upper())) + return NTBS; + assert(0 && "unknown AArch64 subsection type"); + return TYPE_NOT_FOUND; + } + StringRef getSubsectionTypeUnknownError() { return "unknown AArch64 build attributes type, expecting uleb128 or ntbs"; } + + StringRef getPauthABITagsStr(unsigned PauthABITag) { + switch(PauthABITag) { + case TAG_PAUTH_PLATFORM: + return PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]; // Tag_PAuth_Platform = 1 in accordance with the spec + case TAG_PAUTH_SCHEMA: + return PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]; // Tag_PAuth_Schema = 2 in accordance with the spec + case PAUTHABI_TAG_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown pauthabi tag"); + return ""; + } + } + PauthABITags getPauthABITagsID(StringRef PauthABITag) { + if(PauthABITag == PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]) + return TAG_PAUTH_PLATFORM; + if(PauthABITag == PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]) + return TAG_PAUTH_SCHEMA; + assert(0 && "unknown FPauthABI tag"); + return PAUTHABI_TAG_NOT_FOUND; + } + StringRef getPauthabiTagError() { return "unknown tag for the AArch64 Pauthabi subsection"; } + + StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) { + switch(FeatureAndBitsTag) { + case TAG_FEATURE_BTI: + return FeatureAndBitsTagsStr[TAG_FEATURE_BTI]; + case TAG_FEATURE_PAC: + return FeatureAndBitsTagsStr[TAG_FEATURE_PAC]; + case TAG_FEATURE_GCS: + return FeatureAndBitsTagsStr[TAG_FEATURE_GCS]; + case FEATURE_AND_BITS_TAG_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown feature and bits tag"); + return ""; + } + } + FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) { + if(FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_BTI]) + return TAG_FEATURE_BTI; + if(FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_PAC]) + return TAG_FEATURE_PAC; + if(FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_GCS]) + return TAG_FEATURE_GCS; + assert(0 && "unknown Feature and Bits tag"); + return FEATURE_AND_BITS_TAG_NOT_FOUND; + } + StringRef getFeatureAndBitsTagError() { return "unknown tag for the AArch64 Feature And Bits subsection"; } + ///--- AArch64 build attributes + } // namespace ARMBuildAttrs +} // namespace llvm + + using namespace llvm; static const TagNameItem tagData[] = { diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index a12d41e22fb3d..c78b2f3196f1a 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -347,7 +347,7 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { if (const auto *BTE = mdconst::extract_or_null( M.getModuleFlag("branch-target-enforcement"))) { if (!BTE->isZero()) { - BAFlags |= ARMBuildAttrs::PauthabiTagsFlag::Feature_BTI_Flag; + BAFlags |= ARMBuildAttrs::FeatureAndBitsFlag::Feature_BTI_Flag; GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI; } } @@ -355,7 +355,7 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { if (const auto *GCS = mdconst::extract_or_null( M.getModuleFlag("guarded-control-stack"))) { if (!GCS->isZero()) { - BAFlags |= ARMBuildAttrs::PauthabiTagsFlag::Feature_GCS_Flag; + BAFlags |= ARMBuildAttrs::FeatureAndBitsFlag::Feature_GCS_Flag; GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_GCS; } } @@ -363,7 +363,7 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { if (const auto *Sign = mdconst::extract_or_null( M.getModuleFlag("sign-return-address"))) { if (!Sign->isZero()) { - BAFlags |= ARMBuildAttrs::PauthabiTagsFlag::Feature_PAC_Flag; + BAFlags |= ARMBuildAttrs::FeatureAndBitsFlag::Feature_PAC_Flag; GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_PAC; } } @@ -461,18 +461,18 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, uint64_t PAuthABIVersion, AArch64TargetStreamer *TS) { - PAuthABIPlatform = (PAuthABIPlatform == uint64_t(-1)) ? 0 : PAuthABIPlatform; - PAuthABIVersion = (PAuthABIVersion == uint64_t(-1)) ? 0 : PAuthABIVersion; + PAuthABIPlatform = (uint64_t(-1) == PAuthABIPlatform) ? 0 : PAuthABIPlatform; + PAuthABIVersion = (uint64_t(-1) == PAuthABIVersion) ? 0 : PAuthABIVersion; if (PAuthABIPlatform || PAuthABIVersion) { TS->emitSubsection(ARMBuildAttrs::AEABI_PAUTHABI, - ARMBuildAttrs::SubsectionMandatory::OPTIONAL, + ARMBuildAttrs::SubsectionOptional::REQUIRED, ARMBuildAttrs::SubsectionType::ULEB128); TS->emitAttribute(ARMBuildAttrs::AEABI_PAUTHABI, - ARMBuildAttrs::Tag_PAuth_Platform, PAuthABIPlatform, + ARMBuildAttrs::TAG_PAUTH_PLATFORM, PAuthABIPlatform, false); TS->emitAttribute(ARMBuildAttrs::AEABI_PAUTHABI, - ARMBuildAttrs::Tag_PAuth_Schema, PAuthABIVersion, false); + ARMBuildAttrs::TAG_PAUTH_SCHEMA, PAuthABIVersion, false); } unsigned BTIValue = (Flags & ARMBuildAttrs::Feature_BTI_Flag) ? 1 : 0; @@ -481,14 +481,14 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, if (BTIValue || PACValue || GCSValue) { TS->emitSubsection(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::SubsectionMandatory::REQUIRED, + ARMBuildAttrs::SubsectionOptional::OPTIONAL, ARMBuildAttrs::SubsectionType::ULEB128); TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::Tag_Feature_BTI, BTIValue, false); + ARMBuildAttrs::TAG_FEATURE_BTI, BTIValue, false); TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::Tag_Feature_PAC, PACValue, false); + ARMBuildAttrs::TAG_FEATURE_PAC, PACValue, false); TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::Tag_Feature_GCS, GCSValue, false); + ARMBuildAttrs::TAG_FEATURE_GCS, GCSValue, false); } } diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index a9ba35899160c..c17e24e44f3ae 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -42,6 +42,7 @@ #include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/MCValue.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" @@ -228,6 +229,8 @@ class AArch64AsmParser : public MCTargetAsmParser { bool parseDirectiveSEHClearUnwoundToCall(SMLoc L); bool parseDirectiveSEHPACSignLR(SMLoc L); bool parseDirectiveSEHSaveAnyReg(SMLoc L, bool Paired, bool Writeback); + bool parseDirectiveAeabiSubSectionHeader(SMLoc L); + bool parseDirectiveAeabiAArch64Attr(SMLoc L); bool validateInstruction(MCInst &Inst, SMLoc &IDLoc, SmallVectorImpl &Loc); @@ -7064,8 +7067,12 @@ bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) { parseDirectiveSEHSaveAnyReg(Loc, true, true); else return true; - } else - return true; + } else if (!IsMachO && !IsCOFF) { + if (IDVal == ".aeabi_subsection") + parseDirectiveAeabiSubSectionHeader(Loc); + else if (IDVal == ".aeabi_attribute") + parseDirectiveAeabiAArch64Attr(Loc); + } else return true; return false; } @@ -7800,6 +7807,178 @@ bool AArch64AsmParser::parseDirectiveSEHSaveAnyReg(SMLoc L, bool Paired, return false; } +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. + MCAsmParser &Parser = getParser(); + + // Consume the name (subsection name) + StringRef SubsectionName; + ARMBuildAttrs::VendorID SubsectionNameID; + if (Parser.getTok().is(AsmToken::Identifier)) { + StringRef SubsectionName = Parser.getTok().getIdentifier(); + SubsectionNameID = ARMBuildAttrs::getVendorID(SubsectionName); + if (ARMBuildAttrs::VENDOR_NOT_FOUND == SubsectionNameID) { + Error(Parser.getTok().getLoc(), ARMBuildAttrs::getSubsectionUnknownError() + ": " + SubsectionName); + } + } else { + Error(Parser.getTok().getLoc(), "Expecting subsection name"); + return true; + } + Parser.Lex(); + // consume a comma + // parseComma() return *false* on success, and call Lex(), no need to call Lex() again. + if (Parser.parseComma()) { + Error(Parser.getTok().getLoc(), "expected ','"); + return true; + } + + // Consume the first parameter (optionality parameter) + ARMBuildAttrs::SubsectionOptional IsOptional; + // options: optional/required + if (Parser.getTok().is(AsmToken::Identifier)) { + StringRef Name = Parser.getTok().getIdentifier(); + IsOptional = ARMBuildAttrs::getOptionalID(Name); + if (ARMBuildAttrs::OPTIONAL_NOT_FOUND == IsOptional) { + Error(Parser.getTok().getLoc(), ARMBuildAttrs::getSubsectionOptionalUnknownError() + ": " + Name); + return true; + } + } else { + Error(Parser.getTok().getLoc(), "Expecitng optionality parameter \n Hint: use 'optional' | 'required'"); + return true; + } + // Check for possible IsOptional unaccepted values for known subsections + if (ARMBuildAttrs::AEABI_FEATURE_AND_BITS == SubsectionNameID) { + if (ARMBuildAttrs::REQUIRED == IsOptional) { + Error(Parser.getTok().getLoc(), "aeabi_feature_and_bits must be marked as optional"); + return true; + } + } + if (ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { + if (ARMBuildAttrs::OPTIONAL == IsOptional) { + Error(Parser.getTok().getLoc(), "aeabi_pauthabi must be marked as required"); + return true; + } + } + Parser.Lex(); + // consume a comma + if (Parser.parseComma()) { + Error(Parser.getTok().getLoc(), "expected ','"); + return true; + } + + // Consume the second parameter (type parameter) + ARMBuildAttrs::SubsectionType Type; + if (Parser.getTok().is(AsmToken::Identifier)) { + StringRef Name = Parser.getTok().getIdentifier(); + Type = ARMBuildAttrs::getTypeID(Name); + if (ARMBuildAttrs::TYPE_NOT_FOUND == Type) { + Error(Parser.getTok().getLoc(), ARMBuildAttrs::getSubsectionTypeUnknownError() + ": " + Name); + return true; + } + } else { + Error(Parser.getTok().getLoc(), "Expecitng type parameter"); + return true; + } + // Check for possible Type unaccepted values for known subsections + if (ARMBuildAttrs::AEABI_FEATURE_AND_BITS == SubsectionNameID || ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { + if (ARMBuildAttrs::NTBS == Type) { + Error(Parser.getTok().getLoc(), SubsectionName + "must be marked as ULEB128"); + return true; + } + } + Parser.Lex(); + // Parsing finished, check for trailing tokens. + if (Parser.getTok().isNot(llvm::AsmToken::EndOfStatement)) { + Error(Parser.getTok().getLoc(), "unexpected token for AArch64 build attributes subsection header directive"); + return true; + } + + getTargetStreamer().emitSubsection(SubsectionNameID, IsOptional, Type); + + return false; +} + +bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { + // Expecting 2 Tokens: after '.aeabi_attribute', e.g.: + // .aeabi_attribute (1)Tag_Feature_BTI, (2)1 + // separated by a comma. + MCAsmParser &Parser = getParser(); + + StringRef ActiveSubsection = ""; + unsigned ActiveSubsectionID; + StringRef TagStr = ""; + unsigned Tag; + if (Parser.getTok().is(AsmToken::Identifier)) { + TagStr = Parser.getTok().getIdentifier(); + ActiveSubsection = getTargetStreamer().getActiveSubsection(); + if ("" == ActiveSubsection) { + Error(Parser.getTok().getLoc(), "no active subsection, build attribute can not be added"); + return true; + } + if(ARMBuildAttrs::VendorName[ARMBuildAttrs::AEABI_PAUTHABI] == ActiveSubsection) { + ActiveSubsectionID = ARMBuildAttrs::AEABI_PAUTHABI; + Tag = ARMBuildAttrs::getPauthABITagsID(TagStr); + if (ARMBuildAttrs::PAUTHABI_TAG_NOT_FOUND == Tag) { + Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + "' for subsection '" + ActiveSubsection + "'"); + return true; + } + } else if(ARMBuildAttrs::VendorName[ARMBuildAttrs::AEABI_FEATURE_AND_BITS] == ActiveSubsection) { + ActiveSubsectionID = ARMBuildAttrs::AEABI_FEATURE_AND_BITS; + Tag = ARMBuildAttrs::getFeatureAndBitsTagsID(TagStr); + if (ARMBuildAttrs::FEATURE_AND_BITS_TAG_NOT_FOUND == Tag) { + Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + "' for subsection '" + ActiveSubsection + "' \n Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, Tag_Feature_GCS"); + return true; + } + } + // for compatability + } else if(Parser.getTok().is(AsmToken::Integer)) { + Tag = getTok().getIntVal(); + } else { + Error(Parser.getTok().getLoc(), "AArch64 build attributes Tag not found"); + return true; + } + Parser.Lex(); + // consume a comma + // parseComma() return *false* on success, and call Lex(), no need to call Lex() again. + if (Parser.parseComma()) { + Error(Parser.getTok().getLoc(), "expected ','"); + return true; + } + + // Consume the second parameter (attribute value) + unsigned Value; + if (Parser.getTok().is(AsmToken::Integer)) { + Value = getTok().getIntVal(); + } else { + Error(Parser.getTok().getLoc(), "AArch64 build attributes Value not found"); + return true; + } + // Check for possible unaccepted values for known tags + if (TagStr != "") { // Tag was a recognized string + if (0 != Value && 1 != Value) { + Error(Parser.getTok().getLoc(), "Unknown AArch64 build attributes Value for Tag '" + TagStr + "' \n Hint: options are '0'|'1'"); + return true; + } + // Tag was an integer + } else if (0 == Tag || 1 == Tag || 2 == Tag) { // might be at attempt to represent known tags + if (0 != Value && 1 != Value) { + Warning(Parser.getTok().getLoc(), "Unknown AArch64 build attributes Value for any known AArch64 build attributes tags"); + } + } + Parser.Lex(); + // Parsing finished, check for trailing tokens. + if (Parser.getTok().isNot(llvm::AsmToken::EndOfStatement)) { + Error(Parser.getTok().getLoc(), "unexpected token for AArch64 build attributes tag and value attribute directive"); + return true; + } + + getTargetStreamer().emitAttribute(ActiveSubsectionID, Tag, Value, false); + + return false; +} + bool AArch64AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) { // Try @AUTH expressions: they're more complex than the usual symbol variants. if (!parseAuthExpr(Res, EndLoc)) diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index b9c70177436df..00d72d15f1cc6 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -151,27 +151,28 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { OS << "\t.seh_save_any_reg_px\tq" << Reg << ", " << Offset << "\n"; } - void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, + void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override) override { // AArch64 build attributes for assembly attribute form: // .aeabi_attribute tag, value - - switch (Vendor) { - default: - llvm_unreachable("unknown AArch64 build attributes subsection name"); - + switch (VendorID) { + default: { + assert(0 && ARMBuildAttrs::getSubsectionUnknownError().data()); + break; + } case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: switch (Tag) { default: - llvm_unreachable("unknown tag for the feature-and-bits subsection"); - case ARMBuildAttrs::Tag_Feature_BTI: - OS << "\t.aeabi_attribute\t" << "Tag_Feature_BTI" << ", " << Value; + assert(0 && ARMBuildAttrs::getFeatureAndBitsTagError().data()); break; - case ARMBuildAttrs::Tag_Feature_GCS: - OS << "\t.aeabi_attribute\t" << "Tag_Feature_GCS" << ", " << Value; + case ARMBuildAttrs::TAG_FEATURE_BTI: + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr(ARMBuildAttrs::TAG_FEATURE_BTI) << ", " << Value; break; - case ARMBuildAttrs::Tag_Feature_PAC: - OS << "\t.aeabi_attribute\t" << "Tag_Feature_PAC" << ", " << Value; + case ARMBuildAttrs::TAG_FEATURE_GCS: + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr(ARMBuildAttrs::TAG_FEATURE_GCS) << ", " << Value; + break; + case ARMBuildAttrs::TAG_FEATURE_PAC: + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr(ARMBuildAttrs::TAG_FEATURE_PAC) << ", " << Value; break; } break; @@ -179,12 +180,13 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { case ARMBuildAttrs::AEABI_PAUTHABI: switch (Tag) { default: - llvm_unreachable("unknown tag for the feature-and-bits subsection"); - case ARMBuildAttrs::Tag_PAuth_Platform: - OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Platform" << ", " << Value; + assert(0 && ARMBuildAttrs::getFeatureAndBitsTagError().data()); + break; + case ARMBuildAttrs::TAG_PAUTH_PLATFORM: + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getPauthABITagsStr(ARMBuildAttrs::TAG_PAUTH_PLATFORM) << ", " << Value; break; - case ARMBuildAttrs::Tag_PAuth_Schema: - OS << "\t.aeabi_attribute\t" << "Tag_PAuth_Schema" << ", " << Value; + case ARMBuildAttrs::TAG_PAUTH_SCHEMA: + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getPauthABITagsStr(ARMBuildAttrs::TAG_PAUTH_SCHEMA) << ", " << Value; break; break; } @@ -193,43 +195,48 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { } void emitSubsection(unsigned SubsectionName, - ARMBuildAttrs::SubsectionMandatory Optional, + ARMBuildAttrs::SubsectionOptional Optional, ARMBuildAttrs::SubsectionType ParameterType) override { // The AArch64 build attributes assembly subsection header format: // ".aeabi_subsection name, optional, parameter type" // optional: required (0) optional (1) // parameter type: uleb128 or ULEB128 (0) ntbs or NTBS (1) - assert((Optional == 0 || Optional == 1) && - "unsupported parameter for Optional"); - assert((ParameterType == 0 || ParameterType == 1) && - "unsupported parameter for ParameterType"); + assert(( 0 == Optional || 1 == Optional) && + ARMBuildAttrs::getSubsectionOptionalUnknownError().data()); + assert(( 0 == ParameterType || 1 == ParameterType) && + ARMBuildAttrs::getSubsectionTypeUnknownError().data()); - StringRef OptionalStr = Optional ? "optional" : "required"; - StringRef ParameterStr = ParameterType ? "NTBS" : "ULEB128"; + std::string SubsectionTag = ("." + ARMBuildAttrs::getSubsectionTag()).str(); + StringRef OptionalStr = getOptionalStr(Optional); + StringRef ParameterStr = getTypeStr(ParameterType); switch (SubsectionName) { - default: - llvm_unreachable("unknown AArch64 build attributes subsection name"); - - case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: - assert(Optional == 1 && "subsection .aeabi-feature-and-bits should be " - "marked as optional and not as mandatory"); - assert(ParameterType == 0 && "subsection .aeabi-feature-and-bits should " - "be marked as uleb128 and not as ntbs"); - OS << "\t.aeabi_subsection\t" << ".aeabi-feature-and-bits" << ", " - << OptionalStr << ", " << ParameterStr; + default: { + assert(0 && ARMBuildAttrs::getSubsectionUnknownError().data()); break; - - case ARMBuildAttrs::AEABI_PAUTHABI: - assert(Optional == 0 && "subsection .aeabi-pauthabi should be marked as " + } + case ARMBuildAttrs::AEABI_PAUTHABI: { + assert(ARMBuildAttrs::REQUIRED == Optional && "subsection .aeabi-pauthabi should be marked as " "mandatory and not as optional"); - assert(ParameterType == 0 && "subsection .aeabi-pauthabi should be " + assert(ARMBuildAttrs::ULEB128 == ParameterType && "subsection .aeabi-pauthabi should be " "marked as uleb128 and not as ntbs"); - OS << "\t.aeabi_subsection\t" << ".aeabi-pauthabi" << ", " << OptionalStr + StringRef SubsectionName = getVendorName(ARMBuildAttrs::AEABI_PAUTHABI); + OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; break; } + case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: { + assert( ARMBuildAttrs::OPTIONAL == Optional && "subsection .aeabi_feature_and_bits should be " + "marked as optional and not as mandatory"); + assert( ARMBuildAttrs::ULEB128 == ParameterType && "subsection .aeabi_feature_and_bits should " + "be marked as uleb128 and not as ntbs"); + StringRef SubsectionName = getVendorName(ARMBuildAttrs::AEABI_FEATURE_AND_BITS); + OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " + << OptionalStr << ", " << ParameterStr; + break; + } + } OS << "\n"; } @@ -380,56 +387,77 @@ AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() { return static_cast(Streamer); } +void AArch64TargetELFStreamer::activateSubsection(StringRef VendorName) { + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (VendorName == SubSection.VendorName) { + SubSection.IsActive = true; + } else { + SubSection.IsActive = false; + } + } +} + void AArch64TargetELFStreamer::emitSubsection( - unsigned Vendor, ARMBuildAttrs::SubsectionMandatory IsMandatory, + unsigned VendorID, ARMBuildAttrs::SubsectionOptional IsOptional, ARMBuildAttrs::SubsectionType ParameterType) { - StringRef VendorAsStr = ARMBuildAttrs::vendorToStr(Vendor); + StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); // If exists, return. for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { - if (SubSection.Vendor == VendorAsStr) { - llvm_unreachable("AArch64 build attributes subsection already exists"); + if (VendorName == SubSection.VendorName) { + // This path might be reached when an assembly directive switches attribute subsection. + activateSubsection(VendorName); return; } } // else, add the subsection MCELFStreamer::AttributeSubSection AttSubSection; - AttSubSection.Vendor = VendorAsStr; - AttSubSection.IsMandatory = IsMandatory; + AttSubSection.VendorName = VendorName; + AttSubSection.IsOptional = IsOptional; AttSubSection.ParameterType = ParameterType; AttributeSubSections.push_back(AttSubSection); + activateSubsection(VendorName); } -void AArch64TargetELFStreamer::emitAttribute(unsigned Vendor, unsigned Tag, +void AArch64TargetELFStreamer::emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override) { - StringRef VendorAsStr = ARMBuildAttrs::vendorToStr(Vendor); + StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); if (AttributeSubSections.size() == 0) { - llvm_unreachable("Attribute can not be added unless the required AArch64 " - "build attributes subsection exists"); + assert(0 && "Can not add AArch64 build attribute: no AArch64 subsection exists"); return; } for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { - if (SubSection.Vendor == VendorAsStr) { + if (VendorName == SubSection.VendorName) { + if (!SubSection.IsActive) { + assert(0 && "Can not add AArch64 build attribute: subsection is not active"); + return; + } for (MCELFStreamer::AttributeItem &Item : SubSection.Content) { if (Item.Tag == Tag) { if (!Override) { - llvm_unreachable("Attribute exists but override is set to false"); - return; + if (Item.IntValue != Value) { + assert(0 && "Can not add AArch64 build attribute: An attribute with the same tag and a different value allready exists"); + return; + } } } } - MCELFStreamer::AttributeItem AttItem; - AttItem.Type = AttItem.NumericAttribute; - AttItem.Tag = Tag; - AttItem.IntValue = Value; - SubSection.Content.push_back(AttItem); + SubSection.Content.push_back(MCELFStreamer::AttributeItem(MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); return; } } - llvm_unreachable("Attribute can not be added unless the required AArch64 " - "build attributes subsection exists"); + assert(0 && "Can not add AArch64 build attribute: required subsection does not exists"); +} + +StringRef AArch64TargetELFStreamer::getActiveSubsection() { + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (SubSection.IsActive) { + return SubSection.VendorName; + } + } + return ""; } void AArch64TargetELFStreamer::emitInst(uint32_t Inst) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index 1aa207b40a932..ddc0ab77abe0c 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -14,10 +14,7 @@ #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCStreamer.h" #include "llvm/Support/ARMBuildAttributes.h" -#include "llvm/TableGen/Record.h" -#include #include -#include namespace { class AArch64ELFStreamer; @@ -92,11 +89,13 @@ class AArch64TargetStreamer : public MCTargetStreamer { virtual void emitARM64WinCFISaveAnyRegQPX(unsigned Reg, int Offset) {} /// Build attributes implementation - virtual void emitSubsection(unsigned Vendor, - ARMBuildAttrs::SubsectionMandatory IsMandatory, + virtual void emitSubsection(unsigned VendorID, + ARMBuildAttrs::SubsectionOptional IsOptional, ARMBuildAttrs::SubsectionType ParameterType) {} - virtual void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, + virtual void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override) {} + virtual void activateSubsection(StringRef VendorName) {} + virtual StringRef getActiveSubsection() { return ""; } private: std::unique_ptr ConstantPools; @@ -104,26 +103,26 @@ class AArch64TargetStreamer : public MCTargetStreamer { class AArch64TargetELFStreamer : public AArch64TargetStreamer { private: - StringRef CurrentVendor; AArch64ELFStreamer &getStreamer(); MCSection *AttributeSection = nullptr; SmallVector AttributeSubSections; /// Build attributes implementation - void emitSubsection(unsigned Vendor, - ARMBuildAttrs::SubsectionMandatory IsMandatory, + void emitSubsection(unsigned VendorID, + ARMBuildAttrs::SubsectionOptional IsOptional, ARMBuildAttrs::SubsectionType ParameterType) override; - void emitAttribute(unsigned Vendor, unsigned Tag, unsigned Value, - bool Override) override; + void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, + bool Override = false) override; + void activateSubsection(StringRef VendorName) override; + StringRef getActiveSubsection() override; void emitInst(uint32_t Inst) override; void emitDirectiveVariantPCS(MCSymbol *Symbol) override; void finish() override; public: - AArch64TargetELFStreamer(MCStreamer &S) - : AArch64TargetStreamer(S), CurrentVendor("aeabi") {} + AArch64TargetELFStreamer(MCStreamer &S) : AArch64TargetStreamer(S) {} }; class AArch64TargetWinCOFFStreamer : public llvm::AArch64TargetStreamer { From b323e838f04a175a441c3f09a328e4ee065609e7 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Tue, 17 Dec 2024 13:34:17 +0000 Subject: [PATCH 06/21] Formatting --- llvm/include/llvm/MC/MCELFStreamer.h | 6 +- .../include/llvm/Support/ARMBuildAttributes.h | 25 +- llvm/lib/Support/ARMBuildAttrs.cpp | 261 +++++++++--------- .../AArch64/AsmParser/AArch64AsmParser.cpp | 116 +++++--- .../MCTargetDesc/AArch64ELFStreamer.cpp | 78 ++++-- 5 files changed, 283 insertions(+), 203 deletions(-) diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 80742e8c52fc3..06ce9884f15cf 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -107,12 +107,14 @@ class MCELFStreamer : public MCObjectStreamer { unsigned Tag; unsigned IntValue; std::string StringValue; - AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV) : Type(Ty), Tag(Tg), IntValue(IV), StringValue(SV) {} + AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV) + : Type(Ty), Tag(Tg), IntValue(IV), StringValue(SV) {} }; /// ELF object attributes subsection support struct AttributeSubSection { - bool IsActive; // Indicates whether the section is the active section, required for assembly parsing + bool IsActive; // Indicates whether the section is the active section, + // required for assembly parsing // [ NTBS: vendor-name ]* StringRef VendorName; // * diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 2cb5f72d92733..6d396842985dc 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -31,20 +31,29 @@ StringRef getSubsectionTag(); StringRef getAttrTag(); /// AArch64 build attributes vendors IDs (a.k.a subsection name) -enum VendorID : unsigned { AEABI_FEATURE_AND_BITS = 0, AEABI_PAUTHABI = 1, VENDOR_NOT_FOUND = 404 }; -static const StringRef VendorName[] = { "aeabi_feature_and_bits", "aeabi_pauthabi" }; +enum VendorID : unsigned { + AEABI_FEATURE_AND_BITS = 0, + AEABI_PAUTHABI = 1, + VENDOR_NOT_FOUND = 404 +}; +static const StringRef VendorName[] = {"aeabi_feature_and_bits", + "aeabi_pauthabi"}; StringRef getVendorName(unsigned const Vendor); VendorID getVendorID(StringRef const Vendor); StringRef getSubsectionUnknownError(); -enum SubsectionOptional : unsigned { REQUIRED = 0, OPTIONAL = 1, OPTIONAL_NOT_FOUND = 404 }; -static const StringRef OptionalStr[] = { "required", "optional"}; +enum SubsectionOptional : unsigned { + REQUIRED = 0, + OPTIONAL = 1, + OPTIONAL_NOT_FOUND = 404 +}; +static const StringRef OptionalStr[] = {"required", "optional"}; StringRef getOptionalStr(unsigned Optional); SubsectionOptional getOptionalID(StringRef Optional); StringRef getSubsectionOptionalUnknownError(); enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1, TYPE_NOT_FOUND = 404 }; -static const StringRef TypeStr[] = { "uleb128", "ntbs" }; +static const StringRef TypeStr[] = {"uleb128", "ntbs"}; StringRef getTypeStr(unsigned Type); SubsectionType getTypeID(StringRef Type); StringRef getSubsectionTypeUnknownError(); @@ -54,7 +63,8 @@ enum PauthABITags : unsigned { TAG_PAUTH_SCHEMA = 2, PAUTHABI_TAG_NOT_FOUND = 404 }; -static const StringRef PauthABITagsStr[] = { "Tag_PAuth_Platform", "Tag_PAuth_Schema"}; +static const StringRef PauthABITagsStr[] = {"Tag_PAuth_Platform", + "Tag_PAuth_Schema"}; StringRef getPauthABITagsStr(unsigned PauthABITag); PauthABITags getPauthABITagsID(StringRef PauthABITag); StringRef getPauthabiTagError(); @@ -65,7 +75,8 @@ enum FeatureAndBitsTags : unsigned { TAG_FEATURE_GCS = 2, FEATURE_AND_BITS_TAG_NOT_FOUND = 404 }; -static const StringRef FeatureAndBitsTagsStr[] = { "Tag_Feature_BTI", "Tag_Feature_PAC", "Tag_Feature_GCS"}; +static const StringRef FeatureAndBitsTagsStr[] = { + "Tag_Feature_BTI", "Tag_Feature_PAC", "Tag_Feature_GCS"}; StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag); FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag); StringRef getFeatureAndBitsTagError(); diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index eb4ee5f6d15e0..0717a30cfd433 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -8,139 +8,150 @@ #include "llvm/Support/ARMBuildAttributes.h" - namespace llvm { - class StringRef; - namespace ARMBuildAttrs { - // AArch64 build attributes - StringRef getSubsectionTag() { return "aeabi_subsection"; } - StringRef getAttrTag() { return "aeabi_attribute"; } +class StringRef; +namespace ARMBuildAttrs { +// AArch64 build attributes +StringRef getSubsectionTag() { return "aeabi_subsection"; } +StringRef getAttrTag() { return "aeabi_attribute"; } - StringRef getVendorName(unsigned Vendor) { - switch (Vendor) { - case AEABI_FEATURE_AND_BITS: - return VendorName[AEABI_FEATURE_AND_BITS]; - case AEABI_PAUTHABI: - return VendorName[AEABI_PAUTHABI]; - case VENDOR_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown AArch64 vendor"); - return ""; - } - } - VendorID getVendorID(StringRef Vendor) { - if(Vendor == VendorName[AEABI_FEATURE_AND_BITS]) { - return AEABI_FEATURE_AND_BITS; - } - if(Vendor == VendorName[AEABI_PAUTHABI]) { - return AEABI_PAUTHABI; - } - assert(0 && "unknown AArch64 vendor"); - return VENDOR_NOT_FOUND; - } - StringRef getSubsectionUnknownError() { return "unknown AArch64 build attributes subsection"; } +StringRef getVendorName(unsigned Vendor) { + switch (Vendor) { + case AEABI_FEATURE_AND_BITS: + return VendorName[AEABI_FEATURE_AND_BITS]; + case AEABI_PAUTHABI: + return VendorName[AEABI_PAUTHABI]; + case VENDOR_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown AArch64 vendor"); + return ""; + } +} +VendorID getVendorID(StringRef Vendor) { + if (Vendor == VendorName[AEABI_FEATURE_AND_BITS]) { + return AEABI_FEATURE_AND_BITS; + } + if (Vendor == VendorName[AEABI_PAUTHABI]) { + return AEABI_PAUTHABI; + } + assert(0 && "unknown AArch64 vendor"); + return VENDOR_NOT_FOUND; +} +StringRef getSubsectionUnknownError() { + return "unknown AArch64 build attributes subsection"; +} - StringRef getOptionalStr(unsigned Optional) { - switch (Optional) { - case REQUIRED: - return OptionalStr[REQUIRED]; - case OPTIONAL: - return OptionalStr[OPTIONAL]; - case OPTIONAL_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown AArch64 Optional option"); - return ""; - } - } - SubsectionOptional getOptionalID(StringRef Optional) { - if(Optional == OptionalStr[REQUIRED]) - return REQUIRED; - if(Optional == OptionalStr[OPTIONAL]) - return OPTIONAL; - assert(0 && "unknown AArch64 Optional option"); - return OPTIONAL_NOT_FOUND; - } - StringRef getSubsectionOptionalUnknownError() { return "unknown AArch64 build attributes optionality, expecting required|optional"; } +StringRef getOptionalStr(unsigned Optional) { + switch (Optional) { + case REQUIRED: + return OptionalStr[REQUIRED]; + case OPTIONAL: + return OptionalStr[OPTIONAL]; + case OPTIONAL_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown AArch64 Optional option"); + return ""; + } +} +SubsectionOptional getOptionalID(StringRef Optional) { + if (Optional == OptionalStr[REQUIRED]) + return REQUIRED; + if (Optional == OptionalStr[OPTIONAL]) + return OPTIONAL; + assert(0 && "unknown AArch64 Optional option"); + return OPTIONAL_NOT_FOUND; +} +StringRef getSubsectionOptionalUnknownError() { + return "unknown AArch64 build attributes optionality, expecting " + "required|optional"; +} - StringRef getTypeStr(unsigned Type) { - switch (Type) { - case ULEB128: - return TypeStr[ULEB128]; - case NTBS: - return TypeStr[NTBS]; - case TYPE_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown AArch64 subsection type"); - return ""; - } - } - SubsectionType getTypeID(StringRef Type) { - if(Type == TypeStr[ULEB128] || Type == (TypeStr[ULEB128].upper())) - return ULEB128; - if(Type == TypeStr[NTBS]|| Type == (TypeStr[NTBS].upper())) - return NTBS; - assert(0 && "unknown AArch64 subsection type"); - return TYPE_NOT_FOUND; - } - StringRef getSubsectionTypeUnknownError() { return "unknown AArch64 build attributes type, expecting uleb128 or ntbs"; } +StringRef getTypeStr(unsigned Type) { + switch (Type) { + case ULEB128: + return TypeStr[ULEB128]; + case NTBS: + return TypeStr[NTBS]; + case TYPE_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown AArch64 subsection type"); + return ""; + } +} +SubsectionType getTypeID(StringRef Type) { + if (Type == TypeStr[ULEB128] || Type == (TypeStr[ULEB128].upper())) + return ULEB128; + if (Type == TypeStr[NTBS] || Type == (TypeStr[NTBS].upper())) + return NTBS; + assert(0 && "unknown AArch64 subsection type"); + return TYPE_NOT_FOUND; +} +StringRef getSubsectionTypeUnknownError() { + return "unknown AArch64 build attributes type, expecting uleb128 or ntbs"; +} - StringRef getPauthABITagsStr(unsigned PauthABITag) { - switch(PauthABITag) { - case TAG_PAUTH_PLATFORM: - return PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]; // Tag_PAuth_Platform = 1 in accordance with the spec - case TAG_PAUTH_SCHEMA: - return PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]; // Tag_PAuth_Schema = 2 in accordance with the spec - case PAUTHABI_TAG_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown pauthabi tag"); - return ""; - } - } - PauthABITags getPauthABITagsID(StringRef PauthABITag) { - if(PauthABITag == PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]) - return TAG_PAUTH_PLATFORM; - if(PauthABITag == PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]) - return TAG_PAUTH_SCHEMA; - assert(0 && "unknown FPauthABI tag"); - return PAUTHABI_TAG_NOT_FOUND; - } - StringRef getPauthabiTagError() { return "unknown tag for the AArch64 Pauthabi subsection"; } +StringRef getPauthABITagsStr(unsigned PauthABITag) { + switch (PauthABITag) { + case TAG_PAUTH_PLATFORM: + return PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]; // Tag_PAuth_Platform = 1 in + // accordance with the spec + case TAG_PAUTH_SCHEMA: + return PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]; // Tag_PAuth_Schema = 2 in + // accordance with the spec + case PAUTHABI_TAG_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown pauthabi tag"); + return ""; + } +} +PauthABITags getPauthABITagsID(StringRef PauthABITag) { + if (PauthABITag == PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]) + return TAG_PAUTH_PLATFORM; + if (PauthABITag == PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]) + return TAG_PAUTH_SCHEMA; + assert(0 && "unknown FPauthABI tag"); + return PAUTHABI_TAG_NOT_FOUND; +} +StringRef getPauthabiTagError() { + return "unknown tag for the AArch64 Pauthabi subsection"; +} - StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) { - switch(FeatureAndBitsTag) { - case TAG_FEATURE_BTI: - return FeatureAndBitsTagsStr[TAG_FEATURE_BTI]; - case TAG_FEATURE_PAC: - return FeatureAndBitsTagsStr[TAG_FEATURE_PAC]; - case TAG_FEATURE_GCS: - return FeatureAndBitsTagsStr[TAG_FEATURE_GCS]; - case FEATURE_AND_BITS_TAG_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown feature and bits tag"); - return ""; - } - } - FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) { - if(FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_BTI]) - return TAG_FEATURE_BTI; - if(FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_PAC]) - return TAG_FEATURE_PAC; - if(FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_GCS]) - return TAG_FEATURE_GCS; - assert(0 && "unknown Feature and Bits tag"); - return FEATURE_AND_BITS_TAG_NOT_FOUND; - } - StringRef getFeatureAndBitsTagError() { return "unknown tag for the AArch64 Feature And Bits subsection"; } - ///--- AArch64 build attributes - } // namespace ARMBuildAttrs +StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) { + switch (FeatureAndBitsTag) { + case TAG_FEATURE_BTI: + return FeatureAndBitsTagsStr[TAG_FEATURE_BTI]; + case TAG_FEATURE_PAC: + return FeatureAndBitsTagsStr[TAG_FEATURE_PAC]; + case TAG_FEATURE_GCS: + return FeatureAndBitsTagsStr[TAG_FEATURE_GCS]; + case FEATURE_AND_BITS_TAG_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown feature and bits tag"); + return ""; + } +} +FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) { + if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_BTI]) + return TAG_FEATURE_BTI; + if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_PAC]) + return TAG_FEATURE_PAC; + if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_GCS]) + return TAG_FEATURE_GCS; + assert(0 && "unknown Feature and Bits tag"); + return FEATURE_AND_BITS_TAG_NOT_FOUND; +} +StringRef getFeatureAndBitsTagError() { + return "unknown tag for the AArch64 Feature And Bits subsection"; +} +///--- AArch64 build attributes +} // namespace ARMBuildAttrs } // namespace llvm - using namespace llvm; static const TagNameItem tagData[] = { diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index c17e24e44f3ae..cd0f34ddc3290 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -7068,11 +7068,12 @@ bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) { else return true; } else if (!IsMachO && !IsCOFF) { - if (IDVal == ".aeabi_subsection") - parseDirectiveAeabiSubSectionHeader(Loc); - else if (IDVal == ".aeabi_attribute") - parseDirectiveAeabiAArch64Attr(Loc); - } else return true; + if (IDVal == ".aeabi_subsection") + parseDirectiveAeabiSubSectionHeader(Loc); + else if (IDVal == ".aeabi_attribute") + parseDirectiveAeabiAArch64Attr(Loc); + } else + return true; return false; } @@ -7808,9 +7809,9 @@ bool AArch64AsmParser::parseDirectiveSEHSaveAnyReg(SMLoc L, bool Paired, } 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. + // 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. MCAsmParser &Parser = getParser(); // Consume the name (subsection name) @@ -7820,15 +7821,17 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { StringRef SubsectionName = Parser.getTok().getIdentifier(); SubsectionNameID = ARMBuildAttrs::getVendorID(SubsectionName); if (ARMBuildAttrs::VENDOR_NOT_FOUND == SubsectionNameID) { - Error(Parser.getTok().getLoc(), ARMBuildAttrs::getSubsectionUnknownError() + ": " + SubsectionName); + Error(Parser.getTok().getLoc(), + ARMBuildAttrs::getSubsectionUnknownError() + ": " + SubsectionName); } } else { - Error(Parser.getTok().getLoc(), "Expecting subsection name"); - return true; + Error(Parser.getTok().getLoc(), "Expecting subsection name"); + return true; } Parser.Lex(); // consume a comma - // parseComma() return *false* on success, and call Lex(), no need to call Lex() again. + // parseComma() return *false* on success, and call Lex(), no need to call + // Lex() again. if (Parser.parseComma()) { Error(Parser.getTok().getLoc(), "expected ','"); return true; @@ -7841,24 +7844,29 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { StringRef Name = Parser.getTok().getIdentifier(); IsOptional = ARMBuildAttrs::getOptionalID(Name); if (ARMBuildAttrs::OPTIONAL_NOT_FOUND == IsOptional) { - Error(Parser.getTok().getLoc(), ARMBuildAttrs::getSubsectionOptionalUnknownError() + ": " + Name); + Error(Parser.getTok().getLoc(), + ARMBuildAttrs::getSubsectionOptionalUnknownError() + ": " + Name); return true; } } else { - Error(Parser.getTok().getLoc(), "Expecitng optionality parameter \n Hint: use 'optional' | 'required'"); - return true; + Error( + Parser.getTok().getLoc(), + "Expecitng optionality parameter \n Hint: use 'optional' | 'required'"); + return true; } // Check for possible IsOptional unaccepted values for known subsections if (ARMBuildAttrs::AEABI_FEATURE_AND_BITS == SubsectionNameID) { if (ARMBuildAttrs::REQUIRED == IsOptional) { - Error(Parser.getTok().getLoc(), "aeabi_feature_and_bits must be marked as optional"); - return true; + Error(Parser.getTok().getLoc(), + "aeabi_feature_and_bits must be marked as optional"); + return true; } } if (ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { if (ARMBuildAttrs::OPTIONAL == IsOptional) { - Error(Parser.getTok().getLoc(), "aeabi_pauthabi must be marked as required"); - return true; + Error(Parser.getTok().getLoc(), + "aeabi_pauthabi must be marked as required"); + return true; } } Parser.Lex(); @@ -7874,24 +7882,28 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { StringRef Name = Parser.getTok().getIdentifier(); Type = ARMBuildAttrs::getTypeID(Name); if (ARMBuildAttrs::TYPE_NOT_FOUND == Type) { - Error(Parser.getTok().getLoc(), ARMBuildAttrs::getSubsectionTypeUnknownError() + ": " + Name); + Error(Parser.getTok().getLoc(), + ARMBuildAttrs::getSubsectionTypeUnknownError() + ": " + Name); return true; } } else { - Error(Parser.getTok().getLoc(), "Expecitng type parameter"); - return true; + Error(Parser.getTok().getLoc(), "Expecitng type parameter"); + return true; } // Check for possible Type unaccepted values for known subsections - if (ARMBuildAttrs::AEABI_FEATURE_AND_BITS == SubsectionNameID || ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { + if (ARMBuildAttrs::AEABI_FEATURE_AND_BITS == SubsectionNameID || + ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { if (ARMBuildAttrs::NTBS == Type) { - Error(Parser.getTok().getLoc(), SubsectionName + "must be marked as ULEB128"); - return true; + Error(Parser.getTok().getLoc(), + SubsectionName + "must be marked as ULEB128"); + return true; } } Parser.Lex(); // Parsing finished, check for trailing tokens. if (Parser.getTok().isNot(llvm::AsmToken::EndOfStatement)) { - Error(Parser.getTok().getLoc(), "unexpected token for AArch64 build attributes subsection header directive"); + Error(Parser.getTok().getLoc(), "unexpected token for AArch64 build " + "attributes subsection header directive"); return true; } @@ -7914,34 +7926,45 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { TagStr = Parser.getTok().getIdentifier(); ActiveSubsection = getTargetStreamer().getActiveSubsection(); if ("" == ActiveSubsection) { - Error(Parser.getTok().getLoc(), "no active subsection, build attribute can not be added"); + Error(Parser.getTok().getLoc(), + "no active subsection, build attribute can not be added"); return true; } - if(ARMBuildAttrs::VendorName[ARMBuildAttrs::AEABI_PAUTHABI] == ActiveSubsection) { + if (ARMBuildAttrs::VendorName[ARMBuildAttrs::AEABI_PAUTHABI] == + ActiveSubsection) { ActiveSubsectionID = ARMBuildAttrs::AEABI_PAUTHABI; Tag = ARMBuildAttrs::getPauthABITagsID(TagStr); if (ARMBuildAttrs::PAUTHABI_TAG_NOT_FOUND == Tag) { - Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + "' for subsection '" + ActiveSubsection + "'"); + Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + + TagStr + "' for subsection '" + + ActiveSubsection + "'"); return true; } - } else if(ARMBuildAttrs::VendorName[ARMBuildAttrs::AEABI_FEATURE_AND_BITS] == ActiveSubsection) { + } else if (ARMBuildAttrs::VendorName + [ARMBuildAttrs::AEABI_FEATURE_AND_BITS] == + ActiveSubsection) { ActiveSubsectionID = ARMBuildAttrs::AEABI_FEATURE_AND_BITS; Tag = ARMBuildAttrs::getFeatureAndBitsTagsID(TagStr); if (ARMBuildAttrs::FEATURE_AND_BITS_TAG_NOT_FOUND == Tag) { - Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + "' for subsection '" + ActiveSubsection + "' \n Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, Tag_Feature_GCS"); + Error(Parser.getTok().getLoc(), + "Unknown AArch64 build attribute '" + TagStr + + "' for subsection '" + ActiveSubsection + + "' \n Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, " + "Tag_Feature_GCS"); return true; } } - // for compatability - } else if(Parser.getTok().is(AsmToken::Integer)) { + // for compatability + } else if (Parser.getTok().is(AsmToken::Integer)) { Tag = getTok().getIntVal(); } else { - Error(Parser.getTok().getLoc(), "AArch64 build attributes Tag not found"); - return true; + Error(Parser.getTok().getLoc(), "AArch64 build attributes Tag not found"); + return true; } Parser.Lex(); // consume a comma - // parseComma() return *false* on success, and call Lex(), no need to call Lex() again. + // parseComma() return *false* on success, and call Lex(), no need to call + // Lex() again. if (Parser.parseComma()) { Error(Parser.getTok().getLoc(), "expected ','"); return true; @@ -7952,25 +7975,32 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { if (Parser.getTok().is(AsmToken::Integer)) { Value = getTok().getIntVal(); } else { - Error(Parser.getTok().getLoc(), "AArch64 build attributes Value not found"); - return true; + Error(Parser.getTok().getLoc(), "AArch64 build attributes Value not found"); + return true; } // Check for possible unaccepted values for known tags if (TagStr != "") { // Tag was a recognized string if (0 != Value && 1 != Value) { - Error(Parser.getTok().getLoc(), "Unknown AArch64 build attributes Value for Tag '" + TagStr + "' \n Hint: options are '0'|'1'"); + Error(Parser.getTok().getLoc(), + "Unknown AArch64 build attributes Value for Tag '" + TagStr + + "' \n Hint: options are '0'|'1'"); return true; } - // Tag was an integer - } else if (0 == Tag || 1 == Tag || 2 == Tag) { // might be at attempt to represent known tags + // Tag was an integer + } else if (0 == Tag || 1 == Tag || + 2 == Tag) { // might be at attempt to represent known tags if (0 != Value && 1 != Value) { - Warning(Parser.getTok().getLoc(), "Unknown AArch64 build attributes Value for any known AArch64 build attributes tags"); + Warning(Parser.getTok().getLoc(), + "Unknown AArch64 build attributes Value for any known AArch64 " + "build attributes tags"); } } Parser.Lex(); // Parsing finished, check for trailing tokens. if (Parser.getTok().isNot(llvm::AsmToken::EndOfStatement)) { - Error(Parser.getTok().getLoc(), "unexpected token for AArch64 build attributes tag and value attribute directive"); + Error(Parser.getTok().getLoc(), + "unexpected token for AArch64 build attributes tag and value " + "attribute directive"); return true; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 00d72d15f1cc6..902cb3c416d6c 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -166,13 +166,22 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { assert(0 && ARMBuildAttrs::getFeatureAndBitsTagError().data()); break; case ARMBuildAttrs::TAG_FEATURE_BTI: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr(ARMBuildAttrs::TAG_FEATURE_BTI) << ", " << Value; + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" + << ARMBuildAttrs::getFeatureAndBitsTagsStr( + ARMBuildAttrs::TAG_FEATURE_BTI) + << ", " << Value; break; case ARMBuildAttrs::TAG_FEATURE_GCS: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr(ARMBuildAttrs::TAG_FEATURE_GCS) << ", " << Value; + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" + << ARMBuildAttrs::getFeatureAndBitsTagsStr( + ARMBuildAttrs::TAG_FEATURE_GCS) + << ", " << Value; break; case ARMBuildAttrs::TAG_FEATURE_PAC: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr(ARMBuildAttrs::TAG_FEATURE_PAC) << ", " << Value; + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" + << ARMBuildAttrs::getFeatureAndBitsTagsStr( + ARMBuildAttrs::TAG_FEATURE_PAC) + << ", " << Value; break; } break; @@ -183,10 +192,15 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { assert(0 && ARMBuildAttrs::getFeatureAndBitsTagError().data()); break; case ARMBuildAttrs::TAG_PAUTH_PLATFORM: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getPauthABITagsStr(ARMBuildAttrs::TAG_PAUTH_PLATFORM) << ", " << Value; + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" + << ARMBuildAttrs::getPauthABITagsStr( + ARMBuildAttrs::TAG_PAUTH_PLATFORM) + << ", " << Value; break; case ARMBuildAttrs::TAG_PAUTH_SCHEMA: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getPauthABITagsStr(ARMBuildAttrs::TAG_PAUTH_SCHEMA) << ", " << Value; + OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" + << ARMBuildAttrs::getPauthABITagsStr(ARMBuildAttrs::TAG_PAUTH_SCHEMA) + << ", " << Value; break; break; } @@ -202,9 +216,9 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { // optional: required (0) optional (1) // parameter type: uleb128 or ULEB128 (0) ntbs or NTBS (1) - assert(( 0 == Optional || 1 == Optional) && + assert((0 == Optional || 1 == Optional) && ARMBuildAttrs::getSubsectionOptionalUnknownError().data()); - assert(( 0 == ParameterType || 1 == ParameterType) && + assert((0 == ParameterType || 1 == ParameterType) && ARMBuildAttrs::getSubsectionTypeUnknownError().data()); std::string SubsectionTag = ("." + ARMBuildAttrs::getSubsectionTag()).str(); @@ -217,21 +231,26 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { break; } case ARMBuildAttrs::AEABI_PAUTHABI: { - assert(ARMBuildAttrs::REQUIRED == Optional && "subsection .aeabi-pauthabi should be marked as " - "mandatory and not as optional"); - assert(ARMBuildAttrs::ULEB128 == ParameterType && "subsection .aeabi-pauthabi should be " - "marked as uleb128 and not as ntbs"); + assert(ARMBuildAttrs::REQUIRED == Optional && + "subsection .aeabi-pauthabi should be marked as " + "mandatory and not as optional"); + assert(ARMBuildAttrs::ULEB128 == ParameterType && + "subsection .aeabi-pauthabi should be " + "marked as uleb128 and not as ntbs"); StringRef SubsectionName = getVendorName(ARMBuildAttrs::AEABI_PAUTHABI); - OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr - << ", " << ParameterStr; + OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " + << OptionalStr << ", " << ParameterStr; break; } case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: { - assert( ARMBuildAttrs::OPTIONAL == Optional && "subsection .aeabi_feature_and_bits should be " - "marked as optional and not as mandatory"); - assert( ARMBuildAttrs::ULEB128 == ParameterType && "subsection .aeabi_feature_and_bits should " - "be marked as uleb128 and not as ntbs"); - StringRef SubsectionName = getVendorName(ARMBuildAttrs::AEABI_FEATURE_AND_BITS); + assert(ARMBuildAttrs::OPTIONAL == Optional && + "subsection .aeabi_feature_and_bits should be " + "marked as optional and not as mandatory"); + assert(ARMBuildAttrs::ULEB128 == ParameterType && + "subsection .aeabi_feature_and_bits should " + "be marked as uleb128 and not as ntbs"); + StringRef SubsectionName = + getVendorName(ARMBuildAttrs::AEABI_FEATURE_AND_BITS); OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; break; @@ -405,7 +424,8 @@ void AArch64TargetELFStreamer::emitSubsection( // If exists, return. for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { if (VendorName == SubSection.VendorName) { - // This path might be reached when an assembly directive switches attribute subsection. + // This path might be reached when an assembly directive switches + // attribute subsection. activateSubsection(VendorName); return; } @@ -424,38 +444,44 @@ void AArch64TargetELFStreamer::emitAttribute(unsigned VendorID, unsigned Tag, StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); if (AttributeSubSections.size() == 0) { - assert(0 && "Can not add AArch64 build attribute: no AArch64 subsection exists"); + assert(0 && + "Can not add AArch64 build attribute: no AArch64 subsection exists"); return; } for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { if (VendorName == SubSection.VendorName) { if (!SubSection.IsActive) { - assert(0 && "Can not add AArch64 build attribute: subsection is not active"); + assert(0 && + "Can not add AArch64 build attribute: subsection is not active"); return; } for (MCELFStreamer::AttributeItem &Item : SubSection.Content) { if (Item.Tag == Tag) { if (!Override) { if (Item.IntValue != Value) { - assert(0 && "Can not add AArch64 build attribute: An attribute with the same tag and a different value allready exists"); - return; + assert(0 && + "Can not add AArch64 build attribute: An attribute with " + "the same tag and a different value allready exists"); + return; } } } } - SubSection.Content.push_back(MCELFStreamer::AttributeItem(MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); + SubSection.Content.push_back(MCELFStreamer::AttributeItem( + MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); return; } } - assert(0 && "Can not add AArch64 build attribute: required subsection does not exists"); + assert(0 && "Can not add AArch64 build attribute: required subsection does " + "not exists"); } StringRef AArch64TargetELFStreamer::getActiveSubsection() { for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { if (SubSection.IsActive) { return SubSection.VendorName; - } + } } return ""; } From 4505446f019489edc23328dfcb5018a4ab092580 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Tue, 17 Dec 2024 14:19:55 +0000 Subject: [PATCH 07/21] add llvm test files --- .../aarch64-build-attributes-asm-all.ll | 22 +++++++++++++++++++ .../aarch64-build-attributes-asm-bti.ll | 20 +++++++++++++++++ .../aarch64-build-attributes-asm-gcs.ll | 20 +++++++++++++++++ .../aarch64-build-attributes-asm-pac.ll | 20 +++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-all.ll create mode 100644 llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-bti.ll create mode 100644 llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-gcs.ll create mode 100644 llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-pac.ll diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-all.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-all.ll new file mode 100644 index 0000000000000..81ece7aec8793 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-all.ll @@ -0,0 +1,22 @@ +; RUN: llc %s -o - | FileCheck %s --check-prefix=ASM +; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF + +; ASM: .text +; ASM-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 +; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 +; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 + +; ELF: Hex dump of section '.ARM.attributes': +; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +; ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits..... +; ELF-NEXT: 0x00000020 01010201 + + +target triple = "aarch64-unknown-none-elf" + +!llvm.module.flags = !{!1, !2, !3} + +!1 = !{i32 8, !"branch-target-enforcement", i32 1} +!2 = !{i32 8, !"guarded-control-stack", i32 1} +!3 = !{i32 8, !"sign-return-address", i32 1} diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-bti.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-bti.ll new file mode 100644 index 0000000000000..e719e06553cc0 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-bti.ll @@ -0,0 +1,20 @@ +; RUN: llc < %s | FileCheck %s --check-prefix=ASM +; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF + +; ASM: .text +; ASM-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 +; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 +; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 + +; ELF: Hex dump of section '.ARM.attributes': +; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +; ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits..... +; ELF-NEXT: 0x00000020 01000200 + + +target triple = "aarch64-unknown-none-elf" + +!llvm.module.flags = !{!1} + +!1 = !{i32 8, !"branch-target-enforcement", i32 1} diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-gcs.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-gcs.ll new file mode 100644 index 0000000000000..6f231025a11e3 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-gcs.ll @@ -0,0 +1,20 @@ +; RUN: llc < %s | FileCheck %s --check-prefix=ASM +; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF + +; ASM: .text +; ASM-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 +; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 +; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 + +; ELF: Hex dump of section '.ARM.attributes': +; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +; ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... +; ELF-NEXT: 0x00000020 01000201 + + +target triple = "aarch64-unknown-none-elf" + +!llvm.module.flags = !{!1} + +!1 = !{i32 8, !"guarded-control-stack", i32 1} diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-pac.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-pac.ll new file mode 100644 index 0000000000000..54ff12655eb23 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-pac.ll @@ -0,0 +1,20 @@ +; RUN: llc < %s | FileCheck %s --check-prefix=ASM +; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF + +; ASM: .text +; ASM-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +; ASM-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 +; ASM-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 +; ASM-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 + +; ELF: Hex dump of section '.ARM.attributes': +; ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +; ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... +; ELF-NEXT: 0x00000020 01010200 + + +target triple = "aarch64-unknown-none-elf" + +!llvm.module.flags = !{!1} + +!1 = !{i32 8, !"sign-return-address", i32 1} From f4f1b1b5cd5ae0ce28226f54cc88b0b8b21068f8 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Tue, 17 Dec 2024 15:19:03 +0000 Subject: [PATCH 08/21] format --- llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index 922dec799491b..6344a26e1d1ef 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64TARGETSTREAMER_H #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64TARGETSTREAMER_H +#include "AArch64MCExpr.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/Instructions.h" #include "llvm/MC/MCELFStreamer.h" -#include "AArch64MCExpr.h" #include "llvm/MC/MCStreamer.h" #include "llvm/Support/ARMBuildAttributes.h" #include From b651b3c81d38410aff4df7127502dcafb4ffe25e Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Tue, 17 Dec 2024 16:25:34 +0000 Subject: [PATCH 09/21] fix small bug --- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index 1f0b761c6249a..e31405b950d67 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -7824,7 +7824,7 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { StringRef SubsectionName; ARMBuildAttrs::VendorID SubsectionNameID; if (Parser.getTok().is(AsmToken::Identifier)) { - StringRef SubsectionName = Parser.getTok().getIdentifier(); + SubsectionName = Parser.getTok().getIdentifier(); SubsectionNameID = ARMBuildAttrs::getVendorID(SubsectionName); if (ARMBuildAttrs::VENDOR_NOT_FOUND == SubsectionNameID) { Error(Parser.getTok().getLoc(), @@ -7901,7 +7901,7 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { if (ARMBuildAttrs::NTBS == Type) { Error(Parser.getTok().getLoc(), - SubsectionName + "must be marked as ULEB128"); + SubsectionName + " must be marked as ULEB128"); return true; } } From 7cde2152976c1b48f0a958a7b37288fbffd9c7cc Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Wed, 18 Dec 2024 13:13:47 +0000 Subject: [PATCH 10/21] Fix a bug --- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index e31405b950d67..dca39f834cefc 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -6978,6 +6978,7 @@ bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) { const MCContext::Environment Format = getContext().getObjectFileType(); bool IsMachO = Format == MCContext::IsMachO; bool IsCOFF = Format == MCContext::IsCOFF; + bool IsELF = Format == MCContext::IsELF; auto IDVal = DirectiveID.getIdentifier().lower(); SMLoc Loc = DirectiveID.getLoc(); @@ -7073,11 +7074,13 @@ bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) { parseDirectiveSEHSaveAnyReg(Loc, true, true); else return true; - } else if (!IsMachO && !IsCOFF) { + } else if (IsELF) { if (IDVal == ".aeabi_subsection") parseDirectiveAeabiSubSectionHeader(Loc); else if (IDVal == ".aeabi_attribute") parseDirectiveAeabiAArch64Attr(Loc); + else + return true; } else return true; return false; From 07b1f745d7d43e0af198fe8d99734ae0b2aefa74 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Wed, 18 Dec 2024 13:28:14 +0000 Subject: [PATCH 11/21] format --- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index dca39f834cefc..00833892a1a49 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -7080,7 +7080,7 @@ bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) { else if (IDVal == ".aeabi_attribute") parseDirectiveAeabiAArch64Attr(Loc); else - return true; + return true; } else return true; return false; From 06215d91de16eb01afd88bd2df234248027286a8 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Wed, 18 Dec 2024 17:21:15 +0000 Subject: [PATCH 12/21] - add llvm-mc test files - fix bug --- .../MCTargetDesc/AArch64ELFStreamer.cpp | 92 ++++--------------- .../MCTargetDesc/AArch64TargetStreamer.cpp | 78 ++++++++++++++++ .../MCTargetDesc/AArch64TargetStreamer.h | 13 ++- .../aarch64-build-attributes-asm-all.s | 27 ++++++ .../aarch64-build-attributes-asm-bti.s | 19 ++++ .../aarch64-build-attributes-asm-gcs.s | 19 ++++ .../aarch64-build-attributes-asm-none.s | 27 ++++++ ...arch64-build-attributes-asm-out-of-order.s | 50 ++++++++++ .../aarch64-build-attributes-asm-pac.s | 19 ++++ 9 files changed, 262 insertions(+), 82 deletions(-) create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-gcs.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-none.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 902cb3c416d6c..26d1441f3120d 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -170,18 +170,23 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { << ARMBuildAttrs::getFeatureAndBitsTagsStr( ARMBuildAttrs::TAG_FEATURE_BTI) << ", " << Value; + // Keep the data structure consistent with the case of ELF emission + // (important for llvm-mc asm parsing) + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; case ARMBuildAttrs::TAG_FEATURE_GCS: OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr( ARMBuildAttrs::TAG_FEATURE_GCS) << ", " << Value; + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; case ARMBuildAttrs::TAG_FEATURE_PAC: OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getFeatureAndBitsTagsStr( ARMBuildAttrs::TAG_FEATURE_PAC) << ", " << Value; + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; } break; @@ -196,26 +201,26 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { << ARMBuildAttrs::getPauthABITagsStr( ARMBuildAttrs::TAG_PAUTH_PLATFORM) << ", " << Value; + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; case ARMBuildAttrs::TAG_PAUTH_SCHEMA: OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" << ARMBuildAttrs::getPauthABITagsStr(ARMBuildAttrs::TAG_PAUTH_SCHEMA) << ", " << Value; - break; + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; } } OS << "\n"; } - void emitSubsection(unsigned SubsectionName, + void emitSubsection(unsigned Subsection, ARMBuildAttrs::SubsectionOptional Optional, ARMBuildAttrs::SubsectionType ParameterType) override { // The AArch64 build attributes assembly subsection header format: // ".aeabi_subsection name, optional, parameter type" // optional: required (0) optional (1) // parameter type: uleb128 or ULEB128 (0) ntbs or NTBS (1) - assert((0 == Optional || 1 == Optional) && ARMBuildAttrs::getSubsectionOptionalUnknownError().data()); assert((0 == ParameterType || 1 == ParameterType) && @@ -225,7 +230,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { StringRef OptionalStr = getOptionalStr(Optional); StringRef ParameterStr = getTypeStr(ParameterType); - switch (SubsectionName) { + switch (Subsection) { default: { assert(0 && ARMBuildAttrs::getSubsectionUnknownError().data()); break; @@ -240,6 +245,10 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { StringRef SubsectionName = getVendorName(ARMBuildAttrs::AEABI_PAUTHABI); OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; + // Keep the data structure consistent with the case of ELF emission + // (important for llvm-mc asm parsing) + AArch64TargetStreamer::emitSubsection(Subsection, Optional, + ParameterType); break; } case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: { @@ -253,6 +262,8 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { getVendorName(ARMBuildAttrs::AEABI_FEATURE_AND_BITS); OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; + AArch64TargetStreamer::emitSubsection(Subsection, Optional, + ParameterType); break; } } @@ -406,84 +417,15 @@ AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() { return static_cast(Streamer); } -void AArch64TargetELFStreamer::activateSubsection(StringRef VendorName) { - for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { - if (VendorName == SubSection.VendorName) { - SubSection.IsActive = true; - } else { - SubSection.IsActive = false; - } - } -} - void AArch64TargetELFStreamer::emitSubsection( unsigned VendorID, ARMBuildAttrs::SubsectionOptional IsOptional, ARMBuildAttrs::SubsectionType ParameterType) { - StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); - - // If exists, return. - for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { - if (VendorName == SubSection.VendorName) { - // This path might be reached when an assembly directive switches - // attribute subsection. - activateSubsection(VendorName); - return; - } - } - // else, add the subsection - MCELFStreamer::AttributeSubSection AttSubSection; - AttSubSection.VendorName = VendorName; - AttSubSection.IsOptional = IsOptional; - AttSubSection.ParameterType = ParameterType; - AttributeSubSections.push_back(AttSubSection); - activateSubsection(VendorName); + AArch64TargetStreamer::emitSubsection(VendorID, IsOptional, ParameterType); } void AArch64TargetELFStreamer::emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override) { - StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); - - if (AttributeSubSections.size() == 0) { - assert(0 && - "Can not add AArch64 build attribute: no AArch64 subsection exists"); - return; - } - - for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { - if (VendorName == SubSection.VendorName) { - if (!SubSection.IsActive) { - assert(0 && - "Can not add AArch64 build attribute: subsection is not active"); - return; - } - for (MCELFStreamer::AttributeItem &Item : SubSection.Content) { - if (Item.Tag == Tag) { - if (!Override) { - if (Item.IntValue != Value) { - assert(0 && - "Can not add AArch64 build attribute: An attribute with " - "the same tag and a different value allready exists"); - return; - } - } - } - } - SubSection.Content.push_back(MCELFStreamer::AttributeItem( - MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); - return; - } - } - assert(0 && "Can not add AArch64 build attribute: required subsection does " - "not exists"); -} - -StringRef AArch64TargetELFStreamer::getActiveSubsection() { - for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { - if (SubSection.IsActive) { - return SubSection.VendorName; - } - } - return ""; + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); } void AArch64TargetELFStreamer::emitInst(uint32_t Inst) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp index 7bd89c9e29a72..c014ddcab452e 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp @@ -151,3 +151,81 @@ llvm::createAArch64ObjectTargetStreamer(MCStreamer &S, MCTargetStreamer *llvm::createAArch64NullTargetStreamer(MCStreamer &S) { return new AArch64TargetStreamer(S); } + +void AArch64TargetStreamer::emitSubsection( + unsigned VendorID, ARMBuildAttrs::SubsectionOptional IsOptional, + ARMBuildAttrs::SubsectionType ParameterType) { + StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); + + // If exists, return. + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (VendorName == SubSection.VendorName) { + activateSubsection(VendorName); + return; + } + } + // else, add the subsection + MCELFStreamer::AttributeSubSection AttSubSection; + AttSubSection.VendorName = VendorName; + AttSubSection.IsOptional = IsOptional; + AttSubSection.ParameterType = ParameterType; + AttributeSubSections.push_back(AttSubSection); + activateSubsection(VendorName); +} + +StringRef AArch64TargetStreamer::getActiveSubsection() { + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (SubSection.IsActive) { + return SubSection.VendorName; + } + } + return ""; +} + +void AArch64TargetStreamer::emitAttribute(unsigned VendorID, unsigned Tag, + unsigned Value, bool Override) { + StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); + + if (AttributeSubSections.size() == 0) { + assert(0 && + "Can not add AArch64 build attribute: no AArch64 subsection exists"); + return; + } + + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (VendorName == SubSection.VendorName) { + if (!SubSection.IsActive) { + assert(0 && + "Can not add AArch64 build attribute: subsection is not active"); + return; + } + for (MCELFStreamer::AttributeItem &Item : SubSection.Content) { + if (Item.Tag == Tag) { + if (!Override) { + if (Item.IntValue != Value) { + assert(0 && + "Can not add AArch64 build attribute: An attribute with " + "the same tag and a different value allready exists"); + return; + } + } + } + } + SubSection.Content.push_back(MCELFStreamer::AttributeItem( + MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); + return; + } + } + assert(0 && "Can not add AArch64 build attribute: required subsection does " + "not exists"); +} + +void AArch64TargetStreamer::activateSubsection(StringRef VendorName) { + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (VendorName == SubSection.VendorName) { + SubSection.IsActive = true; + } else { + SubSection.IsActive = false; + } + } +} \ No newline at end of file diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index 6344a26e1d1ef..48bab0bbc9905 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -97,11 +97,13 @@ class AArch64TargetStreamer : public MCTargetStreamer { /// Build attributes implementation virtual void emitSubsection(unsigned VendorID, ARMBuildAttrs::SubsectionOptional IsOptional, - ARMBuildAttrs::SubsectionType ParameterType) {} + ARMBuildAttrs::SubsectionType ParameterType); virtual void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, - bool Override) {} - virtual void activateSubsection(StringRef VendorName) {} - virtual StringRef getActiveSubsection() { return ""; } + bool Override); + void activateSubsection(StringRef VendorName); + StringRef getActiveSubsection(); + + SmallVector AttributeSubSections; private: std::unique_ptr ConstantPools; @@ -112,7 +114,6 @@ class AArch64TargetELFStreamer : public AArch64TargetStreamer { AArch64ELFStreamer &getStreamer(); MCSection *AttributeSection = nullptr; - SmallVector AttributeSubSections; /// Build attributes implementation void emitSubsection(unsigned VendorID, @@ -120,8 +121,6 @@ class AArch64TargetELFStreamer : public AArch64TargetStreamer { ARMBuildAttrs::SubsectionType ParameterType) override; void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override = false) override; - void activateSubsection(StringRef VendorName) override; - StringRef getActiveSubsection() override; void emitInst(uint32_t Inst) override; void emitDirectiveVariantPCS(MCSymbol *Symbol) override; diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s new file mode 100644 index 0000000000000..30b552ebba1b7 --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s @@ -0,0 +1,27 @@ +// 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: .text +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute Tag_PAuth_Platform, 1 +// ASM: .aeabi_attribute Tag_PAuth_Schema, 1 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 1 +// ASM: .aeabi_attribute Tag_Feature_PAC, 1 +// ASM: .aeabi_attribute Tag_Feature_GCS, 1 + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 41190000 00616561 62695f70 61757468 A....aeabi_pauth +// ELF-NEXT: 0x00000010 61626900 00000101 02012300 00006165 abi.......#...ae +// ELF-NEXT: 0x00000020 6162695f 66656174 7572655f 616e645f abi_feature_and_ +// ELF-NEXT: 0x00000030 62697473 00010000 01010102 01 + + +.text +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute Tag_PAuth_Platform, 1 +.aeabi_attribute Tag_PAuth_Schema, 1 +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute Tag_Feature_BTI, 1 +.aeabi_attribute Tag_Feature_PAC, 1 +.aeabi_attribute Tag_Feature_GCS, 1 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s new file mode 100644 index 0000000000000..4da0b21fcc191 --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s @@ -0,0 +1,19 @@ +// 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_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 1 +// ASM: .aeabi_attribute Tag_Feature_PAC, 0 +// ASM: .aeabi_attribute Tag_Feature_GCS, 0 + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +// ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits..... +// ELF-NEXT: 0x00000020 01000200 + + +.text +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute Tag_Feature_BTI, 1 +.aeabi_attribute Tag_Feature_PAC, 0 +.aeabi_attribute Tag_Feature_GCS, 0 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-gcs.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-gcs.s new file mode 100644 index 0000000000000..62789c514dc33 --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-gcs.s @@ -0,0 +1,19 @@ +// 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_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 0 +// ASM: .aeabi_attribute Tag_Feature_PAC, 0 +// ASM: .aeabi_attribute Tag_Feature_GCS, 1 + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +// ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... +// ELF-NEXT: 0x00000020 01000201 + + +.text +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute Tag_Feature_BTI, 0 +.aeabi_attribute Tag_Feature_PAC, 0 +.aeabi_attribute Tag_Feature_GCS, 1 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-none.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-none.s new file mode 100644 index 0000000000000..07c89670373de --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-none.s @@ -0,0 +1,27 @@ +// 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: .text +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute Tag_PAuth_Platform, 0 +// ASM: .aeabi_attribute Tag_PAuth_Schema, 0 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 0 +// ASM: .aeabi_attribute Tag_Feature_PAC, 0 +// ASM: .aeabi_attribute Tag_Feature_GCS, 0 + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 41190000 00616561 62695f70 61757468 A....aeabi_pauth +// ELF-NEXT: 0x00000010 61626900 00000100 02002300 00006165 abi.......#...ae +// ELF-NEXT: 0x00000020 6162695f 66656174 7572655f 616e645f abi_feature_and_ +// ELF-NEXT: 0x00000030 62697473 00010000 00010002 00 + + +.text +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute Tag_PAuth_Platform, 0 +.aeabi_attribute Tag_PAuth_Schema, 0 +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute Tag_Feature_BTI, 0 +.aeabi_attribute Tag_Feature_PAC, 0 +.aeabi_attribute Tag_Feature_GCS, 0 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s new file mode 100644 index 0000000000000..8a7f681b5f3e7 --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s @@ -0,0 +1,50 @@ +// 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: .text +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 1 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute Tag_PAuth_Schema, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute Tag_PAuth_Platform, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_GCS, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 1 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_PAC, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute Tag_PAuth_Schema, 1 + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 411b0000 00616561 62695f70 61757468 A....aeabi_pauth +// ELF-NEXT: 0x00000010 61626900 00000201 01010201 25000000 abi.........%... +// ELF-NEXT: 0x00000020 61656162 695f6665 61747572 655f616e aeabi_feature_an +// ELF-NEXT: 0x00000030 645f6269 74730001 00000102 01000101 d_bits.......... +// ELF-NEXT: 0x00000040 01 + + +.text +.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, optional, uleb128 +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute Tag_PAuth_Schema, 1 +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute Tag_PAuth_Platform, 1 +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute Tag_Feature_GCS, 1 +.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, optional, uleb128 +.aeabi_attribute Tag_Feature_PAC, 1 +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute Tag_PAuth_Schema, 1 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s new file mode 100644 index 0000000000000..b67904b9a08fc --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s @@ -0,0 +1,19 @@ +// 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_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 0 +// ASM: .aeabi_attribute Tag_Feature_PAC, 1 +// ASM: .aeabi_attribute Tag_Feature_GCS, 0 + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu +// ELF-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... +// ELF-NEXT: 0x00000020 01010200 + + +.text +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute Tag_Feature_BTI, 0 +.aeabi_attribute Tag_Feature_PAC, 1 +.aeabi_attribute Tag_Feature_GCS, 0 \ No newline at end of file From 3b9f53e43c4902b46b48b525bd855baa8d4cb21c Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Fri, 20 Dec 2024 17:20:14 +0000 Subject: [PATCH 13/21] - Fixed according to comments above - Fixed some errors - Ability to add attributes numerically added - Tests for pauthabi platform/version in codegen - Tests for assembly parser errors - Not added: Tests for attributes with NTBS values - currently all attributes takes only ULEB128 as values. --- ...ld-attributes-aeabi-feature-and-bits-ASM.c | 30 ---- ...ld-attributes-aeabi-feature-and-bits-ELF.c | 30 ---- llvm/include/llvm/MC/MCELFStreamer.h | 22 +-- .../llvm/Support/AArch64BuildAttributes.h | 89 +++++++++++ .../include/llvm/Support/ARMBuildAttributes.h | 62 -------- llvm/lib/MC/MCELFStreamer.cpp | 24 ++- llvm/lib/Support/AArch64BuildAttributes.cpp | 143 +++++++++++++++++ llvm/lib/Support/ARMBuildAttrs.cpp | 144 ------------------ llvm/lib/Support/CMakeLists.txt | 1 + llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 50 +++--- .../AArch64/AsmParser/AArch64AsmParser.cpp | 95 +++++++----- .../MCTargetDesc/AArch64ELFStreamer.cpp | 120 ++++++++------- .../MCTargetDesc/AArch64TargetStreamer.cpp | 22 +-- .../MCTargetDesc/AArch64TargetStreamer.h | 22 +-- .../ARM/MCTargetDesc/ARMELFStreamer.cpp | 135 +++++++--------- .../MCTargetDesc/HexagonMCTargetDesc.cpp | 3 +- .../RISCV/MCTargetDesc/RISCVELFStreamer.cpp | 9 +- ...all.ll => aarch64-build-attributes-all.ll} | 0 ...bti.ll => aarch64-build-attributes-bti.ll} | 0 ...gcs.ll => aarch64-build-attributes-gcs.ll} | 0 ...pac.ll => aarch64-build-attributes-pac.ll} | 0 .../aarch64-build-attributes-pauthabi.ll | 19 +++ .../aarch64-build-attributes-asm-err-attrs.s | 62 ++++++++ ...aarch64-build-attributes-asm-err-headers.s | 84 ++++++++++ ...ch64-build-attributes-asm-numerical-tags.s | 41 +++++ ...arch64-build-attributes-asm-out-of-order.s | 46 +++--- .../gn/secondary/llvm/lib/Support/BUILD.gn | 1 + 27 files changed, 717 insertions(+), 537 deletions(-) delete mode 100644 clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c delete mode 100644 clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c create mode 100644 llvm/include/llvm/Support/AArch64BuildAttributes.h create mode 100644 llvm/lib/Support/AArch64BuildAttributes.cpp rename llvm/test/CodeGen/AArch64/{aarch64-build-attributes-asm-all.ll => aarch64-build-attributes-all.ll} (100%) rename llvm/test/CodeGen/AArch64/{aarch64-build-attributes-asm-bti.ll => aarch64-build-attributes-bti.ll} (100%) rename llvm/test/CodeGen/AArch64/{aarch64-build-attributes-asm-gcs.ll => aarch64-build-attributes-gcs.ll} (100%) rename llvm/test/CodeGen/AArch64/{aarch64-build-attributes-asm-pac.ll => aarch64-build-attributes-pac.ll} (100%) create mode 100644 llvm/test/CodeGen/AArch64/aarch64-build-attributes-pauthabi.ll create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-numerical-tags.s diff --git a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c deleted file mode 100644 index a2c3229b3d86d..0000000000000 --- a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ASM.c +++ /dev/null @@ -1,30 +0,0 @@ -// Test AArch64 build attributes to assmebly: 'aeabi_feature_and_bits' - -// RUN: %clang --target=aarch64-none-elf -mbranch-protection=bti+pac-ret+gcs -S -o- %s | FileCheck %s -check-prefix=ALL -// RUN: %clang --target=aarch64-none-elf -mbranch-protection=bti -S -o- %s | FileCheck %s -check-prefix=BTI -// RUN: %clang --target=aarch64-none-elf -mbranch-protection=pac-ret -S -o- %s | FileCheck %s -check-prefix=PAC -// RUN: %clang --target=aarch64-none-elf -mbranch-protection=gcs -S -o- %s | FileCheck %s -check-prefix=GCS - -// ALL: .text -// ALL-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// ALL-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 -// ALL-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 -// ALL-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 - -// BTI: .text -// BTI-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// BTI-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 -// BTI-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 -// BTI-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 - -// PAC: .text -// PAC-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// PAC-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 -// PAC-NEXT: .aeabi_attribute Tag_Feature_PAC, 1 -// PAC-NEXT: .aeabi_attribute Tag_Feature_GCS, 0 - -// GCS: .text -// GCS-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// GCS-NEXT: .aeabi_attribute Tag_Feature_BTI, 0 -// GCS-NEXT: .aeabi_attribute Tag_Feature_PAC, 0 -// GCS-NEXT: .aeabi_attribute Tag_Feature_GCS, 1 \ No newline at end of file diff --git a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c b/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c deleted file mode 100644 index 64cd4f9e99589..0000000000000 --- a/clang/test/CodeGen/AArch64/aarch64-build-attributes-aeabi-feature-and-bits-ELF.c +++ /dev/null @@ -1,30 +0,0 @@ -// Test AArch64 build attributes to ELF: 'aeabi_feature_and_bits' - -// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=bti+pac-ret+gcs %s -o %t -// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=ALL -// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=bti %s -o %t -// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=BTI -// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=pac-ret %s -o %t -// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=PAC -// RUN: %clang -c --target=aarch64-none-elf -mbranch-protection=gcs %s -o %t -// RUN: llvm-readelf --hex-dump=.ARM.attributes %t | FileCheck %s -check-prefix=GCS - -// ALL: Hex dump of section '.ARM.attributes': -// ALL-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu -// ALL-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits..... -// ALL-NEXT: 0x00000020 01010201 - -// BTI: Hex dump of section '.ARM.attributes': -// BTI-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu -// BTI-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000001 re_and_bits..... -// BTI-NEXT: 0x00000020 01000200 - -// PAC: Hex dump of section '.ARM.attributes': -// PAC-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu -// PAC-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... -// PAC-NEXT: 0x00000020 01010200 - -// GCS: Hex dump of section '.ARM.attributes': -// GCS-NEXT: 0x00000000 41230000 00616561 62695f66 65617475 A#...aeabi_featu -// GCS-NEXT: 0x00000010 72655f61 6e645f62 69747300 01000000 re_and_bits..... -// GCS-NEXT: 0x00000020 01000201 \ No newline at end of file diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 06ce9884f15cf..8984a9ba9d0ed 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -113,27 +113,21 @@ class MCELFStreamer : public MCObjectStreamer { /// ELF object attributes subsection support struct AttributeSubSection { - bool IsActive; // Indicates whether the section is the active section, - // required for assembly parsing - // [ NTBS: vendor-name ]* + bool IsActive; StringRef VendorName; - // * - ARMBuildAttrs::SubsectionOptional IsOptional; - ARMBuildAttrs::SubsectionType ParameterType; + unsigned IsOptional; + unsigned ParameterType; SmallVector Content; }; // Attributes that are added and managed entirely by target. SmallVector Contents; void setAttributeItem(unsigned Attribute, unsigned Value, - bool OverwriteExisting, - SmallVector &Attributes); + bool OverwriteExisting); void setAttributeItem(unsigned Attribute, StringRef Value, - bool OverwriteExisting, - SmallVector &Attributes); + bool OverwriteExisting); void setAttributeItems(unsigned Attribute, unsigned IntValue, - StringRef StringValue, bool OverwriteExisting, - SmallVector &Attributes); + StringRef StringValue, bool OverwriteExisting); void emitAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection) { createAttributesSection(Vendor, Section, Type, AttributeSection, Contents); @@ -142,7 +136,7 @@ class MCELFStreamer : public MCObjectStreamer { emitAttributesSection(MCSection *&AttributeSection, const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { - createAArch64AttributesSection(AttributeSection, Section, Type, + createAttributesWithSubsection(AttributeSection, Section, Type, SubSectionVec); } @@ -153,7 +147,7 @@ class MCELFStreamer : public MCObjectStreamer { void createAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection, SmallVector &AttrsVec); - void createAArch64AttributesSection( + void createAttributesWithSubsection( MCSection *&AttributeSection, const Twine &Section, unsigned Type, SmallVector &SubSectionVec); diff --git a/llvm/include/llvm/Support/AArch64BuildAttributes.h b/llvm/include/llvm/Support/AArch64BuildAttributes.h new file mode 100644 index 0000000000000..dfec69bd425e9 --- /dev/null +++ b/llvm/include/llvm/Support/AArch64BuildAttributes.h @@ -0,0 +1,89 @@ +//===-- AArch64BuildAttributes.h - AARch64 Build Attributes -----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains enumerations and support routines for AArch64 build +// attributes as defined in Build Attributes for the AArch64 document. +// +// Build Attributes for the ArmĀ® 64-bit Architecture (AArch64) 2024Q1 +// +// https://github.com/ARM-software/abi-aa/blob/ada00cc8e04f421cce657e8d9f3a439c69437cf4/buildattr64/buildattr64.rst +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_AARCH64BUILDATTRIBUTES_H +#define LLVM_SUPPORT_AARCH64BUILDATTRIBUTES_H + +#include "llvm/ADT/StringRef.h" + +namespace llvm { + +namespace AArch64BuildAttributes { +// AArch64 build attributes +StringRef getSubsectionTag(); +StringRef getAttrTag(); + +/// AArch64 build attributes vendors IDs (a.k.a subsection name) +enum VendorID : unsigned { + AEABI_FEATURE_AND_BITS = 0, + AEABI_PAUTHABI = 1, + VENDOR_NOT_FOUND = 404 +}; +static const StringRef VendorName[] = {"aeabi_feature_and_bits", + "aeabi_pauthabi"}; +StringRef getVendorName(unsigned const Vendor); +VendorID getVendorID(StringRef const Vendor); +StringRef getSubsectionUnknownError(); + +enum SubsectionOptional : unsigned { + REQUIRED = 0, + OPTIONAL = 1, + OPTIONAL_NOT_FOUND = 404 +}; +static const StringRef OptionalStr[] = {"required", "optional"}; +StringRef getOptionalStr(unsigned Optional); +SubsectionOptional getOptionalID(StringRef Optional); +StringRef getSubsectionOptionalUnknownError(); + +enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1, TYPE_NOT_FOUND = 404 }; +static const StringRef TypeStr[] = {"uleb128", "ntbs"}; +StringRef getTypeStr(unsigned Type); +SubsectionType getTypeID(StringRef Type); +StringRef getSubsectionTypeUnknownError(); + +enum PauthABITags : unsigned { + TAG_PAUTH_PLATFORM = 1, + TAG_PAUTH_SCHEMA = 2, + PAUTHABI_TAG_NOT_FOUND = 404 +}; +static const StringRef PauthABITagsStr[] = {"Tag_PAuth_Platform", + "Tag_PAuth_Schema"}; +StringRef getPauthABITagsStr(unsigned PauthABITag); +PauthABITags getPauthABITagsID(StringRef PauthABITag); +StringRef getPauthabiTagError(); + +enum FeatureAndBitsTags : unsigned { + TAG_FEATURE_BTI = 0, + TAG_FEATURE_PAC = 1, + TAG_FEATURE_GCS = 2, + FEATURE_AND_BITS_TAG_NOT_FOUND = 404 +}; +static const StringRef FeatureAndBitsTagsStr[] = { + "Tag_Feature_BTI", "Tag_Feature_PAC", "Tag_Feature_GCS"}; +StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag); +FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag); +StringRef getFeatureAndBitsTagError(); + +enum FeatureAndBitsFlag : unsigned { + Feature_BTI_Flag = 1 << 0, + Feature_PAC_Flag = 1 << 1, + Feature_GCS_Flag = 1 << 2 +}; +} // namespace AArch64BuildAttributes +} // namespace llvm + +#endif // LLVM_SUPPORT_AARCH64BUILDATTRIBUTES_H \ No newline at end of file diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 6d396842985dc..c4352932dbd21 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -26,68 +26,6 @@ namespace llvm { class StringRef; namespace ARMBuildAttrs { -// AArch64 build attributes -StringRef getSubsectionTag(); -StringRef getAttrTag(); - -/// AArch64 build attributes vendors IDs (a.k.a subsection name) -enum VendorID : unsigned { - AEABI_FEATURE_AND_BITS = 0, - AEABI_PAUTHABI = 1, - VENDOR_NOT_FOUND = 404 -}; -static const StringRef VendorName[] = {"aeabi_feature_and_bits", - "aeabi_pauthabi"}; -StringRef getVendorName(unsigned const Vendor); -VendorID getVendorID(StringRef const Vendor); -StringRef getSubsectionUnknownError(); - -enum SubsectionOptional : unsigned { - REQUIRED = 0, - OPTIONAL = 1, - OPTIONAL_NOT_FOUND = 404 -}; -static const StringRef OptionalStr[] = {"required", "optional"}; -StringRef getOptionalStr(unsigned Optional); -SubsectionOptional getOptionalID(StringRef Optional); -StringRef getSubsectionOptionalUnknownError(); - -enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1, TYPE_NOT_FOUND = 404 }; -static const StringRef TypeStr[] = {"uleb128", "ntbs"}; -StringRef getTypeStr(unsigned Type); -SubsectionType getTypeID(StringRef Type); -StringRef getSubsectionTypeUnknownError(); - -enum PauthABITags : unsigned { - TAG_PAUTH_PLATFORM = 1, - TAG_PAUTH_SCHEMA = 2, - PAUTHABI_TAG_NOT_FOUND = 404 -}; -static const StringRef PauthABITagsStr[] = {"Tag_PAuth_Platform", - "Tag_PAuth_Schema"}; -StringRef getPauthABITagsStr(unsigned PauthABITag); -PauthABITags getPauthABITagsID(StringRef PauthABITag); -StringRef getPauthabiTagError(); - -enum FeatureAndBitsTags : unsigned { - TAG_FEATURE_BTI = 0, - TAG_FEATURE_PAC = 1, - TAG_FEATURE_GCS = 2, - FEATURE_AND_BITS_TAG_NOT_FOUND = 404 -}; -static const StringRef FeatureAndBitsTagsStr[] = { - "Tag_Feature_BTI", "Tag_Feature_PAC", "Tag_Feature_GCS"}; -StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag); -FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag); -StringRef getFeatureAndBitsTagError(); - -enum FeatureAndBitsFlag : unsigned { - Feature_BTI_Flag = 1 << 0, - Feature_PAC_Flag = 1 << 1, - Feature_GCS_Flag = 1 << 2 -}; -///--- AArch64 build attributes - const TagNameMap &getARMAttributeTags(); enum SpecialAttr { diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index b8cb24f3bdf21..ff7c74c62e90a 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -635,11 +635,10 @@ void MCELFStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, llvm_unreachable("ELF doesn't support this directive"); } -void MCELFStreamer::setAttributeItem( - unsigned Attribute, unsigned Value, bool OverwriteExisting, - SmallVector &Attributes) { +void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value, + bool OverwriteExisting) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { + if (AttributeItem *Item = getAttributeItem(Attribute, Contents)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::NumericAttribute; @@ -653,11 +652,10 @@ void MCELFStreamer::setAttributeItem( Contents.push_back(Item); } -void MCELFStreamer::setAttributeItem( - unsigned Attribute, StringRef Value, bool OverwriteExisting, - SmallVector &Attributes) { +void MCELFStreamer::setAttributeItem(unsigned Attribute, StringRef Value, + bool OverwriteExisting) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { + if (AttributeItem *Item = getAttributeItem(Attribute, Contents)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::TextAttribute; @@ -671,11 +669,11 @@ void MCELFStreamer::setAttributeItem( Contents.push_back(Item); } -void MCELFStreamer::setAttributeItems( - unsigned Attribute, unsigned IntValue, StringRef StringValue, - bool OverwriteExisting, SmallVector &Attributes) { +void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue, + StringRef StringValue, + bool OverwriteExisting) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute, Attributes)) { + if (AttributeItem *Item = getAttributeItem(Attribute, Contents)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::NumericAndTextAttributes; @@ -786,7 +784,7 @@ void MCELFStreamer::createAttributesSection( AttrsVec.clear(); } -void MCELFStreamer::createAArch64AttributesSection( +void MCELFStreamer::createAttributesWithSubsection( MCSection *&AttributeSection, const Twine &Section, unsigned Type, SmallVector &SubSectionVec) { // diff --git a/llvm/lib/Support/AArch64BuildAttributes.cpp b/llvm/lib/Support/AArch64BuildAttributes.cpp new file mode 100644 index 0000000000000..bb599ce00c464 --- /dev/null +++ b/llvm/lib/Support/AArch64BuildAttributes.cpp @@ -0,0 +1,143 @@ +//===-- AArch64BuildAttributes.cpp - AArch64 Build Attributes -------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/AArch64BuildAttributes.h" + +namespace llvm { +namespace AArch64BuildAttributes { +// AArch64 build attributes +StringRef getSubsectionTag() { return "aeabi_subsection"; } +StringRef getAttrTag() { return "aeabi_attribute"; } + +StringRef getVendorName(unsigned Vendor) { + switch (Vendor) { + case AEABI_FEATURE_AND_BITS: + return VendorName[AEABI_FEATURE_AND_BITS]; + case AEABI_PAUTHABI: + return VendorName[AEABI_PAUTHABI]; + case VENDOR_NOT_FOUND: + [[fallthrough]]; + default: + assert(0 && "unknown AArch64 vendor"); + return ""; + } +} +VendorID getVendorID(StringRef Vendor) { + if (Vendor == VendorName[AEABI_FEATURE_AND_BITS]) { + return AEABI_FEATURE_AND_BITS; + } + if (Vendor == VendorName[AEABI_PAUTHABI]) { + return AEABI_PAUTHABI; + } + return VENDOR_NOT_FOUND; +} +StringRef getSubsectionUnknownError() { + return "unknown AArch64 build attributes subsection"; +} + +StringRef getOptionalStr(unsigned Optional) { + switch (Optional) { + case REQUIRED: + return OptionalStr[REQUIRED]; + case OPTIONAL: + return OptionalStr[OPTIONAL]; + case OPTIONAL_NOT_FOUND: + [[fallthrough]]; + default: + return ""; + } +} +SubsectionOptional getOptionalID(StringRef Optional) { + if (Optional == OptionalStr[REQUIRED]) + return REQUIRED; + if (Optional == OptionalStr[OPTIONAL]) + return OPTIONAL; + return OPTIONAL_NOT_FOUND; +} +StringRef getSubsectionOptionalUnknownError() { + return "unknown AArch64 build attributes optionality, expecting " + "required|optional"; +} + +StringRef getTypeStr(unsigned Type) { + switch (Type) { + case ULEB128: + return TypeStr[ULEB128]; + case NTBS: + return TypeStr[NTBS]; + case TYPE_NOT_FOUND: + [[fallthrough]]; + default: + return ""; + } +} +SubsectionType getTypeID(StringRef Type) { + if (Type == TypeStr[ULEB128] || Type == (TypeStr[ULEB128].upper())) + return ULEB128; + if (Type == TypeStr[NTBS] || Type == (TypeStr[NTBS].upper())) + return NTBS; + return TYPE_NOT_FOUND; +} +StringRef getSubsectionTypeUnknownError() { + return "unknown AArch64 build attributes type, expecting uleb128|ntbs"; +} + +StringRef getPauthABITagsStr(unsigned PauthABITag) { + switch (PauthABITag) { + case TAG_PAUTH_PLATFORM: + return PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]; // Tag_PAuth_Platform = 1 in + // accordance with the spec + case TAG_PAUTH_SCHEMA: + return PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]; // Tag_PAuth_Schema = 2 in + // accordance with the spec + case PAUTHABI_TAG_NOT_FOUND: + [[fallthrough]]; + default: + return ""; + } +} +PauthABITags getPauthABITagsID(StringRef PauthABITag) { + if (PauthABITag == PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]) + return TAG_PAUTH_PLATFORM; + if (PauthABITag == PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]) + return TAG_PAUTH_SCHEMA; + return PAUTHABI_TAG_NOT_FOUND; +} +StringRef getPauthabiTagError() { + return "unknown tag for the AArch64 Pauthabi subsection"; +} + +StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) { + switch (FeatureAndBitsTag) { + case TAG_FEATURE_BTI: + return FeatureAndBitsTagsStr[TAG_FEATURE_BTI]; + case TAG_FEATURE_PAC: + return FeatureAndBitsTagsStr[TAG_FEATURE_PAC]; + case TAG_FEATURE_GCS: + return FeatureAndBitsTagsStr[TAG_FEATURE_GCS]; + case FEATURE_AND_BITS_TAG_NOT_FOUND: + [[fallthrough]]; + default: + + return ""; + } +} +FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) { + if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_BTI]) + return TAG_FEATURE_BTI; + if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_PAC]) + return TAG_FEATURE_PAC; + if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_GCS]) + return TAG_FEATURE_GCS; + return FEATURE_AND_BITS_TAG_NOT_FOUND; +} +StringRef getFeatureAndBitsTagError() { + return "unknown tag for the AArch64 Feature And Bits subsection"; +} +} // namespace AArch64BuildAttributes +} // namespace llvm diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index 0717a30cfd433..815cfc62a4b0e 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -8,150 +8,6 @@ #include "llvm/Support/ARMBuildAttributes.h" -namespace llvm { -class StringRef; -namespace ARMBuildAttrs { -// AArch64 build attributes -StringRef getSubsectionTag() { return "aeabi_subsection"; } -StringRef getAttrTag() { return "aeabi_attribute"; } - -StringRef getVendorName(unsigned Vendor) { - switch (Vendor) { - case AEABI_FEATURE_AND_BITS: - return VendorName[AEABI_FEATURE_AND_BITS]; - case AEABI_PAUTHABI: - return VendorName[AEABI_PAUTHABI]; - case VENDOR_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown AArch64 vendor"); - return ""; - } -} -VendorID getVendorID(StringRef Vendor) { - if (Vendor == VendorName[AEABI_FEATURE_AND_BITS]) { - return AEABI_FEATURE_AND_BITS; - } - if (Vendor == VendorName[AEABI_PAUTHABI]) { - return AEABI_PAUTHABI; - } - assert(0 && "unknown AArch64 vendor"); - return VENDOR_NOT_FOUND; -} -StringRef getSubsectionUnknownError() { - return "unknown AArch64 build attributes subsection"; -} - -StringRef getOptionalStr(unsigned Optional) { - switch (Optional) { - case REQUIRED: - return OptionalStr[REQUIRED]; - case OPTIONAL: - return OptionalStr[OPTIONAL]; - case OPTIONAL_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown AArch64 Optional option"); - return ""; - } -} -SubsectionOptional getOptionalID(StringRef Optional) { - if (Optional == OptionalStr[REQUIRED]) - return REQUIRED; - if (Optional == OptionalStr[OPTIONAL]) - return OPTIONAL; - assert(0 && "unknown AArch64 Optional option"); - return OPTIONAL_NOT_FOUND; -} -StringRef getSubsectionOptionalUnknownError() { - return "unknown AArch64 build attributes optionality, expecting " - "required|optional"; -} - -StringRef getTypeStr(unsigned Type) { - switch (Type) { - case ULEB128: - return TypeStr[ULEB128]; - case NTBS: - return TypeStr[NTBS]; - case TYPE_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown AArch64 subsection type"); - return ""; - } -} -SubsectionType getTypeID(StringRef Type) { - if (Type == TypeStr[ULEB128] || Type == (TypeStr[ULEB128].upper())) - return ULEB128; - if (Type == TypeStr[NTBS] || Type == (TypeStr[NTBS].upper())) - return NTBS; - assert(0 && "unknown AArch64 subsection type"); - return TYPE_NOT_FOUND; -} -StringRef getSubsectionTypeUnknownError() { - return "unknown AArch64 build attributes type, expecting uleb128 or ntbs"; -} - -StringRef getPauthABITagsStr(unsigned PauthABITag) { - switch (PauthABITag) { - case TAG_PAUTH_PLATFORM: - return PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]; // Tag_PAuth_Platform = 1 in - // accordance with the spec - case TAG_PAUTH_SCHEMA: - return PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]; // Tag_PAuth_Schema = 2 in - // accordance with the spec - case PAUTHABI_TAG_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown pauthabi tag"); - return ""; - } -} -PauthABITags getPauthABITagsID(StringRef PauthABITag) { - if (PauthABITag == PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]) - return TAG_PAUTH_PLATFORM; - if (PauthABITag == PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]) - return TAG_PAUTH_SCHEMA; - assert(0 && "unknown FPauthABI tag"); - return PAUTHABI_TAG_NOT_FOUND; -} -StringRef getPauthabiTagError() { - return "unknown tag for the AArch64 Pauthabi subsection"; -} - -StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) { - switch (FeatureAndBitsTag) { - case TAG_FEATURE_BTI: - return FeatureAndBitsTagsStr[TAG_FEATURE_BTI]; - case TAG_FEATURE_PAC: - return FeatureAndBitsTagsStr[TAG_FEATURE_PAC]; - case TAG_FEATURE_GCS: - return FeatureAndBitsTagsStr[TAG_FEATURE_GCS]; - case FEATURE_AND_BITS_TAG_NOT_FOUND: - [[fallthrough]]; - default: - assert(0 && "unknown feature and bits tag"); - return ""; - } -} -FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) { - if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_BTI]) - return TAG_FEATURE_BTI; - if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_PAC]) - return TAG_FEATURE_PAC; - if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_GCS]) - return TAG_FEATURE_GCS; - assert(0 && "unknown Feature and Bits tag"); - return FEATURE_AND_BITS_TAG_NOT_FOUND; -} -StringRef getFeatureAndBitsTagError() { - return "unknown tag for the AArch64 Feature And Bits subsection"; -} -///--- AArch64 build attributes -} // namespace ARMBuildAttrs -} // namespace llvm - using namespace llvm; static const TagNameItem tagData[] = { diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index 2ecaea4b02bf6..c1989aee2d4ae 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -137,6 +137,7 @@ endif() add_subdirectory(BLAKE3) add_llvm_component_library(LLVMSupport + AArch64BuildAttributes.cpp ABIBreak.cpp AMDGPUMetadata.cpp APFixedPoint.cpp diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index 8c97b581d0df1..85763cee97bb8 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -347,7 +347,7 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { if (const auto *BTE = mdconst::extract_or_null( M.getModuleFlag("branch-target-enforcement"))) { if (!BTE->isZero()) { - BAFlags |= ARMBuildAttrs::FeatureAndBitsFlag::Feature_BTI_Flag; + BAFlags |= AArch64BuildAttributes::FeatureAndBitsFlag::Feature_BTI_Flag; GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI; } } @@ -355,7 +355,7 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { if (const auto *GCS = mdconst::extract_or_null( M.getModuleFlag("guarded-control-stack"))) { if (!GCS->isZero()) { - BAFlags |= ARMBuildAttrs::FeatureAndBitsFlag::Feature_GCS_Flag; + BAFlags |= AArch64BuildAttributes::FeatureAndBitsFlag::Feature_GCS_Flag; GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_GCS; } } @@ -363,7 +363,7 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) { if (const auto *Sign = mdconst::extract_or_null( M.getModuleFlag("sign-return-address"))) { if (!Sign->isZero()) { - BAFlags |= ARMBuildAttrs::FeatureAndBitsFlag::Feature_PAC_Flag; + BAFlags |= AArch64BuildAttributes::FeatureAndBitsFlag::Feature_PAC_Flag; GNUFlags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_PAC; } } @@ -465,30 +465,36 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, PAuthABIVersion = (uint64_t(-1) == PAuthABIVersion) ? 0 : PAuthABIVersion; if (PAuthABIPlatform || PAuthABIVersion) { - TS->emitSubsection(ARMBuildAttrs::AEABI_PAUTHABI, - ARMBuildAttrs::SubsectionOptional::REQUIRED, - ARMBuildAttrs::SubsectionType::ULEB128); - TS->emitAttribute(ARMBuildAttrs::AEABI_PAUTHABI, - ARMBuildAttrs::TAG_PAUTH_PLATFORM, PAuthABIPlatform, + TS->emitAtributesSubsection( + AArch64BuildAttributes::AEABI_PAUTHABI, + AArch64BuildAttributes::SubsectionOptional::REQUIRED, + AArch64BuildAttributes::SubsectionType::ULEB128); + TS->emitAttribute(AArch64BuildAttributes::AEABI_PAUTHABI, + AArch64BuildAttributes::TAG_PAUTH_PLATFORM, + PAuthABIPlatform, false); + TS->emitAttribute(AArch64BuildAttributes::AEABI_PAUTHABI, + AArch64BuildAttributes::TAG_PAUTH_SCHEMA, PAuthABIVersion, false); - TS->emitAttribute(ARMBuildAttrs::AEABI_PAUTHABI, - ARMBuildAttrs::TAG_PAUTH_SCHEMA, PAuthABIVersion, false); } - unsigned BTIValue = (Flags & ARMBuildAttrs::Feature_BTI_Flag) ? 1 : 0; - unsigned PACValue = (Flags & ARMBuildAttrs::Feature_PAC_Flag) ? 1 : 0; - unsigned GCSValue = (Flags & ARMBuildAttrs::Feature_GCS_Flag) ? 1 : 0; + unsigned BTIValue = + (Flags & AArch64BuildAttributes::Feature_BTI_Flag) ? 1 : 0; + unsigned PACValue = + (Flags & AArch64BuildAttributes::Feature_PAC_Flag) ? 1 : 0; + unsigned GCSValue = + (Flags & AArch64BuildAttributes::Feature_GCS_Flag) ? 1 : 0; if (BTIValue || PACValue || GCSValue) { - TS->emitSubsection(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::SubsectionOptional::OPTIONAL, - ARMBuildAttrs::SubsectionType::ULEB128); - TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::TAG_FEATURE_BTI, BTIValue, false); - TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::TAG_FEATURE_PAC, PACValue, false); - TS->emitAttribute(ARMBuildAttrs::AEABI_FEATURE_AND_BITS, - ARMBuildAttrs::TAG_FEATURE_GCS, GCSValue, false); + TS->emitAtributesSubsection( + AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, + AArch64BuildAttributes::SubsectionOptional::OPTIONAL, + AArch64BuildAttributes::SubsectionType::ULEB128); + TS->emitAttribute(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, + AArch64BuildAttributes::TAG_FEATURE_BTI, BTIValue, false); + TS->emitAttribute(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, + AArch64BuildAttributes::TAG_FEATURE_PAC, PACValue, false); + TS->emitAttribute(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, + AArch64BuildAttributes::TAG_FEATURE_GCS, GCSValue, false); } } diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index 00833892a1a49..b5372cc6cfc87 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -7825,13 +7825,15 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { // Consume the name (subsection name) StringRef SubsectionName; - ARMBuildAttrs::VendorID SubsectionNameID; + AArch64BuildAttributes::VendorID SubsectionNameID; if (Parser.getTok().is(AsmToken::Identifier)) { SubsectionName = Parser.getTok().getIdentifier(); - SubsectionNameID = ARMBuildAttrs::getVendorID(SubsectionName); - if (ARMBuildAttrs::VENDOR_NOT_FOUND == SubsectionNameID) { + SubsectionNameID = AArch64BuildAttributes::getVendorID(SubsectionName); + if (AArch64BuildAttributes::VENDOR_NOT_FOUND == SubsectionNameID) { Error(Parser.getTok().getLoc(), - ARMBuildAttrs::getSubsectionUnknownError() + ": " + SubsectionName); + AArch64BuildAttributes::getSubsectionUnknownError() + ": " + + SubsectionName); + return true; } } else { Error(Parser.getTok().getLoc(), "Expecting subsection name"); @@ -7842,19 +7844,19 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { // parseComma() return *false* on success, and call Lex(), no need to call // Lex() again. if (Parser.parseComma()) { - Error(Parser.getTok().getLoc(), "expected ','"); return true; } // Consume the first parameter (optionality parameter) - ARMBuildAttrs::SubsectionOptional IsOptional; + AArch64BuildAttributes::SubsectionOptional IsOptional; // options: optional/required if (Parser.getTok().is(AsmToken::Identifier)) { StringRef Name = Parser.getTok().getIdentifier(); - IsOptional = ARMBuildAttrs::getOptionalID(Name); - if (ARMBuildAttrs::OPTIONAL_NOT_FOUND == IsOptional) { + IsOptional = AArch64BuildAttributes::getOptionalID(Name); + if (AArch64BuildAttributes::OPTIONAL_NOT_FOUND == IsOptional) { Error(Parser.getTok().getLoc(), - ARMBuildAttrs::getSubsectionOptionalUnknownError() + ": " + Name); + AArch64BuildAttributes::getSubsectionOptionalUnknownError() + ": " + + Name); return true; } } else { @@ -7864,15 +7866,15 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } // Check for possible IsOptional unaccepted values for known subsections - if (ARMBuildAttrs::AEABI_FEATURE_AND_BITS == SubsectionNameID) { - if (ARMBuildAttrs::REQUIRED == IsOptional) { + if (AArch64BuildAttributes::AEABI_FEATURE_AND_BITS == SubsectionNameID) { + if (AArch64BuildAttributes::REQUIRED == IsOptional) { Error(Parser.getTok().getLoc(), "aeabi_feature_and_bits must be marked as optional"); return true; } } - if (ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { - if (ARMBuildAttrs::OPTIONAL == IsOptional) { + if (AArch64BuildAttributes::AEABI_PAUTHABI == SubsectionNameID) { + if (AArch64BuildAttributes::OPTIONAL == IsOptional) { Error(Parser.getTok().getLoc(), "aeabi_pauthabi must be marked as required"); return true; @@ -7881,18 +7883,18 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { Parser.Lex(); // consume a comma if (Parser.parseComma()) { - Error(Parser.getTok().getLoc(), "expected ','"); return true; } // Consume the second parameter (type parameter) - ARMBuildAttrs::SubsectionType Type; + AArch64BuildAttributes::SubsectionType Type; if (Parser.getTok().is(AsmToken::Identifier)) { StringRef Name = Parser.getTok().getIdentifier(); - Type = ARMBuildAttrs::getTypeID(Name); - if (ARMBuildAttrs::TYPE_NOT_FOUND == Type) { + Type = AArch64BuildAttributes::getTypeID(Name); + if (AArch64BuildAttributes::TYPE_NOT_FOUND == Type) { Error(Parser.getTok().getLoc(), - ARMBuildAttrs::getSubsectionTypeUnknownError() + ": " + Name); + AArch64BuildAttributes::getSubsectionTypeUnknownError() + ": " + + Name); return true; } } else { @@ -7900,9 +7902,9 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } // Check for possible Type unaccepted values for known subsections - if (ARMBuildAttrs::AEABI_FEATURE_AND_BITS == SubsectionNameID || - ARMBuildAttrs::AEABI_PAUTHABI == SubsectionNameID) { - if (ARMBuildAttrs::NTBS == Type) { + if (AArch64BuildAttributes::AEABI_FEATURE_AND_BITS == SubsectionNameID || + AArch64BuildAttributes::AEABI_PAUTHABI == SubsectionNameID) { + if (AArch64BuildAttributes::NTBS == Type) { Error(Parser.getTok().getLoc(), SubsectionName + " must be marked as ULEB128"); return true; @@ -7916,7 +7918,8 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } - getTargetStreamer().emitSubsection(SubsectionNameID, IsOptional, Type); + getTargetStreamer().emitAtributesSubsection(SubsectionNameID, IsOptional, + Type); return false; } @@ -7926,35 +7929,44 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { // .aeabi_attribute (1)Tag_Feature_BTI, (2)1 // separated by a comma. MCAsmParser &Parser = getParser(); - StringRef ActiveSubsection = ""; - unsigned ActiveSubsectionID; + unsigned ActiveSubsectionID = unsigned(-1); StringRef TagStr = ""; unsigned Tag; + + ActiveSubsection = getTargetStreamer().getActiveAtributesSubsection(); + if ("" == ActiveSubsection) { + Error(Parser.getTok().getLoc(), + "no active subsection, build attribute can not be added"); + return true; + } + if (AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_PAUTHABI] == ActiveSubsection) + ActiveSubsectionID = AArch64BuildAttributes::AEABI_PAUTHABI; + if (AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS] == ActiveSubsection) + ActiveSubsectionID = AArch64BuildAttributes::AEABI_FEATURE_AND_BITS; + if (Parser.getTok().is(AsmToken::Identifier)) { TagStr = Parser.getTok().getIdentifier(); - ActiveSubsection = getTargetStreamer().getActiveSubsection(); - if ("" == ActiveSubsection) { + switch (ActiveSubsectionID) { + default: Error(Parser.getTok().getLoc(), - "no active subsection, build attribute can not be added"); + "Active AArch64 build attribute subsection unknown: " + + Twine(ActiveSubsectionID)); return true; - } - if (ARMBuildAttrs::VendorName[ARMBuildAttrs::AEABI_PAUTHABI] == - ActiveSubsection) { - ActiveSubsectionID = ARMBuildAttrs::AEABI_PAUTHABI; - Tag = ARMBuildAttrs::getPauthABITagsID(TagStr); - if (ARMBuildAttrs::PAUTHABI_TAG_NOT_FOUND == Tag) { + case AArch64BuildAttributes::AEABI_PAUTHABI: + Tag = AArch64BuildAttributes::getPauthABITagsID(TagStr); + if (AArch64BuildAttributes::PAUTHABI_TAG_NOT_FOUND == Tag) { Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + "' for subsection '" + ActiveSubsection + "'"); return true; } - } else if (ARMBuildAttrs::VendorName - [ARMBuildAttrs::AEABI_FEATURE_AND_BITS] == - ActiveSubsection) { - ActiveSubsectionID = ARMBuildAttrs::AEABI_FEATURE_AND_BITS; - Tag = ARMBuildAttrs::getFeatureAndBitsTagsID(TagStr); - if (ARMBuildAttrs::FEATURE_AND_BITS_TAG_NOT_FOUND == Tag) { + break; + case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: + Tag = AArch64BuildAttributes::getFeatureAndBitsTagsID(TagStr); + if (AArch64BuildAttributes::FEATURE_AND_BITS_TAG_NOT_FOUND == Tag) { Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + "' for subsection '" + ActiveSubsection + @@ -7962,8 +7974,8 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { "Tag_Feature_GCS"); return true; } + break; } - // for compatability } else if (Parser.getTok().is(AsmToken::Integer)) { Tag = getTok().getIntVal(); } else { @@ -7975,7 +7987,6 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { // parseComma() return *false* on success, and call Lex(), no need to call // Lex() again. if (Parser.parseComma()) { - Error(Parser.getTok().getLoc(), "expected ','"); return true; } @@ -7988,7 +7999,7 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { return true; } // Check for possible unaccepted values for known tags - if (TagStr != "") { // Tag was a recognized string + if (TagStr != "") { // TagStr was a recognized string if (0 != Value && 1 != Value) { Error(Parser.getTok().getLoc(), "Unknown AArch64 build attributes Value for Tag '" + TagStr + diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 26d1441f3120d..29735b0dea612 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -33,6 +33,7 @@ #include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/MCWinCOFFStreamer.h" +#include "llvm/Support/AArch64BuildAttributes.h" #include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/FormattedStream.h" @@ -157,115 +158,125 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { // .aeabi_attribute tag, value switch (VendorID) { default: { - assert(0 && ARMBuildAttrs::getSubsectionUnknownError().data()); + assert(0 && AArch64BuildAttributes::getSubsectionUnknownError().data()); break; } - case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: + case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: switch (Tag) { - default: - assert(0 && ARMBuildAttrs::getFeatureAndBitsTagError().data()); - break; - case ARMBuildAttrs::TAG_FEATURE_BTI: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" - << ARMBuildAttrs::getFeatureAndBitsTagsStr( - ARMBuildAttrs::TAG_FEATURE_BTI) + default: // allow emitting any attribute by number + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag << ", " << Value; // Keep the data structure consistent with the case of ELF emission // (important for llvm-mc asm parsing) AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; - case ARMBuildAttrs::TAG_FEATURE_GCS: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" - << ARMBuildAttrs::getFeatureAndBitsTagsStr( - ARMBuildAttrs::TAG_FEATURE_GCS) + case AArch64BuildAttributes::TAG_FEATURE_BTI: + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" + << AArch64BuildAttributes::getFeatureAndBitsTagsStr( + AArch64BuildAttributes::TAG_FEATURE_BTI) + << ", " << Value; + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + break; + case AArch64BuildAttributes::TAG_FEATURE_GCS: + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" + << AArch64BuildAttributes::getFeatureAndBitsTagsStr( + AArch64BuildAttributes::TAG_FEATURE_GCS) << ", " << Value; AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; - case ARMBuildAttrs::TAG_FEATURE_PAC: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" - << ARMBuildAttrs::getFeatureAndBitsTagsStr( - ARMBuildAttrs::TAG_FEATURE_PAC) + case AArch64BuildAttributes::TAG_FEATURE_PAC: + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" + << AArch64BuildAttributes::getFeatureAndBitsTagsStr( + AArch64BuildAttributes::TAG_FEATURE_PAC) << ", " << Value; AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; } break; - case ARMBuildAttrs::AEABI_PAUTHABI: + case AArch64BuildAttributes::AEABI_PAUTHABI: switch (Tag) { - default: - assert(0 && ARMBuildAttrs::getFeatureAndBitsTagError().data()); + default: // allow emitting any attribute by number + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag + << ", " << Value; + // Keep the data structure consistent with the case of ELF emission + // (important for llvm-mc asm parsing) + AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; - case ARMBuildAttrs::TAG_PAUTH_PLATFORM: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" - << ARMBuildAttrs::getPauthABITagsStr( - ARMBuildAttrs::TAG_PAUTH_PLATFORM) + case AArch64BuildAttributes::TAG_PAUTH_PLATFORM: + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" + << AArch64BuildAttributes::getPauthABITagsStr( + AArch64BuildAttributes::TAG_PAUTH_PLATFORM) << ", " << Value; AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; - case ARMBuildAttrs::TAG_PAUTH_SCHEMA: - OS << "\t." << ARMBuildAttrs::getAttrTag() << "\t" - << ARMBuildAttrs::getPauthABITagsStr(ARMBuildAttrs::TAG_PAUTH_SCHEMA) + case AArch64BuildAttributes::TAG_PAUTH_SCHEMA: + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" + << AArch64BuildAttributes::getPauthABITagsStr( + AArch64BuildAttributes::TAG_PAUTH_SCHEMA) << ", " << Value; AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); break; } + break; } OS << "\n"; } - void emitSubsection(unsigned Subsection, - ARMBuildAttrs::SubsectionOptional Optional, - ARMBuildAttrs::SubsectionType ParameterType) override { + void emitAtributesSubsection( + unsigned Subsection, AArch64BuildAttributes::SubsectionOptional Optional, + AArch64BuildAttributes::SubsectionType ParameterType) override { // The AArch64 build attributes assembly subsection header format: // ".aeabi_subsection name, optional, parameter type" // optional: required (0) optional (1) // parameter type: uleb128 or ULEB128 (0) ntbs or NTBS (1) assert((0 == Optional || 1 == Optional) && - ARMBuildAttrs::getSubsectionOptionalUnknownError().data()); + AArch64BuildAttributes::getSubsectionOptionalUnknownError().data()); assert((0 == ParameterType || 1 == ParameterType) && - ARMBuildAttrs::getSubsectionTypeUnknownError().data()); + AArch64BuildAttributes::getSubsectionTypeUnknownError().data()); - std::string SubsectionTag = ("." + ARMBuildAttrs::getSubsectionTag()).str(); + std::string SubsectionTag = + ("." + AArch64BuildAttributes::getSubsectionTag()).str(); StringRef OptionalStr = getOptionalStr(Optional); StringRef ParameterStr = getTypeStr(ParameterType); switch (Subsection) { default: { - assert(0 && ARMBuildAttrs::getSubsectionUnknownError().data()); + assert(0 && AArch64BuildAttributes::getSubsectionUnknownError().data()); break; } - case ARMBuildAttrs::AEABI_PAUTHABI: { - assert(ARMBuildAttrs::REQUIRED == Optional && + case AArch64BuildAttributes::AEABI_PAUTHABI: { + assert(AArch64BuildAttributes::REQUIRED == Optional && "subsection .aeabi-pauthabi should be marked as " - "mandatory and not as optional"); - assert(ARMBuildAttrs::ULEB128 == ParameterType && + "required and not as optional"); + assert(AArch64BuildAttributes::ULEB128 == ParameterType && "subsection .aeabi-pauthabi should be " "marked as uleb128 and not as ntbs"); - StringRef SubsectionName = getVendorName(ARMBuildAttrs::AEABI_PAUTHABI); + StringRef SubsectionName = + getVendorName(AArch64BuildAttributes::AEABI_PAUTHABI); OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; // Keep the data structure consistent with the case of ELF emission // (important for llvm-mc asm parsing) - AArch64TargetStreamer::emitSubsection(Subsection, Optional, - ParameterType); + AArch64TargetStreamer::emitAtributesSubsection(Subsection, Optional, + ParameterType); break; - } - case ARMBuildAttrs::AEABI_FEATURE_AND_BITS: { - assert(ARMBuildAttrs::OPTIONAL == Optional && + } break; + case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: { + assert(AArch64BuildAttributes::OPTIONAL == Optional && "subsection .aeabi_feature_and_bits should be " - "marked as optional and not as mandatory"); - assert(ARMBuildAttrs::ULEB128 == ParameterType && + "marked as optional and not as required"); + assert(AArch64BuildAttributes::ULEB128 == ParameterType && "subsection .aeabi_feature_and_bits should " "be marked as uleb128 and not as ntbs"); StringRef SubsectionName = - getVendorName(ARMBuildAttrs::AEABI_FEATURE_AND_BITS); + getVendorName(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS); OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; - AArch64TargetStreamer::emitSubsection(Subsection, Optional, - ParameterType); + AArch64TargetStreamer::emitAtributesSubsection(Subsection, Optional, + ParameterType); break; - } + } break; } OS << "\n"; } @@ -417,10 +428,11 @@ AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() { return static_cast(Streamer); } -void AArch64TargetELFStreamer::emitSubsection( - unsigned VendorID, ARMBuildAttrs::SubsectionOptional IsOptional, - ARMBuildAttrs::SubsectionType ParameterType) { - AArch64TargetStreamer::emitSubsection(VendorID, IsOptional, ParameterType); +void AArch64TargetELFStreamer::emitAtributesSubsection( + unsigned VendorID, AArch64BuildAttributes::SubsectionOptional IsOptional, + AArch64BuildAttributes::SubsectionType ParameterType) { + AArch64TargetStreamer::emitAtributesSubsection(VendorID, IsOptional, + ParameterType); } void AArch64TargetELFStreamer::emitAttribute(unsigned VendorID, unsigned Tag, diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp index c014ddcab452e..5fa0ca6163d4c 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp @@ -152,15 +152,15 @@ MCTargetStreamer *llvm::createAArch64NullTargetStreamer(MCStreamer &S) { return new AArch64TargetStreamer(S); } -void AArch64TargetStreamer::emitSubsection( - unsigned VendorID, ARMBuildAttrs::SubsectionOptional IsOptional, - ARMBuildAttrs::SubsectionType ParameterType) { - StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); +void AArch64TargetStreamer::emitAtributesSubsection( + unsigned VendorID, AArch64BuildAttributes::SubsectionOptional IsOptional, + AArch64BuildAttributes::SubsectionType ParameterType) { + StringRef VendorName = AArch64BuildAttributes::getVendorName(VendorID); // If exists, return. for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { if (VendorName == SubSection.VendorName) { - activateSubsection(VendorName); + activateAtributesSubsection(VendorName); return; } } @@ -170,10 +170,10 @@ void AArch64TargetStreamer::emitSubsection( AttSubSection.IsOptional = IsOptional; AttSubSection.ParameterType = ParameterType; AttributeSubSections.push_back(AttSubSection); - activateSubsection(VendorName); + activateAtributesSubsection(VendorName); } -StringRef AArch64TargetStreamer::getActiveSubsection() { +StringRef AArch64TargetStreamer::getActiveAtributesSubsection() { for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { if (SubSection.IsActive) { return SubSection.VendorName; @@ -184,7 +184,7 @@ StringRef AArch64TargetStreamer::getActiveSubsection() { void AArch64TargetStreamer::emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override) { - StringRef VendorName = ARMBuildAttrs::getVendorName(VendorID); + StringRef VendorName = AArch64BuildAttributes::getVendorName(VendorID); if (AttributeSubSections.size() == 0) { assert(0 && @@ -209,6 +209,10 @@ void AArch64TargetStreamer::emitAttribute(unsigned VendorID, unsigned Tag, return; } } + // Case Item.IntValue == Value, no need to emit twice + assert(0 && "AArch64 build attribute: An attribute with the same tag " + "and a same value allready exists"); + return; } } SubSection.Content.push_back(MCELFStreamer::AttributeItem( @@ -220,7 +224,7 @@ void AArch64TargetStreamer::emitAttribute(unsigned VendorID, unsigned Tag, "not exists"); } -void AArch64TargetStreamer::activateSubsection(StringRef VendorName) { +void AArch64TargetStreamer::activateAtributesSubsection(StringRef VendorName) { for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { if (VendorName == SubSection.VendorName) { SubSection.IsActive = true; diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index 48bab0bbc9905..d8ecf1c0cf957 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -14,7 +14,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/MC/MCELFStreamer.h" #include "llvm/MC/MCStreamer.h" -#include "llvm/Support/ARMBuildAttributes.h" +#include "llvm/Support/AArch64BuildAttributes.h" #include namespace { @@ -95,13 +95,17 @@ class AArch64TargetStreamer : public MCTargetStreamer { virtual void emitARM64WinCFISaveAnyRegQPX(unsigned Reg, int Offset) {} /// Build attributes implementation - virtual void emitSubsection(unsigned VendorID, - ARMBuildAttrs::SubsectionOptional IsOptional, - ARMBuildAttrs::SubsectionType ParameterType); + virtual void + emitAtributesSubsection(unsigned VendorID, + AArch64BuildAttributes::SubsectionOptional IsOptional, + AArch64BuildAttributes::SubsectionType ParameterType); virtual void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override); - void activateSubsection(StringRef VendorName); - StringRef getActiveSubsection(); + void activateAtributesSubsection(StringRef VendorName); + StringRef getActiveAtributesSubsection(); + void + insertAttributeInPlace(const MCELFStreamer::AttributeItem &Attr, + MCELFStreamer::AttributeSubSection &AttSubSection); SmallVector AttributeSubSections; @@ -116,9 +120,9 @@ class AArch64TargetELFStreamer : public AArch64TargetStreamer { MCSection *AttributeSection = nullptr; /// Build attributes implementation - void emitSubsection(unsigned VendorID, - ARMBuildAttrs::SubsectionOptional IsOptional, - ARMBuildAttrs::SubsectionType ParameterType) override; + void emitAtributesSubsection( + unsigned VendorID, AArch64BuildAttributes::SubsectionOptional IsOptional, + AArch64BuildAttributes::SubsectionType ParameterType) override; void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, bool Override = false) override; diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 8c7fc4e7a1771..c528526382a2b 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -793,23 +793,20 @@ void ARMTargetELFStreamer::switchVendor(StringRef Vendor) { void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) { getStreamer().setAttributeItem(Attribute, Value, - /* OverwriteExisting= */ true, - getStreamer().Contents); + /* OverwriteExisting= */ true); } void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute, StringRef Value) { getStreamer().setAttributeItem(Attribute, Value, - /* OverwriteExisting= */ true, - getStreamer().Contents); + /* OverwriteExisting= */ true); } void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) { getStreamer().setAttributeItems(Attribute, IntValue, StringValue, - /* OverwriteExisting= */ true, - getStreamer().Contents); + /* OverwriteExisting= */ true); } void ARMTargetELFStreamer::emitArch(ARM::ArchKind Value) { @@ -824,19 +821,16 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { using namespace ARMBuildAttrs; ARMELFStreamer &S = getStreamer(); - S.setAttributeItem(CPU_name, ARM::getCPUAttr(Arch), false, - getStreamer().Contents); + S.setAttributeItem(CPU_name, ARM::getCPUAttr(Arch), false); if (EmittedArch == ARM::ArchKind::INVALID) - S.setAttributeItem(CPU_arch, ARM::getArchAttr(Arch), false, - getStreamer().Contents); + S.setAttributeItem(CPU_arch, ARM::getArchAttr(Arch), false); else - S.setAttributeItem(CPU_arch, ARM::getArchAttr(EmittedArch), false, - getStreamer().Contents); + S.setAttributeItem(CPU_arch, ARM::getArchAttr(EmittedArch), false); switch (Arch) { case ARM::ArchKind::ARMV4: - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false); break; case ARM::ArchKind::ARMV4T: @@ -844,50 +838,42 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { case ARM::ArchKind::XSCALE: case ARM::ArchKind::ARMV5TE: case ARM::ArchKind::ARMV6: - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, Allowed, false); break; case ARM::ArchKind::ARMV6T2: - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, - getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); break; case ARM::ArchKind::ARMV6K: case ARM::ArchKind::ARMV6KZ: - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(Virtualization_use, AllowTZ, false, - getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, Allowed, false); + S.setAttributeItem(Virtualization_use, AllowTZ, false); break; case ARM::ArchKind::ARMV6M: - S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, Allowed, false); break; case ARM::ArchKind::ARMV7A: - S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, - getStreamer().Contents); - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, - getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); break; case ARM::ArchKind::ARMV7R: - S.setAttributeItem(CPU_arch_profile, RealTimeProfile, false, - getStreamer().Contents); - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, - getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, RealTimeProfile, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); break; case ARM::ArchKind::ARMV7EM: case ARM::ArchKind::ARMV7M: - S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, - getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, - getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); break; case ARM::ArchKind::ARMV8A: @@ -907,34 +893,29 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { case ARM::ArchKind::ARMV9_4A: case ARM::ArchKind::ARMV9_5A: case ARM::ArchKind::ARMV9_6A: - S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false, - getStreamer().Contents); - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false, - getStreamer().Contents); - S.setAttributeItem(MPextension_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(Virtualization_use, AllowTZVirtualization, false, - getStreamer().Contents); + S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false); + S.setAttributeItem(MPextension_use, Allowed, false); + S.setAttributeItem(Virtualization_use, AllowTZVirtualization, false); break; case ARM::ArchKind::ARMV8MBaseline: case ARM::ArchKind::ARMV8MMainline: - S.setAttributeItem(THUMB_ISA_use, AllowThumbDerived, false, - getStreamer().Contents); - S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false, - getStreamer().Contents); + S.setAttributeItem(THUMB_ISA_use, AllowThumbDerived, false); + S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false); break; case ARM::ArchKind::IWMMXT: - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(WMMX_arch, AllowWMMXv1, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, Allowed, false); + S.setAttributeItem(WMMX_arch, AllowWMMXv1, false); break; case ARM::ArchKind::IWMMXT2: - S.setAttributeItem(ARM_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(THUMB_ISA_use, Allowed, false, getStreamer().Contents); - S.setAttributeItem(WMMX_arch, AllowWMMXv2, false, getStreamer().Contents); + S.setAttributeItem(ARM_ISA_use, Allowed, false); + S.setAttributeItem(THUMB_ISA_use, Allowed, false); + S.setAttributeItem(WMMX_arch, AllowWMMXv2, false); break; default: @@ -952,47 +933,47 @@ void ARMTargetELFStreamer::emitFPUDefaultAttributes() { case ARM::FK_VFP: case ARM::FK_VFPV2: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv2, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_VFPV3: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_VFPV3_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_VFPV3_D16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_VFPV3_D16_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_VFPV3XD: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_VFPV3XD_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3B, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_VFPV4: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv4A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; // ABI_HardFP_use is handled in ARMAsmPrinter, so _SP_D16 is treated the same @@ -1000,12 +981,12 @@ void ARMTargetELFStreamer::emitFPUDefaultAttributes() { case ARM::FK_FPV4_SP_D16: case ARM::FK_VFPV4_D16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv4B, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_FP_ARMV8: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPARMv8A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; // FPV5_D16 is identical to FP_ARMV8 except for the number of D registers, so @@ -1017,39 +998,39 @@ void ARMTargetELFStreamer::emitFPUDefaultAttributes() { case ARM::FK_FP_ARMV8_FULLFP16_SP_D16: case ARM::FK_FP_ARMV8_FULLFP16_D16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPARMv8B, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_NEON: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch, ARMBuildAttrs::AllowNeon, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_NEON_FP16: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv3A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch, ARMBuildAttrs::AllowNeon, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); S.setAttributeItem(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_NEON_VFPV4: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPv4A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch, ARMBuildAttrs::AllowNeon2, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); break; case ARM::FK_NEON_FP_ARMV8: case ARM::FK_CRYPTO_NEON_FP_ARMV8: S.setAttributeItem(ARMBuildAttrs::FP_arch, ARMBuildAttrs::AllowFPARMv8A, - /* OverwriteExisting= */ false, getStreamer().Contents); + /* OverwriteExisting= */ false); // 'Advanced_SIMD_arch' must be emitted not here, but within // ARMAsmPrinter::emitAttributes(), depending on hasV8Ops() and hasV8_1a() break; diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp index 4bc205e3f4b6d..aa86b2df85629 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -330,8 +330,7 @@ class HexagonTargetELFStreamer : public HexagonTargetStreamer { void emitAttribute(uint32_t Attribute, uint32_t Value) override { getStreamer().setAttributeItem(Attribute, Value, - /*OverwriteExisting=*/true, - getStreamer().Contents); + /*OverwriteExisting=*/true); } }; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp index b5e2338f379b6..ea0e9fcde21cf 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp @@ -57,22 +57,19 @@ void RISCVTargetELFStreamer::emitDirectiveOptionRelax() {} void RISCVTargetELFStreamer::emitDirectiveOptionNoRelax() {} void RISCVTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) { - getStreamer().setAttributeItem(Attribute, Value, /*OverwriteExisting=*/true, - getStreamer().Contents); + getStreamer().setAttributeItem(Attribute, Value, /*OverwriteExisting=*/true); } void RISCVTargetELFStreamer::emitTextAttribute(unsigned Attribute, StringRef String) { - getStreamer().setAttributeItem(Attribute, String, /*OverwriteExisting=*/true, - getStreamer().Contents); + getStreamer().setAttributeItem(Attribute, String, /*OverwriteExisting=*/true); } void RISCVTargetELFStreamer::emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) { getStreamer().setAttributeItems(Attribute, IntValue, StringValue, - /*OverwriteExisting=*/true, - getStreamer().Contents); + /*OverwriteExisting=*/true); } void RISCVTargetELFStreamer::finishAttributeSection() { diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-all.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll similarity index 100% rename from llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-all.ll rename to llvm/test/CodeGen/AArch64/aarch64-build-attributes-all.ll diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-bti.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-bti.ll similarity index 100% rename from llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-bti.ll rename to llvm/test/CodeGen/AArch64/aarch64-build-attributes-bti.ll diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-gcs.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-gcs.ll similarity index 100% rename from llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-gcs.ll rename to llvm/test/CodeGen/AArch64/aarch64-build-attributes-gcs.ll diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-pac.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-pac.ll similarity index 100% rename from llvm/test/CodeGen/AArch64/aarch64-build-attributes-asm-pac.ll rename to llvm/test/CodeGen/AArch64/aarch64-build-attributes-pac.ll diff --git a/llvm/test/CodeGen/AArch64/aarch64-build-attributes-pauthabi.ll b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-pauthabi.ll new file mode 100644 index 0000000000000..7e41167e8fff5 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/aarch64-build-attributes-pauthabi.ll @@ -0,0 +1,19 @@ +; RUN: llc < %s | FileCheck %s --check-prefix=ASM +; RUN: llc %s -filetype=obj -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF + +; ASM: .text +; ASM-NEXT: .aeabi_subsection aeabi_pauthabi, required, uleb128 +; ASM-NEXT: .aeabi_attribute Tag_PAuth_Platform, 2 +; ASM-NEXT: .aeabi_attribute Tag_PAuth_Schema, 31 + +; ELF: Hex dump of section '.ARM.attributes': +; ELF-NEXT: 0x00000000 41190000 00616561 62695f70 61757468 A....aeabi_pauth +; ELF-NEXT: 0x00000010 61626900 00000102 021f + + +target triple = "aarch64-unknown-none-elf" + +!llvm.module.flags = !{!1, !2} + +!1 = !{i32 1, !"aarch64-elf-pauthabi-platform", i32 2} +!2 = !{i32 1, !"aarch64-elf-pauthabi-version", i32 31} diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s new file mode 100644 index 0000000000000..72dbc5bd69809 --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s @@ -0,0 +1,62 @@ +// RUN: not llvm-mc -triple=aarch64 %s -o %t > %t.out 2>&1 +// RUN: FileCheck --input-file=%t.out --check-prefix=ERR %s + +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute Tag_Feature_BTI, 1 +// ERR: error: Unknown AArch64 build attribute 'Tag_Feature_BTI' for subsection 'aeabi_pauthabi' +// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 + +.aeabi_attribute a, 1 +// ERR: Unknown AArch64 build attribute 'a' for subsection 'aeabi_pauthabi' +// ERR-NEXT: .aeabi_attribute a, 1 + +.aeabi_attribute Tag_PAuth_Platform, Tag_PAuth_Platform +// ERR: error: AArch64 build attributes Value not found +// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, Tag_PAuth_Platform + +.aeabi_attribute Tag_PAuth_Platform, a +// ERR: error: AArch64 build attributes Value not found +// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, a + +.aeabi_attribute Tag_PAuth_Platform, +// ERR: error: AArch64 build attributes Value not found +// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, + +.aeabi_attribute Tag_PAuth_Platform +// ERR: error: expected comma +// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform + +.aeabi_attribute +// ERR: error: AArch64 build attributes Tag not found +// ERR-NEXT: .aeabi_attribute + +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute Tag_PAuth_Platform, 1 +// ERR: error: Unknown AArch64 build attribute 'Tag_PAuth_Platform' for subsection 'aeabi_feature_and_bits' +// ERR-NEXT: Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, Tag_Feature_GCS +// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, 1 + +.aeabi_attribute a, 1 +// ERR: error: Unknown AArch64 build attribute 'a' for subsection 'aeabi_feature_and_bits' +// ERR-NEXT: Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, Tag_Feature_GCS +// ERR-NEXT: .aeabi_attribute a, 1 + +.aeabi_attribute Tag_Feature_BTI, Tag_Feature_BTI +// ERR: error: AArch64 build attributes Value not found +// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, Tag_Feature_BTI + +.aeabi_attribute Tag_Feature_BTI, a +// ERR: error: AArch64 build attributes Value not found +// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, a + +.aeabi_attribute Tag_Feature_BTI, +// ERR: AArch64 build attributes Value not found +// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, + +.aeabi_attribute Tag_Feature_BTI +// ERR: error: expected comma +// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI + +.aeabi_attribute +// ERR: error: AArch64 build attributes Tag not found +// ERR-NEXT: .aeabi_attribute \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s new file mode 100644 index 0000000000000..c0d792ba08d68 --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s @@ -0,0 +1,84 @@ +// RUN: not llvm-mc -triple=aarch64 %s -o %t > %t.out 2>&1 +// RUN: FileCheck --input-file=%t.out --check-prefix=ERR %s + +.aeabi_subsection aeabi_pauthabi, optional, uleb128 +// ERR: error: aeabi_pauthabi must be marked as required +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, optional, uleb128 + +.aeabi_subsection aeabi_pauthabi, required, ntbs +// ERR: error: aeabi_pauthabi must be marked as ULEB128 +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, ntbs + +.aeabi_subsection aeabi_feature_and_bits, required, uleb128 +// ERR: error: aeabi_feature_and_bits must be marked as optional +// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, required, uleb128 + +.aeabi_subsection aeabi_feature_and_bits, optional, ntbs +// ERR: error: aeabi_feature_and_bits must be marked as ULEB128 +// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, ntbs + +.aeabi_subsection a, required, uleb128 +// ERR: error: unknown AArch64 build attributes subsection: a +// ERR-NEXT: .aeabi_subsection a, required, uleb128 + +.aeabi_subsection 1, required, uleb128 +// ERR: error: Expecting subsection name +// ERR-NEXT: .aeabi_subsection 1, required, uleb128 + +.aeabi_subsection , required, uleb128 +// ERR: error: Expecting subsection name +// ERR-NEXT: .aeabi_subsection , required, uleb128 + +.aeabi_subsection required, uleb128 +// ERR: error: unknown AArch64 build attributes subsection: required +// ERR-NEXT: .aeabi_subsection required, uleb128 + +.aeabi_subsection aeabi_pauthabi, a, uleb128 +// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: a +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, a, uleb128 + +.aeabi_subsection aeabi_pauthabi, 1, uleb128 +// ERR: error: Expecitng optionality parameter +// ERR-NEXT: Hint: use 'optional' | 'required' +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, 1, uleb128 + +.aeabi_subsection aeabi_pauthabi, ,uleb128 +// ERR: error: Expecitng optionality parameter +// ERR-NEXT: Hint: use 'optional' | 'required' +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, ,uleb128 + +.aeabi_subsection aeabi_pauthabi,uleb128 +// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: uleb128 +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi,uleb128 + +.aeabi_subsection aeabi_pauthabi uleb128 +// ERR: expected comma +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi uleb128 + +.aeabi_subsection aeabi_pauthabi, required +// ERR: error: expected comma +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required + +.aeabi_subsection aeabi_pauthabi, required, +// ERR: error: Expecitng type parameter +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, + +.aeabi_subsection aeabi_pauthabi, required, a +// ERR: error: unknown AArch64 build attributes type, expecting uleb128|ntbs: a +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, a + +.aeabi_subsection aeabi_pauthabi, required, 1 +// ERR: error: Expecitng type parameter +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, 1 + +.aeabi_subsection aeabi_pauthabi +// ERR: error: expected comma +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi + +.aeabi_subsection aeabi_feature_and_bits, a, uleb128 +// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: a +// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, a, uleb128 + +.aeabi_subsection aeabi_feature_and_bits, optional, 1 +// ERR: error: Expecitng type parameter +// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, 1 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-numerical-tags.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-numerical-tags.s new file mode 100644 index 0000000000000..2cdae778df5de --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-numerical-tags.s @@ -0,0 +1,41 @@ +// RUN: llvm-mc -triple=aarch64 %s -o - | FileCheck %s --check-prefix=ASM + +// ASM: .text +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute 0, 1 +// ASM: .aeabi_attribute Tag_PAuth_Platform, 1 +// ASM: .aeabi_attribute Tag_PAuth_Schema, 1 +// ASM: .aeabi_attribute 3, 1 +// ASM: .aeabi_attribute 4, 1 +// ASM: .aeabi_attribute 5, 1 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 1 +// ASM: .aeabi_attribute Tag_Feature_PAC, 1 +// ASM: .aeabi_attribute Tag_Feature_GCS, 1 +// ASM: .aeabi_attribute 3, 1 +// ASM: .aeabi_attribute 4, 1 +// ASM: .aeabi_attribute 5, 1 + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 41210000 00616561 62695f70 61757468 A!...aeabi_pauth +// ELF-NEXT: 0x00000010 61626900 00000001 01010201 03010401 abi............. +// ELF-NEXT: 0x00000020 05012900 00006165 6162695f 66656174 ..)...aeabi_feat +// ELF-NEXT: 0x00000030 7572655f 616e645f 62697473 00010000 ure_and_bits.... +// ELF-NEXT: 0x00000040 01010102 01030104 010501 + + +.text +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 +.aeabi_attribute 2, 1 +.aeabi_attribute 3, 1 +.aeabi_attribute 4, 1 +.aeabi_attribute 5, 1 +.aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 +.aeabi_attribute 2, 1 +.aeabi_attribute 3, 1 +.aeabi_attribute 4, 1 +.aeabi_attribute 5, 1 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s index 8a7f681b5f3e7..08ea2173ab86c 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-out-of-order.s @@ -2,30 +2,30 @@ // RUN: llvm-mc -triple=aarch64 -filetype=obj %s -o - | llvm-readelf --hex-dump=.ARM.attributes - | FileCheck %s --check-prefix=ELF // ASM: .text -// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 -// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// ASM: .aeabi_attribute Tag_Feature_BTI, 1 -// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 -// ASM: .aeabi_attribute Tag_PAuth_Schema, 1 -// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 -// ASM: .aeabi_attribute Tag_PAuth_Platform, 1 -// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 -// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// ASM: .aeabi_attribute Tag_Feature_GCS, 1 -// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 -// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// ASM: .aeabi_attribute Tag_Feature_BTI, 1 -// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -// ASM: .aeabi_attribute Tag_Feature_PAC, 1 -// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 -// ASM: .aeabi_attribute Tag_PAuth_Schema, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_BTI, 1 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute Tag_PAuth_Schema, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_attribute Tag_PAuth_Platform, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_GCS, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute Tag_Feature_PAC, 0 +// ASM: .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 +// ASM: .aeabi_attribute 7, 1 +// ASM: .aeabi_subsection aeabi_pauthabi, required, uleb128 +// 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 01010201 25000000 abi.........%... +// ELF-NEXT: 0x00000010 61626900 00000201 01010700 25000000 abi.........%... // ELF-NEXT: 0x00000020 61656162 695f6665 61747572 655f616e aeabi_feature_an -// ELF-NEXT: 0x00000030 645f6269 74730001 00000102 01000101 d_bits.......... +// ELF-NEXT: 0x00000030 645f6269 74730001 00000102 01010007 d_bits.......... // ELF-NEXT: 0x00000040 01 @@ -43,8 +43,8 @@ .aeabi_attribute Tag_Feature_GCS, 1 .aeabi_subsection aeabi_pauthabi, required, uleb128 .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -.aeabi_attribute Tag_Feature_BTI, 1 +.aeabi_attribute Tag_Feature_PAC, 0 .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 -.aeabi_attribute Tag_Feature_PAC, 1 +.aeabi_attribute 7, 1 .aeabi_subsection aeabi_pauthabi, required, uleb128 -.aeabi_attribute Tag_PAuth_Schema, 1 \ No newline at end of file +.aeabi_attribute 7, 0 \ No newline at end of file diff --git a/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn index d152aec19d1b5..861790d5081c8 100644 --- a/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn @@ -33,6 +33,7 @@ static_library("Support") { "Windows", ] sources = [ + "AArch64BuildAttributes.cpp" "ABIBreak.cpp", "AMDGPUMetadata.cpp", "APFixedPoint.cpp", From a09c7312d3218e3d03fea757594b058d4f4441ca Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Fri, 20 Dec 2024 18:07:49 +0000 Subject: [PATCH 14/21] - remove unused variables and includes --- llvm/include/llvm/MC/MCELFStreamer.h | 5 +---- llvm/include/llvm/Support/ARMBuildAttributes.h | 5 +---- llvm/lib/MC/MCELFStreamer.cpp | 11 +++++------ .../lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp | 2 -- .../AArch64/MCTargetDesc/AArch64ELFStreamer.cpp | 5 +---- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 8984a9ba9d0ed..5a1cdd9e96cad 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -10,10 +10,8 @@ #define LLVM_MC_MCELFSTREAMER_H #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCObjectStreamer.h" -#include "llvm/Support/ARMBuildAttributes.h" namespace llvm { @@ -141,8 +139,7 @@ class MCELFStreamer : public MCObjectStreamer { } private: - AttributeItem *getAttributeItem(unsigned Attribute, - SmallVector &Attributes); + AttributeItem *getAttributeItem(unsigned Attribute); size_t calculateContentSize(SmallVector &AttrsVec) const; void createAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection, diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index c4352932dbd21..35f8992ca9329 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -19,13 +19,10 @@ #define LLVM_SUPPORT_ARMBUILDATTRIBUTES_H #include "llvm/Support/ELFAttributes.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/TableGen/Record.h" namespace llvm { -class StringRef; - namespace ARMBuildAttrs { + const TagNameMap &getARMAttributeTags(); enum SpecialAttr { diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index ff7c74c62e90a..282c82198507d 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -638,7 +638,7 @@ void MCELFStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value, bool OverwriteExisting) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute, Contents)) { + if (AttributeItem *Item = getAttributeItem(Attribute)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::NumericAttribute; @@ -655,7 +655,7 @@ void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value, void MCELFStreamer::setAttributeItem(unsigned Attribute, StringRef Value, bool OverwriteExisting) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute, Contents)) { + if (AttributeItem *Item = getAttributeItem(Attribute)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::TextAttribute; @@ -673,7 +673,7 @@ void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue, StringRef StringValue, bool OverwriteExisting) { // Look for existing attribute item - if (AttributeItem *Item = getAttributeItem(Attribute, Contents)) { + if (AttributeItem *Item = getAttributeItem(Attribute)) { if (!OverwriteExisting) return; Item->Type = AttributeItem::NumericAndTextAttributes; @@ -689,9 +689,8 @@ void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue, } MCELFStreamer::AttributeItem * -MCELFStreamer::getAttributeItem(unsigned Attribute, - SmallVector &Attributes) { - for (AttributeItem &Item : Attributes) +MCELFStreamer::getAttributeItem(unsigned Attribute) { + for (AttributeItem &Item : Contents) if (Item.Tag == Attribute) return &Item; return nullptr; diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index b5372cc6cfc87..9e395388596fa 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -42,8 +42,6 @@ #include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/MCValue.h" #include "llvm/MC/TargetRegistry.h" -#include "llvm/Support/ARMBuildAttributes.h" -#include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 29735b0dea612..cd275e5efad9d 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -34,7 +34,6 @@ #include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/MCWinCOFFStreamer.h" #include "llvm/Support/AArch64BuildAttributes.h" -#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/raw_ostream.h" @@ -48,7 +47,6 @@ class AArch64ELFStreamer; class AArch64TargetAsmStreamer : public AArch64TargetStreamer { formatted_raw_ostream &OS; std::string VendorTag; - bool IsVerboseAsm; void emitInst(uint32_t Inst) override; @@ -287,8 +285,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { AArch64TargetAsmStreamer::AArch64TargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS) - : AArch64TargetStreamer(S), OS(OS), VendorTag("eabi"), - IsVerboseAsm(S.isVerboseAsm()) {} + : AArch64TargetStreamer(S), OS(OS) {} void AArch64TargetAsmStreamer::emitInst(uint32_t Inst) { OS << "\t.inst\t0x" << Twine::utohexstr(Inst) << "\n"; From 22bee6f36590bd8c86cfaacacbc280cba4a2508b Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Fri, 10 Jan 2025 15:37:50 +0000 Subject: [PATCH 15/21] Add support for private subsections, add tests for type NTBS --- .../llvm/Support/AArch64BuildAttributes.h | 3 +- llvm/lib/Support/AArch64BuildAttributes.cpp | 11 +- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 34 +++-- .../AArch64/AsmParser/AArch64AsmParser.cpp | 123 ++++++++++++------ .../MCTargetDesc/AArch64ELFStreamer.cpp | 93 ++++++++----- .../MCTargetDesc/AArch64TargetStreamer.cpp | 43 +++--- .../MCTargetDesc/AArch64TargetStreamer.h | 17 +-- .../aarch64-build-attributes-asm-err-attrs.s | 8 +- ...aarch64-build-attributes-asm-err-headers.s | 8 +- .../aarch64-build-attributes-asm-pac.s | 2 +- ...d-attributes-asm-private-subsections-err.s | 12 ++ ...build-attributes-asm-private-subsections.s | 41 ++++++ 12 files changed, 270 insertions(+), 125 deletions(-) create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s create mode 100644 llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s diff --git a/llvm/include/llvm/Support/AArch64BuildAttributes.h b/llvm/include/llvm/Support/AArch64BuildAttributes.h index dfec69bd425e9..0ca8533abf5d7 100644 --- a/llvm/include/llvm/Support/AArch64BuildAttributes.h +++ b/llvm/include/llvm/Support/AArch64BuildAttributes.h @@ -31,13 +31,12 @@ StringRef getAttrTag(); enum VendorID : unsigned { AEABI_FEATURE_AND_BITS = 0, AEABI_PAUTHABI = 1, - VENDOR_NOT_FOUND = 404 + VENDOR_UNKNOWN = 404 // Treated as a private subsection name }; static const StringRef VendorName[] = {"aeabi_feature_and_bits", "aeabi_pauthabi"}; StringRef getVendorName(unsigned const Vendor); VendorID getVendorID(StringRef const Vendor); -StringRef getSubsectionUnknownError(); enum SubsectionOptional : unsigned { REQUIRED = 0, diff --git a/llvm/lib/Support/AArch64BuildAttributes.cpp b/llvm/lib/Support/AArch64BuildAttributes.cpp index bb599ce00c464..cdf25725cc86e 100644 --- a/llvm/lib/Support/AArch64BuildAttributes.cpp +++ b/llvm/lib/Support/AArch64BuildAttributes.cpp @@ -20,10 +20,10 @@ StringRef getVendorName(unsigned Vendor) { return VendorName[AEABI_FEATURE_AND_BITS]; case AEABI_PAUTHABI: return VendorName[AEABI_PAUTHABI]; - case VENDOR_NOT_FOUND: - [[fallthrough]]; + case VENDOR_UNKNOWN: + return ""; default: - assert(0 && "unknown AArch64 vendor"); + assert(0 && "Vendor name error"); return ""; } } @@ -34,10 +34,7 @@ VendorID getVendorID(StringRef Vendor) { if (Vendor == VendorName[AEABI_PAUTHABI]) { return AEABI_PAUTHABI; } - return VENDOR_NOT_FOUND; -} -StringRef getSubsectionUnknownError() { - return "unknown AArch64 build attributes subsection"; + return VENDOR_UNKNOWN; } StringRef getOptionalStr(unsigned Optional) { diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index 85763cee97bb8..e1ae7818fcc2c 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -466,15 +466,18 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, if (PAuthABIPlatform || PAuthABIVersion) { TS->emitAtributesSubsection( - AArch64BuildAttributes::AEABI_PAUTHABI, + AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_PAUTHABI], AArch64BuildAttributes::SubsectionOptional::REQUIRED, AArch64BuildAttributes::SubsectionType::ULEB128); - TS->emitAttribute(AArch64BuildAttributes::AEABI_PAUTHABI, + TS->emitAttribute(AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_PAUTHABI], AArch64BuildAttributes::TAG_PAUTH_PLATFORM, - PAuthABIPlatform, false); - TS->emitAttribute(AArch64BuildAttributes::AEABI_PAUTHABI, + PAuthABIPlatform, "", false); + TS->emitAttribute(AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_PAUTHABI], AArch64BuildAttributes::TAG_PAUTH_SCHEMA, PAuthABIVersion, - false); + "", false); } unsigned BTIValue = @@ -486,15 +489,22 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, if (BTIValue || PACValue || GCSValue) { TS->emitAtributesSubsection( - AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, + AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], AArch64BuildAttributes::SubsectionOptional::OPTIONAL, AArch64BuildAttributes::SubsectionType::ULEB128); - TS->emitAttribute(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, - AArch64BuildAttributes::TAG_FEATURE_BTI, BTIValue, false); - TS->emitAttribute(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, - AArch64BuildAttributes::TAG_FEATURE_PAC, PACValue, false); - TS->emitAttribute(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS, - AArch64BuildAttributes::TAG_FEATURE_GCS, GCSValue, false); + TS->emitAttribute(AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], + AArch64BuildAttributes::TAG_FEATURE_BTI, BTIValue, "", + false); + TS->emitAttribute(AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], + AArch64BuildAttributes::TAG_FEATURE_PAC, PACValue, "", + false); + TS->emitAttribute(AArch64BuildAttributes::VendorName + [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], + AArch64BuildAttributes::TAG_FEATURE_GCS, GCSValue, "", + false); } } diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index 9e395388596fa..c6f2e94d85f1e 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -7821,18 +7821,19 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { // (3)uleb128 separated by 2 commas. MCAsmParser &Parser = getParser(); + bool HasActiveSubsection = true; + std::unique_ptr ActiveSubsection = + getTargetStreamer().getActiveAtributesSubsection(); + if (nullptr == ActiveSubsection) { + HasActiveSubsection = false; + } + // Consume the name (subsection name) StringRef SubsectionName; AArch64BuildAttributes::VendorID SubsectionNameID; if (Parser.getTok().is(AsmToken::Identifier)) { SubsectionName = Parser.getTok().getIdentifier(); SubsectionNameID = AArch64BuildAttributes::getVendorID(SubsectionName); - if (AArch64BuildAttributes::VENDOR_NOT_FOUND == SubsectionNameID) { - Error(Parser.getTok().getLoc(), - AArch64BuildAttributes::getSubsectionUnknownError() + ": " + - SubsectionName); - return true; - } } else { Error(Parser.getTok().getLoc(), "Expecting subsection name"); return true; @@ -7849,14 +7850,25 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { AArch64BuildAttributes::SubsectionOptional IsOptional; // options: optional/required if (Parser.getTok().is(AsmToken::Identifier)) { - StringRef Name = Parser.getTok().getIdentifier(); - IsOptional = AArch64BuildAttributes::getOptionalID(Name); + StringRef Optinality = Parser.getTok().getIdentifier(); + IsOptional = AArch64BuildAttributes::getOptionalID(Optinality); if (AArch64BuildAttributes::OPTIONAL_NOT_FOUND == IsOptional) { Error(Parser.getTok().getLoc(), AArch64BuildAttributes::getSubsectionOptionalUnknownError() + ": " + - Name); + Optinality); return true; } + if (HasActiveSubsection && + (SubsectionName == ActiveSubsection->VendorName)) { + if (IsOptional != ActiveSubsection->IsOptional) { + Error(Parser.getTok().getLoc(), + "Optinality mismatch! Subsection " + SubsectionName + + " allready exists with optinality defined as '" + + Twine(ActiveSubsection->IsOptional) + "' and not '" + + Twine(IsOptional) + "'! (0: required, 1: optional)"); + return true; + } + } } else { Error( Parser.getTok().getLoc(), @@ -7895,6 +7907,17 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { Name); return true; } + if (HasActiveSubsection && + (SubsectionName == ActiveSubsection->VendorName)) { + if (Type != ActiveSubsection->ParameterType) { + Error(Parser.getTok().getLoc(), + "Type mismatch! Subsection " + SubsectionName + + " allready exists with Type defined as '" + + Twine(ActiveSubsection->ParameterType) + "' and not '" + + Twine(Type) + "'! (0: uleb128, 1: ntbs)"); + return true; + } + } } else { Error(Parser.getTok().getLoc(), "Expecitng type parameter"); return true; @@ -7916,49 +7939,53 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } - getTargetStreamer().emitAtributesSubsection(SubsectionNameID, IsOptional, - Type); + getTargetStreamer().emitAtributesSubsection(SubsectionName, IsOptional, Type); return false; } bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { // Expecting 2 Tokens: after '.aeabi_attribute', e.g.: - // .aeabi_attribute (1)Tag_Feature_BTI, (2)1 + // .aeabi_attribute (1)Tag_Feature_BTI, (2)[uleb128|ntbs] // separated by a comma. MCAsmParser &Parser = getParser(); - StringRef ActiveSubsection = ""; - unsigned ActiveSubsectionID = unsigned(-1); - StringRef TagStr = ""; - unsigned Tag; - ActiveSubsection = getTargetStreamer().getActiveAtributesSubsection(); - if ("" == ActiveSubsection) { + std::unique_ptr ActiveSubsection = + getTargetStreamer().getActiveAtributesSubsection(); + if (nullptr == ActiveSubsection) { Error(Parser.getTok().getLoc(), "no active subsection, build attribute can not be added"); return true; } + StringRef ActiveSubsectionName = ActiveSubsection->VendorName; + unsigned ActiveSubsectionType = ActiveSubsection->ParameterType; + + unsigned ActiveSubsectionID = AArch64BuildAttributes::VENDOR_UNKNOWN; if (AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_PAUTHABI] == ActiveSubsection) + [AArch64BuildAttributes::AEABI_PAUTHABI] == ActiveSubsectionName) ActiveSubsectionID = AArch64BuildAttributes::AEABI_PAUTHABI; if (AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS] == ActiveSubsection) + [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS] == + ActiveSubsectionName) ActiveSubsectionID = AArch64BuildAttributes::AEABI_FEATURE_AND_BITS; + StringRef TagStr = ""; + unsigned Tag; if (Parser.getTok().is(AsmToken::Identifier)) { TagStr = Parser.getTok().getIdentifier(); switch (ActiveSubsectionID) { default: - Error(Parser.getTok().getLoc(), - "Active AArch64 build attribute subsection unknown: " + - Twine(ActiveSubsectionID)); - return true; + assert(0 && "Subsection name error"); + break; + case AArch64BuildAttributes::VENDOR_UNKNOWN: + // Private subsection, accept any tag. + break; case AArch64BuildAttributes::AEABI_PAUTHABI: Tag = AArch64BuildAttributes::getPauthABITagsID(TagStr); if (AArch64BuildAttributes::PAUTHABI_TAG_NOT_FOUND == Tag) { Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + "' for subsection '" + - ActiveSubsection + "'"); + ActiveSubsectionName + "'"); return true; } break; @@ -7967,7 +7994,7 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { if (AArch64BuildAttributes::FEATURE_AND_BITS_TAG_NOT_FOUND == Tag) { Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + TagStr + - "' for subsection '" + ActiveSubsection + + "' for subsection '" + ActiveSubsectionName + "' \n Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, " "Tag_Feature_GCS"); return true; @@ -7989,29 +8016,38 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { } // Consume the second parameter (attribute value) - unsigned Value; + unsigned ValueInt = unsigned(-1); + std::string ValueStr = ""; if (Parser.getTok().is(AsmToken::Integer)) { - Value = getTok().getIntVal(); + if (AArch64BuildAttributes::NTBS == ActiveSubsectionType) { + Error( + Parser.getTok().getLoc(), + "active subsection type is NTBS (string), found ULEB128 (unsigned)"); + return true; + } + ValueInt = getTok().getIntVal(); + } else if (Parser.getTok().is(AsmToken::Identifier)) { + if (AArch64BuildAttributes::ULEB128 == ActiveSubsectionType) { + Error( + Parser.getTok().getLoc(), + "active subsection type is ULEB128 (unsigned), found NTBS (string)"); + return true; + } + ValueStr = Parser.getTok().getIdentifier(); } else { Error(Parser.getTok().getLoc(), "AArch64 build attributes Value not found"); return true; } - // Check for possible unaccepted values for known tags - if (TagStr != "") { // TagStr was a recognized string - if (0 != Value && 1 != Value) { + // Check for possible unaccepted values for known tags (AEABI_PAUTHABI, + // AEABI_FEATURE_AND_BITS) + if (!(ActiveSubsectionID == AArch64BuildAttributes::VENDOR_UNKNOWN) && + TagStr != "") { // TagStr was a recognized string + if (0 != ValueInt && 1 != ValueInt) { Error(Parser.getTok().getLoc(), "Unknown AArch64 build attributes Value for Tag '" + TagStr + "' \n Hint: options are '0'|'1'"); return true; } - // Tag was an integer - } else if (0 == Tag || 1 == Tag || - 2 == Tag) { // might be at attempt to represent known tags - if (0 != Value && 1 != Value) { - Warning(Parser.getTok().getLoc(), - "Unknown AArch64 build attributes Value for any known AArch64 " - "build attributes tags"); - } } Parser.Lex(); // Parsing finished, check for trailing tokens. @@ -8022,8 +8058,15 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { return true; } - getTargetStreamer().emitAttribute(ActiveSubsectionID, Tag, Value, false); + if (unsigned(-1) != ValueInt) { + getTargetStreamer().emitAttribute(ActiveSubsectionName, Tag, ValueInt, "", + false); + } + if ("" != ValueStr) { + getTargetStreamer().emitAttribute(ActiveSubsectionName, Tag, unsigned(-1), + ValueStr, false); + } return false; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index cd275e5efad9d..34969118e8db5 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -150,15 +150,36 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { OS << "\t.seh_save_any_reg_px\tq" << Reg << ", " << Offset << "\n"; } - void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, - bool Override) override { + void emitAttribute(StringRef VendorName, unsigned Tag, unsigned Value, + std::string String, bool Override) override { // AArch64 build attributes for assembly attribute form: // .aeabi_attribute tag, value + if (unsigned(-1) == Value && "" == String) { + assert(0 && "Arguments error"); + return; + } + + unsigned VendorID = AArch64BuildAttributes::getVendorID(VendorName); + switch (VendorID) { - default: { - assert(0 && AArch64BuildAttributes::getSubsectionUnknownError().data()); + default: + assert(0 && "Subsection name error"); break; - } + case AArch64BuildAttributes::VENDOR_UNKNOWN: + if (unsigned(-1) != Value) { + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag + << ", " << Value; + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); + } + if ("" != String) { + OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag + << ", " << String; + AArch64TargetStreamer::emitAttribute(VendorName, Tag, unsigned(-1), + String, Override); + } + break; + // Note: AEABI_FEATURE_AND_BITS takes only unsigned values case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: switch (Tag) { default: // allow emitting any attribute by number @@ -166,32 +187,36 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { << ", " << Value; // Keep the data structure consistent with the case of ELF emission // (important for llvm-mc asm parsing) - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); break; case AArch64BuildAttributes::TAG_FEATURE_BTI: OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << AArch64BuildAttributes::getFeatureAndBitsTagsStr( AArch64BuildAttributes::TAG_FEATURE_BTI) << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); break; case AArch64BuildAttributes::TAG_FEATURE_GCS: OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << AArch64BuildAttributes::getFeatureAndBitsTagsStr( AArch64BuildAttributes::TAG_FEATURE_GCS) << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); break; case AArch64BuildAttributes::TAG_FEATURE_PAC: OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << AArch64BuildAttributes::getFeatureAndBitsTagsStr( AArch64BuildAttributes::TAG_FEATURE_PAC) << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); break; } break; - + // Note: AEABI_PAUTHABI takes only unsigned values case AArch64BuildAttributes::AEABI_PAUTHABI: switch (Tag) { default: // allow emitting any attribute by number @@ -199,21 +224,24 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { << ", " << Value; // Keep the data structure consistent with the case of ELF emission // (important for llvm-mc asm parsing) - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); break; case AArch64BuildAttributes::TAG_PAUTH_PLATFORM: OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << AArch64BuildAttributes::getPauthABITagsStr( AArch64BuildAttributes::TAG_PAUTH_PLATFORM) << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); break; case AArch64BuildAttributes::TAG_PAUTH_SCHEMA: OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << AArch64BuildAttributes::getPauthABITagsStr( AArch64BuildAttributes::TAG_PAUTH_SCHEMA) << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", + Override); break; } break; @@ -222,12 +250,15 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { } void emitAtributesSubsection( - unsigned Subsection, AArch64BuildAttributes::SubsectionOptional Optional, + StringRef SubsectionName, + AArch64BuildAttributes::SubsectionOptional Optional, AArch64BuildAttributes::SubsectionType ParameterType) override { // The AArch64 build attributes assembly subsection header format: // ".aeabi_subsection name, optional, parameter type" // optional: required (0) optional (1) // parameter type: uleb128 or ULEB128 (0) ntbs or NTBS (1) + unsigned SubsectionID = AArch64BuildAttributes::getVendorID(SubsectionName); + assert((0 == Optional || 1 == Optional) && AArch64BuildAttributes::getSubsectionOptionalUnknownError().data()); assert((0 == ParameterType || 1 == ParameterType) && @@ -238,9 +269,18 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { StringRef OptionalStr = getOptionalStr(Optional); StringRef ParameterStr = getTypeStr(ParameterType); - switch (Subsection) { + switch (SubsectionID) { default: { - assert(0 && AArch64BuildAttributes::getSubsectionUnknownError().data()); + assert(0 && "Subsection error"); + break; + } + case AArch64BuildAttributes::VENDOR_UNKNOWN: { + // Keep the data structure consistent with the case of ELF emission + // (important for llvm-mc asm parsing) + OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " + << OptionalStr << ", " << ParameterStr; + AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, + ParameterType); break; } case AArch64BuildAttributes::AEABI_PAUTHABI: { @@ -250,13 +290,9 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { assert(AArch64BuildAttributes::ULEB128 == ParameterType && "subsection .aeabi-pauthabi should be " "marked as uleb128 and not as ntbs"); - StringRef SubsectionName = - getVendorName(AArch64BuildAttributes::AEABI_PAUTHABI); OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; - // Keep the data structure consistent with the case of ELF emission - // (important for llvm-mc asm parsing) - AArch64TargetStreamer::emitAtributesSubsection(Subsection, Optional, + AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, ParameterType); break; } break; @@ -267,11 +303,9 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { assert(AArch64BuildAttributes::ULEB128 == ParameterType && "subsection .aeabi_feature_and_bits should " "be marked as uleb128 and not as ntbs"); - StringRef SubsectionName = - getVendorName(AArch64BuildAttributes::AEABI_FEATURE_AND_BITS); OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr << ", " << ParameterStr; - AArch64TargetStreamer::emitAtributesSubsection(Subsection, Optional, + AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, ParameterType); break; } break; @@ -426,15 +460,16 @@ AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() { } void AArch64TargetELFStreamer::emitAtributesSubsection( - unsigned VendorID, AArch64BuildAttributes::SubsectionOptional IsOptional, + StringRef VendorName, AArch64BuildAttributes::SubsectionOptional IsOptional, AArch64BuildAttributes::SubsectionType ParameterType) { - AArch64TargetStreamer::emitAtributesSubsection(VendorID, IsOptional, + AArch64TargetStreamer::emitAtributesSubsection(VendorName, IsOptional, ParameterType); } -void AArch64TargetELFStreamer::emitAttribute(unsigned VendorID, unsigned Tag, - unsigned Value, bool Override) { - AArch64TargetStreamer::emitAttribute(VendorID, Tag, Value, Override); +void AArch64TargetELFStreamer::emitAttribute(StringRef VendorName, unsigned Tag, + unsigned Value, std::string String, + bool Override) { + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); } void AArch64TargetELFStreamer::emitInst(uint32_t Inst) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp index 5fa0ca6163d4c..1c89187df5f87 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp @@ -153,9 +153,8 @@ MCTargetStreamer *llvm::createAArch64NullTargetStreamer(MCStreamer &S) { } void AArch64TargetStreamer::emitAtributesSubsection( - unsigned VendorID, AArch64BuildAttributes::SubsectionOptional IsOptional, + StringRef VendorName, AArch64BuildAttributes::SubsectionOptional IsOptional, AArch64BuildAttributes::SubsectionType ParameterType) { - StringRef VendorName = AArch64BuildAttributes::getVendorName(VendorID); // If exists, return. for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { @@ -173,19 +172,23 @@ void AArch64TargetStreamer::emitAtributesSubsection( activateAtributesSubsection(VendorName); } -StringRef AArch64TargetStreamer::getActiveAtributesSubsection() { +std::unique_ptr +AArch64TargetStreamer::getActiveAtributesSubsection() { for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { if (SubSection.IsActive) { - return SubSection.VendorName; + return std::make_unique(SubSection); } } - return ""; + return nullptr; } -void AArch64TargetStreamer::emitAttribute(unsigned VendorID, unsigned Tag, - unsigned Value, bool Override) { - StringRef VendorName = AArch64BuildAttributes::getVendorName(VendorID); - +void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag, + unsigned Value, std::string String, + bool Override) { + if (unsigned(-1) == Value && "" == String) { + assert(0 && "Arguments error"); + return; + } if (AttributeSubSections.size() == 0) { assert(0 && "Can not add AArch64 build attribute: no AArch64 subsection exists"); @@ -202,21 +205,29 @@ void AArch64TargetStreamer::emitAttribute(unsigned VendorID, unsigned Tag, for (MCELFStreamer::AttributeItem &Item : SubSection.Content) { if (Item.Tag == Tag) { if (!Override) { - if (Item.IntValue != Value) { + if ((unsigned(-1) != Value && Item.IntValue != Value) || + ("" != String && Item.StringValue != String)) { assert(0 && "Can not add AArch64 build attribute: An attribute with " "the same tag and a different value allready exists"); return; + } else { + // Case Item.IntValue == Value, no need to emit twice + assert(0 && + "AArch64 build attribute: An attribute with the same tag " + "and a same value allready exists"); + return; } } - // Case Item.IntValue == Value, no need to emit twice - assert(0 && "AArch64 build attribute: An attribute with the same tag " - "and a same value allready exists"); - return; } } - SubSection.Content.push_back(MCELFStreamer::AttributeItem( - MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); + if (unsigned(-1) != Value) + SubSection.Content.push_back(MCELFStreamer::AttributeItem( + MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); + if ("" != String) + SubSection.Content.push_back(MCELFStreamer::AttributeItem( + MCELFStreamer::AttributeItem::NumericAttribute, Tag, unsigned(-1), + String)); return; } } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index d8ecf1c0cf957..3bb03eb5797cd 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -96,13 +96,14 @@ class AArch64TargetStreamer : public MCTargetStreamer { /// Build attributes implementation virtual void - emitAtributesSubsection(unsigned VendorID, + emitAtributesSubsection(StringRef VendorName, AArch64BuildAttributes::SubsectionOptional IsOptional, AArch64BuildAttributes::SubsectionType ParameterType); - virtual void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, - bool Override); + virtual void emitAttribute(StringRef VendorName, unsigned Tag, unsigned Value, + std::string String, bool Override); void activateAtributesSubsection(StringRef VendorName); - StringRef getActiveAtributesSubsection(); + std::unique_ptr + getActiveAtributesSubsection(); void insertAttributeInPlace(const MCELFStreamer::AttributeItem &Attr, MCELFStreamer::AttributeSubSection &AttSubSection); @@ -121,11 +122,11 @@ class AArch64TargetELFStreamer : public AArch64TargetStreamer { /// Build attributes implementation void emitAtributesSubsection( - unsigned VendorID, AArch64BuildAttributes::SubsectionOptional IsOptional, + StringRef VendorName, + AArch64BuildAttributes::SubsectionOptional IsOptional, AArch64BuildAttributes::SubsectionType ParameterType) override; - void emitAttribute(unsigned VendorID, unsigned Tag, unsigned Value, - bool Override = false) override; - + void emitAttribute(StringRef VendorName, unsigned Tag, unsigned Value, + std::string String, bool Override = false) override; void emitInst(uint32_t Inst) override; void emitDirectiveVariantPCS(MCSymbol *Symbol) override; void finish() override; diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s index 72dbc5bd69809..47670e044a917 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s @@ -11,11 +11,11 @@ // ERR-NEXT: .aeabi_attribute a, 1 .aeabi_attribute Tag_PAuth_Platform, Tag_PAuth_Platform -// ERR: error: AArch64 build attributes Value not found +// ERR: error: active subsection type is ULEB128 (unsigned), found NTBS (string) // ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, Tag_PAuth_Platform .aeabi_attribute Tag_PAuth_Platform, a -// ERR: error: AArch64 build attributes Value not found +// ERR: error: active subsection type is ULEB128 (unsigned), found NTBS (string) // ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, a .aeabi_attribute Tag_PAuth_Platform, @@ -42,11 +42,11 @@ // ERR-NEXT: .aeabi_attribute a, 1 .aeabi_attribute Tag_Feature_BTI, Tag_Feature_BTI -// ERR: error: AArch64 build attributes Value not found +// ERR: error: active subsection type is ULEB128 (unsigned), found NTBS (string) // ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, Tag_Feature_BTI .aeabi_attribute Tag_Feature_BTI, a -// ERR: error: AArch64 build attributes Value not found +// ERR: error: active subsection type is ULEB128 (unsigned), found NTBS (string) // ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, a .aeabi_attribute Tag_Feature_BTI, diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s index c0d792ba08d68..adcc0040e0365 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s @@ -17,10 +17,6 @@ // ERR: error: aeabi_feature_and_bits must be marked as ULEB128 // ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, ntbs -.aeabi_subsection a, required, uleb128 -// ERR: error: unknown AArch64 build attributes subsection: a -// ERR-NEXT: .aeabi_subsection a, required, uleb128 - .aeabi_subsection 1, required, uleb128 // ERR: error: Expecting subsection name // ERR-NEXT: .aeabi_subsection 1, required, uleb128 @@ -30,7 +26,7 @@ // ERR-NEXT: .aeabi_subsection , required, uleb128 .aeabi_subsection required, uleb128 -// ERR: error: unknown AArch64 build attributes subsection: required +// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: uleb128 // ERR-NEXT: .aeabi_subsection required, uleb128 .aeabi_subsection aeabi_pauthabi, a, uleb128 @@ -81,4 +77,4 @@ .aeabi_subsection aeabi_feature_and_bits, optional, 1 // ERR: error: Expecitng type parameter -// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, 1 \ No newline at end of file +// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, 1 diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s index b67904b9a08fc..483cae0e09cc7 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-pac.s @@ -16,4 +16,4 @@ .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 .aeabi_attribute Tag_Feature_BTI, 0 .aeabi_attribute Tag_Feature_PAC, 1 -.aeabi_attribute Tag_Feature_GCS, 0 \ No newline at end of file +.aeabi_attribute Tag_Feature_GCS, 0 diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s new file mode 100644 index 0000000000000..1d2618d4c20e0 --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s @@ -0,0 +1,12 @@ +// RUN: not llvm-mc -triple=aarch64 %s -o %t > %t.out 2>&1 +// RUN: FileCheck --input-file=%t.out --check-prefix=ERR %s + +.aeabi_subsection private_subsection, optional, uleb128 + +.aeabi_subsection private_subsection, required, uleb128 +// ERR: error: Optinality mismatch! Subsection private_subsection allready exists with optinality defined as '1' and not '0'! (0: required, 1: optional) +// ERR-NEXT: .aeabi_subsection private_subsection, required, uleb128 + +.aeabi_subsection private_subsection, optional, ntbs +// ERR: error: Type mismatch! Subsection private_subsection allready exists with Type defined as '0' and not '1'! (0: uleb128, 1: ntbs) +// ERR-NEXT: .aeabi_subsection private_subsection, optional, ntbs \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s new file mode 100644 index 0000000000000..269e53acfa32b --- /dev/null +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s @@ -0,0 +1,41 @@ +// RUN: llvm-mc -triple=aarch64 %s -o - | FileCheck %s --check-prefix=CHECK + +.aeabi_subsection private_subsection_1, optional, uleb128 +.aeabi_attribute 12, 257 +// CHECK: .aeabi_subsection private_subsection_1, optional, uleb128 +// CHECK: .aeabi_attribute 12, 257 + +.aeabi_subsection private_subsection_2, required, uleb128 +.aeabi_attribute 76, 257 +// CHECK: .aeabi_subsection private_subsection_2, required, uleb128 +// CHECK: .aeabi_attribute 76, 257 + +.aeabi_subsection private_subsection_3, optional, ntbs +.aeabi_attribute 34, hello_llvm +// CHECK: .aeabi_subsection private_subsection_3, optional, ntbs +// CHECK: .aeabi_attribute 34, hello_llvm + +.aeabi_subsection private_subsection_4, required, ntbs +.aeabi_attribute 777, hello_llvm +// CHECK: .aeabi_subsection private_subsection_4, required, ntbs +// CHECK: .aeabi_attribute 777, hello_llvm + +.aeabi_subsection private_subsection_1, optional, uleb128 +.aeabi_attribute 876, 257 +// CHECK: .aeabi_subsection private_subsection_1, optional, uleb128 +// CHECK: .aeabi_attribute 876, 257 + +.aeabi_subsection private_subsection_2, required, uleb128 +.aeabi_attribute 876, 257 +// CHECK: .aeabi_subsection private_subsection_2, required, uleb128 +// CHECK: .aeabi_attribute 876, 257 + +.aeabi_subsection private_subsection_3, optional, ntbs +.aeabi_attribute 876, hello_llvm +// CHECK: .aeabi_subsection private_subsection_3, optional, ntbs +// CHECK: .aeabi_attribute 876, hello_llvm + +.aeabi_subsection private_subsection_4, required, ntbs +.aeabi_attribute 876, hello_llvm +// CHECK: .aeabi_subsection private_subsection_4, required, ntbs +// CHECK: .aeabi_attribute 876, hello_llvm \ No newline at end of file From 56f496b6f3798e8747ea17e52de1e1ee0ffa3bd4 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Fri, 10 Jan 2025 17:45:18 +0000 Subject: [PATCH 16/21] fix string attr for elf + test --- .../MCTargetDesc/AArch64ELFStreamer.cpp | 7 ++- .../MCTargetDesc/AArch64TargetStreamer.cpp | 3 +- ...build-attributes-asm-private-subsections.s | 57 +++++++++++-------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 34969118e8db5..d34531ddabef9 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -152,6 +152,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { void emitAttribute(StringRef VendorName, unsigned Tag, unsigned Value, std::string String, bool Override) override { + // AArch64 build attributes for assembly attribute form: // .aeabi_attribute tag, value if (unsigned(-1) == Value && "" == String) { @@ -469,7 +470,11 @@ void AArch64TargetELFStreamer::emitAtributesSubsection( void AArch64TargetELFStreamer::emitAttribute(StringRef VendorName, unsigned Tag, unsigned Value, std::string String, bool Override) { - AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); + if (unsigned(-1) != Value) + AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); + if ("" != String) + AArch64TargetStreamer::emitAttribute(VendorName, Tag, unsigned(-1), String, + Override); } void AArch64TargetELFStreamer::emitInst(uint32_t Inst) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp index 1c89187df5f87..e09648dcc9c3f 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp @@ -185,6 +185,7 @@ AArch64TargetStreamer::getActiveAtributesSubsection() { void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag, unsigned Value, std::string String, bool Override) { + if (unsigned(-1) == Value && "" == String) { assert(0 && "Arguments error"); return; @@ -226,7 +227,7 @@ void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag, MCELFStreamer::AttributeItem::NumericAttribute, Tag, Value, "")); if ("" != String) SubSection.Content.push_back(MCELFStreamer::AttributeItem( - MCELFStreamer::AttributeItem::NumericAttribute, Tag, unsigned(-1), + MCELFStreamer::AttributeItem::TextAttribute, Tag, unsigned(-1), String)); return; } diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s index 269e53acfa32b..1b9bcfcfbb35e 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s @@ -1,41 +1,50 @@ -// RUN: llvm-mc -triple=aarch64 %s -o - | FileCheck %s --check-prefix=CHECK +// 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 private_subsection_1, optional, uleb128 +// ASM: .aeabi_attribute 12, 257 +// ASM: .aeabi_subsection private_subsection_2, required, uleb128 +// ASM: .aeabi_attribute 76, 257 +// ASM: .aeabi_subsection private_subsection_3, optional, ntbs +// ASM: .aeabi_attribute 34, hello_llvm +// ASM: .aeabi_subsection private_subsection_4, required, ntbs +// ASM: .aeabi_attribute 777, hello_llvm +// ASM: .aeabi_subsection private_subsection_1, optional, uleb128 +// ASM: .aeabi_attribute 876, 257 +// ASM: .aeabi_subsection private_subsection_2, required, uleb128 +// ASM: .aeabi_attribute 876, 257 +// ASM: .aeabi_subsection private_subsection_3, optional, ntbs +// ASM: .aeabi_attribute 876, hello_llvm +// ASM: .aeabi_subsection private_subsection_4, required, ntbs +// ASM: .aeabi_attribute 876, hello_llvm + +// ELF: Hex dump of section '.ARM.attributes': +// ELF-NEXT: 0x00000000 41220000 00707269 76617465 5f737562 A"...private_sub +// ELF-NEXT: 0x00000010 73656374 696f6e5f 31000100 0c8102ec section_1....... +// ELF-NEXT: 0x00000020 06810222 00000070 72697661 74655f73 ..."...private_s +// ELF-NEXT: 0x00000030 75627365 6374696f 6e5f3200 00004c81 ubsection_2...L. +// ELF-NEXT: 0x00000040 02ec0681 02340000 00707269 76617465 .....4...private +// ELF-NEXT: 0x00000050 5f737562 73656374 696f6e5f 33000101 _subsection_3... +// ELF-NEXT: 0x00000060 2268656c 6c6f5f6c 6c766d00 ec066865 "hello_llvm...he +// ELF-NEXT: 0x00000070 6c6c6f5f 6c6c766d 00350000 00707269 llo_llvm.5...pri +// ELF-NEXT: 0x00000080 76617465 5f737562 73656374 696f6e5f vate_subsection_ +// ELF-NEXT: 0x00000090 34000001 89066865 6c6c6f5f 6c6c766d 4.....hello_llvm +// ELF-NEXT: 0x000000a0 00ec0668 656c6c6f 5f6c6c76 6d00 ...hello_llvm. + .aeabi_subsection private_subsection_1, optional, uleb128 .aeabi_attribute 12, 257 -// CHECK: .aeabi_subsection private_subsection_1, optional, uleb128 -// CHECK: .aeabi_attribute 12, 257 - .aeabi_subsection private_subsection_2, required, uleb128 .aeabi_attribute 76, 257 -// CHECK: .aeabi_subsection private_subsection_2, required, uleb128 -// CHECK: .aeabi_attribute 76, 257 - .aeabi_subsection private_subsection_3, optional, ntbs .aeabi_attribute 34, hello_llvm -// CHECK: .aeabi_subsection private_subsection_3, optional, ntbs -// CHECK: .aeabi_attribute 34, hello_llvm - .aeabi_subsection private_subsection_4, required, ntbs .aeabi_attribute 777, hello_llvm -// CHECK: .aeabi_subsection private_subsection_4, required, ntbs -// CHECK: .aeabi_attribute 777, hello_llvm - .aeabi_subsection private_subsection_1, optional, uleb128 .aeabi_attribute 876, 257 -// CHECK: .aeabi_subsection private_subsection_1, optional, uleb128 -// CHECK: .aeabi_attribute 876, 257 - .aeabi_subsection private_subsection_2, required, uleb128 .aeabi_attribute 876, 257 -// CHECK: .aeabi_subsection private_subsection_2, required, uleb128 -// CHECK: .aeabi_attribute 876, 257 - .aeabi_subsection private_subsection_3, optional, ntbs .aeabi_attribute 876, hello_llvm -// CHECK: .aeabi_subsection private_subsection_3, optional, ntbs -// CHECK: .aeabi_attribute 876, hello_llvm - .aeabi_subsection private_subsection_4, required, ntbs .aeabi_attribute 876, hello_llvm -// CHECK: .aeabi_subsection private_subsection_4, required, ntbs -// CHECK: .aeabi_attribute 876, hello_llvm \ No newline at end of file From 5082f0885d731af374e9be6bd2309daf9d744573 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Mon, 13 Jan 2025 20:28:22 +0000 Subject: [PATCH 17/21] fix spelling, add required test cases, remove unused, improve getting unsigned/string --- .../llvm/Support/AArch64BuildAttributes.h | 15 +-- llvm/lib/Support/AArch64BuildAttributes.cpp | 99 ++++++++----------- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 29 +++--- .../AArch64/AsmParser/AArch64AsmParser.cpp | 64 ++++++------ .../MCTargetDesc/AArch64ELFStreamer.cpp | 56 +++-------- .../MCTargetDesc/AArch64TargetStreamer.cpp | 6 +- .../aarch64-build-attributes-asm-all.s | 2 +- .../aarch64-build-attributes-asm-bti.s | 2 +- .../aarch64-build-attributes-asm-err-attrs.s | 38 ++++--- ...aarch64-build-attributes-asm-err-headers.s | 42 +++----- ...d-attributes-asm-private-subsections-err.s | 14 ++- ...build-attributes-asm-private-subsections.s | 21 ++-- 12 files changed, 166 insertions(+), 222 deletions(-) diff --git a/llvm/include/llvm/Support/AArch64BuildAttributes.h b/llvm/include/llvm/Support/AArch64BuildAttributes.h index 0ca8533abf5d7..ea293b72f9bb1 100644 --- a/llvm/include/llvm/Support/AArch64BuildAttributes.h +++ b/llvm/include/llvm/Support/AArch64BuildAttributes.h @@ -11,7 +11,7 @@ // // Build Attributes for the ArmĀ® 64-bit Architecture (AArch64) 2024Q1 // -// https://github.com/ARM-software/abi-aa/blob/ada00cc8e04f421cce657e8d9f3a439c69437cf4/buildattr64/buildattr64.rst +// https://github.com/ARM-software/abi-aa/pull/230 // //===----------------------------------------------------------------------===// @@ -23,9 +23,6 @@ namespace llvm { namespace AArch64BuildAttributes { -// AArch64 build attributes -StringRef getSubsectionTag(); -StringRef getAttrTag(); /// AArch64 build attributes vendors IDs (a.k.a subsection name) enum VendorID : unsigned { @@ -33,8 +30,6 @@ enum VendorID : unsigned { AEABI_PAUTHABI = 1, VENDOR_UNKNOWN = 404 // Treated as a private subsection name }; -static const StringRef VendorName[] = {"aeabi_feature_and_bits", - "aeabi_pauthabi"}; StringRef getVendorName(unsigned const Vendor); VendorID getVendorID(StringRef const Vendor); @@ -43,13 +38,11 @@ enum SubsectionOptional : unsigned { OPTIONAL = 1, OPTIONAL_NOT_FOUND = 404 }; -static const StringRef OptionalStr[] = {"required", "optional"}; StringRef getOptionalStr(unsigned Optional); SubsectionOptional getOptionalID(StringRef Optional); StringRef getSubsectionOptionalUnknownError(); enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1, TYPE_NOT_FOUND = 404 }; -static const StringRef TypeStr[] = {"uleb128", "ntbs"}; StringRef getTypeStr(unsigned Type); SubsectionType getTypeID(StringRef Type); StringRef getSubsectionTypeUnknownError(); @@ -59,11 +52,8 @@ enum PauthABITags : unsigned { TAG_PAUTH_SCHEMA = 2, PAUTHABI_TAG_NOT_FOUND = 404 }; -static const StringRef PauthABITagsStr[] = {"Tag_PAuth_Platform", - "Tag_PAuth_Schema"}; StringRef getPauthABITagsStr(unsigned PauthABITag); PauthABITags getPauthABITagsID(StringRef PauthABITag); -StringRef getPauthabiTagError(); enum FeatureAndBitsTags : unsigned { TAG_FEATURE_BTI = 0, @@ -71,11 +61,8 @@ enum FeatureAndBitsTags : unsigned { TAG_FEATURE_GCS = 2, FEATURE_AND_BITS_TAG_NOT_FOUND = 404 }; -static const StringRef FeatureAndBitsTagsStr[] = { - "Tag_Feature_BTI", "Tag_Feature_PAC", "Tag_Feature_GCS"}; StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag); FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag); -StringRef getFeatureAndBitsTagError(); enum FeatureAndBitsFlag : unsigned { Feature_BTI_Flag = 1 << 0, diff --git a/llvm/lib/Support/AArch64BuildAttributes.cpp b/llvm/lib/Support/AArch64BuildAttributes.cpp index cdf25725cc86e..2c70e37f37ec6 100644 --- a/llvm/lib/Support/AArch64BuildAttributes.cpp +++ b/llvm/lib/Support/AArch64BuildAttributes.cpp @@ -7,19 +7,17 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/AArch64BuildAttributes.h" +#include "llvm/ADT/StringSwitch.h" namespace llvm { namespace AArch64BuildAttributes { -// AArch64 build attributes -StringRef getSubsectionTag() { return "aeabi_subsection"; } -StringRef getAttrTag() { return "aeabi_attribute"; } StringRef getVendorName(unsigned Vendor) { switch (Vendor) { case AEABI_FEATURE_AND_BITS: - return VendorName[AEABI_FEATURE_AND_BITS]; + return "aeabi_feature_and_bits"; case AEABI_PAUTHABI: - return VendorName[AEABI_PAUTHABI]; + return "aeabi_pauthabi"; case VENDOR_UNKNOWN: return ""; default: @@ -28,113 +26,98 @@ StringRef getVendorName(unsigned Vendor) { } } VendorID getVendorID(StringRef Vendor) { - if (Vendor == VendorName[AEABI_FEATURE_AND_BITS]) { - return AEABI_FEATURE_AND_BITS; - } - if (Vendor == VendorName[AEABI_PAUTHABI]) { - return AEABI_PAUTHABI; - } - return VENDOR_UNKNOWN; + return StringSwitch(Vendor) + .Case("aeabi_feature_and_bits", AEABI_FEATURE_AND_BITS) + .Case("aeabi_pauthabi", AEABI_PAUTHABI) + .Default(VENDOR_UNKNOWN); } StringRef getOptionalStr(unsigned Optional) { switch (Optional) { case REQUIRED: - return OptionalStr[REQUIRED]; + return "required"; case OPTIONAL: - return OptionalStr[OPTIONAL]; + return "optional"; case OPTIONAL_NOT_FOUND: - [[fallthrough]]; + LLVM_FALLTHROUGH; default: return ""; } } SubsectionOptional getOptionalID(StringRef Optional) { - if (Optional == OptionalStr[REQUIRED]) - return REQUIRED; - if (Optional == OptionalStr[OPTIONAL]) - return OPTIONAL; - return OPTIONAL_NOT_FOUND; + return StringSwitch(Optional) + .Case("required", REQUIRED) + .Case("optional", OPTIONAL) + .Default(OPTIONAL_NOT_FOUND); } StringRef getSubsectionOptionalUnknownError() { - return "unknown AArch64 build attributes optionality, expecting " + return "unknown AArch64 build attributes optionality, expected " "required|optional"; } StringRef getTypeStr(unsigned Type) { switch (Type) { case ULEB128: - return TypeStr[ULEB128]; + return "uleb128"; case NTBS: - return TypeStr[NTBS]; + return "ntbs"; case TYPE_NOT_FOUND: - [[fallthrough]]; + LLVM_FALLTHROUGH; default: return ""; } } SubsectionType getTypeID(StringRef Type) { - if (Type == TypeStr[ULEB128] || Type == (TypeStr[ULEB128].upper())) - return ULEB128; - if (Type == TypeStr[NTBS] || Type == (TypeStr[NTBS].upper())) - return NTBS; - return TYPE_NOT_FOUND; + return StringSwitch(Type) + .Case("uleb128", ULEB128) + .Case("ULEB128", ULEB128) + .Case("NTBS", NTBS) + .Case("ntbs", NTBS) + .Default(TYPE_NOT_FOUND); } StringRef getSubsectionTypeUnknownError() { - return "unknown AArch64 build attributes type, expecting uleb128|ntbs"; + return "unknown AArch64 build attributes type, expected uleb128|ntbs"; } StringRef getPauthABITagsStr(unsigned PauthABITag) { switch (PauthABITag) { case TAG_PAUTH_PLATFORM: - return PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]; // Tag_PAuth_Platform = 1 in - // accordance with the spec + return "Tag_PAuth_Platform"; case TAG_PAUTH_SCHEMA: - return PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]; // Tag_PAuth_Schema = 2 in - // accordance with the spec + return "Tag_PAuth_Schema"; case PAUTHABI_TAG_NOT_FOUND: - [[fallthrough]]; + LLVM_FALLTHROUGH; default: return ""; } } PauthABITags getPauthABITagsID(StringRef PauthABITag) { - if (PauthABITag == PauthABITagsStr[TAG_PAUTH_PLATFORM - 1]) - return TAG_PAUTH_PLATFORM; - if (PauthABITag == PauthABITagsStr[TAG_PAUTH_SCHEMA - 1]) - return TAG_PAUTH_SCHEMA; - return PAUTHABI_TAG_NOT_FOUND; -} -StringRef getPauthabiTagError() { - return "unknown tag for the AArch64 Pauthabi subsection"; + return StringSwitch(PauthABITag) + .Case("Tag_PAuth_Platform", TAG_PAUTH_PLATFORM) + .Case("Tag_PAuth_Schema", TAG_PAUTH_SCHEMA) + .Default(PAUTHABI_TAG_NOT_FOUND); } StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) { switch (FeatureAndBitsTag) { case TAG_FEATURE_BTI: - return FeatureAndBitsTagsStr[TAG_FEATURE_BTI]; + return "Tag_Feature_BTI"; case TAG_FEATURE_PAC: - return FeatureAndBitsTagsStr[TAG_FEATURE_PAC]; + return "Tag_Feature_PAC"; case TAG_FEATURE_GCS: - return FeatureAndBitsTagsStr[TAG_FEATURE_GCS]; + return "Tag_Feature_GCS"; case FEATURE_AND_BITS_TAG_NOT_FOUND: - [[fallthrough]]; + LLVM_FALLTHROUGH; default: - return ""; } } FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) { - if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_BTI]) - return TAG_FEATURE_BTI; - if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_PAC]) - return TAG_FEATURE_PAC; - if (FeatureAndBitsTag == FeatureAndBitsTagsStr[TAG_FEATURE_GCS]) - return TAG_FEATURE_GCS; - return FEATURE_AND_BITS_TAG_NOT_FOUND; -} -StringRef getFeatureAndBitsTagError() { - return "unknown tag for the AArch64 Feature And Bits subsection"; + return StringSwitch(FeatureAndBitsTag) + .Case("Tag_Feature_BTI", TAG_FEATURE_BTI) + .Case("Tag_Feature_PAC", TAG_FEATURE_PAC) + .Case("Tag_Feature_GCS", TAG_FEATURE_GCS) + .Default(FEATURE_AND_BITS_TAG_NOT_FOUND); } } // namespace AArch64BuildAttributes } // namespace llvm diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index e1ae7818fcc2c..b1c586c5daf07 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -54,7 +54,6 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/TargetRegistry.h" -#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" @@ -466,16 +465,16 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, if (PAuthABIPlatform || PAuthABIVersion) { TS->emitAtributesSubsection( - AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_PAUTHABI], + AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_PAUTHABI), AArch64BuildAttributes::SubsectionOptional::REQUIRED, AArch64BuildAttributes::SubsectionType::ULEB128); - TS->emitAttribute(AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_PAUTHABI], + TS->emitAttribute(AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_PAUTHABI), AArch64BuildAttributes::TAG_PAUTH_PLATFORM, PAuthABIPlatform, "", false); - TS->emitAttribute(AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_PAUTHABI], + TS->emitAttribute(AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_PAUTHABI), AArch64BuildAttributes::TAG_PAUTH_SCHEMA, PAuthABIVersion, "", false); } @@ -489,20 +488,20 @@ void AArch64AsmPrinter::emitAttributes(unsigned Flags, if (BTIValue || PACValue || GCSValue) { TS->emitAtributesSubsection( - AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], + AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_FEATURE_AND_BITS), AArch64BuildAttributes::SubsectionOptional::OPTIONAL, AArch64BuildAttributes::SubsectionType::ULEB128); - TS->emitAttribute(AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], + TS->emitAttribute(AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_FEATURE_AND_BITS), AArch64BuildAttributes::TAG_FEATURE_BTI, BTIValue, "", false); - TS->emitAttribute(AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], + TS->emitAttribute(AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_FEATURE_AND_BITS), AArch64BuildAttributes::TAG_FEATURE_PAC, PACValue, "", false); - TS->emitAttribute(AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS], + TS->emitAttribute(AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_FEATURE_AND_BITS), AArch64BuildAttributes::TAG_FEATURE_GCS, GCSValue, "", false); } diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index c6f2e94d85f1e..14cb32b1b5347 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -7835,7 +7835,7 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { SubsectionName = Parser.getTok().getIdentifier(); SubsectionNameID = AArch64BuildAttributes::getVendorID(SubsectionName); } else { - Error(Parser.getTok().getLoc(), "Expecting subsection name"); + Error(Parser.getTok().getLoc(), "subsection name not found"); return true; } Parser.Lex(); @@ -7850,29 +7850,28 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { AArch64BuildAttributes::SubsectionOptional IsOptional; // options: optional/required if (Parser.getTok().is(AsmToken::Identifier)) { - StringRef Optinality = Parser.getTok().getIdentifier(); - IsOptional = AArch64BuildAttributes::getOptionalID(Optinality); + StringRef Optionality = Parser.getTok().getIdentifier(); + IsOptional = AArch64BuildAttributes::getOptionalID(Optionality); if (AArch64BuildAttributes::OPTIONAL_NOT_FOUND == IsOptional) { Error(Parser.getTok().getLoc(), AArch64BuildAttributes::getSubsectionOptionalUnknownError() + ": " + - Optinality); + Optionality); return true; } if (HasActiveSubsection && (SubsectionName == ActiveSubsection->VendorName)) { if (IsOptional != ActiveSubsection->IsOptional) { Error(Parser.getTok().getLoc(), - "Optinality mismatch! Subsection " + SubsectionName + - " allready exists with optinality defined as '" + + "optionality mismatch! subsection '" + SubsectionName + + "' already exists with optionality defined as '" + Twine(ActiveSubsection->IsOptional) + "' and not '" + - Twine(IsOptional) + "'! (0: required, 1: optional)"); + Twine(IsOptional) + "' (0: required, 1: optional)"); return true; } } } else { - Error( - Parser.getTok().getLoc(), - "Expecitng optionality parameter \n Hint: use 'optional' | 'required'"); + Error(Parser.getTok().getLoc(), + "optionality parameter not found, expected required|optinal"); return true; } // Check for possible IsOptional unaccepted values for known subsections @@ -7911,18 +7910,19 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { (SubsectionName == ActiveSubsection->VendorName)) { if (Type != ActiveSubsection->ParameterType) { Error(Parser.getTok().getLoc(), - "Type mismatch! Subsection " + SubsectionName + - " allready exists with Type defined as '" + + "type mismatch! subsection '" + SubsectionName + + "' already exists with type defined as '" + Twine(ActiveSubsection->ParameterType) + "' and not '" + - Twine(Type) + "'! (0: uleb128, 1: ntbs)"); + Twine(Type) + "' (0: uleb128, 1: ntbs)"); return true; } } } else { - Error(Parser.getTok().getLoc(), "Expecitng type parameter"); + Error(Parser.getTok().getLoc(), + "type parameter not found, expected uleb128|ntbs"); return true; } - // Check for possible Type unaccepted values for known subsections + // Check for possible unaccepted 'type' values for known subsections if (AArch64BuildAttributes::AEABI_FEATURE_AND_BITS == SubsectionNameID || AArch64BuildAttributes::AEABI_PAUTHABI == SubsectionNameID) { if (AArch64BuildAttributes::NTBS == Type) { @@ -7961,11 +7961,11 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { unsigned ActiveSubsectionType = ActiveSubsection->ParameterType; unsigned ActiveSubsectionID = AArch64BuildAttributes::VENDOR_UNKNOWN; - if (AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_PAUTHABI] == ActiveSubsectionName) + if (AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_PAUTHABI) == ActiveSubsectionName) ActiveSubsectionID = AArch64BuildAttributes::AEABI_PAUTHABI; - if (AArch64BuildAttributes::VendorName - [AArch64BuildAttributes::AEABI_FEATURE_AND_BITS] == + if (AArch64BuildAttributes::getVendorName( + AArch64BuildAttributes::AEABI_FEATURE_AND_BITS) == ActiveSubsectionName) ActiveSubsectionID = AArch64BuildAttributes::AEABI_FEATURE_AND_BITS; @@ -7983,7 +7983,7 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { case AArch64BuildAttributes::AEABI_PAUTHABI: Tag = AArch64BuildAttributes::getPauthABITagsID(TagStr); if (AArch64BuildAttributes::PAUTHABI_TAG_NOT_FOUND == Tag) { - Error(Parser.getTok().getLoc(), "Unknown AArch64 build attribute '" + + Error(Parser.getTok().getLoc(), "unknown AArch64 build attribute '" + TagStr + "' for subsection '" + ActiveSubsectionName + "'"); return true; @@ -7992,11 +7992,9 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: Tag = AArch64BuildAttributes::getFeatureAndBitsTagsID(TagStr); if (AArch64BuildAttributes::FEATURE_AND_BITS_TAG_NOT_FOUND == Tag) { - Error(Parser.getTok().getLoc(), - "Unknown AArch64 build attribute '" + TagStr + - "' for subsection '" + ActiveSubsectionName + - "' \n Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, " - "Tag_Feature_GCS"); + Error(Parser.getTok().getLoc(), "unknown AArch64 build attribute '" + + TagStr + "' for subsection '" + + ActiveSubsectionName + "'"); return true; } break; @@ -8004,7 +8002,7 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { } else if (Parser.getTok().is(AsmToken::Integer)) { Tag = getTok().getIntVal(); } else { - Error(Parser.getTok().getLoc(), "AArch64 build attributes Tag not found"); + Error(Parser.getTok().getLoc(), "AArch64 build attributes tag not found"); return true; } Parser.Lex(); @@ -8034,8 +8032,16 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { return true; } ValueStr = Parser.getTok().getIdentifier(); + } else if (Parser.getTok().is(AsmToken::String)) { + if (AArch64BuildAttributes::ULEB128 == ActiveSubsectionType) { + Error( + Parser.getTok().getLoc(), + "active subsection type is ULEB128 (unsigned), found NTBS (string)"); + return true; + } + ValueStr = Parser.getTok().getString(); } else { - Error(Parser.getTok().getLoc(), "AArch64 build attributes Value not found"); + Error(Parser.getTok().getLoc(), "AArch64 build attributes value not found"); return true; } // Check for possible unaccepted values for known tags (AEABI_PAUTHABI, @@ -8044,8 +8050,8 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) { TagStr != "") { // TagStr was a recognized string if (0 != ValueInt && 1 != ValueInt) { Error(Parser.getTok().getLoc(), - "Unknown AArch64 build attributes Value for Tag '" + TagStr + - "' \n Hint: options are '0'|'1'"); + "unknown AArch64 build attributes Value for Tag '" + TagStr + + "' options are 0|1"); return true; } } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index d34531ddabef9..0851ce212fc5b 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -168,14 +168,12 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { break; case AArch64BuildAttributes::VENDOR_UNKNOWN: if (unsigned(-1) != Value) { - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag - << ", " << Value; + OS << "\t.aeabi_attribute" << "\t" << Tag << ", " << Value; AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); } if ("" != String) { - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag - << ", " << String; + OS << "\t.aeabi_attribute" << "\t" << Tag << ", " << String; AArch64TargetStreamer::emitAttribute(VendorName, Tag, unsigned(-1), String, Override); } @@ -184,34 +182,20 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: switch (Tag) { default: // allow emitting any attribute by number - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag - << ", " << Value; + OS << "\t.aeabi_attribute" << "\t" << Tag << ", " << Value; // Keep the data structure consistent with the case of ELF emission // (important for llvm-mc asm parsing) AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); break; case AArch64BuildAttributes::TAG_FEATURE_BTI: - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" - << AArch64BuildAttributes::getFeatureAndBitsTagsStr( - AArch64BuildAttributes::TAG_FEATURE_BTI) - << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", - Override); - break; + LLVM_FALLTHROUGH; case AArch64BuildAttributes::TAG_FEATURE_GCS: - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" - << AArch64BuildAttributes::getFeatureAndBitsTagsStr( - AArch64BuildAttributes::TAG_FEATURE_GCS) - << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", - Override); - break; + LLVM_FALLTHROUGH; case AArch64BuildAttributes::TAG_FEATURE_PAC: - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" - << AArch64BuildAttributes::getFeatureAndBitsTagsStr( - AArch64BuildAttributes::TAG_FEATURE_PAC) - << ", " << Value; + OS << "\t.aeabi_attribute" << "\t" + << AArch64BuildAttributes::getFeatureAndBitsTagsStr(Tag) << ", " + << Value; AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); break; @@ -221,26 +205,17 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { case AArch64BuildAttributes::AEABI_PAUTHABI: switch (Tag) { default: // allow emitting any attribute by number - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" << Tag - << ", " << Value; + OS << "\t.aeabi_attribute" << "\t" << Tag << ", " << Value; // Keep the data structure consistent with the case of ELF emission // (important for llvm-mc asm parsing) AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); break; case AArch64BuildAttributes::TAG_PAUTH_PLATFORM: - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" - << AArch64BuildAttributes::getPauthABITagsStr( - AArch64BuildAttributes::TAG_PAUTH_PLATFORM) - << ", " << Value; - AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", - Override); - break; + LLVM_FALLTHROUGH; case AArch64BuildAttributes::TAG_PAUTH_SCHEMA: - OS << "\t." << AArch64BuildAttributes::getAttrTag() << "\t" - << AArch64BuildAttributes::getPauthABITagsStr( - AArch64BuildAttributes::TAG_PAUTH_SCHEMA) - << ", " << Value; + OS << "\t.aeabi_attribute" << "\t" + << AArch64BuildAttributes::getPauthABITagsStr(Tag) << ", " << Value; AArch64TargetStreamer::emitAttribute(VendorName, Tag, Value, "", Override); break; @@ -265,8 +240,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { assert((0 == ParameterType || 1 == ParameterType) && AArch64BuildAttributes::getSubsectionTypeUnknownError().data()); - std::string SubsectionTag = - ("." + AArch64BuildAttributes::getSubsectionTag()).str(); + std::string SubsectionTag = ".aeabi_subsection"; StringRef OptionalStr = getOptionalStr(Optional); StringRef ParameterStr = getTypeStr(ParameterType); @@ -296,7 +270,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, ParameterType); break; - } break; + } case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: { assert(AArch64BuildAttributes::OPTIONAL == Optional && "subsection .aeabi_feature_and_bits should be " @@ -309,7 +283,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, ParameterType); break; - } break; + } } OS << "\n"; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp index e09648dcc9c3f..ee17de26d1caf 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp @@ -210,13 +210,13 @@ void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag, ("" != String && Item.StringValue != String)) { assert(0 && "Can not add AArch64 build attribute: An attribute with " - "the same tag and a different value allready exists"); + "the same tag and a different value already exists"); return; } else { // Case Item.IntValue == Value, no need to emit twice assert(0 && "AArch64 build attribute: An attribute with the same tag " - "and a same value allready exists"); + "and a same value already exists"); return; } } @@ -233,7 +233,7 @@ void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag, } } assert(0 && "Can not add AArch64 build attribute: required subsection does " - "not exists"); + "not exist"); } void AArch64TargetStreamer::activateAtributesSubsection(StringRef VendorName) { diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s index 30b552ebba1b7..a895821f3b05d 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-all.s @@ -24,4 +24,4 @@ .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 .aeabi_attribute Tag_Feature_BTI, 1 .aeabi_attribute Tag_Feature_PAC, 1 -.aeabi_attribute Tag_Feature_GCS, 1 \ No newline at end of file +.aeabi_attribute Tag_Feature_GCS, 1 diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s index 4da0b21fcc191..25573a0cabeca 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-bti.s @@ -16,4 +16,4 @@ .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 .aeabi_attribute Tag_Feature_BTI, 1 .aeabi_attribute Tag_Feature_PAC, 0 -.aeabi_attribute Tag_Feature_GCS, 0 \ No newline at end of file +.aeabi_attribute Tag_Feature_GCS, 0 diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s index 47670e044a917..e8daec0525591 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-attrs.s @@ -1,13 +1,20 @@ -// RUN: not llvm-mc -triple=aarch64 %s -o %t > %t.out 2>&1 -// RUN: FileCheck --input-file=%t.out --check-prefix=ERR %s +// RUN: not llvm-mc -triple=aarch64 %s 2>&1 | FileCheck --check-prefix=ERR %s + +.aeabi_attribute Tag_Feature_BTI, 1 +// ERR: error: no active subsection, build attribute can not be added +// ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 .aeabi_subsection aeabi_pauthabi, required, uleb128 .aeabi_attribute Tag_Feature_BTI, 1 -// ERR: error: Unknown AArch64 build attribute 'Tag_Feature_BTI' for subsection 'aeabi_pauthabi' +// ERR: error: unknown AArch64 build attribute 'Tag_Feature_BTI' for subsection 'aeabi_pauthabi' // ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, 1 +.aeabi_attribute Tag_PAuth_Platform, 4 +// ERR: error: unknown AArch64 build attributes Value for Tag 'Tag_PAuth_Platform' options are 0|1 +// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, 4 + .aeabi_attribute a, 1 -// ERR: Unknown AArch64 build attribute 'a' for subsection 'aeabi_pauthabi' +// ERR: error: unknown AArch64 build attribute 'a' for subsection 'aeabi_pauthabi' // ERR-NEXT: .aeabi_attribute a, 1 .aeabi_attribute Tag_PAuth_Platform, Tag_PAuth_Platform @@ -19,7 +26,7 @@ // ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, a .aeabi_attribute Tag_PAuth_Platform, -// ERR: error: AArch64 build attributes Value not found +// ERR: error: AArch64 build attributes value not found // ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, .aeabi_attribute Tag_PAuth_Platform @@ -27,19 +34,15 @@ // ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform .aeabi_attribute -// ERR: error: AArch64 build attributes Tag not found +// ERR: error: AArch64 build attributes tag not found // ERR-NEXT: .aeabi_attribute .aeabi_subsection aeabi_feature_and_bits, optional, uleb128 .aeabi_attribute Tag_PAuth_Platform, 1 -// ERR: error: Unknown AArch64 build attribute 'Tag_PAuth_Platform' for subsection 'aeabi_feature_and_bits' -// ERR-NEXT: Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, Tag_Feature_GCS -// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, 1 +// ERR: unknown AArch64 build attribute 'Tag_PAuth_Platform' for subsection 'aeabi_feature_and_bits' .aeabi_attribute a, 1 -// ERR: error: Unknown AArch64 build attribute 'a' for subsection 'aeabi_feature_and_bits' -// ERR-NEXT: Hint: options are: Tag_Feature_BTI, Tag_Feature_PAC, Tag_Feature_GCS -// ERR-NEXT: .aeabi_attribute a, 1 +// ERR: error: unknown AArch64 build attribute 'a' for subsection 'aeabi_feature_and_bits' .aeabi_attribute Tag_Feature_BTI, Tag_Feature_BTI // ERR: error: active subsection type is ULEB128 (unsigned), found NTBS (string) @@ -50,7 +53,7 @@ // ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, a .aeabi_attribute Tag_Feature_BTI, -// ERR: AArch64 build attributes Value not found +// ERR: error: AArch64 build attributes value not found // ERR-NEXT: .aeabi_attribute Tag_Feature_BTI, .aeabi_attribute Tag_Feature_BTI @@ -58,5 +61,10 @@ // ERR-NEXT: .aeabi_attribute Tag_Feature_BTI .aeabi_attribute -// ERR: error: AArch64 build attributes Tag not found -// ERR-NEXT: .aeabi_attribute \ No newline at end of file +// ERR: error: AArch64 build attributes tag not found +// ERR-NEXT: .aeabi_attribute + +.aeabi_subsection aeabi_pauthabi, required, uleb128 +.aeabi_attribute Tag_PAuth_Platform, 1 some_text +// ERR: error: unexpected token for AArch64 build attributes tag and value attribute directive +// ERR-NEXT: .aeabi_attribute Tag_PAuth_Platform, 1 some_text \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s index adcc0040e0365..40e59f80cd0d6 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s @@ -1,5 +1,4 @@ -// RUN: not llvm-mc -triple=aarch64 %s -o %t > %t.out 2>&1 -// RUN: FileCheck --input-file=%t.out --check-prefix=ERR %s +// RUN: not llvm-mc -triple=aarch64 %s 2>&1 | FileCheck --check-prefix=ERR %s .aeabi_subsection aeabi_pauthabi, optional, uleb128 // ERR: error: aeabi_pauthabi must be marked as required @@ -18,33 +17,31 @@ // ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, ntbs .aeabi_subsection 1, required, uleb128 -// ERR: error: Expecting subsection name +// ERR: error: subsection name not found // ERR-NEXT: .aeabi_subsection 1, required, uleb128 .aeabi_subsection , required, uleb128 -// ERR: error: Expecting subsection name +// ERR: error: subsection name not found // ERR-NEXT: .aeabi_subsection , required, uleb128 -.aeabi_subsection required, uleb128 -// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: uleb128 -// ERR-NEXT: .aeabi_subsection required, uleb128 +.aeabi_subsection aeabi_pauthabi, a, uleb128 +// ERR: error: unknown AArch64 build attributes optionality, expected required|optional: a +// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, a, uleb128 .aeabi_subsection aeabi_pauthabi, a, uleb128 -// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: a +// ERR: error: unknown AArch64 build attributes optionality, expected required|optional: a // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, a, uleb128 .aeabi_subsection aeabi_pauthabi, 1, uleb128 -// ERR: error: Expecitng optionality parameter -// ERR-NEXT: Hint: use 'optional' | 'required' +// ERR: error: optionality parameter not found, expected required|optinal // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, 1, uleb128 .aeabi_subsection aeabi_pauthabi, ,uleb128 -// ERR: error: Expecitng optionality parameter -// ERR-NEXT: Hint: use 'optional' | 'required' +// ERR: error: optionality parameter not found, expected required|optinal // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, ,uleb128 .aeabi_subsection aeabi_pauthabi,uleb128 -// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: uleb128 +// ERR: error: unknown AArch64 build attributes optionality, expected required|optional: uleb128 // ERR-NEXT: .aeabi_subsection aeabi_pauthabi,uleb128 .aeabi_subsection aeabi_pauthabi uleb128 @@ -56,25 +53,10 @@ // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required .aeabi_subsection aeabi_pauthabi, required, -// ERR: error: Expecitng type parameter +// ERR: error: type parameter not found, expected uleb128|ntbs // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, .aeabi_subsection aeabi_pauthabi, required, a -// ERR: error: unknown AArch64 build attributes type, expecting uleb128|ntbs: a +// ERR: error: unknown AArch64 build attributes type, expected uleb128|ntbs: a // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, a -.aeabi_subsection aeabi_pauthabi, required, 1 -// ERR: error: Expecitng type parameter -// ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, 1 - -.aeabi_subsection aeabi_pauthabi -// ERR: error: expected comma -// ERR-NEXT: .aeabi_subsection aeabi_pauthabi - -.aeabi_subsection aeabi_feature_and_bits, a, uleb128 -// ERR: error: unknown AArch64 build attributes optionality, expecting required|optional: a -// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, a, uleb128 - -.aeabi_subsection aeabi_feature_and_bits, optional, 1 -// ERR: error: Expecitng type parameter -// ERR-NEXT: .aeabi_subsection aeabi_feature_and_bits, optional, 1 diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s index 1d2618d4c20e0..ad6bb4d1856b7 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s @@ -1,12 +1,16 @@ -// RUN: not llvm-mc -triple=aarch64 %s -o %t > %t.out 2>&1 -// RUN: FileCheck --input-file=%t.out --check-prefix=ERR %s +// RUN: not llvm-mc -triple=aarch64 %s 2>&1 | FileCheck --check-prefix=ERR %s .aeabi_subsection private_subsection, optional, uleb128 .aeabi_subsection private_subsection, required, uleb128 -// ERR: error: Optinality mismatch! Subsection private_subsection allready exists with optinality defined as '1' and not '0'! (0: required, 1: optional) +// ERR: error: optionality mismatch! subsection 'private_subsection' already exists with optionality defined as '1' and not '0' (0: required, 1: optional) // ERR-NEXT: .aeabi_subsection private_subsection, required, uleb128 .aeabi_subsection private_subsection, optional, ntbs -// ERR: error: Type mismatch! Subsection private_subsection allready exists with Type defined as '0' and not '1'! (0: uleb128, 1: ntbs) -// ERR-NEXT: .aeabi_subsection private_subsection, optional, ntbs \ No newline at end of file +// ERR: error: type mismatch! subsection 'private_subsection' already exists with type defined as '0' and not '1' (0: uleb128, 1: ntbs) +// ERR-NEXT: .aeabi_subsection private_subsection, optional, ntbs + +.aeabi_subsection private_subsection_1, optional, ntbs +.aeabi_attribute 324, 1 +// ERR: error: active subsection type is NTBS (string), found ULEB128 (unsigned) +// ERR-NEXT: .aeabi_attribute 324, 1 \ No newline at end of file diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s index 1b9bcfcfbb35e..229033a9f6b70 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections.s @@ -8,13 +8,13 @@ // ASM: .aeabi_subsection private_subsection_3, optional, ntbs // ASM: .aeabi_attribute 34, hello_llvm // ASM: .aeabi_subsection private_subsection_4, required, ntbs -// ASM: .aeabi_attribute 777, hello_llvm +// ASM: .aeabi_attribute 777, "hello_llvm" // ASM: .aeabi_subsection private_subsection_1, optional, uleb128 // ASM: .aeabi_attribute 876, 257 // ASM: .aeabi_subsection private_subsection_2, required, uleb128 // ASM: .aeabi_attribute 876, 257 // ASM: .aeabi_subsection private_subsection_3, optional, ntbs -// ASM: .aeabi_attribute 876, hello_llvm +// ASM: .aeabi_attribute 876, "hello_llvm" // ASM: .aeabi_subsection private_subsection_4, required, ntbs // ASM: .aeabi_attribute 876, hello_llvm @@ -23,13 +23,14 @@ // ELF-NEXT: 0x00000010 73656374 696f6e5f 31000100 0c8102ec section_1....... // ELF-NEXT: 0x00000020 06810222 00000070 72697661 74655f73 ..."...private_s // ELF-NEXT: 0x00000030 75627365 6374696f 6e5f3200 00004c81 ubsection_2...L. -// ELF-NEXT: 0x00000040 02ec0681 02340000 00707269 76617465 .....4...private +// ELF-NEXT: 0x00000040 02ec0681 02360000 00707269 76617465 .....6...private // ELF-NEXT: 0x00000050 5f737562 73656374 696f6e5f 33000101 _subsection_3... -// ELF-NEXT: 0x00000060 2268656c 6c6f5f6c 6c766d00 ec066865 "hello_llvm...he -// ELF-NEXT: 0x00000070 6c6c6f5f 6c6c766d 00350000 00707269 llo_llvm.5...pri -// ELF-NEXT: 0x00000080 76617465 5f737562 73656374 696f6e5f vate_subsection_ -// ELF-NEXT: 0x00000090 34000001 89066865 6c6c6f5f 6c6c766d 4.....hello_llvm -// ELF-NEXT: 0x000000a0 00ec0668 656c6c6f 5f6c6c76 6d00 ...hello_llvm. +// ELF-NEXT: 0x00000060 2268656c 6c6f5f6c 6c766d00 ec062268 "hello_llvm..."h +// ELF-NEXT: 0x00000070 656c6c6f 5f6c6c76 6d220037 00000070 ello_llvm".7...p +// ELF-NEXT: 0x00000080 72697661 74655f73 75627365 6374696f rivate_subsectio +// ELF-NEXT: 0x00000090 6e5f3400 00018906 2268656c 6c6f5f6c n_4....."hello_l +// ELF-NEXT: 0x000000a0 6c766d22 00ec0668 656c6c6f 5f6c6c76 lvm"...hello_llv +// ELF-NEXT: 0x000000b0 6d00 m. .aeabi_subsection private_subsection_1, optional, uleb128 @@ -39,12 +40,12 @@ .aeabi_subsection private_subsection_3, optional, ntbs .aeabi_attribute 34, hello_llvm .aeabi_subsection private_subsection_4, required, ntbs -.aeabi_attribute 777, hello_llvm +.aeabi_attribute 777, "hello_llvm" .aeabi_subsection private_subsection_1, optional, uleb128 .aeabi_attribute 876, 257 .aeabi_subsection private_subsection_2, required, uleb128 .aeabi_attribute 876, 257 .aeabi_subsection private_subsection_3, optional, ntbs -.aeabi_attribute 876, hello_llvm +.aeabi_attribute 876, "hello_llvm" .aeabi_subsection private_subsection_4, required, ntbs .aeabi_attribute 876, hello_llvm From 85819a65cee0992d17c150d79ed525b9929f21ee Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Wed, 15 Jan 2025 16:03:38 +0000 Subject: [PATCH 18/21] fix according to comments --- llvm/lib/Support/AArch64BuildAttributes.cpp | 10 ++----- .../AArch64/AsmParser/AArch64AsmParser.cpp | 30 +++++++++---------- .../MCTargetDesc/AArch64ELFStreamer.cpp | 28 +++++------------ .../MCTargetDesc/AArch64TargetStreamer.cpp | 10 +++++++ .../MCTargetDesc/AArch64TargetStreamer.h | 2 ++ ...aarch64-build-attributes-asm-err-headers.s | 5 ++-- ...d-attributes-asm-private-subsections-err.s | 14 ++++++++- 7 files changed, 50 insertions(+), 49 deletions(-) diff --git a/llvm/lib/Support/AArch64BuildAttributes.cpp b/llvm/lib/Support/AArch64BuildAttributes.cpp index 2c70e37f37ec6..ada34eb3f927d 100644 --- a/llvm/lib/Support/AArch64BuildAttributes.cpp +++ b/llvm/lib/Support/AArch64BuildAttributes.cpp @@ -39,7 +39,6 @@ StringRef getOptionalStr(unsigned Optional) { case OPTIONAL: return "optional"; case OPTIONAL_NOT_FOUND: - LLVM_FALLTHROUGH; default: return ""; } @@ -62,17 +61,14 @@ StringRef getTypeStr(unsigned Type) { case NTBS: return "ntbs"; case TYPE_NOT_FOUND: - LLVM_FALLTHROUGH; default: return ""; } } SubsectionType getTypeID(StringRef Type) { return StringSwitch(Type) - .Case("uleb128", ULEB128) - .Case("ULEB128", ULEB128) - .Case("NTBS", NTBS) - .Case("ntbs", NTBS) + .Cases("uleb128", "ULEB128", ULEB128) + .Cases("ntbs", "NTBS", NTBS) .Default(TYPE_NOT_FOUND); } StringRef getSubsectionTypeUnknownError() { @@ -86,7 +82,6 @@ StringRef getPauthABITagsStr(unsigned PauthABITag) { case TAG_PAUTH_SCHEMA: return "Tag_PAuth_Schema"; case PAUTHABI_TAG_NOT_FOUND: - LLVM_FALLTHROUGH; default: return ""; } @@ -107,7 +102,6 @@ StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) { case TAG_FEATURE_GCS: return "Tag_Feature_GCS"; case FEATURE_AND_BITS_TAG_NOT_FOUND: - LLVM_FALLTHROUGH; default: return ""; } diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index 14cb32b1b5347..f6306c4c5c950 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -7821,13 +7821,6 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { // (3)uleb128 separated by 2 commas. MCAsmParser &Parser = getParser(); - bool HasActiveSubsection = true; - std::unique_ptr ActiveSubsection = - getTargetStreamer().getActiveAtributesSubsection(); - if (nullptr == ActiveSubsection) { - HasActiveSubsection = false; - } - // Consume the name (subsection name) StringRef SubsectionName; AArch64BuildAttributes::VendorID SubsectionNameID; @@ -7846,6 +7839,13 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } + bool SubsectionExists = true; + std::unique_ptr ExistingSubsection = + getTargetStreamer().getActiveSubsectionByName(SubsectionName); + if (nullptr == ExistingSubsection) { + SubsectionExists = false; + } + // Consume the first parameter (optionality parameter) AArch64BuildAttributes::SubsectionOptional IsOptional; // options: optional/required @@ -7858,20 +7858,19 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { Optionality); return true; } - if (HasActiveSubsection && - (SubsectionName == ActiveSubsection->VendorName)) { - if (IsOptional != ActiveSubsection->IsOptional) { + if (SubsectionExists) { + if (IsOptional != ExistingSubsection->IsOptional) { Error(Parser.getTok().getLoc(), "optionality mismatch! subsection '" + SubsectionName + "' already exists with optionality defined as '" + - Twine(ActiveSubsection->IsOptional) + "' and not '" + + Twine(ExistingSubsection->IsOptional) + "' and not '" + Twine(IsOptional) + "' (0: required, 1: optional)"); return true; } } } else { Error(Parser.getTok().getLoc(), - "optionality parameter not found, expected required|optinal"); + "optionality parameter not found, expected required|optional"); return true; } // Check for possible IsOptional unaccepted values for known subsections @@ -7906,13 +7905,12 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { Name); return true; } - if (HasActiveSubsection && - (SubsectionName == ActiveSubsection->VendorName)) { - if (Type != ActiveSubsection->ParameterType) { + if (SubsectionExists) { + if (Type != ExistingSubsection->ParameterType) { Error(Parser.getTok().getLoc(), "type mismatch! subsection '" + SubsectionName + "' already exists with type defined as '" + - Twine(ActiveSubsection->ParameterType) + "' and not '" + + Twine(ExistingSubsection->ParameterType) + "' and not '" + Twine(Type) + "' (0: uleb128, 1: ntbs)"); return true; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 0851ce212fc5b..9f7a60074daeb 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -189,9 +189,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { Override); break; case AArch64BuildAttributes::TAG_FEATURE_BTI: - LLVM_FALLTHROUGH; case AArch64BuildAttributes::TAG_FEATURE_GCS: - LLVM_FALLTHROUGH; case AArch64BuildAttributes::TAG_FEATURE_PAC: OS << "\t.aeabi_attribute" << "\t" << AArch64BuildAttributes::getFeatureAndBitsTagsStr(Tag) << ", " @@ -212,7 +210,6 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { Override); break; case AArch64BuildAttributes::TAG_PAUTH_PLATFORM: - LLVM_FALLTHROUGH; case AArch64BuildAttributes::TAG_PAUTH_SCHEMA: OS << "\t.aeabi_attribute" << "\t" << AArch64BuildAttributes::getPauthABITagsStr(Tag) << ", " << Value; @@ -246,16 +243,7 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { switch (SubsectionID) { default: { - assert(0 && "Subsection error"); - break; - } - case AArch64BuildAttributes::VENDOR_UNKNOWN: { - // Keep the data structure consistent with the case of ELF emission - // (important for llvm-mc asm parsing) - OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " - << OptionalStr << ", " << ParameterStr; - AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, - ParameterType); + // Treated as a private subsection break; } case AArch64BuildAttributes::AEABI_PAUTHABI: { @@ -265,10 +253,6 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { assert(AArch64BuildAttributes::ULEB128 == ParameterType && "subsection .aeabi-pauthabi should be " "marked as uleb128 and not as ntbs"); - OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " - << OptionalStr << ", " << ParameterStr; - AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, - ParameterType); break; } case AArch64BuildAttributes::AEABI_FEATURE_AND_BITS: { @@ -278,13 +262,15 @@ class AArch64TargetAsmStreamer : public AArch64TargetStreamer { assert(AArch64BuildAttributes::ULEB128 == ParameterType && "subsection .aeabi_feature_and_bits should " "be marked as uleb128 and not as ntbs"); - OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " - << OptionalStr << ", " << ParameterStr; - AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, - ParameterType); break; } } + OS << "\t" << SubsectionTag << "\t" << SubsectionName << ", " << OptionalStr + << ", " << ParameterStr; + // Keep the data structure consistent with the case of ELF emission + // (important for llvm-mc asm parsing) + AArch64TargetStreamer::emitAtributesSubsection(SubsectionName, Optional, + ParameterType); OS << "\n"; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp index ee17de26d1caf..f9c2d2ec41444 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp @@ -182,6 +182,16 @@ AArch64TargetStreamer::getActiveAtributesSubsection() { return nullptr; } +std::unique_ptr +AArch64TargetStreamer::getActiveSubsectionByName(StringRef name) { + for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { + if (name == SubSection.VendorName) { + return std::make_unique(SubSection); + } + } + return nullptr; +} + void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag, unsigned Value, std::string String, bool Override) { diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index 3bb03eb5797cd..f8b8140d30046 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -104,6 +104,8 @@ class AArch64TargetStreamer : public MCTargetStreamer { void activateAtributesSubsection(StringRef VendorName); std::unique_ptr getActiveAtributesSubsection(); + std::unique_ptr + getActiveSubsectionByName(StringRef name); void insertAttributeInPlace(const MCELFStreamer::AttributeItem &Attr, MCELFStreamer::AttributeSubSection &AttSubSection); diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s index 40e59f80cd0d6..9e6dca341e9f8 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-err-headers.s @@ -33,11 +33,11 @@ // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, a, uleb128 .aeabi_subsection aeabi_pauthabi, 1, uleb128 -// ERR: error: optionality parameter not found, expected required|optinal +// ERR: error: optionality parameter not found, expected required|optional // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, 1, uleb128 .aeabi_subsection aeabi_pauthabi, ,uleb128 -// ERR: error: optionality parameter not found, expected required|optinal +// ERR: error: optionality parameter not found, expected required|optional // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, ,uleb128 .aeabi_subsection aeabi_pauthabi,uleb128 @@ -59,4 +59,3 @@ .aeabi_subsection aeabi_pauthabi, required, a // ERR: error: unknown AArch64 build attributes type, expected uleb128|ntbs: a // ERR-NEXT: .aeabi_subsection aeabi_pauthabi, required, a - diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s index ad6bb4d1856b7..98fc8717d13c3 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s @@ -13,4 +13,16 @@ .aeabi_subsection private_subsection_1, optional, ntbs .aeabi_attribute 324, 1 // ERR: error: active subsection type is NTBS (string), found ULEB128 (unsigned) -// ERR-NEXT: .aeabi_attribute 324, 1 \ No newline at end of file +// ERR-NEXT: .aeabi_attribute 324, 1 + +.aeabi_subsection foo, optional, uleb128 +.aeabi_subsection bar, optional, uleb128 +.aeabi_subsection foo, required, uleb128 +// ERR: error: optionality mismatch! subsection 'foo' already exists with optionality defined as '1' and not '0' (0: required, 1: optional) +// ERR-NEXT: .aeabi_subsection foo, required, uleb128 + +.aeabi_subsection goo, optional, ntbs +.aeabi_subsection zar, optional, ntbs +.aeabi_subsection goo, optional, uleb128 +// ERR: error: type mismatch! subsection 'goo' already exists with type defined as '1' and not '0' (0: uleb128, 1: ntbs) +// ERR-NEXT: .aeabi_subsection goo, optional, uleb128 \ No newline at end of file From 0fde842bf2a8acbb5e24891514049a58b7e40d72 Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Tue, 21 Jan 2025 13:16:43 +0000 Subject: [PATCH 19/21] Add AArch64BuildAttributes.cpp to lib/Support/BUILD.gn --- llvm/lib/Support/CMakeLists.txt | 2 +- llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index c1989aee2d4ae..122240c27b1fc 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -137,7 +137,6 @@ endif() add_subdirectory(BLAKE3) add_llvm_component_library(LLVMSupport - AArch64BuildAttributes.cpp ABIBreak.cpp AMDGPUMetadata.cpp APFixedPoint.cpp @@ -145,6 +144,7 @@ add_llvm_component_library(LLVMSupport APInt.cpp APSInt.cpp ARMBuildAttrs.cpp + AArch64BuildAttributes.cpp ARMAttributeParser.cpp ARMWinEH.cpp Allocator.cpp diff --git a/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn index 861790d5081c8..008715a0b3dea 100644 --- a/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn @@ -42,6 +42,7 @@ static_library("Support") { "APSInt.cpp", "ARMAttributeParser.cpp", "ARMBuildAttrs.cpp", + "AArch64BuildAttributes.cpp", "ARMWinEH.cpp", "Allocator.cpp", "AutoConvert.cpp", From 330cb7917bfcca9a979d0095aa600a984d27e23d Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Tue, 21 Jan 2025 17:57:52 +0000 Subject: [PATCH 20/21] fix according to comments above --- .../AArch64/AsmParser/AArch64AsmParser.cpp | 25 ++++++++++--------- .../MCTargetDesc/AArch64TargetStreamer.cpp | 4 +-- .../MCTargetDesc/AArch64TargetStreamer.h | 2 +- ...d-attributes-asm-private-subsections-err.s | 6 ++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index f6306c4c5c950..4a47f2cde6d66 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -42,6 +42,7 @@ #include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/MCValue.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/Support/AArch64BuildAttributes.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" @@ -7839,12 +7840,8 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } - bool SubsectionExists = true; - std::unique_ptr ExistingSubsection = - getTargetStreamer().getActiveSubsectionByName(SubsectionName); - if (nullptr == ExistingSubsection) { - SubsectionExists = false; - } + std::unique_ptr SubsectionExists = + getTargetStreamer().getAtributesSubsectionByName(SubsectionName); // Consume the first parameter (optionality parameter) AArch64BuildAttributes::SubsectionOptional IsOptional; @@ -7859,12 +7856,14 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } if (SubsectionExists) { - if (IsOptional != ExistingSubsection->IsOptional) { + if (IsOptional != SubsectionExists->IsOptional) { Error(Parser.getTok().getLoc(), "optionality mismatch! subsection '" + SubsectionName + "' already exists with optionality defined as '" + - Twine(ExistingSubsection->IsOptional) + "' and not '" + - Twine(IsOptional) + "' (0: required, 1: optional)"); + AArch64BuildAttributes::getOptionalStr( + SubsectionExists->IsOptional) + + "' and not '" + + AArch64BuildAttributes::getOptionalStr(IsOptional) + "'"); return true; } } @@ -7906,12 +7905,14 @@ bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) { return true; } if (SubsectionExists) { - if (Type != ExistingSubsection->ParameterType) { + if (Type != SubsectionExists->ParameterType) { Error(Parser.getTok().getLoc(), "type mismatch! subsection '" + SubsectionName + "' already exists with type defined as '" + - Twine(ExistingSubsection->ParameterType) + "' and not '" + - Twine(Type) + "' (0: uleb128, 1: ntbs)"); + AArch64BuildAttributes::getTypeStr( + SubsectionExists->ParameterType) + + "' and not '" + AArch64BuildAttributes::getTypeStr(Type) + + "'"); return true; } } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp index f9c2d2ec41444..74ffe5f97f1b6 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp @@ -183,9 +183,9 @@ AArch64TargetStreamer::getActiveAtributesSubsection() { } std::unique_ptr -AArch64TargetStreamer::getActiveSubsectionByName(StringRef name) { +AArch64TargetStreamer::getAtributesSubsectionByName(StringRef Name) { for (MCELFStreamer::AttributeSubSection &SubSection : AttributeSubSections) { - if (name == SubSection.VendorName) { + if (Name == SubSection.VendorName) { return std::make_unique(SubSection); } } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h index f8b8140d30046..b2b9afe867073 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h @@ -105,7 +105,7 @@ class AArch64TargetStreamer : public MCTargetStreamer { std::unique_ptr getActiveAtributesSubsection(); std::unique_ptr - getActiveSubsectionByName(StringRef name); + getAtributesSubsectionByName(StringRef Name); void insertAttributeInPlace(const MCELFStreamer::AttributeItem &Attr, MCELFStreamer::AttributeSubSection &AttSubSection); diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s index 98fc8717d13c3..cf8dbddbe866c 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s @@ -3,7 +3,7 @@ .aeabi_subsection private_subsection, optional, uleb128 .aeabi_subsection private_subsection, required, uleb128 -// ERR: error: optionality mismatch! subsection 'private_subsection' already exists with optionality defined as '1' and not '0' (0: required, 1: optional) +// ERR: error: optionality mismatch! subsection 'private_subsection' already exists with optionality defined as 'optional' and not 'required' // ERR-NEXT: .aeabi_subsection private_subsection, required, uleb128 .aeabi_subsection private_subsection, optional, ntbs @@ -18,11 +18,11 @@ .aeabi_subsection foo, optional, uleb128 .aeabi_subsection bar, optional, uleb128 .aeabi_subsection foo, required, uleb128 -// ERR: error: optionality mismatch! subsection 'foo' already exists with optionality defined as '1' and not '0' (0: required, 1: optional) +// ERR: error: optionality mismatch! subsection 'foo' already exists with optionality defined as 'optional' and not 'required' // ERR-NEXT: .aeabi_subsection foo, required, uleb128 .aeabi_subsection goo, optional, ntbs .aeabi_subsection zar, optional, ntbs .aeabi_subsection goo, optional, uleb128 -// ERR: error: type mismatch! subsection 'goo' already exists with type defined as '1' and not '0' (0: uleb128, 1: ntbs) +// ERR: error: type mismatch! subsection 'goo' already exists with type defined as 'ntbs' and not 'uleb128' // ERR-NEXT: .aeabi_subsection goo, optional, uleb128 \ No newline at end of file From 1535a88d815957d2b2dfa823999463ea6a3bbbdf Mon Sep 17 00:00:00 2001 From: Sivan Shani Date: Wed, 22 Jan 2025 13:02:08 +0000 Subject: [PATCH 21/21] fix error in a test file --- .../aarch64-build-attributes-asm-private-subsections-err.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s index cf8dbddbe866c..2b4cbcc721acd 100644 --- a/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s +++ b/llvm/test/MC/AArch64/aarch64-build-attributes-asm-private-subsections-err.s @@ -7,7 +7,7 @@ // ERR-NEXT: .aeabi_subsection private_subsection, required, uleb128 .aeabi_subsection private_subsection, optional, ntbs -// ERR: error: type mismatch! subsection 'private_subsection' already exists with type defined as '0' and not '1' (0: uleb128, 1: ntbs) +// ERR: error: type mismatch! subsection 'private_subsection' already exists with type defined as 'uleb128' and not 'ntbs' // ERR-NEXT: .aeabi_subsection private_subsection, optional, ntbs .aeabi_subsection private_subsection_1, optional, ntbs