[llvm] [aarch64] XOR the frame pointer with the stack cookie when protecting the stack (PR #161114)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 18 11:05:47 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);
----------------
efriedma-quic wrote:
Please don't use the result of getRegister as an operand to a target-independent ISD::ADD. Register operands aren't values; they are intended only for use with specific operations which are expecting them.
It might appear to work here, sort-of, but other parts of the DAG aren't expecting it, and it will lead to weird results in general. And I'm not sure it actually is working correctly here... what's the actual encoding you're getting?
https://github.com/llvm/llvm-project/pull/161114
More information about the llvm-commits
mailing list