Loading...
src/dyld.cpp dyld-44.2 dyld-43.1
--- dyld/dyld-44.2/src/dyld.cpp
+++ dyld/dyld-43.1/src/dyld.cpp
@@ -116,7 +116,6 @@
 static cpu_type_t					sHostCPU;
 static cpu_subtype_t				sHostCPUsubtype;
 static ImageLoader*					sMainExecutable = NULL;
-static bool							sAllImagesMightContainUnlinkedImages;	 // necessary until will support dylib unloading
 static std::vector<ImageLoader*>	sAllImages;
 static std::vector<ImageLoader*>	sImageRoots;
 static std::vector<ImageLoader*>	sImageFilesNeedingTermination;
@@ -653,7 +652,7 @@
 	}
 }
 
-static void checkEnvironmentVariables(const char* envp[], bool ignoreEnviron)
+static void checkEnvironmentVariables(const char* envp[])
 {
 	const char* home = NULL;
 	const char** p;
@@ -661,7 +660,7 @@
 		const char* keyEqualsValue = *p;
 	    if ( strncmp(keyEqualsValue, "DYLD_", 5) == 0 ) {
 			const char* equals = strchr(keyEqualsValue, '=');
-			if ( (equals != NULL) && !ignoreEnviron ) {
+			if ( equals != NULL ) {
 				const char* value = &equals[1];
 				const int keyLen = equals-keyEqualsValue;
 				char key[keyLen+1];
@@ -742,36 +741,15 @@
 
 uint32_t getImageCount()
 {
-	if ( sAllImagesMightContainUnlinkedImages ) {
-		uint32_t count = 0;
-		for (std::vector<ImageLoader*>::iterator it=sAllImages.begin(); it != sAllImages.end(); it++) {
-			if ( (*it)->isLinked() )
-				++count;
-		}
-		return count;
-	}
-	else {
-		return sAllImages.size();
-	}
+	return sAllImages.size();
 }
 
 ImageLoader* getIndexedImage(unsigned int index)
 {
-	if ( sAllImagesMightContainUnlinkedImages ) {
-		uint32_t count = 0;
-		for (std::vector<ImageLoader*>::iterator it=sAllImages.begin(); it != sAllImages.end(); it++) {
-			if ( (*it)->isLinked() ) {
-				if ( index == count )
-					return *it;
-				++count;
-			}
-		}
-	}
-	else {
-		if ( index < sAllImages.size() )
-			return sAllImages[index];
-	}
-	return NULL;
+	if ( index < sAllImages.size() )
+		return sAllImages[index];
+	else
+		return NULL;
 }
 
 ImageLoader* findImageByMachHeader(const struct mach_header* target)
@@ -1174,7 +1152,7 @@
 			pread(fd, firstPage, 4096, fileOffset);
 		}
 		else {
-			throw "no matching architecture in universal wrapper";
+			throw "no matching architecture in fat wrapper";
 		}
 	}
 	
@@ -1457,8 +1435,8 @@
 	if ( image != NULL )
 		return image;
 	
-	// try fallback paths during second time (will open file)
-	if ( (exceptions != NULL) && ((sEnv.DYLD_FALLBACK_FRAMEWORK_PATH != NULL) || (sEnv.DYLD_FALLBACK_LIBRARY_PATH != NULL)) ) {
+	// try fallback paths
+	if ( (sEnv.DYLD_FALLBACK_FRAMEWORK_PATH != NULL) || (sEnv.DYLD_FALLBACK_LIBRARY_PATH != NULL) ) {
 		image = loadPhase2(path, context, sEnv.DYLD_FALLBACK_FRAMEWORK_PATH, sEnv.DYLD_FALLBACK_LIBRARY_PATH, exceptions);
 		if ( image != NULL )
 			return image;
@@ -1583,20 +1561,6 @@
 
 ImageLoader* loadFromMemory(const uint8_t* mem, uint64_t len, const char* moduleName)
 {
-	// if fat wrapper, find usable sub-file
-	const fat_header* memStartAsFat = (fat_header*)mem;
-	uint64_t fileOffset = 0;
-	uint64_t fileLength = len;
-	if ( memStartAsFat->magic == OSSwapBigToHostInt32(FAT_MAGIC) ) {
-		if ( fatFindBest(memStartAsFat, &fileOffset, &fileLength) ) {
-			mem = &mem[fileOffset];
-			len = fileLength;
-		}
-		else {
-			throw "no matching architecture in universal wrapper";
-		}
-	}
-
 	// try mach-o each loader
 	if ( isCompatibleMachO(mem) ) {
 		ImageLoader* image = new ImageLoaderMachO(moduleName, (mach_header*)mem, len, gLinkContext);
@@ -1865,23 +1829,7 @@
 	gLinkContext.apple					= apple;
 }
 
-static bool checkEmulation()
-{
-#if __i386__
-	int mib[] = { CTL_KERN, KERN_CLASSIC, getpid() };
-	int is_classic = 0;
-	size_t len = sizeof(int);
-	int ret = sysctl(mib, 3, &is_classic, &len, NULL, 0);
-	if ((ret != -1) && is_classic) {
-		// When a 32-bit ppc program is run under emulation on an Intel processor,
-		// we want any i386 dylibs (e.g. the emulator) to not load in the shared region
-		// because the shared region is being used by ppc dylibs
-		gLinkContext.sharedRegionMode = ImageLoader::kDontUseSharedRegion;
-		return true;
-	}
-#endif
-	return false;
-}
+
 
 void link(ImageLoader* image, ImageLoader::BindingLaziness bindness, ImageLoader::InitializerRunning runInitializers)
 {
@@ -1903,13 +1851,7 @@
 	}
 
 	// process images
-	try {
-		image->link(gLinkContext, bindness, runInitializers, sAddImageCallbacks.size());
-	}
-	catch (const char* msg) {
-		sAllImagesMightContainUnlinkedImages = true;
-		throw msg;
-	}
+	image->link(gLinkContext, bindness, runInitializers, sAddImageCallbacks.size());
 	
 #if OLD_GDB_DYLD_INTERFACE
 	// notify gdb that loaded libraries have changed
@@ -1943,8 +1885,7 @@
 	}
 	uintptr_t result = 0;
 	sMainExecutableMachHeader = mainExecutableMH;
-	bool isEmulated = checkEmulation();
-	checkEnvironmentVariables(envp, isEmulated);
+	checkEnvironmentVariables(envp);
 	if ( sEnv.DYLD_PRINT_OPTS ) 
 		printOptions(argv);
 	if ( sEnv.DYLD_PRINT_ENV )