Skip to content

[runtime] Directly reference objc_setHook_getImageName #19414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions stdlib/public/runtime/ObjCRuntimeGetImageNameFromClass.mm
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,16 @@ static void patchGetImageNameInImage(const struct mach_header *mh,
void swift::setUpObjCRuntimeGetImageNameFromClass() {
assert(defaultGetImageNameFromClass == nullptr && "already set up");

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

} else {
// On older OSs, manually patch in our new implementation of
Expand Down