aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringBase.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2025-08-23 10:21:00 +0900
committerGitHub <noreply@github.com>2025-08-23 10:21:00 +0900
commit65d12622faa2a16f7e5d1fc6b101a670dbf26391 (patch)
treee6d01813a660d7e60f32082898d193faf6750986 /llvm/lib/CodeGen/TargetLoweringBase.cpp
parentfd330dedcbb729bb0a77abec58162b2f5ec2136c (diff)
downloadllvm-65d12622faa2a16f7e5d1fc6b101a670dbf26391.zip
llvm-65d12622faa2a16f7e5d1fc6b101a670dbf26391.tar.gz
llvm-65d12622faa2a16f7e5d1fc6b101a670dbf26391.tar.bz2
RuntimeLibcalls: Add entries for stackprotector globals (#154930)
Add entries for_stack_chk_guard, __ssp_canary_word, __security_cookie, and __guard_local. As far as I can tell these are all just different names for the same shaped functionality on different systems. These aren't really functions, but special global variable names. They should probably be treated the same way; all the same contexts that need to know about emittable function names also need to know about this. This avoids a special case check in IRSymtab. This isn't a complete change, there's a lot more cleanup which should be done. The stack protector configuration system is a complete mess. There are multiple overlapping controls, used in 3 different places. Some of the target control implementations overlap with conditions used in the emission points, and some use correlated but not identical conditions in different contexts. i.e. useLoadStackGuardNode, getIRStackGuard, getSSPStackGuardCheck and insertSSPDeclarations are all used in inconsistent ways so I don't know if I've tracked the intention of the system correctly. The PowerPC test change is a bug fix on linux. Previously the manual conditions were based around !isOSOpenBSD, which is not the condition where __stack_chk_guard are used. Now getSDagStackGuard returns the proper global reference, resulting in LOAD_STACK_GUARD getting a MachineMemOperand which allows scheduling.
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 {