@@ -21287,21 +21287,28 @@ bool ARMTargetLowering::useLoadStackGuardNode(const Module &M) const {
2128721287}
2128821288
2128921289void ARMTargetLowering::insertSSPDeclarations(Module &M) const {
21290+ // MSVC CRT provides functionalities for stack protection.
2129021291 RTLIB::LibcallImpl SecurityCheckCookieLibcall =
2129121292 getLibcallImpl(RTLIB::SECURITY_CHECK_COOKIE);
21292- if (SecurityCheckCookieLibcall == RTLIB::Unsupported)
21293- return TargetLowering::insertSSPDeclarations(M);
2129421293
21295- // MSVC CRT has a global variable holding security cookie.
21296- M.getOrInsertGlobal("__security_cookie",
21297- PointerType::getUnqual(M.getContext()));
21294+ RTLIB::LibcallImpl SecurityCookieVar =
21295+ getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
21296+ if (SecurityCheckCookieLibcall != RTLIB::Unsupported &&
21297+ SecurityCookieVar != RTLIB::Unsupported) {
21298+ // MSVC CRT has a global variable holding security cookie.
21299+ M.getOrInsertGlobal(getLibcallImplName(SecurityCookieVar),
21300+ PointerType::getUnqual(M.getContext()));
2129821301
21299- // MSVC CRT has a function to validate security cookie.
21300- FunctionCallee SecurityCheckCookie = M.getOrInsertFunction(
21301- getLibcallImplName(SecurityCheckCookieLibcall),
21302- Type::getVoidTy(M.getContext()), PointerType::getUnqual(M.getContext()));
21303- if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee()))
21304- F->addParamAttr(0, Attribute::AttrKind::InReg);
21302+ // MSVC CRT has a function to validate security cookie.
21303+ FunctionCallee SecurityCheckCookie =
21304+ M.getOrInsertFunction(getLibcallImplName(SecurityCheckCookieLibcall),
21305+ Type::getVoidTy(M.getContext()),
21306+ PointerType::getUnqual(M.getContext()));
21307+ if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee()))
21308+ F->addParamAttr(0, Attribute::AttrKind::InReg);
21309+ }
21310+
21311+ TargetLowering::insertSSPDeclarations(M);
2130521312}
2130621313
2130721314Function *ARMTargetLowering::getSSPStackGuardCheck(const Module &M) const {
0 commit comments