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

Jon Roelofs via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 29 15:19:48 PST 2023


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

>From 603983e237e73b2d939bf9ee12e39ecc7983f7f1 Mon Sep 17 00:00:00 2001
From: Jon Roelofs <jonathan_roelofs at apple.com>
Date: Wed, 29 Nov 2023 14:21:54 -0800
Subject: [PATCH] add a note about the dispatch_once block

Created using spr 1.3.4
---
 compiler-rt/lib/builtins/cpu_model.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/compiler-rt/lib/builtins/cpu_model.c b/compiler-rt/lib/builtins/cpu_model.c
index 5f5182859080c49..001467a9f7ff511 100644
--- a/compiler-rt/lib/builtins/cpu_model.c
+++ b/compiler-rt/lib/builtins/cpu_model.c
@@ -1285,6 +1285,14 @@ static bool isKnownAndSupported(const char *name) {
 }
 
 void __init_cpu_features_resolver(void) {
+  // On Darwin platforms, this may be called concurrently by multiple threads
+  // because the resolvers that use it are called lazily at runtime (unlike on
+  // ELF platforms, where IFuncs are resolved serially at load time).  This
+  // function's effect on __aarch64_cpu_features should be idempotent, but even
+  // so we need dispatch_once to resolve the race condition.  Dispatch is
+  // available through libSystem, which we need anyway for the sysctl, so this
+  // does not add a new dependency.
+
   static dispatch_once_t onceToken = 0;
   dispatch_once(&onceToken, ^{
     // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics



More information about the llvm-branch-commits mailing list