================
@@ -0,0 +1,164 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// clang-format off
+
+// REQUIRES: target={{aarch64.*}}
+// UNSUPPORTED: target={{.*-windows.*}}
+
+// The libSystem unwinder does not correctly read UNW_AARCH64_RA_SIGN_STATE, at
+// least through OS version 27.0
+// XFAIL: stdlib=apple-libc++ &&
target={{.*}}-apple-{{.*}}{{(11|12|13|14|15|26)(\.\d+)?}}
+// XFAIL: stdlib=apple-libc++ && target={{.*}}-apple-{{.*}}27.0
+
+// clang-format on
+
+#undef NDEBUG
+#include "../src/config.h"
+#include "support/func_bounds.h"
+
+#include <assert.h>
+#include <inttypes.h>
+#include <libunwind.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <unwind.h>
+
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+#endif
+#if defined(_LIBUNWIND_HAVE_GETAUXVAL) || defined(_LIBUNWIND_HAVE_ELF_AUX_INFO)
+#include <sys/auxv.h>
+#endif
+
+// Note: This test requires FEAT_PAuth (and is setup to pass on other targets).
+
+#if defined(__APPLE__)
+static bool checkHasPAuth() {
+ int has_pauth = 0;
+ size_t size = sizeof(has_pauth);
+ if (sysctlbyname("hw.optional.arm.FEAT_PAuth", &has_pauth, &size, NULL, 0))
+ return false;
+ return has_pauth != 0;
+}
+#elif defined(_LIBUNWIND_HAVE_GETAUXVAL)
+static bool checkHasPAuth() {
+ constexpr unsigned long hwcap_paca = (1UL << 30);
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & hwcap_paca) != 0;
+}
+#elif defined(_LIBUNWIND_HAVE_ELF_AUX_INFO)
+static bool checkHasPAuth() {
+ constexpr unsigned long hwcap_paca = (1UL << 30);
+ unsigned long hwcap = 0;
+ elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
+ return (hwcap & hwcap_paca) != 0;
+}
+#else
+static bool checkHasPAuth() {
+ // TODO: Support other platforms.
+ return false;
+}
+#endif
----------------
cofibrant wrote:
```suggestion
static bool checkHasPAuth() {
#if defined(__APPLE__)
int has_pauth = 0;
size_t size = sizeof(has_pauth);
if (sysctlbyname("hw.optional.arm.FEAT_PAuth", &has_pauth, &size, NULL, 0))
return false;
return has_pauth != 0;
#elif defined(_LIBUNWIND_HAVE_GETAUXVAL)
constexpr unsigned long hwcap_paca = (1UL << 30);
unsigned long hwcap = getauxval(AT_HWCAP);
return (hwcap & hwcap_paca) != 0;
#elif defined(_LIBUNWIND_HAVE_ELF_AUX_INFO)
constexpr unsigned long hwcap_paca = (1UL << 30);
unsigned long hwcap = 0;
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
return (hwcap & hwcap_paca) != 0;
#else
// TODO: Support other platforms.
return false;
#endif
}
```
Complete bikeshed, sorry
https://github.com/llvm/llvm-project/pull/209947
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits