diff options
Diffstat (limited to 'llvm/lib/Target/AArch64/AArch64BranchTargets.cpp')
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64BranchTargets.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp b/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp index d3b5166585c3..d2acd1de74c8 100644 --- a/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp +++ b/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp @@ -64,7 +64,6 @@ bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) { LLVM_DEBUG( dbgs() << "********** AArch64 Branch Targets **********\n" << "********** Function: " << MF.getName() << '\n'); - const Function &F = MF.getFunction(); // 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 @@ -78,13 +77,16 @@ bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) { bool MadeChange = false; for (MachineBasicBlock &MBB : MF) { bool CouldCall = false, CouldJump = false; - // If the function is address-taken or externally-visible, it could be - // indirectly called. PLT entries and tail-calls use BR, but when they are + // Even in cases where a function has internal linkage and is only called + // directly in its translation unit, it can still be called indirectly if + // the linker decides to add a thunk to it for whatever reason (say, for + // example, if it is finally placed far from its call site and a BL is not + // long-range enough). PLT entries and tail-calls use BR, but when they are // are in guarded pages should all use x16 or x17 to hold the called // address, so we don't need to set CouldJump here. BR instructions in // non-guarded pages (which might be non-BTI-aware code) are allowed to // branch to a "BTI c" using any register. - if (&MBB == &*MF.begin() && (F.hasAddressTaken() || !F.hasLocalLinkage())) + if (&MBB == &*MF.begin()) CouldCall = true; // If the block itself is address-taken, it could be indirectly branched @@ -119,8 +121,10 @@ void AArch64BranchTargets::addBTI(MachineBasicBlock &MBB, bool CouldCall, auto MBBI = MBB.begin(); - // Skip the meta instuctions, those will be removed anyway. - for (; MBBI != MBB.end() && MBBI->isMetaInstruction(); ++MBBI) + // Skip the meta instructions, those will be removed anyway. + for (; MBBI != MBB.end() && + (MBBI->isMetaInstruction() || MBBI->getOpcode() == AArch64::EMITBKEY); + ++MBBI) ; // SCTLR_EL1.BT[01] is set to 0 by default which means |