Skip to content

Commit 029a023

Browse files
committed
TargetLowering: Avoid hardcoding OpenBSD + __guard_local name
Query RuntimeLibcalls for the support and the name. The check that the implementation is exactly __guard_local instead of unsupported feels a bit strange.
1 parent 87da620 commit 029a023

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,16 +2116,18 @@ bool TargetLoweringBase::isLegalAddressingMode(const DataLayout &DL,
21162116
// For OpenBSD return its special guard variable. Otherwise return nullptr,
21172117
// so that SelectionDAG handle SSP.
21182118
Value *TargetLoweringBase::getIRStackGuard(IRBuilderBase &IRB) const {
2119-
if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
2120-
Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
2121-
const DataLayout &DL = M.getDataLayout();
2122-
PointerType *PtrTy =
2123-
PointerType::get(M.getContext(), DL.getDefaultGlobalsAddressSpace());
2124-
GlobalVariable *G = M.getOrInsertGlobal("__guard_local", PtrTy);
2125-
G->setVisibility(GlobalValue::HiddenVisibility);
2126-
return G;
2127-
}
2128-
return nullptr;
2119+
RTLIB::LibcallImpl GuardLocalImpl = getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
2120+
if (GuardLocalImpl != RTLIB::impl___guard_local)
2121+
return nullptr;
2122+
2123+
Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
2124+
const DataLayout &DL = M.getDataLayout();
2125+
PointerType *PtrTy =
2126+
PointerType::get(M.getContext(), DL.getDefaultGlobalsAddressSpace());
2127+
GlobalVariable *G =
2128+
M.getOrInsertGlobal(getLibcallImplName(GuardLocalImpl), PtrTy);
2129+
G->setVisibility(GlobalValue::HiddenVisibility);
2130+
return G;
21292131
}
21302132

21312133
// Currently only support "standard" __stack_chk_guard.

0 commit comments

Comments
 (0)