[llvm-branch-commits] [llvm] release/20.x: Fix crash lowering stack guard on OpenBSD/aarch64. (#125416) (PR #136458)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Apr 19 13:11:41 PDT 2025


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/136458

Backport c180e249d0013474d502cd779ec65b33cf7e9468

Requested by: @brad0

>From 30dbc5ffd9816052991242cfeb29ebb6372354fb Mon Sep 17 00:00:00 2001
From: 3405691582 <dsk at google.com>
Date: Mon, 31 Mar 2025 12:17:55 -0400
Subject: [PATCH] Fix crash lowering stack guard on OpenBSD/aarch64. (#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.

(cherry picked from commit c180e249d0013474d502cd779ec65b33cf7e9468)
---
 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 9c56912aa6ba0..411f59e714b0e 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-branch-commits mailing list