[llvm] [aarch64] XOR the frame pointer with the stack cookie when protecting the stack (PR #161114)
Pan Tao via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 26 19:19:54 PST 2025
================
@@ -29242,6 +29242,24 @@ bool AArch64TargetLowering::useLoadStackGuardNode(const Module &M) const {
return true;
}
+bool AArch64TargetLowering::useStackGuardMixCookie() const {
+ // Currently only MSVC CRTs XOR the frame pointer into the stack guard value.
+ return Subtarget->getTargetTriple().isOSMSVCRT() &&
+ !getTargetMachine().Options.EnableGlobalISel;
+}
+
+SDValue AArch64TargetLowering::emitStackGuardMixCookie(SelectionDAG &DAG,
+ SDValue Val,
+ const SDLoc &DL,
+ bool FailureBB) const {
+ if (FailureBB) {
+ return DAG.getNode(
+ ISD::ADD, DL, Val.getValueType(),
+ DAG.getRegister(getStackPointerRegisterToSaveRestore(), MVT::i64), Val);
----------------
PanTao2 wrote:
When running llvm/test/CodeGen/AArch64/stack-protector-target.ll, the SDValue returned by DAG.getRegister (getRegister(getStackPointerRegisterToSaveRestore(), MVT:: i64) is "t4: i64 = Register $physreg8".
DAG.getRegister wraps Register as SDValue, while DAG.getCopyFromReg (used in previous version) uses DAG.getRegister and adds a move (copy) instruction.
https://github.com/llvm/llvm-project/pull/161114
More information about the llvm-commits
mailing list