Loading...
src/dyldAPIs.cpp dyld-421.2 dyld-353.2.3
--- dyld/dyld-421.2/src/dyldAPIs.cpp
+++ dyld/dyld-353.2.3/src/dyldAPIs.cpp
@@ -51,7 +51,6 @@
 #include "mach-o/dyld_priv.h"
 
 #include "ImageLoader.h"
-#include "ImageLoaderMachO.h"
 #include "dyld.h"
 #include "dyldLibSystemInterface.h"
 
@@ -63,10 +62,6 @@
 
 // from dyld_gdb.cpp 
 extern void addImagesToAllImages(uint32_t infoCount, const dyld_image_info info[]);
-extern uint32_t allImagesCount();
-extern const mach_header* allImagesIndexedMachHeader(uint32_t index);
-extern const char* allImagesIndexedPath(uint32_t index);
-
 
 // deprecated APIs are still availble on Mac OS X, but not on iPhone OS
 #if __IPHONE_OS_VERSION_MIN_REQUIRED	
@@ -108,8 +103,6 @@
 #endif // DEPRECATED_APIS_SUPPORTED
 #if SUPPORT_ZERO_COST_EXCEPTIONS
 static bool client_dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info);
-#endif
-#if DEPRECATED_APIS_SUPPORTED
 #endif
 
 static void unimplemented()
@@ -139,6 +132,7 @@
     {"__dyld__NSGetExecutablePath",						(void*)_NSGetExecutablePath },
 
 	// SPIs
+	{"__dyld_dyld_register_image_state_change_handler",	(void*)dyld_register_image_state_change_handler },
   	{"__dyld_register_thread_helpers",					(void*)registerThreadHelpers },
 	{"__dyld_fork_child",								(void*)_dyld_fork_child },
     {"__dyld_make_delayed_module_initializer_calls",	(void*)_dyld_make_delayed_module_initializer_calls },
@@ -153,17 +147,10 @@
 	{"__dyld_shared_cache_some_image_overridden",		(void*)dyld_shared_cache_some_image_overridden },
 	{"__dyld_process_is_restricted",					(void*)dyld::processIsRestricted },
 	{"__dyld_dynamic_interpose",						(void*)dyld_dynamic_interpose },
-#if DYLD_SHARED_CACHE_SUPPORT
-	{"__dyld_shared_cache_file_path",					(void*)dyld::getStandardSharedCacheFilePath },
-#endif
-    {"__dyld_get_image_header_containing_address",		(void*)dyld_image_header_containing_address },
-    {"__dyld_is_memory_immutable",						(void*)_dyld_is_memory_immutable },
-    {"__dyld_objc_notify_register",						(void*)_dyld_objc_notify_register },
-    {"__dyld_get_shared_cache_uuid",					(void*)_dyld_get_shared_cache_uuid },
-
 
 	// deprecated
 #if DEPRECATED_APIS_SUPPORTED
+    {"__dyld_get_image_header_containing_address",		(void*)_dyld_get_image_header_containing_address },
     {"__dyld_lookup_and_bind",						(void*)client_dyld_lookup_and_bind },
     {"__dyld_lookup_and_bind_with_hint",			(void*)_dyld_lookup_and_bind_with_hint },
     {"__dyld_lookup_and_bind_fully",				(void*)_dyld_lookup_and_bind_fully },
@@ -306,23 +293,27 @@
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s()\n", __func__);
-	return allImagesCount();
+	return dyld::getImageCount();
 }
 
 const struct mach_header* _dyld_get_image_header(uint32_t image_index)
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%u)\n", __func__, image_index);
-	return allImagesIndexedMachHeader(image_index);
+	ImageLoader* image = dyld::getIndexedImage(image_index);
+	if ( image != NULL )
+		return (struct mach_header*)image->machHeader();
+	else
+		return NULL;
 }
 
 intptr_t _dyld_get_image_vmaddr_slide(uint32_t image_index)
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%u)\n", __func__, image_index);
-	const struct mach_header* mh = allImagesIndexedMachHeader(image_index);
-	if ( mh != NULL )
-		return ImageLoaderMachO::computeSlide(mh);
+	ImageLoader* image = dyld::getIndexedImage(image_index);
+	if ( image != NULL )
+		return image->getSlide();
 	else
 		return 0;
 }
@@ -331,7 +322,11 @@
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%p)\n", __func__, mh);
-	return ImageLoaderMachO::computeSlide(mh);
+	ImageLoader* image = dyld::findImageByMachHeader(mh);
+	if ( image != NULL )
+		return image->getSlide();
+	else
+		return 0;
 }
 
 
@@ -339,19 +334,17 @@
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%u)\n", __func__, image_index);
-	return allImagesIndexedPath(image_index);
-}
-
-const struct mach_header * dyld_image_header_containing_address(const void* address)
+	ImageLoader* image = dyld::getIndexedImage(image_index);
+	if ( image != NULL )
+		return image->getRealPath();
+	else
+		return NULL;
+}
+
+const struct mach_header * _dyld_get_image_header_containing_address(const void* address)
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%p)\n", __func__, address);
-#if SUPPORT_ACCELERATE_TABLES
-	const mach_header* mh;
-	const char* path;
-	if ( dyld::addressInCache(address, &mh, &path) )
-		return mh;
-#endif
 	ImageLoader* image = dyld::findImageContainingAddress(address);
 	if ( image != NULL ) 
 		return image->machHeader();
@@ -547,13 +540,12 @@
 		context.canBePIE			= false;
 		context.origin				= callerImage != NULL ? callerImage->getPath() : NULL; // caller's image's path
 		context.rpath				= &callersRPaths; 	// rpaths from caller and main executable
-
-		unsigned cacheIndex;
-		image = load(path, context, cacheIndex);
+				
+		image = load(path, context);
 		if ( image != NULL ) {
 			if ( context.matchByInstallName )
 				image->setMatchInstallPath(true);
-			dyld::link(image, false, false, callersRPaths, cacheIndex);
+			dyld::link(image, false, false, callersRPaths);
 			dyld::runInitializers(image);
 			// images added with NSAddImage() can never be unloaded
 			image->setNeverUnload(); 
@@ -798,8 +790,7 @@
 		context.origin				= callerImage != NULL ? callerImage->getPath() : NULL; // caller's image's path
 		context.rpath				= NULL; // support not yet implemented
 
-		unsigned cacheIndex;
-		ImageLoader* image = dyld::load(pathName, context, cacheIndex);
+		ImageLoader* image = dyld::load(pathName, context);
 		// Note:  We DO NOT link the image!  NSLinkModule will do that
 		if ( image != NULL ) {
 			if ( !image->isBundle() ) {
@@ -1013,7 +1004,7 @@
 		bool forceLazysBound = ( (options & NSLINKMODULE_OPTION_BINDNOW) != 0 );
 		
 		// load libraries, rebase, bind, to make this image usable
-		dyld::link(objectFileImage->image, forceLazysBound, false, ImageLoader::RPathChain(NULL,NULL), UINT32_MAX);
+		dyld::link(objectFileImage->image, forceLazysBound, false, ImageLoader::RPathChain(NULL,NULL));
 		
 		// bump reference count to keep this bundle from being garbage collected
 		objectFileImage->image->incrementDlopenReferenceCount();
@@ -1059,7 +1050,7 @@
 			bool forceLazysBound = ( (options & NSLINKMODULE_OPTION_BINDNOW) != 0 );
 			
 			// load libraries, rebase, bind, to make this image usable
-			dyld::link(image, forceLazysBound, false, ImageLoader::RPathChain(NULL,NULL), UINT32_MAX);
+			dyld::link(image, forceLazysBound, false, ImageLoader::RPathChain(NULL,NULL));
 			
 			// run initializers unless magic flag says not to
 			if ( (options & NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES) == 0 )
@@ -1124,7 +1115,7 @@
 		return false;
 	dyld::runImageStaticTerminators(image);
 	if ( (dyld::gLibSystemHelpers != NULL) && (dyld::gLibSystemHelpers->version >= 13) ) {
-		__cxa_range_t ranges[image->segmentCount()];
+		__cxa_range_t ranges[3];
 		int rangeCount = 0;
 		for (unsigned int j=0; j < image->segmentCount(); ++j) {
 			if ( !image->segExecutable(j) )
@@ -1268,6 +1259,9 @@
 {
 	dyld::gLibSystemHelpers = helpers;
 	
+	// let gdb know it is safe to run code in inferior that might call malloc()
+	dyld::gProcessInfo->libSystemInitialized = true;	
+	
 #if !SUPPORT_ZERO_COST_EXCEPTIONS
 	if ( helpers->version >= 5 )  {
 		// create key use by dyld exception handling
@@ -1315,42 +1309,14 @@
 
 	dlerrorClear();
 	
-	CRSetCrashLogMessage("dyld: in dlopen_preflight()");
-
-	const bool leafName = (strchr(path, '/') == NULL);
-	const bool absolutePath = (path[0] == '/');
-#if __IPHONE_OS_VERSION_MIN_REQUIRED
-	char canonicalPath[PATH_MAX]; 
-	// <rdar://problem/7017050> dlopen() not opening frameworks from shared cache with // or ./ in path
-	if ( !leafName ) {
-		// make path canonical if it contains a // or ./
-		if ( (strstr(path, "//") != NULL) || (strstr(path, "./") != NULL) ) {
-			const char* lastSlash = strrchr(path, '/');
-			char dirPath[PATH_MAX]; 
-			if ( strlcpy(dirPath, path, sizeof(dirPath)) < sizeof(dirPath) ) {
-				dirPath[lastSlash-path] = '\0';
-				if ( realpath(dirPath, canonicalPath) ) {
-					strlcat(canonicalPath, "/", sizeof(canonicalPath));
-					if ( strlcat(canonicalPath, lastSlash+1, sizeof(canonicalPath)) < sizeof(canonicalPath) ) {
-						// if all fit in buffer, use new canonical path
-						path = canonicalPath;
-					}
-				}
-			}
-		}
-	}
-#endif
-#if SUPPORT_ACCELERATE_TABLES
-	if  ( dyld::isPathInCache(path) )
-		return true;
-#endif
-
 #if DYLD_SHARED_CACHE_SUPPORT
 	// <rdar://problem/5910137> dlopen_preflight() on image in shared cache leaves it loaded but not objc initialized
 	// if requested path is to something in the dyld shared cache, always succeed
 	if ( dyld::inSharedCache(path) )
 		return true;
 #endif
+	
+	CRSetCrashLogMessage("dyld: in dlopen_preflight()");
 	
 	bool result = false;
 	std::vector<const char*> rpathsFromCallerImage;
@@ -1366,6 +1332,29 @@
 		}
 
 		ImageLoader*	image = NULL;
+		const bool leafName = (strchr(path, '/') == NULL);
+		const bool absolutePath = (path[0] == '/');
+#if __IPHONE_OS_VERSION_MIN_REQUIRED
+		char canonicalPath[PATH_MAX]; 
+		// <rdar://problem/7017050> dlopen() not opening frameworks from shared cache with // or ./ in path
+		if ( !leafName ) {
+			// make path canonical if it contains a // or ./
+			if ( (strstr(path, "//") != NULL) || (strstr(path, "./") != NULL) ) {
+				const char* lastSlash = strrchr(path, '/');
+				char dirPath[PATH_MAX]; 
+				if ( strlcpy(dirPath, path, sizeof(dirPath)) < sizeof(dirPath) ) {
+					dirPath[lastSlash-path] = '\0';
+					if ( realpath(dirPath, canonicalPath) ) {
+						strlcat(canonicalPath, "/", sizeof(canonicalPath));
+						if ( strlcat(canonicalPath, lastSlash+1, sizeof(canonicalPath)) < sizeof(canonicalPath) ) {
+							// if all fit in buffer, use new canonical path
+							path = canonicalPath;
+						}
+					}
+				}
+			}
+		}
+#endif
 		dyld::LoadContext context;
 		context.useSearchPaths	= true;
 		context.useFallbackPaths= leafName;					// a partial path implies don't use fallback paths
@@ -1378,11 +1367,10 @@
 		context.canBePIE		= true;
 		context.origin			= callerImage != NULL ? callerImage->getPath() : NULL; // caller's image's path
 		context.rpath			= &callersRPaths;	// rpaths from caller and main executable
-
-		unsigned cacheIndex;
-		image = load(path, context, cacheIndex);
+		
+		image = load(path, context);
 		if ( image != NULL ) {
-			dyld::preflight(image, callersRPaths, cacheIndex);	// image object deleted by dyld::preflight()
+			dyld::preflight(image, callersRPaths);	// image object deleted by dyld::preflight()
 			result = true;
 		}
 	}
@@ -1401,43 +1389,14 @@
 	return result;
 }
 
-#if SUPPORT_ACCELERATE_TABLES
-bool static callerIsNonOSApp(void* callerAddress, const char** shortName)
-{
-	*shortName = NULL;
-	const mach_header* unusedMh;
-	const char* unusedPath;
-	unsigned unusedIndex;
-	// any address in shared cache is not from app
-	if ( dyld::addressInCache(callerAddress, &unusedMh, &unusedPath, &unusedIndex) )
-		return false;
-
-	ImageLoader* callerImage = dyld::findImageContainingAddress(callerAddress);
-	if ( callerImage == NULL )
-		return false;
-
-	*shortName = callerImage->getShortName();
-	return ( strncmp(callerImage->getPath(), "/var/containers/", 16) == 0 );
-}
-#endif
 
 void* dlopen(const char* path, int mode)
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%s, 0x%08X)\n", __func__, ((path==NULL) ? "NULL" : path), mode);
 
-#if SUPPORT_ACCELERATE_TABLES
-	if ( dyld::gLogAppAPIs ) {
-		void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
-		const char* shortName;
-		if ( callerIsNonOSApp(callerAddress, &shortName) ) {
-			dyld::log("%s: %s(%s, 0x%08X)\n", shortName, __func__, ((path==NULL) ? "NULL" : path), mode);
-		}
-	}
-#endif
-
 	dlerrorClear();
-
+	
 	// passing NULL for path means return magic object
 	if ( path == NULL ) {
 		// RTLD_FIRST means any dlsym() calls on the handle should only search that handle and not subsequent images
@@ -1456,52 +1415,42 @@
 	}
 		
 	void* result = NULL;
-	const bool leafName = (strchr(path, '/') == NULL);
-	const bool absolutePath = (path[0] == '/');
+	ImageLoader* image = NULL;
+	std::vector<const char*> rpathsFromCallerImage;
+	try {
+		void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
+		ImageLoader* callerImage = dyld::findImageContainingAddress(callerAddress);
+		// for dlopen, use rpath from caller image and from main executable
+		if ( callerImage != NULL )
+			callerImage->getRPaths(dyld::gLinkContext, rpathsFromCallerImage);
+		ImageLoader::RPathChain callersRPaths(NULL, &rpathsFromCallerImage);
+		if ( callerImage != dyld::mainExecutable() ) {
+			dyld::mainExecutable()->getRPaths(dyld::gLinkContext, rpathsFromCallerImage);
+		}
+ 
+		const bool leafName = (strchr(path, '/') == NULL);
+		const bool absolutePath = (path[0] == '/');
 #if __IPHONE_OS_VERSION_MIN_REQUIRED
-	char canonicalPath[PATH_MAX]; 
-	// <rdar://problem/7017050> dlopen() not opening frameworks from shared cache with // or ./ in path
-	if ( !leafName ) {
-		// make path canonical if it contains a // or ./
-		if ( (strstr(path, "//") != NULL) || (strstr(path, "./") != NULL) ) {
-			const char* lastSlash = strrchr(path, '/');
-			char dirPath[PATH_MAX]; 
-			if ( strlcpy(dirPath, path, sizeof(dirPath)) < sizeof(dirPath) ) {
-				dirPath[lastSlash-path] = '\0';
-				if ( realpath(dirPath, canonicalPath) ) {
-					strlcat(canonicalPath, "/", sizeof(canonicalPath));
-					if ( strlcat(canonicalPath, lastSlash+1, sizeof(canonicalPath)) < sizeof(canonicalPath) ) {
-						// if all fit in buffer, use new canonical path
-						path = canonicalPath;
+		char canonicalPath[PATH_MAX]; 
+		// <rdar://problem/7017050> dlopen() not opening frameworks from shared cache with // or ./ in path
+		if ( !leafName ) {
+			// make path canonical if it contains a // or ./
+			if ( (strstr(path, "//") != NULL) || (strstr(path, "./") != NULL) ) {
+				const char* lastSlash = strrchr(path, '/');
+				char dirPath[PATH_MAX]; 
+				if ( strlcpy(dirPath, path, sizeof(dirPath)) < sizeof(dirPath) ) {
+					dirPath[lastSlash-path] = '\0';
+					if ( realpath(dirPath, canonicalPath) ) {
+						strlcat(canonicalPath, "/", sizeof(canonicalPath));
+						if ( strlcat(canonicalPath, lastSlash+1, sizeof(canonicalPath)) < sizeof(canonicalPath) ) {
+							// if all fit in buffer, use new canonical path
+							path = canonicalPath;
+						}
 					}
 				}
 			}
 		}
-	}
 #endif
-#if SUPPORT_ACCELERATE_TABLES
-	if ( dyld::dlopenFromCache(path, mode, &result) ) {
-		// Note: dlopenFromCache() releases the lock
-		if ( dyld::gLogAPIs )
-			dyld::log("  %s(%s) ==> %p\n", __func__, path, result);
-		return result;
-	}
-#endif
-
-	ImageLoader* image = NULL;
-	std::vector<const char*> rpathsFromCallerImage;
-	ImageLoader::RPathChain callersRPaths(NULL, &rpathsFromCallerImage);
-	try {
-		void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
-		ImageLoader* callerImage = dyld::findImageContainingAddress(callerAddress);
-		if ( (mode & RTLD_NOLOAD) == 0 ) {
-			// for dlopen, use rpath from caller image and from main executable
-			if ( callerImage != NULL )
-				callerImage->getRPaths(dyld::gLinkContext, rpathsFromCallerImage);
-			if ( callerImage != dyld::mainExecutable() )
-				dyld::mainExecutable()->getRPaths(dyld::gLinkContext, rpathsFromCallerImage);
-		}
- 
 		dyld::LoadContext context;
 		context.useSearchPaths	= true;
 		context.useFallbackPaths= leafName;				// a partial path means no fallback paths
@@ -1514,20 +1463,8 @@
 		context.canBePIE		= true;
 		context.origin			= callerImage != NULL ? callerImage->getPath() : NULL; // caller's image's path
 		context.rpath			= &callersRPaths;				// rpaths from caller and main executable
-
-		unsigned cacheIndex;
-		image = load(path, context, cacheIndex);
-#if SUPPORT_ACCELERATE_TABLES
-		if ( (image != NULL) && (cacheIndex != UINT32_MAX) ) {
-			if ( dyld::makeCacheHandle(image, cacheIndex, mode, &result) ) {
-				if ( dyld::gLogAPIs )
-					dyld::log("  %s(%s) ==> %p\n", __func__, path, result);
-				if ( lockHeld )
-					dyld::gLibSystemHelpers->releaseGlobalDyldLock();
-				return result;
-			}
-		}
-#endif
+		
+		image = load(path, context);
 		if ( image != NULL ) {
 			// bump reference count.  Do this before link() so that if an initializer calls dlopen and fails
 			// this image is not garbage collected
@@ -1536,7 +1473,7 @@
 			if ( (mode & RTLD_NOLOAD) == 0 ) {
 				bool alreadyLinked = image->isLinked();
 				bool forceLazysBound = ( (mode & RTLD_NOW) != 0 );
-				dyld::link(image, forceLazysBound, false, callersRPaths, cacheIndex);
+				dyld::link(image, forceLazysBound, false, callersRPaths);
 				if ( ! alreadyLinked ) {
 					// only hide exports if image is not already in use
 					if ( (mode & RTLD_LOCAL) != 0 )
@@ -1653,13 +1590,6 @@
 		dyld::log("%s(%p, %p)\n", __func__, address, info);
 
 	CRSetCrashLogMessage("dyld: in dladdr()");
-#if SUPPORT_ACCELERATE_TABLES
-	if ( dyld::dladdrFromCache(address, info) ) {
-		CRSetCrashLogMessage(NULL);
-		return 1; // success
-	}
-#endif
-
 	ImageLoader* image = dyld::findImageContainingAddress(address);
 	if ( image != NULL ) {
 		info->dli_fname = image->getRealPath();
@@ -1724,22 +1654,11 @@
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%p, %s)\n", __func__, handle, symbolName);
 
-#if SUPPORT_ACCELERATE_TABLES
-	if ( dyld::gLogAppAPIs ) {
-		void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
-		const char* shortName;
-		if ( callerIsNonOSApp(callerAddress, &shortName) ) {
-			dyld::log("%s: %s(%p, %s)\n", shortName, __func__, handle, symbolName);
-		}
-	}
-#endif
-
 	CRSetCrashLogMessage("dyld: in dlsym()");
 	dlerrorClear();
 
 	const ImageLoader* image;
 	const ImageLoader::Symbol* sym;
-	void* result;
 
 	// dlsym() assumes symbolName passed in is same as in C source code
 	// dyld assumes all symbol names have an underscore prefix
@@ -1751,113 +1670,60 @@
 	if ( handle == RTLD_DEFAULT ) {
 		if ( dyld::flatFindExportedSymbol(underscoredName, &sym, &image) ) {
 			CRSetCrashLogMessage(NULL);
-			result = (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext, NULL, false, underscoredName);
-			if ( dyld::gLogAPIs )
-				dyld::log("  %s(RTLD_DEFAULT, %s) ==> %p\n", __func__, symbolName, result);
-			return result;
+			return (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext);
 		}
 		const char* str = dyld::mkstringf("dlsym(RTLD_DEFAULT, %s): symbol not found", symbolName);
 		dlerrorSet(str);
 		free((void*)str);
 		CRSetCrashLogMessage(NULL);
-		if ( dyld::gLogAPIs )
-			dyld::log("  %s(RTLD_DEFAULT, %s) ==> NULL\n", __func__, symbolName);
 		return NULL;
 	}
 	
 	// magic "search only main executable" handle
-	else if ( handle == RTLD_MAIN_ONLY ) {
+	if ( handle == RTLD_MAIN_ONLY ) {
 		image = dyld::mainExecutable();
 		sym = image->findExportedSymbol(underscoredName, true, &image); // search RTLD_FIRST way
 		if ( sym != NULL ) {
 			CRSetCrashLogMessage(NULL);
-			result = (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext, NULL, false, underscoredName);
-			if ( dyld::gLogAPIs )
-				dyld::log("  %s(RTLD_MAIN_ONLY, %s) ==> %p\n", __func__, symbolName, result);
-			return result;
+			return (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext);
 		}
 		const char* str = dyld::mkstringf("dlsym(RTLD_MAIN_ONLY, %s): symbol not found", symbolName);
 		dlerrorSet(str);
 		free((void*)str);
 		CRSetCrashLogMessage(NULL);
-		if ( dyld::gLogAPIs )
-			dyld::log("  %s(RTLD_MAIN_ONLY, %s) ==> NULL\n", __func__, symbolName);
 		return NULL;
 	}
 	
 	// magic "search what I would see" handle
-	else if ( handle == RTLD_NEXT ) {
+	if ( handle == RTLD_NEXT ) {
 		void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
-#if SUPPORT_ACCELERATE_TABLES
-		const mach_header* mh;
-		const char* path;
-		unsigned index;
-		if ( dyld::addressInCache(callerAddress, &mh, &path, &index) ) {
-			// if dylib in cache is calling dlsym(RTLD_NEXT,xxx) handle search differently
-			result = dyld::dlsymFromCache(RTLD_NEXT, underscoredName, index);
-			if ( dyld::gLogAPIs )
-				dyld::log("  %s(RTLD_NEXT, %s) ==> %p\n", __func__, symbolName, result);
-			return result;
-		}
-#endif
 		ImageLoader* callerImage = dyld::findImageContainingAddress(callerAddress);
 		sym = callerImage->findExportedSymbolInDependentImages(underscoredName, dyld::gLinkContext, &image); // don't search image, but do search what it links against
 		if ( sym != NULL ) {
 			CRSetCrashLogMessage(NULL);
-			result = (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext , callerImage, false, underscoredName);
-			if ( dyld::gLogAPIs )
-				dyld::log("  %s(RTLD_NEXT, %s) ==> %p\n", __func__, symbolName, result);
-			return result;
+			return (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext);
 		}
 		const char* str = dyld::mkstringf("dlsym(RTLD_NEXT, %s): symbol not found", symbolName);
 		dlerrorSet(str);
 		free((void*)str);
 		CRSetCrashLogMessage(NULL);
-		if ( dyld::gLogAPIs )
-			dyld::log("  %s(RTLD_NEXT, %s) ==> NULL\n", __func__, symbolName);
 		return NULL;
 	}
 	// magic "search me, then what I would see" handle
-	else if ( handle == RTLD_SELF ) {
+	if ( handle == RTLD_SELF ) {
 		void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
-#if SUPPORT_ACCELERATE_TABLES
-		const mach_header* mh;
-		const char* path;
-		unsigned index;
-		if ( dyld::addressInCache(callerAddress, &mh, &path, &index) ) {
-			// if dylib in cache is calling dlsym(RTLD_SELF,xxx) handle search differently
-			result = dyld::dlsymFromCache(RTLD_SELF, underscoredName, index);
-			if ( dyld::gLogAPIs )
-				dyld::log("  %s(RTLD_SELF, %s) ==> %p\n", __func__, symbolName, result);
-			return result;
-		}
-#endif
 		ImageLoader* callerImage = dyld::findImageContainingAddress(callerAddress);
 		sym = callerImage->findExportedSymbolInImageOrDependentImages(underscoredName, dyld::gLinkContext, &image); // search image and what it links against
 		if ( sym != NULL ) {
 			CRSetCrashLogMessage(NULL);
-			result = (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext, callerImage, false, underscoredName);
-			if ( dyld::gLogAPIs )
-				dyld::log("  %s(RTLD_SELF, %s) ==> %p\n", __func__, symbolName, result);
-			return result;
+			return (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext);
 		}
 		const char* str = dyld::mkstringf("dlsym(RTLD_SELF, %s): symbol not found", symbolName);
 		dlerrorSet(str);
 		free((void*)str);
 		CRSetCrashLogMessage(NULL);
-		if ( dyld::gLogAPIs )
-			dyld::log("  %s(RTLD_SELF, %s) ==> NULL\n", __func__, symbolName);
 		return NULL;
 	}
-#if SUPPORT_ACCELERATE_TABLES
-	// check for mega dylib handle
-	else if ( dyld::isCacheHandle(handle) ) {
-		result = dyld::dlsymFromCache(handle, underscoredName, 0);
-		if ( dyld::gLogAPIs )
-			dyld::log("  %s(%p, %s) ==> %p\n", __func__, handle, symbolName, result);
-		return result;
-	}
-#endif
 	// real handle
 	image = (ImageLoader*)(((uintptr_t)handle) & (-4));	// clear mode bits
 	if ( dyld::validImage(image) ) {
@@ -1874,10 +1740,7 @@
 				void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue
 				callerImage = dyld::findImageContainingAddress(callerAddress);
 			}
-			result = (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext, callerImage, false, underscoredName);
-			if ( dyld::gLogAPIs )
-				dyld::log("  %s(%p, %s) ==> %p\n", __func__, handle, symbolName, result);
-			return result;
+			return (void*)image->getExportedSymbolAddress(sym, dyld::gLinkContext, callerImage);
 		}
 		const char* str = dyld::mkstringf("dlsym(%p, %s): symbol not found", handle, symbolName);
 		dlerrorSet(str);
@@ -1887,8 +1750,6 @@
 		dlerrorSet("invalid handle passed to dlsym()");
 	}
 	CRSetCrashLogMessage(NULL);
-	if ( dyld::gLogAPIs )
-		dyld::log("  %s(%p, %s) ==> NULL\n", __func__, handle, symbolName);
 	return NULL;
 }
 
@@ -1905,7 +1766,6 @@
 {
 	return dyld::gProcessInfo;
 }
-
 
 #if SUPPORT_ZERO_COST_EXCEPTIONS
 static bool client_dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info)
@@ -1913,10 +1773,6 @@
 	//if ( dyld::gLogAPIs )
 	//	dyld::log("%s(%p, %p)\n", __func__, addr, info);
 	
-#if SUPPORT_ACCELERATE_TABLES
-	if ( dyld::findUnwindSections(addr, info) )
-		return true;
-#endif
 	ImageLoader* image = dyld::findImageContainingAddress(addr);
 	if ( image != NULL ) {
 		image->getUnwindInfo(info);
@@ -1927,17 +1783,21 @@
 #endif
 
 
+void dyld_register_image_state_change_handler(dyld_image_states state, bool batch, 
+											dyld_image_state_change_handler handler)
+{
+	if ( dyld::gLogAPIs )
+		dyld::log("%s(%d, %d, %p)\n", __func__, state, batch, handler);
+	if ( batch )
+		dyld::registerImageStateBatchChangeHandler(state, handler);
+	else
+		dyld::registerImageStateSingleChangeHandler(state, handler);
+}
+
 const char* dyld_image_path_containing_address(const void* address)
 {
 	if ( dyld::gLogAPIs )
 		dyld::log("%s(%p)\n", __func__, address);
-
-#if SUPPORT_ACCELERATE_TABLES
-	const mach_header* mh;
-	const char* path;
-	if ( dyld::addressInCache(address, &mh, &path) )
-		return path;
-#endif
 
 	ImageLoader* image = dyld::findImageContainingAddress(address);
 	if ( image != NULL )
@@ -1983,52 +1843,4 @@
 }
 
 
-bool _dyld_is_memory_immutable(const void* addr, size_t length)
-{
-	if ( dyld::gLogAPIs )
-		dyld::log("%s(%p, %ld)\n", __func__, addr, length);
-
-	uintptr_t checkStart = (uintptr_t)addr;
-	uintptr_t checkEnd   = checkStart + length;
-
-#if DYLD_SHARED_CACHE_SUPPORT
-	// quick check to see if in r/o region of shared cache.  If so return true.
-	if ( dyld_shared_cache_ranges.sharedRegionsCount > 2 ) {
-		uintptr_t roStart    = dyld_shared_cache_ranges.ranges[0].start;
-		uintptr_t roEnd      = roStart + dyld_shared_cache_ranges.ranges[0].length;
-		if ( (roStart < checkStart) && (checkEnd < roEnd) )
-			return true;
-	}
-#endif
-
-	// Otherwise find if addr is in a dyld loaded image
-	ImageLoader* image = dyld::findImageContainingAddress(addr);
-	if ( image != NULL ) {
-		// <rdar://problem/24091154> already checked for r/o portion of cache
-		if ( image->inSharedCache() )
-			return false;
-		if ( !image->neverUnload() )
-			return false;
-		for (unsigned i=0, e=image->segmentCount(); i < e; ++i) {
-			if ( (image->segActualLoadAddress(i) < checkStart) && (checkEnd < image->segActualEndAddress(i)) ) {
-				return !image->segWriteable(i);
-			}
-		}
-	}
-	return false;
-}
-
-
-
-void _dyld_objc_notify_register(_dyld_objc_notify_mapped    mapped,
-                                _dyld_objc_notify_init      init,
-                                _dyld_objc_notify_unmapped  unmapped)
-{
-	dyld::registerObjCNotifiers(mapped, init, unmapped);
-}
-
-
-bool _dyld_get_shared_cache_uuid(uuid_t uuid)
-{
-	return dyld::sharedCacheUUID(uuid);
-}
+