[llvm-branch-commits] [clang] [llvm] [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 14:09:36 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:

Thanks for the explanation. If `__init_cpu_features_resolver` can be called concurrently, I think it is worth a comment, since the other `__init_*` functions are guaranteed to be very early in the program startup sequence and is serial.

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


More information about the llvm-branch-commits mailing list