Skip to content

Commit 9cb6d39

Browse files
committed
[runtime] Directly reference objc_setHook_getImageName
(instead of using dlsym) The original use went in before <objc/runtime.h> was updated, but now it should be present in all Xcode 10 SDKs. rdar://problem/42137765
1 parent 7d78b09 commit 9cb6d39

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

stdlib/public/runtime/ObjCRuntimeGetImageNameFromClass.mm

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,16 @@ static void patchGetImageNameInImage(const struct mach_header *mh,
336336
void swift::setUpObjCRuntimeGetImageNameFromClass() {
337337
assert(defaultGetImageNameFromClass == nullptr && "already set up");
338338

339-
// FIXME: This is from a later version of <objc/runtime.h>. Once the
340-
// declaration is available in SDKs, we can access this directly instead of
341-
// using dlsym.
342-
if (void *setHookPtr = dlsym(RTLD_DEFAULT, "objc_setHook_getImageName")) {
343-
auto setHook = reinterpret_cast<
344-
void(*)(objc_hook_getImageName _Nonnull,
345-
objc_hook_getImageName _Nullable * _Nonnull)>(setHookPtr);
346-
setHook(replacementGetImageNameFromClass, &defaultGetImageNameFromClass);
339+
#pragma clang diagnostic push
340+
#pragma clang diagnostic ignored "-Wunguarded-availability"
341+
// If we're on a newer OS, install the customized class_getImageName through
342+
// the ObjC runtime.
343+
// Note: We're checking this the old-fashioned way instead of using @available
344+
// to make it easier to build from open-source.
345+
if (&objc_setHook_getImageName != nullptr) {
346+
objc_setHook_getImageName(replacementGetImageNameFromClass,
347+
&defaultGetImageNameFromClass);
348+
#pragma clang diagnostic pop
347349

348350
} else {
349351
// On older OSs, manually patch in our new implementation of

0 commit comments

Comments
 (0)