Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Target/AArch64/AArch64BranchTargets.cpp
Show All 10 Lines | |||||
// trap when an indirect branch or call instruction targets an instruction | // trap when an indirect branch or call instruction targets an instruction | ||||
// which is not a valid BTI instruction. This is intended to guard against | // which is not a valid BTI instruction. This is intended to guard against | ||||
// control-flow hijacking attacks. Note that this does not do anything for RET | // control-flow hijacking attacks. Note that this does not do anything for RET | ||||
// instructions, as they can be more precisely protected by return address | // instructions, as they can be more precisely protected by return address | ||||
// signing. | // signing. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "AArch64MachineFunctionInfo.h" | |||||
#include "AArch64Subtarget.h" | #include "AArch64Subtarget.h" | ||||
#include "llvm/CodeGen/MachineFunctionPass.h" | #include "llvm/CodeGen/MachineFunctionPass.h" | ||||
#include "llvm/CodeGen/MachineInstrBuilder.h" | #include "llvm/CodeGen/MachineInstrBuilder.h" | ||||
#include "llvm/CodeGen/MachineJumpTableInfo.h" | #include "llvm/CodeGen/MachineJumpTableInfo.h" | ||||
#include "llvm/CodeGen/MachineModuleInfo.h" | #include "llvm/CodeGen/MachineModuleInfo.h" | ||||
#include "llvm/Support/Debug.h" | #include "llvm/Support/Debug.h" | ||||
using namespace llvm; | using namespace llvm; | ||||
Show All 25 Lines | void AArch64BranchTargets::getAnalysisUsage(AnalysisUsage &AU) const { | ||||
MachineFunctionPass::getAnalysisUsage(AU); | MachineFunctionPass::getAnalysisUsage(AU); | ||||
} | } | ||||
FunctionPass *llvm::createAArch64BranchTargetsPass() { | FunctionPass *llvm::createAArch64BranchTargetsPass() { | ||||
return new AArch64BranchTargets(); | return new AArch64BranchTargets(); | ||||
} | } | ||||
bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) { | bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) { | ||||
const Function &F = MF.getFunction(); | if (!MF.getInfo<AArch64FunctionInfo>()->branchTargetEnforcement()) | ||||
if (!F.hasFnAttribute("branch-target-enforcement")) | |||||
return false; | return false; | ||||
LLVM_DEBUG( | LLVM_DEBUG( | ||||
dbgs() << "********** AArch64 Branch Targets **********\n" | dbgs() << "********** AArch64 Branch Targets **********\n" | ||||
<< "********** Function: " << MF.getName() << '\n'); | << "********** Function: " << MF.getName() << '\n'); | ||||
const Function &F = MF.getFunction(); | |||||
// LLVM does not consider basic blocks which are the targets of jump tables | // LLVM does not consider basic blocks which are the targets of jump tables | ||||
// to be address-taken (the address can't escape anywhere else), but they are | // to be address-taken (the address can't escape anywhere else), but they are | ||||
// used for indirect branches, so need BTI instructions. | // used for indirect branches, so need BTI instructions. | ||||
SmallPtrSet<MachineBasicBlock *, 8> JumpTableTargets; | SmallPtrSet<MachineBasicBlock *, 8> JumpTableTargets; | ||||
if (auto *JTI = MF.getJumpTableInfo()) | if (auto *JTI = MF.getJumpTableInfo()) | ||||
for (auto &JTE : JTI->getJumpTables()) | for (auto &JTE : JTI->getJumpTables()) | ||||
for (auto *MBB : JTE.MBBs) | for (auto *MBB : JTE.MBBs) | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |