[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
llvmbot wrote: /pull-request llvm/llvm-project#126589 https://github.com/llvm/llvm-project/pull/125280 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
asl wrote: /cherry-pick https://github.com/llvm/llvm-project/commit/84b0c128a751acfbf5b439edc724ba27d1da653e https://github.com/llvm/llvm-project/pull/125280 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
https://github.com/asl milestoned https://github.com/llvm/llvm-project/pull/125280 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
@@ -0,0 +1,28 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang -target aarch64-linux-pauthtest %s -S -emit-llvm -o - 2>&1 |
FileCheck --implicit-check-not=warning: %s
+// RUN: %clang -target aarch64 -fptrauth-returns %s -S -emit-llvm -o - 2>&1 |
FileCheck --implicit-check-not=warning: %s
+
+/// Unsupported with pauthtest, warning emitted
+__attribute__((target("branch-protection=pac-ret"))) void f1() {}
+// CHECK: warning: unsupported 'branch-protection' in the 'target'
attribute string; 'target' attribute ignored [-Wignored-attributes]
+// CHECK-NEXT: __attribute__((target("branch-protection=pac-ret"))) void f1()
{}
+__attribute__((target("branch-protection=gcs"))) void f2() {}
+// CHECK: warning: unsupported 'branch-protection' in the 'target'
attribute string; 'target' attribute ignored [-Wignored-attributes]
+// CHECK-NEXT: __attribute__((target("branch-protection=gcs"))) void f2() {}
+__attribute__((target("branch-protection=standard"))) void f3() {}
+// CHECK: warning: unsupported 'branch-protection' in the 'target'
attribute string; 'target' attribute ignored [-Wignored-attributes]
+// CHECK-NEXT: __attribute__((target("branch-protection=standard"))) void f3()
{}
+
+/// Supported with pauthtest, no warning emitted
+__attribute__((target("branch-protection=bti"))) void f4() {}
DanielKristofKiss wrote:
I'd add a test case of the "branch-protection=none".
https://github.com/llvm/llvm-project/pull/125280
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
https://github.com/DanielKristofKiss edited https://github.com/llvm/llvm-project/pull/125280 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
https://github.com/DanielKristofKiss approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/125280 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
llvmbot wrote:
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-backend-arm
Author: Daniil Kovalev (kovdan01)
Changes
This patch does two things.
1. Previously, when checking driver arguments, we emitted an error for
unsupported values of `-mbranch-protection` when using pauthtest ABI. The
reason for that was ptrauth-returns being enabled as part of pauthtest. This
patch changes the check against pauthtest to a check against ptrauth-returns.
2. Similarly, check against values of the following function attribute which
are unsupported with ptrauth-returns:
`__attribute__((target("branch-protection=XXX`. Note that existing
`validateBranchProtection` function is used, and current behavior is to ignore
the unsupported attribute value, so no error is emitted.
---
Full diff: https://github.com/llvm/llvm-project/pull/125280.diff
11 Files Affected:
- (modified) clang/include/clang/Basic/TargetInfo.h (+1)
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+8)
- (modified) clang/lib/Basic/Targets/AArch64.h (+1)
- (modified) clang/lib/Basic/Targets/ARM.cpp (+1)
- (modified) clang/lib/Basic/Targets/ARM.h (+1)
- (modified) clang/lib/CodeGen/Targets/AArch64.cpp (+2-2)
- (modified) clang/lib/CodeGen/Targets/ARM.cpp (+2-2)
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+24-22)
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+2-1)
- (modified) clang/test/Driver/aarch64-ptrauth.c (+18-9)
- (added) clang/test/Frontend/aarch64-ignore-branch-protection-attribute.c
(+28)
``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h
b/clang/include/clang/Basic/TargetInfo.h
index 43c09cf1f973e3..03f7b704110d20 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1468,6 +1468,7 @@ class TargetInfo : public TransferrableTargetInfo,
/// specification
virtual bool validateBranchProtection(StringRef Spec, StringRef Arch,
BranchProtectionInfo &BPI,
+const LangOptions &LO,
StringRef &Err) const {
Err = "";
return false;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp
b/clang/lib/Basic/Targets/AArch64.cpp
index 0b899137bbb5c7..176aeb7b426be5 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -253,11 +253,19 @@ bool AArch64TargetInfo::validateGlobalRegisterVariable(
bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
BranchProtectionInfo &BPI,
+ const LangOptions &LO,
StringRef &Err) const {
llvm::ARM::ParsedBranchProtection PBP;
if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err, HasPAuthLR))
return false;
+ // GCS is currently untested with ptrauth-returns, but enabling this could be
+ // allowed in future after testing with a suitable system.
+ if (LO.PointerAuthReturns &&
+ (PBP.Scope != "none" || PBP.BranchProtectionPAuthLR ||
+ PBP.GuardedControlStack))
+return false;
+
BPI.SignReturnAddr =
llvm::StringSwitch(PBP.Scope)
.Case("non-leaf", LangOptions::SignReturnAddressScopeKind::NonLeaf)
diff --git a/clang/lib/Basic/Targets/AArch64.h
b/clang/lib/Basic/Targets/AArch64.h
index 8695c0750ee32d..357205a153ae5c 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -132,6 +132,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public
TargetInfo {
bool validateBranchProtection(StringRef Spec, StringRef Arch,
BranchProtectionInfo &BPI,
+const LangOptions &LO,
StringRef &Err) const override;
bool isValidCPUName(StringRef Name) const override;
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 5aa2baeb81b731..29be9a6eb34890 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -405,6 +405,7 @@ bool
ARMTargetInfo::isBranchProtectionSupportedArch(StringRef Arch) const {
bool ARMTargetInfo::validateBranchProtection(StringRef Spec, StringRef Arch,
BranchProtectionInfo &BPI,
+ const LangOptions &LO,
StringRef &Err) const {
llvm::ARM::ParsedBranchProtection PBP;
if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err))
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index 5f4acce7af5a46..12fd7ed7fcc92e 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -155,6 +155,7 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public
TargetInfo {
bool isBranchProtectionSupportedArch(StringRef Arch) const override;
bool validateBranchProtection(Str
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
https://github.com/kovdan01 ready_for_review https://github.com/llvm/llvm-project/pull/125280 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC] Do not support some values of branch-protection with ptrauth-returns (PR #125280)
https://github.com/kovdan01 created
https://github.com/llvm/llvm-project/pull/125280
This patch does two things.
1. Previously, when checking driver arguments, we emitted an error for
unsupported values of `-mbranch-protection` when using pauthtest ABI. The
reason for that was ptrauth-returns being enabled as part of pauthtest. This
patch changes the check against pauthtest to a check against ptrauth-returns.
2. Similarly, check against values of the following function attribute which
are unsupported with ptrauth-returns:
`__attribute__((target("branch-protection=XXX`. Note that existing
`validateBranchProtection` function is used, and current behavior is to ignore
the unsupported attribute value, so no error is emitted.
>From 174c0f3a8893fc886d0c1152bef9620abeace6b8 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev
Date: Fri, 31 Jan 2025 22:57:10 +0300
Subject: [PATCH] [PAC] Do not support some values of branch-protection with
ptrauth-returns
This patch does two things.
1. Previously, when checking driver arguments, we emitted an error for
unsupported values of `-mbranch-protection` when using pauthtest ABI. The
reason for that was ptrauth-returns being enabled as part of pauthtest.
This patch changes the check against pauthtest to a check against
ptrauth-returns.
2. Similarly, check against values of the following function attribute which
are unsupported with ptrauth-returns:
`__attribute__((target("branch-protection=XXX`. Note that existing
`validateBranchProtection` function is used, and current behavior is
to ignore the unsupported attribute value, so no error is emitted.
---
clang/include/clang/Basic/TargetInfo.h| 1 +
clang/lib/Basic/Targets/AArch64.cpp | 8
clang/lib/Basic/Targets/AArch64.h | 1 +
clang/lib/Basic/Targets/ARM.cpp | 1 +
clang/lib/Basic/Targets/ARM.h | 1 +
clang/lib/CodeGen/Targets/AArch64.cpp | 4 +-
clang/lib/CodeGen/Targets/ARM.cpp | 4 +-
clang/lib/Driver/ToolChains/Clang.cpp | 46 ++-
clang/lib/Sema/SemaDeclAttr.cpp | 3 +-
clang/test/Driver/aarch64-ptrauth.c | 27 +++
...rch64-ignore-branch-protection-attribute.c | 28 +++
11 files changed, 88 insertions(+), 36 deletions(-)
create mode 100644
clang/test/Frontend/aarch64-ignore-branch-protection-attribute.c
diff --git a/clang/include/clang/Basic/TargetInfo.h
b/clang/include/clang/Basic/TargetInfo.h
index 43c09cf1f973e3..03f7b704110d20 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1468,6 +1468,7 @@ class TargetInfo : public TransferrableTargetInfo,
/// specification
virtual bool validateBranchProtection(StringRef Spec, StringRef Arch,
BranchProtectionInfo &BPI,
+const LangOptions &LO,
StringRef &Err) const {
Err = "";
return false;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp
b/clang/lib/Basic/Targets/AArch64.cpp
index 0b899137bbb5c7..176aeb7b426be5 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -253,11 +253,19 @@ bool AArch64TargetInfo::validateGlobalRegisterVariable(
bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
BranchProtectionInfo &BPI,
+ const LangOptions &LO,
StringRef &Err) const {
llvm::ARM::ParsedBranchProtection PBP;
if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err, HasPAuthLR))
return false;
+ // GCS is currently untested with ptrauth-returns, but enabling this could be
+ // allowed in future after testing with a suitable system.
+ if (LO.PointerAuthReturns &&
+ (PBP.Scope != "none" || PBP.BranchProtectionPAuthLR ||
+ PBP.GuardedControlStack))
+return false;
+
BPI.SignReturnAddr =
llvm::StringSwitch(PBP.Scope)
.Case("non-leaf", LangOptions::SignReturnAddressScopeKind::NonLeaf)
diff --git a/clang/lib/Basic/Targets/AArch64.h
b/clang/lib/Basic/Targets/AArch64.h
index 8695c0750ee32d..357205a153ae5c 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -132,6 +132,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public
TargetInfo {
bool validateBranchProtection(StringRef Spec, StringRef Arch,
BranchProtectionInfo &BPI,
+const LangOptions &LO,
StringRef &Err) const override;
bool isValidCPUName(StringRef Name) const override;
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 5aa2baeb81b731..29be9a6eb34890 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/
