[clang] [PAC][Driver] Enable BTI and PAC by default on OpenBSD/aarch64 (PR #125392)
Brad Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 5 23:07:49 PST 2025
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/125392
>From c4c2716546cb4203468c81947adbd7c953a052fe Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Sun, 2 Feb 2025 05:09:59 -0500
Subject: [PATCH] [PAC][Driver] Enable BTI and PAC by default on
OpenBSD/aarch64
---
clang/lib/Driver/ToolChains/Clang.cpp | 12 +++++++++---
clang/test/Driver/openbsd.c | 5 +++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 9b5132c5625faa0..fce3f5e3c8c528c 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,7 @@ 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;
+ IndirectBranches = Triple.isOSOpenBSD() && isAArch64;
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"
More information about the cfe-commits
mailing list