[PATCH] D150397: [darwin] Declare _availability_version_check as weak_import instead of looking it up at runtime using dlsym

Akira Hatanaka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 14:01:55 PDT 2023


ahatanak created this revision.
ahatanak added reviewers: arphaman, pete.
Herald added a subscriber: Enna1.
Herald added a project: All.
ahatanak requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150397

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


Index: compiler-rt/lib/builtins/os_version_check.c
===================================================================
--- compiler-rt/lib/builtins/os_version_check.c
+++ compiler-rt/lib/builtins/os_version_check.c
@@ -86,6 +86,10 @@
                                             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 @@
   }
 
   // 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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150397.521436.patch
Type: text/x-patch
Size: 1099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230511/e8ab28af/attachment.bin>


More information about the llvm-commits mailing list