From 029a0231d28a502aaf71539380507880e06aaeb6 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 14 Oct 2025 08:01:55 +0900 Subject: [PATCH] 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. --- llvm/lib/CodeGen/TargetLoweringBase.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp index 77d9b156e2672..4f6f8c68eeb5a 100644 --- a/llvm/lib/CodeGen/TargetLoweringBase.cpp +++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -2116,16 +2116,18 @@ bool TargetLoweringBase::isLegalAddressingMode(const DataLayout &DL, // For OpenBSD return its special guard variable. Otherwise return nullptr, // so that SelectionDAG handle SSP. Value *TargetLoweringBase::getIRStackGuard(IRBuilderBase &IRB) const { - if (getTargetMachine().getTargetTriple().isOSOpenBSD()) { - Module &M = *IRB.GetInsertBlock()->getParent()->getParent(); - const DataLayout &DL = M.getDataLayout(); - PointerType *PtrTy = - PointerType::get(M.getContext(), DL.getDefaultGlobalsAddressSpace()); - GlobalVariable *G = M.getOrInsertGlobal("__guard_local", PtrTy); - G->setVisibility(GlobalValue::HiddenVisibility); - return G; - } - return nullptr; + RTLIB::LibcallImpl GuardLocalImpl = getLibcallImpl(RTLIB::STACK_CHECK_GUARD); + if (GuardLocalImpl != RTLIB::impl___guard_local) + return nullptr; + + Module &M = *IRB.GetInsertBlock()->getParent()->getParent(); + const DataLayout &DL = M.getDataLayout(); + PointerType *PtrTy = + PointerType::get(M.getContext(), DL.getDefaultGlobalsAddressSpace()); + GlobalVariable *G = + M.getOrInsertGlobal(getLibcallImplName(GuardLocalImpl), PtrTy); + G->setVisibility(GlobalValue::HiddenVisibility); + return G; } // Currently only support "standard" __stack_chk_guard.