From 5e530090040731790f0243f616309bad88c4aef5 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 12 Nov 2023 16:33:23 +0000 Subject: [PATCH] Fix parsing of branch target protection options on arm64 to enable BTI and PAC again by default on OpenBSD. ok robert@ --- gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp b/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp index 1300c5667bc..28feeed46eb 100644 --- a/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp +++ b/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp @@ -1566,15 +1566,21 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) { 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()) { + 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(); @@ -1613,13 +1619,6 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, Args.MakeArgString(Twine("-msign-return-address-key=") + Key)); if (IndirectBranches) CmdArgs.push_back("-mbranch-target-enforce"); - else { - if (Triple.isOSOpenBSD()) { - CmdArgs.push_back("-msign-return-address=non-leaf"); - CmdArgs.push_back("-msign-return-address-key=a_key"); - CmdArgs.push_back("-mbranch-target-enforce"); - } - } } void Clang::AddARMTargetArgs(const llvm::Triple &Triple, const ArgList &Args, -- 2.20.1