-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[PAC][Driver] Enable BTI and PAC by default on OpenBSD/aarch64 #125392
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
Conversation
|
@llvm/pr-subscribers-clang Author: Brad Smith (brad0) ChangesFull diff: https://github.com/llvm/llvm-project/pull/125392.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 9b5132c5625faa0..710086cbc0ece43 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1560,15 +1560,21 @@ static void handlePAuthABI(const ArgList &DriverArgs, ArgStringList &CC1Args) {
static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs, bool isAArch64) {
+ const llvm::Triple &Triple = TC.getEffectiveTriple();
const Arg *A = isAArch64
? Args.getLastArg(options::OPT_msign_return_address_EQ,
options::OPT_mbranch_protection_EQ)
: Args.getLastArg(options::OPT_mbranch_protection_EQ);
- if (!A)
+ if (!A) {
+ if (Triple.isOSOpenBSD() && isAArch64) {
+ CmdArgs.push_back("-msign-return-address=non-leaf");
+ CmdArgs.push_back("-msign-return-address-key=a_key");
+ CmdArgs.push_back("-mbranch-target-enforce");
+ }
return;
+ }
const Driver &D = TC.getDriver();
- const llvm::Triple &Triple = TC.getEffectiveTriple();
if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass())))
D.Diag(diag::warn_incompatible_branch_protection_option)
<< Triple.getArchName();
@@ -1582,7 +1588,10 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
D.Diag(diag::err_drv_unsupported_option_argument)
<< A->getSpelling() << Scope;
Key = "a_key";
- IndirectBranches = false;
+ if (Triple.isOSOpenBSD() && isAArch64)
+ IndirectBranches = true;
+ else
+ IndirectBranches = false;
BranchProtectionPAuthLR = false;
GuardedControlStack = false;
} else {
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 672cd3adf44a691..68c114f063d04cd 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -136,3 +136,8 @@
// RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
// CHECK-LTO-FLAGS: "-plugin-opt=mcpu=x86-64"
+
+// Check 64-bit ARM for BTI and PAC flags
+// RUN: %clang --target=aarch64-unknown-openbsd -### -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-AARCH64-BTI-PAC %s
+// CHECK-AARCH64-BTI-PAC: "-msign-return-address=non-leaf" "-msign-return-address-key=a_key" "-mbranch-target-enforce"
|
|
@llvm/pr-subscribers-clang-driver Author: Brad Smith (brad0) ChangesFull diff: https://github.com/llvm/llvm-project/pull/125392.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 9b5132c5625faa..710086cbc0ece4 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1560,15 +1560,21 @@ static void handlePAuthABI(const ArgList &DriverArgs, ArgStringList &CC1Args) {
static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs, bool isAArch64) {
+ const llvm::Triple &Triple = TC.getEffectiveTriple();
const Arg *A = isAArch64
? Args.getLastArg(options::OPT_msign_return_address_EQ,
options::OPT_mbranch_protection_EQ)
: Args.getLastArg(options::OPT_mbranch_protection_EQ);
- if (!A)
+ if (!A) {
+ if (Triple.isOSOpenBSD() && isAArch64) {
+ CmdArgs.push_back("-msign-return-address=non-leaf");
+ CmdArgs.push_back("-msign-return-address-key=a_key");
+ CmdArgs.push_back("-mbranch-target-enforce");
+ }
return;
+ }
const Driver &D = TC.getDriver();
- const llvm::Triple &Triple = TC.getEffectiveTriple();
if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass())))
D.Diag(diag::warn_incompatible_branch_protection_option)
<< Triple.getArchName();
@@ -1582,7 +1588,10 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
D.Diag(diag::err_drv_unsupported_option_argument)
<< A->getSpelling() << Scope;
Key = "a_key";
- IndirectBranches = false;
+ if (Triple.isOSOpenBSD() && isAArch64)
+ IndirectBranches = true;
+ else
+ IndirectBranches = false;
BranchProtectionPAuthLR = false;
GuardedControlStack = false;
} else {
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 672cd3adf44a69..68c114f063d04c 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -136,3 +136,8 @@
// RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
// CHECK-LTO-FLAGS: "-plugin-opt=mcpu=x86-64"
+
+// Check 64-bit ARM for BTI and PAC flags
+// RUN: %clang --target=aarch64-unknown-openbsd -### -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-AARCH64-BTI-PAC %s
+// CHECK-AARCH64-BTI-PAC: "-msign-return-address=non-leaf" "-msign-return-address-key=a_key" "-mbranch-target-enforce"
|
2c3d81a to
c4c2716
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/15350 Here is the relevant piece of the build log for the reference |
No description provided.