Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -404,10 +404,11 @@ case "$host_os" in darwin*) AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"]) AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_SUBST(REEXPORT_LIBOBJC, ["-Wl,-reexport-lobjc"]) + LDFLAGS="$LDFLAGS -Wl,-U,_CFRetain" ]) AS_IF([test x"$objc_runtime" = x"ObjFW runtime"], [ AS_IF([test x"$exception_type" = x"DWARF"], [ LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_v0" Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -56,10 +56,14 @@ #if defined(OF_HAVE_ATOMIC_OPS) # import "atomic.h" #elif defined(OF_HAVE_THREADS) # import "threading.h" #endif + +#ifdef OF_APPLE_RUNTIME +extern void* CFRetain(void*) __attribute__((__weak__)); +#endif #if defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR) extern id of_forward(id, SEL, ...); extern struct stret of_forward_stret(id, SEL, ...); #else @@ -213,11 +217,21 @@ #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) objc_setUncaughtExceptionHandler(uncaughtExceptionHandler); #endif #if defined(OF_APPLE_RUNTIME) - objc_setForwardHandler((void*)&of_forward, (void*)&of_forward_stret); + /* + * If the CFRetain symbol is defined, we are linked against + * CoreFoundation. Since CoreFoundation sets its own forward handler + * on load, we should not set ours, as this will break CoreFoundation. + * + * Unfortunately, there is no way to check if a forward handler has + * already been set, so this is the best we can do. + */ + if (&CFRetain == NULL) + objc_setForwardHandler((void*)&of_forward, + (void*)&of_forward_stret); #else objc_setForwardHandler((IMP)&of_forward, (IMP)&of_forward_stret); #endif objc_setEnumerationMutationHandler(enumerationMutationHandler);