[libunwind] Be more careful about enabling GCS (#101973)
authorJohn Brawn <john.brawn@arm.com>
Mon, 5 Aug 2024 17:54:05 +0000 (18:54 +0100)
committerTobias Hieta <tobias@hieta.se>
Tue, 20 Aug 2024 07:29:19 +0000 (09:29 +0200)
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.

(cherry picked from commit c649194a71b47431f2eb2e041435d564e3b51072)

libunwind/src/cet_unwind.h

index 45c11973cb7fa3eb23e7dad3e6c47df67d50f9e2..47d7616a7322c3224ed4569735731ee8275606df 100644 (file)
 // 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)) {                                             \