[llvm] [AArch64][BTI] Add BTI at EH entries. (PR #155308)

Shashi Shankar via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 28 05:21:11 PDT 2025


================
@@ -143,11 +161,33 @@ void AArch64BranchTargets::addBTI(MachineBasicBlock &MBB, bool CouldCall,
        MBBI->getOpcode() == AArch64::PACIBSP))
     return;
 
-  if (HasWinCFI && MBBI->getFlag(MachineInstr::FrameSetup)) {
+  // If there's already a HINT at the insertion point, handle BTI safely.
+  if (MBBI != MBB.end() && MBBI->getOpcode() == AArch64::HINT) {
+    // Only "upgrade" if it is actually a BTI HINT (base 32). Otherwise,
+    // fall through and insert a BTI before this non-BTI hint, so the
+    // first executed instruction is BTI/PAC as required by enforcement.
+    if (MBBI->getOperand(0).isImm()) {
+      int64_t Imm = MBBI->getOperand(0).getImm();
+      if ((Imm & ~int64_t(BTIMask)) == BTIBase) {
+        unsigned Have = unsigned(Imm) & BTIMask;
----------------
shashforge wrote:

Done. I removed the in‑place “BTI HINT upgrade” block 

The insertion rule is now simple and correct: skip EH_LABEL + meta/CFI/EMITBKEY → insert BTI at the first executable instruction. If there were ever a non‑BTI HINT at entry in the future, we would still be correct because we insert the BTI before it (we build at MBBI).

I also replaced the remaining numeric immediate with small named constants (BTIBase/BTIC/BTIJ/BTIMask) so the intent is self‑documenting.

https://github.com/llvm/llvm-project/pull/155308


More information about the llvm-commits mailing list