aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringBase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringBase.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringBase.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 350948a..9ffced8 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -2059,29 +2059,37 @@ Value *TargetLoweringBase::getIRStackGuard(IRBuilderBase &IRB) const {
// Currently only support "standard" __stack_chk_guard.
// TODO: add LOAD_STACK_GUARD support.
void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
- if (!M.getNamedValue("__stack_chk_guard")) {
- auto *GV = new GlobalVariable(M, PointerType::getUnqual(M.getContext()),
- false, GlobalVariable::ExternalLinkage,
- nullptr, "__stack_chk_guard");
-
- // FreeBSD has "__stack_chk_guard" defined externally on libc.so
- if (M.getDirectAccessExternalData() &&
- !TM.getTargetTriple().isOSCygMing() &&
- !(TM.getTargetTriple().isPPC64() &&
- TM.getTargetTriple().isOSFreeBSD()) &&
- (!TM.getTargetTriple().isOSDarwin() ||
- TM.getRelocationModel() == Reloc::Static))
- GV->setDSOLocal(true);
- }
+ RTLIB::LibcallImpl StackGuardImpl = getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
+ if (StackGuardImpl == RTLIB::Unsupported)
+ return;
+
+ StringRef StackGuardVarName = getLibcallImplName(StackGuardImpl);
+ M.getOrInsertGlobal(
+ StackGuardVarName, PointerType::getUnqual(M.getContext()), [=, &M]() {
+ auto *GV = new GlobalVariable(M, PointerType::getUnqual(M.getContext()),
+ false, GlobalVariable::ExternalLinkage,
+ nullptr, StackGuardVarName);
+
+ // FreeBSD has "__stack_chk_guard" defined externally on libc.so
+ if (M.getDirectAccessExternalData() &&
+ !TM.getTargetTriple().isOSCygMing() &&
+ !(TM.getTargetTriple().isPPC64() &&
+ TM.getTargetTriple().isOSFreeBSD()) &&
+ (!TM.getTargetTriple().isOSDarwin() ||
+ TM.getRelocationModel() == Reloc::Static))
+ GV->setDSOLocal(true);
+
+ return GV;
+ });
}
// Currently only support "standard" __stack_chk_guard.
// TODO: add LOAD_STACK_GUARD support.
Value *TargetLoweringBase::getSDagStackGuard(const Module &M) const {
- if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
- return M.getNamedValue("__guard_local");
- }
- return M.getNamedValue("__stack_chk_guard");
+ RTLIB::LibcallImpl GuardVarImpl = getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
+ if (GuardVarImpl == RTLIB::Unsupported)
+ return nullptr;
+ return M.getNamedValue(getLibcallImplName(GuardVarImpl));
}
Function *TargetLoweringBase::getSSPStackGuardCheck(const Module &M) const {