From dfb425ffcde09bd3cb3f51375875c5fc4108aac1 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 15 Aug 2024 20:50:12 -0400 Subject: [PATCH 1/2] [builitins] Only try to use getauxval on Linux (#104047) OpenBSD now has sys/auxv.h but does not use getauxval. --- compiler-rt/lib/builtins/cpu_model/aarch64.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64.c b/compiler-rt/lib/builtins/cpu_model/aarch64.c index 604051f57984d..320da769aee8e 100644 --- a/compiler-rt/lib/builtins/cpu_model/aarch64.c +++ b/compiler-rt/lib/builtins/cpu_model/aarch64.c @@ -47,7 +47,7 @@ _Bool __aarch64_have_lse_atomics = false; #elif defined(__ANDROID__) #include "aarch64/hwcap.inc" #include "aarch64/lse_atomics/android.inc" -#elif __has_include() +#elif defined(__linux__) && __has_include() #include "aarch64/hwcap.inc" #include "aarch64/lse_atomics/sysauxv.inc" #else @@ -80,7 +80,7 @@ __attribute__((__visibility__("hidden"), __nocommon__)) #elif defined(__ANDROID__) #include "aarch64/fmv/mrs.inc" #include "aarch64/fmv/android.inc" -#elif __has_include() +#elif defined(__linux__) && __has_include() #include "aarch64/fmv/mrs.inc" #include "aarch64/fmv/sysauxv.inc" #else From 42ee2be239dd4f306cc9e1f2f846ae9c29a88899 Mon Sep 17 00:00:00 2001 From: 3405691582 Date: Mon, 31 Mar 2025 12:17:55 -0400 Subject: [PATCH 2/2] 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. --- 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 2be7fc90a0e75..fa1831de53729 100644 --- a/llvm/lib/CodeGen/TargetLoweringBase.cpp +++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -1961,6 +1961,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"); }