-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[LLVM][Clang][AArch64] Implement AArch64 build attributes #118771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
a10af46
c1c4c46
8bc5b42
6e09e35
3450b35
b323e83
4505446
e86ca8d
f4f1b1b
b651b3c
7cde215
07b1f74
06215d9
3b9f53e
a09c731
22bee6f
56f496b
5082f08
85819a6
0fde842
330cb79
1535a88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| //===-- 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_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); | ||
|
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| //===-- 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In ARM we have ARMBuildAttrs. Should this be shortened to AArch64BuildAttrs?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That indeed will be more consistent, on the other hand, Attributes is more descriptive than Attrs, so perhaps changing ARMBuildAttrs to ARMBuildAttributes instead will give both the benefit of consistency and of clarity? Other files use Attributes as well, and not Attrs (for example: ELFAttributes.cpp, ELFAttributeParser.cpp, HexagonAttributes.cpp, HexagonAttributeParser.cpp, CSKYAttributes.cpp, CSKYAttributeParser.cpp, MSP430Attributes.cpp, MSP430AttributeParser.cpp) Correction: the files names indeed does not use 'Attrs' but the names inside them does. |
||
| // AArch64 build attributes | ||
| StringRef getSubsectionTag() { return "aeabi_subsection"; } | ||
| StringRef getAttrTag() { return "aeabi_attribute"; } | ||
|
|
||
| StringRef getVendorName(unsigned Vendor) { | ||
| switch (Vendor) { | ||
| case AEABI_FEATURE_AND_BITS: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These switch statements will need updating every time a new enum value is added, so I don't think the |
||
| return VendorName[AEABI_FEATURE_AND_BITS]; | ||
| case AEABI_PAUTHABI: | ||
| return VendorName[AEABI_PAUTHABI]; | ||
| case VENDOR_UNKNOWN: | ||
| return ""; | ||
| default: | ||
| assert(0 && "Vendor name error"); | ||
| 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_UNKNOWN; | ||
| } | ||
|
|
||
| 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this URL points to an un-committed PR, so I don't know if it will remain live after the PR is merged. It would be better to get the spec committed before landing this, but if that's not possible then I think it would be better to link to the PR here (ARM-software/abi-aa#230) because that URL will last longer.