[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 29 13:15:00 PST 2023


================
@@ -1259,6 +1270,64 @@ struct {
   // As features grows new fields could be added
 } __aarch64_cpu_features __attribute__((visibility("hidden"), nocommon));
 
+#if defined(__APPLE__)
+#include <TargetConditionals.h>
+#if TARGET_OS_OSX || TARGET_OS_IPHONE
+#include <dispatch/dispatch.h>
+#include <sys/sysctl.h>
+
+static bool isKnownAndSupported(const char *name) {
+  int32_t val = 0;
+  size_t size = sizeof(val);
+  if (sysctlbyname(name, &val, &size, NULL, 0))
+    return false;
+  return val;
+}
+
+void __init_cpu_features_resolver(void) {
+  static dispatch_once_t onceToken = 0;
+  dispatch_once(&onceToken, ^{
----------------
MaskRay wrote:

I am not familiar with blocks. Does this introduce any dependency on libcalls? Can this reuse `if (__aarch64_cpu_features.features)` used by ELF?

https://github.com/llvm/llvm-project/pull/73685


More information about the llvm-branch-commits mailing list