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_roel...@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

_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to