[compiler-rt] b653a28 - Declare _availability_version_check as weak_import instead of looking it

Akira Hatanaka via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 17:23:12 PDT 2023


Author: Akira Hatanaka
Date: 2023-05-11T17:22:50-07:00
New Revision: b653a2823fe4b4c9c6d85cfe119f31d8e70c2fa0

URL: https://github.com/llvm/llvm-project/commit/b653a2823fe4b4c9c6d85cfe119f31d8e70c2fa0
DIFF: https://github.com/llvm/llvm-project/commit/b653a2823fe4b4c9c6d85cfe119f31d8e70c2fa0.diff

LOG: Declare _availability_version_check as weak_import instead of looking it
up at runtime using dlsym

Calling dlsym with RTLD_DEFAULT can be very slow as all images in the
process are searched for the symbol.

Differential Revision: https://reviews.llvm.org/D150397

Added: 
    

Modified: 
    compiler-rt/lib/builtins/os_version_check.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/os_version_check.c b/compiler-rt/lib/builtins/os_version_check.c
index ebfb2dfc72ddd..182eabe7a6ae2 100644
--- a/compiler-rt/lib/builtins/os_version_check.c
+++ b/compiler-rt/lib/builtins/os_version_check.c
@@ -86,6 +86,10 @@ typedef Boolean (*CFStringGetCStringFuncTy)(CFStringRef, char *, CFIndex,
                                             CFStringEncoding);
 typedef void (*CFReleaseFuncTy)(CFTypeRef);
 
+extern __attribute__((weak_import))
+bool _availability_version_check(uint32_t count,
+                                 dyld_build_version_t versions[]);
+
 static void _initializeAvailabilityCheck(bool LoadPlist) {
   if (AvailabilityVersionCheck && !LoadPlist) {
     // New API is supported and we're not being asked to load the plist,
@@ -94,8 +98,8 @@ static void _initializeAvailabilityCheck(bool LoadPlist) {
   }
 
   // Use the new API if it's is available.
-  AvailabilityVersionCheck = (AvailabilityVersionCheckFuncTy)dlsym(
-      RTLD_DEFAULT, "_availability_version_check");
+  if (_availability_version_check)
+    AvailabilityVersionCheck = &_availability_version_check;
 
   if (AvailabilityVersionCheck && !LoadPlist) {
     // New API is supported and we're not being asked to load the plist,


        


More information about the llvm-commits mailing list