Update FEAT_PAuth_LR behaviour for AArch64 (#90614)
Currently, LLVM enables `-mbranch-protection=standard` as `bti+pac-ret`. To align LLVM with the behaviour in GNU, this has been updated to `bti+pac-ret+pc` when FEAT_PAuth_LR is enabled as an optional feature via the `-mcpu=` options. If this is not enabled, then this will revert to the existing behaviour.
This commit is contained in:
parent
6ce4c4ca2b
commit
6aac30fa43
@ -225,7 +225,7 @@ bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
|
|||||||
BranchProtectionInfo &BPI,
|
BranchProtectionInfo &BPI,
|
||||||
StringRef &Err) const {
|
StringRef &Err) const {
|
||||||
llvm::ARM::ParsedBranchProtection PBP;
|
llvm::ARM::ParsedBranchProtection PBP;
|
||||||
if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err))
|
if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err, HasPAuthLR))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BPI.SignReturnAddr =
|
BPI.SignReturnAddr =
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
#include "llvm/Support/Process.h"
|
#include "llvm/Support/Process.h"
|
||||||
#include "llvm/Support/YAMLParser.h"
|
#include "llvm/Support/YAMLParser.h"
|
||||||
|
#include "llvm/TargetParser/AArch64TargetParser.h"
|
||||||
#include "llvm/TargetParser/ARMTargetParserCommon.h"
|
#include "llvm/TargetParser/ARMTargetParserCommon.h"
|
||||||
#include "llvm/TargetParser/Host.h"
|
#include "llvm/TargetParser/Host.h"
|
||||||
#include "llvm/TargetParser/LoongArchTargetParser.h"
|
#include "llvm/TargetParser/LoongArchTargetParser.h"
|
||||||
@ -1511,7 +1512,24 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
|
|||||||
} else {
|
} else {
|
||||||
StringRef DiagMsg;
|
StringRef DiagMsg;
|
||||||
llvm::ARM::ParsedBranchProtection PBP;
|
llvm::ARM::ParsedBranchProtection PBP;
|
||||||
if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg))
|
bool EnablePAuthLR = false;
|
||||||
|
|
||||||
|
// To know if we need to enable PAuth-LR As part of the standard branch
|
||||||
|
// protection option, it needs to be determined if the feature has been
|
||||||
|
// activated in the `march` argument. This information is stored within the
|
||||||
|
// CmdArgs variable and can be found using a search.
|
||||||
|
if (isAArch64) {
|
||||||
|
auto isPAuthLR = [](const char *member) {
|
||||||
|
llvm::AArch64::ExtensionInfo pauthlr_extension =
|
||||||
|
llvm::AArch64::getExtensionByID(llvm::AArch64::AEK_PAUTHLR);
|
||||||
|
return (pauthlr_extension.Feature.compare(member) == 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (std::any_of(CmdArgs.begin(), CmdArgs.end(), isPAuthLR))
|
||||||
|
EnablePAuthLR = true;
|
||||||
|
}
|
||||||
|
if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg,
|
||||||
|
EnablePAuthLR))
|
||||||
D.Diag(diag::err_drv_unsupported_option_argument)
|
D.Diag(diag::err_drv_unsupported_option_argument)
|
||||||
<< A->getSpelling() << DiagMsg;
|
<< A->getSpelling() << DiagMsg;
|
||||||
if (!isAArch64 && PBP.Key == "b_key")
|
if (!isAArch64 && PBP.Key == "b_key")
|
||||||
|
@ -616,6 +616,9 @@
|
|||||||
// ================== Check Armv9.5-A Pointer Authentication Enhancements(PAuth_LR).
|
// ================== Check Armv9.5-A Pointer Authentication Enhancements(PAuth_LR).
|
||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s
|
||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s
|
||||||
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR-OFF,CHECK-BRANCH-PROTECTION-NO-PC %s
|
||||||
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a+pauth-lr -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC %s
|
||||||
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a+nopauth-lr -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR-OFF,CHECK-BRANCH-PROTECTION-NO-PC %s
|
||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth -mbranch-protection=none -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth -mbranch-protection=none -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s
|
||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=none -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=none -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR %s
|
||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR %s
|
||||||
@ -636,6 +639,7 @@
|
|||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=pac-ret+pc+b-key -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC-BKEY %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=pac-ret+pc+b-key -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC-BKEY %s
|
||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=pac-ret+pc+leaf -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC-LEAF %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=pac-ret+pc+leaf -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC-LEAF %s
|
||||||
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=pac-ret+pc+leaf+b-key -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC-LEAF-BKEY %s
|
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth-lr -mbranch-protection=pac-ret+pc+leaf+b-key -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC-LEAF-BKEY %s
|
||||||
|
// CHECK-BRANCH-PROTECTION-NO-PC: #define __ARM_FEATURE_PAC_DEFAULT 1
|
||||||
// CHECK-BRANCH-PROTECTION-PC: #define __ARM_FEATURE_PAC_DEFAULT 9
|
// CHECK-BRANCH-PROTECTION-PC: #define __ARM_FEATURE_PAC_DEFAULT 9
|
||||||
// CHECK-BRANCH-PROTECTION-PC-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 10
|
// CHECK-BRANCH-PROTECTION-PC-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 10
|
||||||
// CHECK-BRANCH-PROTECTION-PC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 13
|
// CHECK-BRANCH-PROTECTION-PC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 13
|
||||||
|
@ -76,6 +76,11 @@ Changes to the AArch64 Backend
|
|||||||
* Added support for Cortex-A78AE, Cortex-A520AE, Cortex-A720AE,
|
* Added support for Cortex-A78AE, Cortex-A520AE, Cortex-A720AE,
|
||||||
Cortex-R82AE, Neoverse-N3, Neoverse-V3 and Neoverse-V3AE CPUs.
|
Cortex-R82AE, Neoverse-N3, Neoverse-V3 and Neoverse-V3AE CPUs.
|
||||||
|
|
||||||
|
* ``-mbranch-protection=standard`` now enables FEAT_PAuth_LR by
|
||||||
|
default when the feature is enabled. The new behaviour results
|
||||||
|
in ``standard`` being equal to ``bti+pac-ret+pc`` when ``+pauth-lr``
|
||||||
|
is passed as part of ``-mcpu=`` options.
|
||||||
|
|
||||||
Changes to the AMDGPU Backend
|
Changes to the AMDGPU Backend
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
|
@ -676,6 +676,8 @@ inline constexpr Alias CpuAliases[] = {{"cobalt-100", "neoverse-n2"},
|
|||||||
|
|
||||||
inline constexpr Alias ExtAliases[] = {{"rdma", "rdm"}};
|
inline constexpr Alias ExtAliases[] = {{"rdma", "rdm"}};
|
||||||
|
|
||||||
|
const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));
|
||||||
|
|
||||||
bool getExtensionFeatures(
|
bool getExtensionFeatures(
|
||||||
const AArch64::ExtensionBitset &Extensions,
|
const AArch64::ExtensionBitset &Extensions,
|
||||||
std::vector<StringRef> &Features);
|
std::vector<StringRef> &Features);
|
||||||
|
@ -46,7 +46,7 @@ struct ParsedBranchProtection {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
|
bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
|
||||||
StringRef &Err);
|
StringRef &Err, bool EnablePAuthLR = false);
|
||||||
|
|
||||||
} // namespace ARM
|
} // namespace ARM
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
@ -280,3 +280,8 @@ bool AArch64::ExtensionSet::parseModifier(StringRef Modifier) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AArch64::ExtensionInfo &
|
||||||
|
AArch64::getExtensionByID(AArch64::ArchExtKind ExtID) {
|
||||||
|
return lookupExtensionByID(ExtID);
|
||||||
|
}
|
||||||
|
@ -139,7 +139,7 @@ ARM::EndianKind ARM::parseArchEndian(StringRef Arch) {
|
|||||||
// returned in `PBP`. Returns false in error, with `Err` containing
|
// returned in `PBP`. Returns false in error, with `Err` containing
|
||||||
// an erroneous part of the spec.
|
// an erroneous part of the spec.
|
||||||
bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
|
bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
|
||||||
StringRef &Err) {
|
StringRef &Err, bool EnablePAuthLR) {
|
||||||
PBP = {"none", "a_key", false, false, false};
|
PBP = {"none", "a_key", false, false, false};
|
||||||
if (Spec == "none")
|
if (Spec == "none")
|
||||||
return true; // defaults are ok
|
return true; // defaults are ok
|
||||||
@ -148,6 +148,7 @@ bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
|
|||||||
PBP.Scope = "non-leaf";
|
PBP.Scope = "non-leaf";
|
||||||
PBP.BranchTargetEnforcement = true;
|
PBP.BranchTargetEnforcement = true;
|
||||||
PBP.GuardedControlStack = true;
|
PBP.GuardedControlStack = true;
|
||||||
|
PBP.BranchProtectionPAuthLR = EnablePAuthLR;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user