[llvm] Fix crash lowering stack guard on OpenBSD/aarch64. (PR #125416)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 2 08:09:35 PST 2025
https://github.com/3405691582 created https://github.com/llvm/llvm-project/pull/125416
TargetLoweringBase::getIRStackGuard refers to a platform-specific guard variable. Before this change, TargetLoweringBase::getSDagStackGuard only referred to a different variable.
This means that SelectionDAGBuilder's getLoadStackGuard does not get memory operands. However, AArch64InstrInfo::expandPostRAPseudo assumes that the passed MachineInstr has nonzero memoperands, causing a segfault.
We have two possible options here: either disabling the LOAD_STACK_GUARD node entirely in AArch64TargetLowering::useLoadStackGuardNode or just making the platform-specific values match across TargetLoweringBase. Here, we try the latter.
>From 2aa48cf2c31d40d3c6bf3b13243f71d89191f934 Mon Sep 17 00:00:00 2001
From: 3405691582 <dsk at google.com>
Date: Sun, 2 Feb 2025 10:51:03 -0500
Subject: [PATCH] Fix crash lowering stack guard on OpenBSD/aarch64.
TargetLoweringBase::getIRStackGuard refers to a platform-specific guard
variable. Before this change, TargetLoweringBase::getSDagStackGuard
only referred to a different variable.
This means that SelectionDAGBuilder's getLoadStackGuard does not get
memory operands. However, AArch64InstrInfo::expandPostRAPseudo assumes
that the passed MachineInstr has nonzero memoperands, causing a
segfault.
We have two possible options here: either disabling the LOAD_STACK_GUARD
node entirely in AArch64TargetLowering::useLoadStackGuardNode or just
making the platform-specific values match across TargetLoweringBase.
Here, we try the latter.
---
llvm/lib/CodeGen/TargetLoweringBase.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 9c56912aa6ba031..411f59e714b0efe 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -1987,6 +1987,9 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
// 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");
}
More information about the llvm-commits
mailing list