Skip to content

Commit 1d73b68

Browse files
authored
TargetLowering: Avoid hardcoding OpenBSD + __guard_local name (#167744)
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 c34f76d commit 1d73b68

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
@@ -2117,16 +2117,18 @@ bool TargetLoweringBase::isLegalAddressingMode(const DataLayout &DL,
21172117
// For OpenBSD return its special guard variable. Otherwise return nullptr,
21182118
// so that SelectionDAG handle SSP.
21192119
Value *TargetLoweringBase::getIRStackGuard(IRBuilderBase &IRB) const {
2120-
if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
2121-
Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
2122-
const DataLayout &DL = M.getDataLayout();
2123-
PointerType *PtrTy =
2124-
PointerType::get(M.getContext(), DL.getDefaultGlobalsAddressSpace());
2125-
GlobalVariable *G = M.getOrInsertGlobal("__guard_local", PtrTy);
2126-
G->setVisibility(GlobalValue::HiddenVisibility);
2127-
return G;
2128-
}
2129-
return nullptr;
2120+
RTLIB::LibcallImpl GuardLocalImpl = getLibcallImpl(RTLIB::STACK_CHECK_GUARD);
2121+
if (GuardLocalImpl != RTLIB::impl___guard_local)
2122+
return nullptr;
2123+
2124+
Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
2125+
const DataLayout &DL = M.getDataLayout();
2126+
PointerType *PtrTy =
2127+
PointerType::get(M.getContext(), DL.getDefaultGlobalsAddressSpace());
2128+
GlobalVariable *G =
2129+
M.getOrInsertGlobal(getLibcallImplName(GuardLocalImpl), PtrTy);
2130+
G->setVisibility(GlobalValue::HiddenVisibility);
2131+
return G;
21302132
}
21312133

21322134
// Currently only support "standard" __stack_chk_guard.

0 commit comments

Comments
 (0)