[libunwind] [libunwind] Be more careful about enabling GCS (PR #101973)

John Brawn via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 06:19:02 PDT 2024


https://github.com/john-brawn-arm created https://github.com/llvm/llvm-project/pull/101973

We need both GCS to be enabled by the compiler (which we do by checking if __ARM_FEATURE_GCS_DEFAULT is defined) and for arm_acle.h to define the GCS intrinsics. Check the latter by checking if _CHKFEAT_GCS is defined.

>From 4db7aa210047c8f4b9243b4a6cdf8f04f03d8e1d Mon Sep 17 00:00:00 2001
From: John Brawn <john.brawn at arm.com>
Date: Mon, 5 Aug 2024 14:11:41 +0100
Subject: [PATCH] [libunwind] Be more careful about enabling GCS

We need both GCS to be enabled by the compiler (which we do by
checking if __ARM_FEATURE_GCS_DEFAULT is defined) and for arm_acle.h
to define the GCS intrinsics. Check the latter by checking if
_CHKFEAT_GCS is defined.
---
 libunwind/src/cet_unwind.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libunwind/src/cet_unwind.h b/libunwind/src/cet_unwind.h
index 45c11973cb7fa..47d7616a7322c 100644
--- a/libunwind/src/cet_unwind.h
+++ b/libunwind/src/cet_unwind.h
@@ -39,9 +39,13 @@
 // need to guard any use of GCS instructions with __chkfeat though, as GCS may
 // not be enabled.
 #if defined(_LIBUNWIND_TARGET_AARCH64) && defined(__ARM_FEATURE_GCS_DEFAULT)
-#define _LIBUNWIND_USE_GCS 1
 #include <arm_acle.h>
 
+// We can only use GCS if arm_acle.h defines the GCS intrinsics.
+#ifdef _CHKFEAT_GCS
+#define _LIBUNWIND_USE_GCS 1
+#endif
+
 #define _LIBUNWIND_POP_CET_SSP(x)                                              \
   do {                                                                         \
     if (__chkfeat(_CHKFEAT_GCS)) {                                             \



More information about the cfe-commits mailing list