-
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 18 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,75 @@ | ||
| //===-- 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/pull/230 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_SUPPORT_AARCH64BUILDATTRIBUTES_H | ||
| #define LLVM_SUPPORT_AARCH64BUILDATTRIBUTES_H | ||
|
|
||
| #include "llvm/ADT/StringRef.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| namespace AArch64BuildAttributes { | ||
|
|
||
| /// 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 | ||
| }; | ||
| StringRef getVendorName(unsigned const Vendor); | ||
| VendorID getVendorID(StringRef const Vendor); | ||
|
|
||
| enum SubsectionOptional : unsigned { | ||
| REQUIRED = 0, | ||
| OPTIONAL = 1, | ||
| OPTIONAL_NOT_FOUND = 404 | ||
| }; | ||
| StringRef getOptionalStr(unsigned Optional); | ||
| SubsectionOptional getOptionalID(StringRef Optional); | ||
| StringRef getSubsectionOptionalUnknownError(); | ||
|
|
||
| enum SubsectionType : unsigned { ULEB128 = 0, NTBS = 1, TYPE_NOT_FOUND = 404 }; | ||
| 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 | ||
| }; | ||
| StringRef getPauthABITagsStr(unsigned PauthABITag); | ||
| PauthABITags getPauthABITagsID(StringRef PauthABITag); | ||
|
|
||
| enum FeatureAndBitsTags : unsigned { | ||
| TAG_FEATURE_BTI = 0, | ||
| TAG_FEATURE_PAC = 1, | ||
| TAG_FEATURE_GCS = 2, | ||
| FEATURE_AND_BITS_TAG_NOT_FOUND = 404 | ||
| }; | ||
| StringRef getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag); | ||
| FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag); | ||
|
|
||
| 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,123 @@ | ||
| //===-- 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" | ||
| #include "llvm/ADT/StringSwitch.h" | ||
|
|
||
| namespace llvm { | ||
| namespace AArch64BuildAttributes { | ||
|
|
||
| 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 "aeabi_feature_and_bits"; | ||
| case AEABI_PAUTHABI: | ||
| return "aeabi_pauthabi"; | ||
| case VENDOR_UNKNOWN: | ||
| return ""; | ||
| default: | ||
| assert(0 && "Vendor name error"); | ||
| return ""; | ||
| } | ||
| } | ||
| VendorID getVendorID(StringRef Vendor) { | ||
| return StringSwitch<VendorID>(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 "required"; | ||
| case OPTIONAL: | ||
| return "optional"; | ||
| case OPTIONAL_NOT_FOUND: | ||
| LLVM_FALLTHROUGH; | ||
| default: | ||
| return ""; | ||
| } | ||
| } | ||
| SubsectionOptional getOptionalID(StringRef Optional) { | ||
| return StringSwitch<SubsectionOptional>(Optional) | ||
| .Case("required", REQUIRED) | ||
| .Case("optional", OPTIONAL) | ||
| .Default(OPTIONAL_NOT_FOUND); | ||
| } | ||
| StringRef getSubsectionOptionalUnknownError() { | ||
| return "unknown AArch64 build attributes optionality, expected " | ||
| "required|optional"; | ||
| } | ||
|
|
||
| StringRef getTypeStr(unsigned Type) { | ||
| switch (Type) { | ||
| case ULEB128: | ||
| return "uleb128"; | ||
| case NTBS: | ||
| return "ntbs"; | ||
| case TYPE_NOT_FOUND: | ||
| LLVM_FALLTHROUGH; | ||
| default: | ||
| return ""; | ||
| } | ||
| } | ||
| SubsectionType getTypeID(StringRef Type) { | ||
| return StringSwitch<SubsectionType>(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, expected uleb128|ntbs"; | ||
| } | ||
|
|
||
| StringRef getPauthABITagsStr(unsigned PauthABITag) { | ||
| switch (PauthABITag) { | ||
| case TAG_PAUTH_PLATFORM: | ||
| return "Tag_PAuth_Platform"; | ||
| case TAG_PAUTH_SCHEMA: | ||
| return "Tag_PAuth_Schema"; | ||
| case PAUTHABI_TAG_NOT_FOUND: | ||
| LLVM_FALLTHROUGH; | ||
| default: | ||
| return ""; | ||
| } | ||
| } | ||
| PauthABITags getPauthABITagsID(StringRef PauthABITag) { | ||
| return StringSwitch<PauthABITags>(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 "Tag_Feature_BTI"; | ||
| case TAG_FEATURE_PAC: | ||
| return "Tag_Feature_PAC"; | ||
| case TAG_FEATURE_GCS: | ||
| return "Tag_Feature_GCS"; | ||
| case FEATURE_AND_BITS_TAG_NOT_FOUND: | ||
| LLVM_FALLTHROUGH; | ||
| default: | ||
| return ""; | ||
| } | ||
| } | ||
| FeatureAndBitsTags getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) { | ||
| return StringSwitch<FeatureAndBitsTags>(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 | ||
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.
In ARM we have ARMBuildAttrs. Should this be shortened to AArch64BuildAttrs?
Uh oh!
There was an error while loading. Please reload this page.
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.
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)
While 'attrs' does not seems to be used elsewhere.
Correction: the files names indeed does not use 'Attrs' but the names inside them does.
Not sure why I was fixated on the files names.
Will change AArch64 accordingly to match.