Loading...
--- dyld/dyld-852.2/src/ImageLoaderMachOClassic.cpp
+++ dyld/dyld-551.4/src/ImageLoaderMachOClassic.cpp
@@ -43,7 +43,6 @@
#include <sys/sysctl.h>
#include <libkern/OSAtomic.h>
#include <libkern/OSCacheControl.h>
-#include <mach-o/dyld_images.h>
#if __x86_64__
#include <mach-o/x86_64/reloc.h>
@@ -53,6 +52,7 @@
#endif
#include "ImageLoaderMachOClassic.h"
+#include "mach-o/dyld_images.h"
// in dyldStartup.s
extern "C" void stub_binding_helper_i386_old();
@@ -168,6 +168,11 @@
// make sure path is stable before recording in dyld_all_image_infos
image->setMapped(context);
+ // pre-fetch content of __DATA segment for faster launches
+ // don't do this on prebound images or if prefetching is disabled
+ if ( !context.preFetchDisabled && !image->isPrebindable())
+ image->preFetchDATA(fd, offsetInFat, context);
+
}
catch (...) {
// ImageLoader::setMapped() can throw an exception to block loading of image
@@ -331,6 +336,41 @@
fDynamicInfo = dynSym;
}
+void ImageLoaderMachOClassic::prefetchLINKEDIT(const LinkContext& context)
+{
+ // always prefetch a subrange of __LINKEDIT pages
+ uintptr_t symbolTableStart = (uintptr_t)fSymbolTable;
+ uintptr_t stringTableStart = (uintptr_t)fStrings;
+ uintptr_t start;
+ // if image did not load at preferred address
+ if ( segPreferredLoadAddress(0) != (uintptr_t)fMachOData ) {
+ // local relocations will be processed, so start pre-fetch at local symbols
+ start = (uintptr_t)fMachOData + fDynamicInfo->locreloff;
+ }
+ else {
+ // otherwise start pre-fetch at global symbols section of symbol table
+ start = symbolTableStart + fDynamicInfo->iextdefsym * sizeof(macho_nlist);
+ }
+ // prefetch ends at end of last undefined string in string pool
+ uintptr_t end = stringTableStart;
+ if ( fDynamicInfo->nundefsym != 0 )
+ end += fSymbolTable[fDynamicInfo->iundefsym+fDynamicInfo->nundefsym-1].n_un.n_strx;
+ else if ( fDynamicInfo->nextdefsym != 0 )
+ end += fSymbolTable[fDynamicInfo->iextdefsym+fDynamicInfo->nextdefsym-1].n_un.n_strx;
+
+ // round to whole pages
+ start = dyld_page_trunc(start);
+ end = dyld_page_round(end);
+
+ // skip if there is only one page
+ if ( (end-start) > dyld_page_size ) {
+ madvise((void*)start, end-start, MADV_WILLNEED);
+ fgTotalBytesPreFetched += (end-start);
+ if ( context.verboseMapping ) {
+ dyld::log("%18s prefetching 0x%0lX -> 0x%0lX\n", "__LINKEDIT", start, end-1);
+ }
+ }
+}
#if SPLIT_SEG_DYLIB_SUPPORT
@@ -561,13 +601,11 @@
return true;
if ( context.imageSuffix != NULL ) {
// when DYLD_IMAGE_SUFFIX is used, lastSlash string needs imageSuffix removed from end
- for(const char* const* suffix = context.imageSuffix; *suffix != NULL; ++suffix) {
- char reexportAndSuffix[strlen(*suffix)+strlen(exportThruName)+1];
- strcpy(reexportAndSuffix, exportThruName);
- strcat(reexportAndSuffix, *suffix);
- if ( strcmp(&lastSlash[1], reexportAndSuffix) == 0 )
- return true;
- }
+ char reexportAndSuffix[strlen(context.imageSuffix)+strlen(exportThruName)+1];
+ strcpy(reexportAndSuffix, exportThruName);
+ strcat(reexportAndSuffix, context.imageSuffix);
+ if ( strcmp(&lastSlash[1], reexportAndSuffix) == 0 )
+ return true;
}
}
}
@@ -609,13 +647,11 @@
return true;
if ( context.imageSuffix != NULL ) {
// when DYLD_IMAGE_SUFFIX is used, childLeafName string needs imageSuffix removed from end
- for(const char* const* suffix = context.imageSuffix; *suffix != NULL; ++suffix) {
- char aSubLibNameAndSuffix[strlen(*suffix)+strlen(aSubLibName)+1];
- strcpy(aSubLibNameAndSuffix, aSubLibName);
- strcat(aSubLibNameAndSuffix, *suffix);
- if ( strcmp(aSubLibNameAndSuffix, childLeafName) == 0 )
- return true;
- }
+ char aSubLibNameAndSuffix[strlen(context.imageSuffix)+strlen(aSubLibName)+1];
+ strcpy(aSubLibNameAndSuffix, aSubLibName);
+ strcat(aSubLibNameAndSuffix, context.imageSuffix);
+ if ( strcmp(aSubLibNameAndSuffix, childLeafName) == 0 )
+ return true;
}
}
break;
@@ -644,13 +680,11 @@
return true;
if ( context.imageSuffix != NULL ) {
// when DYLD_IMAGE_SUFFIX is used, lastSlash string needs imageSuffix removed from end
- for(const char* const* suffix = context.imageSuffix; *suffix != NULL; ++suffix) {
- char umbrellaAndSuffix[strlen(*suffix)+strlen(aSubUmbrellaName)+1];
- strcpy(umbrellaAndSuffix, aSubUmbrellaName);
- strcat(umbrellaAndSuffix, *suffix);
- if ( strcmp(umbrellaAndSuffix, &lastSlash[1]) == 0 )
- return true;
- }
+ char umbrellaAndSuffix[strlen(context.imageSuffix)+strlen(aSubUmbrellaName)+1];
+ strcpy(umbrellaAndSuffix, aSubUmbrellaName);
+ strcat(umbrellaAndSuffix, context.imageSuffix);
+ if ( strcmp(umbrellaAndSuffix, &lastSlash[1]) == 0 )
+ return true;
}
}
break;
@@ -727,7 +761,11 @@
{
CRSetCrashLogMessage2(this->getPath());
const uintptr_t relocBase = this->getRelocBase();
-
+
+ // prefetch any LINKEDIT pages needed
+ if ( !context.preFetchDisabled && !this->isPrebindable())
+ this->prefetchLINKEDIT(context);
+
// loop through all local (internal) relocation records
const relocation_info* const relocsStart = (struct relocation_info*)(&fLinkEditBase[fDynamicInfo->locreloff]);
const relocation_info* const relocsEnd = &relocsStart[fDynamicInfo->nlocrel];
@@ -1045,7 +1083,7 @@
// symbol requires searching images with coalesced symbols (not done during prebinding)
if ( !context.prebinding && !dontCoalesce && (symbolIsWeakReference(undefinedSymbol) || symbolIsWeakDefinition(undefinedSymbol)) ) {
const Symbol* sym;
- if ( context.coalescedExportFinder(symbolName, &sym, foundIn, nullptr) ) {
+ if ( context.coalescedExportFinder(symbolName, &sym, foundIn) ) {
if ( *foundIn != this )
context.addDynamicReference(this, const_cast<ImageLoader*>(*foundIn));
return (*foundIn)->getExportedSymbolAddress(sym, context, this);
@@ -1234,7 +1272,7 @@
lastUndefinedSymbol = undefinedSymbol;
symbolAddrCached = false;
}
- if ( context.verboseBind && (undefinedSymbol != NULL) ) {
+ if ( context.verboseBind ) {
const char *path = NULL;
if ( image != NULL ) {
path = image->getShortName();
@@ -1351,8 +1389,7 @@
throw "compressed LINKEDIT lazy binder called with classic LINKEDIT";
}
-uintptr_t ImageLoaderMachOClassic::doBindLazySymbol(uintptr_t* lazyPointer, const LinkContext& context,
- DyldSharedCache::DataConstLazyScopedWriter& patcher)
+uintptr_t ImageLoaderMachOClassic::doBindLazySymbol(uintptr_t* lazyPointer, const LinkContext& context)
{
// scan for all lazy-pointer sections
const bool twoLevel = this->usesTwoLevelNameSpace();
@@ -1606,7 +1643,7 @@
if ( reloc->r_pcrel )
type = BIND_TYPE_TEXT_PCREL32;
#endif
- this->bindLocation(context, this->imageBaseAddress(), (uintptr_t)location, value, type, symbolName, addend, this->getPath(), targetImage ? targetImage->getPath() : NULL, "weak ", NULL, fSlide);
+ this->bindLocation(context, (uintptr_t)location, value, type, symbolName, addend, this->getPath(), targetImage ? targetImage->getPath() : NULL, "weak ");
boundSomething = true;
}
}
@@ -1629,7 +1666,6 @@
if ( ((sect->flags & S_ATTR_SELF_MODIFYING_CODE) ==0) || (sect->reserved2 != 5) )
continue;
elementSize = 5;
- [[clang::fallthrough]];
#endif
case S_NON_LAZY_SYMBOL_POINTERS:
case S_LAZY_SYMBOL_POINTERS:
@@ -1763,7 +1799,7 @@
}
uintptr_t symbolAddr = resolveUndefined(context, sym, twoLevel, dontCoalesce, false, &image);
// update pointer
- this->bindIndirectSymbol((uintptr_t*)ptrToBind, sect, &fStrings[sym->n_un.n_strx], symbolAddr, image, context);
+ symbolAddr = this->bindIndirectSymbol((uintptr_t*)ptrToBind, sect, &fStrings[sym->n_un.n_strx], symbolAddr, image, context);
// update stats
++fgTotalBindFixups;
}
@@ -1853,7 +1889,7 @@
#endif // __i386__
-void ImageLoaderMachOClassic::doBind(const LinkContext& context, bool forceLazysBound, const ImageLoader* reExportParent)
+void ImageLoaderMachOClassic::doBind(const LinkContext& context, bool forceLazysBound)
{
CRSetCrashLogMessage2(this->getPath());
#if __i386__
@@ -1895,7 +1931,7 @@
CRSetCrashLogMessage2(NULL);
}
-void ImageLoaderMachOClassic::doBindJustLazies(const LinkContext& context, DyldSharedCache::DataConstLazyScopedWriter& patcher)
+void ImageLoaderMachOClassic::doBindJustLazies(const LinkContext& context)
{
// some API called requested that all lazy pointers in this image be force bound
this->bindIndirectSymbolPointers(context, false, true);