[llvm] [CodeGen] Inline stack guard check on Windows (PR #136290)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 16:54:19 PDT 2025
================
@@ -3126,14 +3099,66 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
/// For a high level explanation of how this fits into the stack protector
/// generation see the comment on the declaration of class
/// StackProtectorDescriptor.
-void
-SelectionDAGBuilder::visitSPDescriptorFailure(StackProtectorDescriptor &SPD) {
+void SelectionDAGBuilder::visitSPDescriptorFailure(
+ StackProtectorDescriptor &SPD) {
+
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- TargetLowering::MakeLibCallOptions CallOptions;
- CallOptions.setDiscardResult(true);
- SDValue Chain = TLI.makeLibCall(DAG, RTLIB::STACKPROTECTOR_CHECK_FAIL,
- MVT::isVoid, {}, CallOptions, getCurSDLoc())
- .second;
+ MachineBasicBlock *ParentBB = SPD.getParentMBB();
+ const Module &M = *ParentBB->getParent()->getFunction().getParent();
+ SDValue Chain;
+
+ // Retrieve guard check function, nullptr if instrumentation is inlined.
+ if (const Function *GuardCheckFn = TLI.getSSPStackGuardCheck(M)) {
+
+ // First create the loads to the guard/stack slot for the comparison.
+ EVT PtrTy = TLI.getPointerTy(DAG.getDataLayout());
----------------
efriedma-quic wrote:
The stack protector is an invented value which doesn't have any inherent width from the IR or datalayout. The width is part of the ABI. In practice, on CPU targets it's "pointer width".
We could add a method to TargetLowering, I guess. Something like `virtual MVT getStackProtectorTy(const DataLayout &DL) { return getPointerTy(DL, 0); }`.
https://github.com/llvm/llvm-project/pull/136290
More information about the llvm-commits
mailing list