Skip to content

Commit f9bb727

Browse files
brad0github-actions[bot]
authored andcommitted
Automerge: [PAC][Driver] Enable BTI and PAC by default on OpenBSD/aarch64 (#125392)
2 parents 0a74d04 + 6567122 commit f9bb727

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -1560,15 +1560,21 @@ static void handlePAuthABI(const ArgList &DriverArgs, ArgStringList &CC1Args) {
15601560

15611561
static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
15621562
ArgStringList &CmdArgs, bool isAArch64) {
1563+
const llvm::Triple &Triple = TC.getEffectiveTriple();
15631564
const Arg *A = isAArch64
15641565
? Args.getLastArg(options::OPT_msign_return_address_EQ,
15651566
options::OPT_mbranch_protection_EQ)
15661567
: Args.getLastArg(options::OPT_mbranch_protection_EQ);
1567-
if (!A)
1568+
if (!A) {
1569+
if (Triple.isOSOpenBSD() && isAArch64) {
1570+
CmdArgs.push_back("-msign-return-address=non-leaf");
1571+
CmdArgs.push_back("-msign-return-address-key=a_key");
1572+
CmdArgs.push_back("-mbranch-target-enforce");
1573+
}
15681574
return;
1575+
}
15691576

15701577
const Driver &D = TC.getDriver();
1571-
const llvm::Triple &Triple = TC.getEffectiveTriple();
15721578
if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass())))
15731579
D.Diag(diag::warn_incompatible_branch_protection_option)
15741580
<< Triple.getArchName();
@@ -1582,7 +1588,7 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
15821588
D.Diag(diag::err_drv_unsupported_option_argument)
15831589
<< A->getSpelling() << Scope;
15841590
Key = "a_key";
1585-
IndirectBranches = false;
1591+
IndirectBranches = Triple.isOSOpenBSD() && isAArch64;
15861592
BranchProtectionPAuthLR = false;
15871593
GuardedControlStack = false;
15881594
} else {

clang/test/Driver/openbsd.c

+5
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@
136136
// RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \
137137
// RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
138138
// CHECK-LTO-FLAGS: "-plugin-opt=mcpu=x86-64"
139+
140+
// Check 64-bit ARM for BTI and PAC flags
141+
// RUN: %clang --target=aarch64-unknown-openbsd -### -c %s 2>&1 \
142+
// RUN: | FileCheck -check-prefix=CHECK-AARCH64-BTI-PAC %s
143+
// CHECK-AARCH64-BTI-PAC: "-msign-return-address=non-leaf" "-msign-return-address-key=a_key" "-mbranch-target-enforce"

0 commit comments

Comments
 (0)