Skip to content

Commit 0cefd5c

Browse files
authored
CodeGen: Fix hardcoded libcall names in insertSSPDeclarations (NFC) (#163710)
1 parent a358043 commit 0cefd5c

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21287,21 +21287,28 @@ bool ARMTargetLowering::useLoadStackGuardNode(const Module &M) const {
2128721287
}
2128821288

2128921289
void 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

2130721314
Function *ARMTargetLowering::getSSPStackGuardCheck(const Module &M) const {

llvm/lib/Target/X86/X86ISelLoweringCall.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,16 +606,24 @@ Value *X86TargetLowering::getIRStackGuard(IRBuilderBase &IRB) const {
606606

607607
void X86TargetLowering::insertSSPDeclarations(Module &M) const {
608608
// MSVC CRT provides functionalities for stack protection.
609-
if (Subtarget.getTargetTriple().isWindowsMSVCEnvironment() ||
610-
Subtarget.getTargetTriple().isWindowsItaniumEnvironment()) {
609+
RTLIB::LibcallImpl SecurityCheckCookieLibcall =
610+
getLibcallImpl(RTLIB::SECURITY_CHECK_COOKIE);
611+
612+
RTLIB::LibcallImpl SecurityCookieVar =
613+
getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
614+
if (SecurityCheckCookieLibcall != RTLIB::Unsupported &&
615+
SecurityCookieVar != RTLIB::Unsupported) {
616+
// MSVC CRT provides functionalities for stack protection.
611617
// MSVC CRT has a global variable holding security cookie.
612-
M.getOrInsertGlobal("__security_cookie",
618+
M.getOrInsertGlobal(getLibcallImplName(SecurityCookieVar),
613619
PointerType::getUnqual(M.getContext()));
614620

615621
// MSVC CRT has a function to validate security cookie.
616-
FunctionCallee SecurityCheckCookie = M.getOrInsertFunction(
617-
"__security_check_cookie", Type::getVoidTy(M.getContext()),
618-
PointerType::getUnqual(M.getContext()));
622+
FunctionCallee SecurityCheckCookie =
623+
M.getOrInsertFunction(getLibcallImplName(SecurityCheckCookieLibcall),
624+
Type::getVoidTy(M.getContext()),
625+
PointerType::getUnqual(M.getContext()));
626+
619627
if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) {
620628
F->setCallingConv(CallingConv::X86_FastCall);
621629
F->addParamAttr(0, Attribute::AttrKind::InReg);

0 commit comments

Comments
 (0)