Author: Jon Roelofs Date: 2023-11-29T14:21:54-08:00 New Revision: 603983e237e73b2d939bf9ee12e39ecc7983f7f1
URL: https://github.com/llvm/llvm-project/commit/603983e237e73b2d939bf9ee12e39ecc7983f7f1 DIFF: https://github.com/llvm/llvm-project/commit/603983e237e73b2d939bf9ee12e39ecc7983f7f1.diff LOG: add a note about the dispatch_once block Created using spr 1.3.4 Added: Modified: compiler-rt/lib/builtins/cpu_model.c Removed: ################################################################################ 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