diff --git a/PlayTools/PlayLoader.m b/PlayTools/PlayLoader.m index ca928d69..9e8db0bb 100644 --- a/PlayTools/PlayLoader.m +++ b/PlayTools/PlayLoader.m @@ -5,6 +5,8 @@ #include #include +#include +#include #include #import "PlayLoader.h" @@ -327,6 +329,33 @@ static int pt_usleep(useconds_t time) { DYLD_INTERPOSE(pt_unlink, unlink) DYLD_INTERPOSE(pt_usleep, usleep) +static _Atomic(void *) pt_ogles_handle = NULL; + +// Redirect gl* dlsym(RTLD_DEFAULT, ...) lookups to OpenGLES when loaded so macOS libGL.dylib does not shadow it. +static void *pt_dlsym(void *handle, const char *symbol) { + if (handle == RTLD_DEFAULT && symbol != NULL && strncmp(symbol, "gl", 2) == 0) { + void *ogles = atomic_load_explicit(&pt_ogles_handle, memory_order_relaxed); + if (ogles == NULL) { + ogles = dlopen("/System/iOSSupport/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY | RTLD_NOLOAD); + if (ogles == NULL) { + ogles = dlopen("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY | RTLD_NOLOAD); + } + if (ogles != NULL) { + atomic_store_explicit(&pt_ogles_handle, ogles, memory_order_relaxed); + } + } + if (ogles != NULL) { + void *sym = dlsym(ogles, symbol); + if (sym != NULL) { + return sym; + } + } + } + return dlsym(handle, symbol); +} + +DYLD_INTERPOSE(pt_dlsym, dlsym) + @implementation PlayLoader static void __attribute__((constructor)) initialize(void) {