Skip to content

Commit

Permalink
Declare _availability_version_check as weak_import instead of looking it
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ahatanaka committed May 12, 2023
1 parent ba566ff commit b653a28
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler-rt/lib/builtins/os_version_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit b653a28

Please sign in to comment.