@@ -3059,33 +3059,6 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
3059
3059
if (TLI.useStackGuardXorFP ())
3060
3060
GuardVal = TLI.emitStackGuardXorFP (DAG, GuardVal, dl);
3061
3061
3062
- // Retrieve guard check function, nullptr if instrumentation is inlined.
3063
- if (const Function *GuardCheckFn = TLI.getSSPStackGuardCheck (M)) {
3064
- // The target provides a guard check function to validate the guard value.
3065
- // Generate a call to that function with the content of the guard slot as
3066
- // argument.
3067
- FunctionType *FnTy = GuardCheckFn->getFunctionType ();
3068
- assert (FnTy->getNumParams () == 1 && " Invalid function signature" );
3069
-
3070
- TargetLowering::ArgListTy Args;
3071
- TargetLowering::ArgListEntry Entry;
3072
- Entry.Node = GuardVal;
3073
- Entry.Ty = FnTy->getParamType (0 );
3074
- if (GuardCheckFn->hasParamAttribute (0 , Attribute::AttrKind::InReg))
3075
- Entry.IsInReg = true ;
3076
- Args.push_back (Entry);
3077
-
3078
- TargetLowering::CallLoweringInfo CLI (DAG);
3079
- CLI.setDebugLoc (getCurSDLoc ())
3080
- .setChain (DAG.getEntryNode ())
3081
- .setCallee (GuardCheckFn->getCallingConv (), FnTy->getReturnType (),
3082
- getValue (GuardCheckFn), std::move (Args));
3083
-
3084
- std::pair<SDValue, SDValue> Result = TLI.LowerCallTo (CLI);
3085
- DAG.setRoot (Result.second );
3086
- return ;
3087
- }
3088
-
3089
3062
// If useLoadStackGuardNode returns true, generate LOAD_STACK_GUARD.
3090
3063
// Otherwise, emit a volatile load to retrieve the stack guard value.
3091
3064
SDValue Chain = DAG.getEntryNode ();
@@ -3126,14 +3099,66 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
3126
3099
// / For a high level explanation of how this fits into the stack protector
3127
3100
// / generation see the comment on the declaration of class
3128
3101
// / StackProtectorDescriptor.
3129
- void
3130
- SelectionDAGBuilder::visitSPDescriptorFailure (StackProtectorDescriptor &SPD) {
3102
+ void SelectionDAGBuilder::visitSPDescriptorFailure (
3103
+ StackProtectorDescriptor &SPD) {
3104
+
3131
3105
const TargetLowering &TLI = DAG.getTargetLoweringInfo ();
3132
- TargetLowering::MakeLibCallOptions CallOptions;
3133
- CallOptions.setDiscardResult (true );
3134
- SDValue Chain = TLI.makeLibCall (DAG, RTLIB::STACKPROTECTOR_CHECK_FAIL,
3135
- MVT::isVoid, {}, CallOptions, getCurSDLoc ())
3136
- .second ;
3106
+ MachineBasicBlock *ParentBB = SPD.getParentMBB ();
3107
+ const Module &M = *ParentBB->getParent ()->getFunction ().getParent ();
3108
+ SDValue Chain;
3109
+
3110
+ // Retrieve guard check function, nullptr if instrumentation is inlined.
3111
+ if (const Function *GuardCheckFn = TLI.getSSPStackGuardCheck (M)) {
3112
+
3113
+ // First create the loads to the guard/stack slot for the comparison.
3114
+ EVT PtrTy = TLI.getPointerTy (DAG.getDataLayout ());
3115
+ EVT PtrMemTy = TLI.getPointerMemTy (DAG.getDataLayout ());
3116
+
3117
+ MachineFrameInfo &MFI = ParentBB->getParent ()->getFrameInfo ();
3118
+ int FI = MFI.getStackProtectorIndex ();
3119
+
3120
+ SDLoc dl = getCurSDLoc ();
3121
+ SDValue StackSlotPtr = DAG.getFrameIndex (FI, PtrTy);
3122
+ Align Align = DAG.getDataLayout ().getPrefTypeAlign (
3123
+ PointerType::get (M.getContext (), 0 ));
3124
+
3125
+ // Generate code to load the content of the guard slot.
3126
+ SDValue GuardVal = DAG.getLoad (
3127
+ PtrMemTy, dl, DAG.getEntryNode (), StackSlotPtr,
3128
+ MachinePointerInfo::getFixedStack (DAG.getMachineFunction (), FI), Align,
3129
+ MachineMemOperand::MOVolatile);
3130
+
3131
+ if (TLI.useStackGuardXorFP ())
3132
+ GuardVal = TLI.emitStackGuardXorFP (DAG, GuardVal, dl);
3133
+
3134
+ // The target provides a guard check function to validate the guard value.
3135
+ // Generate a call to that function with the content of the guard slot as
3136
+ // argument.
3137
+ FunctionType *FnTy = GuardCheckFn->getFunctionType ();
3138
+ assert (FnTy->getNumParams () == 1 && " Invalid function signature" );
3139
+
3140
+ TargetLowering::ArgListTy Args;
3141
+ TargetLowering::ArgListEntry Entry;
3142
+ Entry.Node = GuardVal;
3143
+ Entry.Ty = FnTy->getParamType (0 );
3144
+ if (GuardCheckFn->hasParamAttribute (0 , Attribute::AttrKind::InReg))
3145
+ Entry.IsInReg = true ;
3146
+ Args.push_back (Entry);
3147
+
3148
+ TargetLowering::CallLoweringInfo CLI (DAG);
3149
+ CLI.setDebugLoc (getCurSDLoc ())
3150
+ .setChain (DAG.getEntryNode ())
3151
+ .setCallee (GuardCheckFn->getCallingConv (), FnTy->getReturnType (),
3152
+ getValue (GuardCheckFn), std::move (Args));
3153
+
3154
+ Chain = TLI.LowerCallTo (CLI).second ;
3155
+ } else {
3156
+ TargetLowering::MakeLibCallOptions CallOptions;
3157
+ CallOptions.setDiscardResult (true );
3158
+ Chain = TLI.makeLibCall (DAG, RTLIB::STACKPROTECTOR_CHECK_FAIL, MVT::isVoid,
3159
+ {}, CallOptions, getCurSDLoc ())
3160
+ .second ;
3161
+ }
3137
3162
3138
3163
// Emit a trap instruction if we are required to do so.
3139
3164
const TargetOptions &TargetOpts = DAG.getTarget ().Options ;
0 commit comments