Loading...
src/ImageLoader.cpp dyld-832.7.1 dyld-733.8
--- dyld/dyld-832.7.1/src/ImageLoader.cpp
+++ dyld/dyld-733.8/src/ImageLoader.cpp
@@ -84,9 +84,6 @@
 	fPathOwnedByImage(false), fIsReferencedDownward(false), 
 	fWeakSymbolsBound(false)
 {
-#if __x86_64__
-	fAotPath = NULL;
-#endif
 	if ( fPath != NULL )
 		fPathHash = hash(fPath);
 	if ( libCount > 512 )
@@ -106,10 +103,6 @@
 		delete [] fRealPath;
 	if ( fPathOwnedByImage && (fPath != NULL) ) 
 		delete [] fPath;
-#if __x86_64__
-	if ( fAotPath != NULL )
-		delete [] fAotPath;
-#endif
 }
 
 void ImageLoader::setFileInfo(dev_t device, ino_t inode, time_t modDate)
@@ -409,8 +402,10 @@
 void ImageLoader::applyInterposingToDyldCache(const LinkContext& context) {
 	if (!context.dyldCache)
 		return;
+#if !__arm64e__ // until arm64e cache builder sets builtFromChainedFixups
 	if (!context.dyldCache->header.builtFromChainedFixups)
 		return;
+#endif
 	if (fgInterposingTuples.empty())
 		return;
 	// For each of the interposed addresses, see if any of them are in the shared cache.  If so, find
@@ -480,7 +475,7 @@
 // <rdar://problem/29099600> dyld should tell the kernel when it is doing root fix-ups
 void ImageLoader::vmAccountingSetSuspended(const LinkContext& context, bool suspend)
 {
-#if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
+#if __arm__ || __arm64__
 	static bool sVmAccountingSuspended = false;
 	if ( suspend == sVmAccountingSuspended )
 		return;
@@ -515,7 +510,7 @@
 
 	uint64_t t1 = mach_absolute_time();
 	context.clearAllDepths();
-	this->updateDepth(context.imageCount());
+	this->recursiveUpdateDepth(context.imageCount());
 
 	__block uint64_t t2, t3, t4, t5;
 	{
@@ -669,19 +664,7 @@
 	
 }
 
-unsigned int ImageLoader::updateDepth(unsigned int maxDepth)
-{
-	STACK_ALLOC_ARRAY(ImageLoader*, danglingUpwards, maxDepth);
-	unsigned int depth = this->recursiveUpdateDepth(maxDepth, danglingUpwards);
-	for (auto& danglingUpward : danglingUpwards) {
-		if ( danglingUpward->fDepth != 0)
-			continue;
-		danglingUpward->recursiveUpdateDepth(maxDepth, danglingUpwards);
-	}
-	return depth;
-}
-
-unsigned int ImageLoader::recursiveUpdateDepth(unsigned int maxDepth, dyld3::Array<ImageLoader*>& danglingUpwards)
+unsigned int ImageLoader::recursiveUpdateDepth(unsigned int maxDepth)
 {
 	// the purpose of this phase is to make the images sortable such that 
 	// in a sort list of images, every image that an image depends on
@@ -694,29 +677,17 @@
 		unsigned int minDependentDepth = maxDepth;
 		for(unsigned int i=0; i < libraryCount(); ++i) {
 			ImageLoader* dependentImage = libImage(i);
-			if ( dependentImage != NULL ) {
-				if ( libIsUpward(i) ) {
-					if ( dependentImage->fDepth == 0) {
-						if ( !danglingUpwards.contains(dependentImage) )
-							danglingUpwards.push_back(dependentImage);
-					}
-				} else {
-					unsigned int d = dependentImage->recursiveUpdateDepth(maxDepth, danglingUpwards);
-					if ( d < minDependentDepth )
-						minDependentDepth = d;
-				}
-			}
-			// <rdar://problem/60878811> make sure need to re-bind propagates up
-			if ( dependentImage != NULL ) {
-				if ( fAllLibraryChecksumsAndLoadAddressesMatch && !dependentImage->fAllLibraryChecksumsAndLoadAddressesMatch ) {
-					fAllLibraryChecksumsAndLoadAddressesMatch = false;
-				}
-			}
-		}
+			if ( (dependentImage != NULL) && !libIsUpward(i) ) {
+				unsigned int d = dependentImage->recursiveUpdateDepth(maxDepth);
+				if ( d < minDependentDepth )
+					minDependentDepth = d;
+			}
+		}
+	
 		// make me less deep then all my dependents
 		fDepth = minDependentDepth - 1;
-
-	}
+	}
+	
 	return fDepth;
 }
 
@@ -828,21 +799,22 @@
 		// tell each to load its dependents
 		for(unsigned int i=0; i < libraryCount(); ++i) {
 			ImageLoader* dependentImage = libImage(i);
-			if ( dependentImage != NULL ) {
+			if ( dependentImage != NULL ) {	
 				dependentImage->recursiveLoadLibraries(context, preflightOnly, thisRPaths, libraryInfos[i].name);
 			}
 		}
+		
 		// do deep prebind check
 		if ( fAllLibraryChecksumsAndLoadAddressesMatch ) {
 			for(unsigned int i=0; i < libraryCount(); ++i){
 				ImageLoader* dependentImage = libImage(i);
-				if ( dependentImage != NULL ) {
+				if ( dependentImage != NULL ) {	
 					if ( !dependentImage->allDependentLibrariesAsWhenPreBound() )
 						fAllLibraryChecksumsAndLoadAddressesMatch = false;
 				}
 			}
 		}
-
+		
 		// free rpaths (getRPaths() malloc'ed each string)
 		for(std::vector<const char*>::iterator it=rpathsFromThisImage.begin(); it != rpathsFromThisImage.end(); ++it) {
 			const char* str = *it;
@@ -940,11 +912,11 @@
 
 void ImageLoader::recursiveBindWithAccounting(const LinkContext& context, bool forceLazysBound, bool neverUnload)
 {
-	this->recursiveBind(context, forceLazysBound, neverUnload, nullptr);
+	this->recursiveBind(context, forceLazysBound, neverUnload);
 	vmAccountingSetSuspended(context, false);
 }
 
-void ImageLoader::recursiveBind(const LinkContext& context, bool forceLazysBound, bool neverUnload, const ImageLoader* parent)
+void ImageLoader::recursiveBind(const LinkContext& context, bool forceLazysBound, bool neverUnload)
 {
 	// Normally just non-lazy pointers are bound immediately.
 	// The exceptions are:
@@ -958,15 +930,11 @@
 			// bind lower level libraries first
 			for(unsigned int i=0; i < libraryCount(); ++i) {
 				ImageLoader* dependentImage = libImage(i);
-				if ( dependentImage != NULL )  {
-					const ImageLoader* reExportParent = nullptr;
-					if ( libReExported(i) )
-						reExportParent = this;
-					dependentImage->recursiveBind(context, forceLazysBound, neverUnload, reExportParent);
-				}
+				if ( dependentImage != NULL )
+					dependentImage->recursiveBind(context, forceLazysBound, neverUnload);
 			}
 			// bind this image
-			this->doBind(context, forceLazysBound, parent);
+			this->doBind(context, forceLazysBound);	
 			// mark if lazys are also bound
 			if ( forceLazysBound || this->usablePrebinding(context) )
 				fAllLazyPointersBound = true;
@@ -1044,7 +1012,7 @@
 			new (&context.weakDefMap) dyld3::Map<const char*, std::pair<const ImageLoader*, uintptr_t>, ImageLoader::HashCString, ImageLoader::EqualCString>();
 			context.weakDefMapInitialized = true;
 		}
-#if TARGET_OS_OSX
+#if __MAC_OS_X_VERSION_MIN_REQUIRED
 	  // only do alternate algorithm for dlopen(). Use traditional algorithm for launch
 	  if ( !context.linkingMainExecutable ) {
 		  // Don't take the memory hit of weak defs on the launch path until we hit a dlopen with more weak symbols to bind
@@ -1064,8 +1032,8 @@
 
 				  Diagnostics diag;
 				  const dyld3::MachOAnalyzer* ma = (const dyld3::MachOAnalyzer*)image->machHeader();
-				  ma->forEachWeakDef(diag, ^(const char *symbolName, uint64_t imageOffset, bool isFromExportTrie) {
-					  uintptr_t targetAddr = (uintptr_t)ma + (uintptr_t)imageOffset;
+				  ma->forEachWeakDef(diag, ^(const char *symbolName, uintptr_t imageOffset, bool isFromExportTrie) {
+					  uintptr_t targetAddr = (uintptr_t)ma + imageOffset;
 					  if ( isFromExportTrie ) {
 						  // Avoid duplicating the string if we already have the symbol name
 						  if ( context.weakDefMap.find(symbolName) != context.weakDefMap.end() )
@@ -1087,8 +1055,8 @@
 				  continue;
 			  Diagnostics diag;
 			  const dyld3::MachOAnalyzer* ma = (const dyld3::MachOAnalyzer*)image->machHeader();
-			  ma->forEachWeakDef(diag, ^(const char *symbolName, uint64_t imageOffset, bool isFromExportTrie) {
-				  uintptr_t targetAddr = (uintptr_t)ma + (uintptr_t)imageOffset;
+			  ma->forEachWeakDef(diag, ^(const char *symbolName, uintptr_t imageOffset, bool isFromExportTrie) {
+				  uintptr_t targetAddr = (uintptr_t)ma + imageOffset;
 				  if ( isFromExportTrie ) {
 					  // Avoid duplicating the string if we already have the symbol name
 					  if ( context.weakDefMap.find(symbolName) != context.weakDefMap.end() )
@@ -1167,7 +1135,7 @@
 		}
 	  }
 	  else
-#endif // TARGET_OS_OSX
+#endif // __MAC_OS_X_VERSION_MIN_REQUIRED
 	  {
 		// make symbol iterators for each
 		ImageLoader::CoalIterator iterators[count];
@@ -1331,7 +1299,7 @@
 
 	// don't need to do any coalescing if only one image has overrides, or all have already been done
 	if ( (countOfImagesWithWeakDefinitionsNotInSharedCache > 0) && (countNotYetWeakBound > 0) ) {
-#if TARGET_OS_OSX
+#if __MAC_OS_X_VERSION_MIN_REQUIRED
 	  // only do alternate algorithm for dlopen(). Use traditional algorithm for launch
 	  if ( !context.linkingMainExecutable ) {
 		// for all images that need weak binding
@@ -1392,7 +1360,7 @@
 		}
 	  }
 	  else
-#endif // TARGET_OS_OSX
+#endif // __MAC_OS_X_VERSION_MIN_REQUIRED
 	  {
 		// make symbol iterators for each
 		ImageLoader::CoalIterator iterators[count];
@@ -1915,25 +1883,11 @@
 		bit += 7;
 	} while (byte & 0x80);
 	// sign extend negative numbers
-	if ( ((byte & 0x40) != 0) && (bit < 64) )
+	if ( (byte & 0x40) != 0 )
 		result |= (~0ULL) << bit;
 	return (intptr_t)result;
 }
 
-void ImageLoader::forEachReExportDependent( void (^callback)(const ImageLoader*, bool& stop)) const
-{
-	bool stop = false;
-	for (unsigned int i=0; i < libraryCount(); ++i) {
-		if ( libReExported(i) ) {
-			if ( ImageLoader* dependentImage = libImage(i) ) {
-				callback(dependentImage, stop);
-			}
-		}
-		if (stop)
-			break;
-	}
-}
-
 
 VECTOR_NEVER_DESTRUCTED_IMPL(ImageLoader::InterposeTuple);
 VECTOR_NEVER_DESTRUCTED_IMPL(ImagePair);