Skip to content

Commit

Permalink
Revert "[llvm][AArch64] Insert "bti j" after call to setjmp"
Browse files Browse the repository at this point in the history
This reverts commit eb5ecbb
due to failures on buildbots with expensive checks enabled.
  • Loading branch information
DavidSpickett committed Mar 23, 2022
1 parent ba2be80 commit edb7ba7
Show file tree
Hide file tree
Showing 14 changed files with 5 additions and 276 deletions.
2 changes: 1 addition & 1 deletion clang/docs/ClangCommandLineReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3329,7 +3329,7 @@ Work around VLLDM erratum CVE-2021-35465 (ARM only)

.. option:: -mno-bti-at-return-twice

Do not add a BTI instruction after a setjmp or other return-twice construct (AArch32/AArch64 only)
Do not add a BTI instruction after a setjmp or other return-twice construct (Arm only)

.. option:: -mno-movt

Expand Down
5 changes: 0 additions & 5 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ DWARF Support in Clang
Arm and AArch64 Support in Clang
--------------------------------

- When using ``-mbranch-protection=bti`` with AArch64, calls to setjmp will
now be followed by a BTI instruction. This is done to be compatible with
setjmp implementations that return with a br instead of a ret. You can
disable this behaviour using the ``-mno-bti-at-return-twice`` option.

Floating Point Support in Clang
-------------------------------

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,7 @@ def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
def mno_bti_at_return_twice : Flag<["-"], "mno-bti-at-return-twice">,
Group<m_arm_Features_Group>,
HelpText<"Do not add a BTI instruction after a setjmp or other"
" return-twice construct (Arm/AArch64 only)">;
" return-twice construct (Arm only)">;

foreach i = {1-31} in
def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group<m_Group>,
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Driver/ToolChains/Arch/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,4 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
// Enabled A53 errata (835769) workaround by default on android
Features.push_back("+fix-cortex-a53-835769");
}

if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
Features.push_back("+no-bti-at-return-twice");
}
5 changes: 0 additions & 5 deletions llvm/lib/Target/AArch64/AArch64.td
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,6 @@ def FeatureEL3 : SubtargetFeature<"el3", "HasEL3", "true",
def FeatureFixCortexA53_835769 : SubtargetFeature<"fix-cortex-a53-835769",
"FixCortexA53_835769", "true", "Mitigate Cortex-A53 Erratum 835769">;

def FeatureNoBTIAtReturnTwice : SubtargetFeature<"no-bti-at-return-twice",
"NoBTIAtReturnTwice", "true",
"Don't place a BTI instruction "
"after a return-twice">;

//===----------------------------------------------------------------------===//
// Architectures.
//
Expand Down
34 changes: 0 additions & 34 deletions llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class AArch64ExpandPseudo : public MachineFunctionPass {
unsigned N);
bool expandCALL_RVMARKER(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI);
bool expandCALL_BTI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI);
bool expandStoreSwiftAsyncContext(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI);
};
Expand Down Expand Up @@ -760,37 +759,6 @@ bool AArch64ExpandPseudo::expandCALL_RVMARKER(
return true;
}

bool AArch64ExpandPseudo::expandCALL_BTI(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI) {
// Expand CALL_BTI pseudo to:
// - a branch to the call target
// - a BTI instruction
// Mark the sequence as a bundle, to avoid passes moving other code in
// between.

MachineInstr &MI = *MBBI;
MachineOperand &CallTarget = MI.getOperand(0);
assert((CallTarget.isGlobal() || CallTarget.isReg()) &&
"invalid operand for regular call");
unsigned Opc = CallTarget.isGlobal() ? AArch64::BL : AArch64::BLR;
MachineInstr *Call =
BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc)).getInstr();
Call->addOperand(CallTarget);

MachineInstr *BTI =
BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::HINT))
// BTI J so that setjmp can to BR to this.
.addImm(36)
.getInstr();

if (MI.shouldUpdateCallSiteInfo())
MBB.getParent()->moveCallSiteInfo(&MI, Call);

MI.eraseFromParent();
finalizeBundle(MBB, Call->getIterator(), std::next(BTI->getIterator()));
return true;
}

bool AArch64ExpandPseudo::expandStoreSwiftAsyncContext(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
Register CtxReg = MBBI->getOperand(0).getReg();
Expand Down Expand Up @@ -1270,8 +1238,6 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
return expandSVESpillFill(MBB, MBBI, AArch64::LDR_ZXI, 2);
case AArch64::BLR_RVMARKER:
return expandCALL_RVMARKER(MBB, MBBI);
case AArch64::BLR_BTI:
return expandCALL_BTI(MBB, MBBI);
case AArch64::StoreSwiftAsyncContext:
return expandStoreSwiftAsyncContext(MBB, MBBI);
}
Expand Down
8 changes: 0 additions & 8 deletions llvm/lib/Target/AArch64/AArch64FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "AArch64.h"
#include "AArch64CallingConvention.h"
#include "AArch64MachineFunctionInfo.h"
#include "AArch64RegisterInfo.h"
#include "AArch64Subtarget.h"
#include "MCTargetDesc/AArch64AddressingModes.h"
Expand Down Expand Up @@ -3128,13 +3127,6 @@ bool AArch64FastISel::fastLowerCall(CallLoweringInfo &CLI) {
if (!Callee && !Symbol)
return false;

// Allow SelectionDAG isel to handle calls to functions like setjmp that need
// a bti instruction following the call.
if (CLI.CB && CLI.CB->hasFnAttr(Attribute::ReturnsTwice) &&
!Subtarget->noBTIAtReturnTwice() &&
MF->getInfo<AArch64FunctionInfo>()->branchTargetEnforcement())
return false;

// Allow SelectionDAG isel to handle tail calls.
if (IsTailCall)
return false;
Expand Down
10 changes: 1 addition & 9 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,6 @@ const char *AArch64TargetLowering::getTargetNodeName(unsigned Opcode) const {
MAKE_CASE(AArch64ISD::MOPS_MEMSET_TAGGING)
MAKE_CASE(AArch64ISD::MOPS_MEMCOPY)
MAKE_CASE(AArch64ISD::MOPS_MEMMOVE)
MAKE_CASE(AArch64ISD::CALL_BTI)
}
#undef MAKE_CASE
return nullptr;
Expand Down Expand Up @@ -6179,12 +6178,6 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
bool TailCallOpt = MF.getTarget().Options.GuaranteedTailCallOpt;
bool IsSibCall = false;
bool GuardWithBTI = false;

if (CLI.CB && CLI.CB->getAttributes().hasFnAttr(Attribute::ReturnsTwice) &&
!Subtarget->noBTIAtReturnTwice()) {
GuardWithBTI = FuncInfo->branchTargetEnforcement();
}

// Check callee args/returns for SVE registers and set calling convention
// accordingly.
Expand Down Expand Up @@ -6619,8 +6612,7 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
Function *ARCFn = *objcarc::getAttachedARCFunction(CLI.CB);
auto GA = DAG.getTargetGlobalAddress(ARCFn, DL, PtrVT);
Ops.insert(Ops.begin() + 1, GA);
} else if (GuardWithBTI)
CallOpc = AArch64ISD::CALL_BTI;
}

// Returns a chain and a flag for retval copy to use.
Chain = DAG.getNode(CallOpc, DL, NodeTys, Ops);
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ enum NodeType : unsigned {
// x29, x29` marker instruction.
CALL_RVMARKER,

CALL_BTI, // Function call followed by a BTI instruction.

// Produces the full sequence of instructions for getting the thread pointer
// offset of a variable into X0, using the TLSDesc model.
TLSDESC_CALLSEQ,
Expand Down
10 changes: 0 additions & 10 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,6 @@ def AArch64call : SDNode<"AArch64ISD::CALL",
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
SDNPVariadic]>;

def AArch64call_bti : SDNode<"AArch64ISD::CALL_BTI",
SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
SDNPVariadic]>;

def AArch64call_rvmarker: SDNode<"AArch64ISD::CALL_RVMARKER",
SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Expand Down Expand Up @@ -2333,8 +2328,6 @@ let isCall = 1, Defs = [LR], Uses = [SP] in {
PseudoInstExpansion<(BLR GPR64:$Rn)>;
def BLR_RVMARKER : Pseudo<(outs), (ins variable_ops), []>,
Sched<[WriteBrReg]>;
def BLR_BTI : Pseudo<(outs), (ins GPR64:$Rn), []>,
Sched<[WriteBrReg]>;
} // isCall

def : Pat<(AArch64call GPR64:$Rn),
Expand All @@ -2348,9 +2341,6 @@ def : Pat<(AArch64call_rvmarker (i64 tglobaladdr:$rvfunc), GPR64:$Rn),
(BLR_RVMARKER tglobaladdr:$rvfunc, GPR64:$Rn)>,
Requires<[NoSLSBLRMitigation]>;

def : Pat<(AArch64call_bti GPR64:$Rn),
(BLR_BTI GPR64:$Rn)>;

let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
def BR : BranchReg<0b0000, "br", [(brind GPR64:$Rn)]>;
} // isBranch, isTerminator, isBarrier, isIndirectBranch
Expand Down
11 changes: 2 additions & 9 deletions llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,20 +1129,12 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
// Create a temporarily-floating call instruction so we can add the implicit
// uses of arg registers.

const AArch64Subtarget &Subtarget = MF.getSubtarget<AArch64Subtarget>();
unsigned Opc = 0;
// Calls with operand bundle "clang.arc.attachedcall" are special. They should
// be expanded to the call, directly followed by a special marker sequence and
// a call to an ObjC library function.
unsigned Opc = 0;
if (Info.CB && objcarc::hasAttachedCallOpBundle(Info.CB))
Opc = AArch64::BLR_RVMARKER;
// A call to a returns twice function like setjmp must be followed by a bti
// instruction.
else if (Info.CB &&
Info.CB->getAttributes().hasFnAttr(Attribute::ReturnsTwice) &&
!Subtarget.noBTIAtReturnTwice() &&
MF.getInfo<AArch64FunctionInfo>()->branchTargetEnforcement())
Opc = AArch64::BLR_BTI;
else
Opc = getCallOpcode(MF, Info.Callee.isReg(), false);

Expand All @@ -1161,6 +1153,7 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder,

// Tell the call which registers are clobbered.
const uint32_t *Mask;
const AArch64Subtarget &Subtarget = MF.getSubtarget<AArch64Subtarget>();
const auto *TRI = Subtarget.getRegisterInfo();

AArch64OutgoingValueAssigner Assigner(AssignFnFixed, AssignFnVarArg,
Expand Down
51 changes: 0 additions & 51 deletions llvm/test/CodeGen/AArch64/setjmp-bti-no-enforcement.ll

This file was deleted.

83 changes: 0 additions & 83 deletions llvm/test/CodeGen/AArch64/setjmp-bti-outliner.ll

This file was deleted.

Loading

0 comments on commit edb7ba7

Please sign in to comment.