]> git.saurik.com Git - apple/dyld.git/blobdiff - src/ImageLoaderMachOClassic.cpp
dyld-635.2.tar.gz
[apple/dyld.git] / src / ImageLoaderMachOClassic.cpp
index fa71b097f281b3a50c59a45601b89f9a30e11ddf..70068cdd12b7dd3c672269ae008cf385dad1b68e 100644 (file)
@@ -436,14 +436,14 @@ ImageLoaderMachOClassic::mapSplitSegDylibOutsideSharedRegion(int fd,
        while ( ! foundRoom ) {
                foundRoom = true;
                for(unsigned int i=0; i < regionCount; ++i) {
        while ( ! foundRoom ) {
                foundRoom = true;
                for(unsigned int i=0; i < regionCount; ++i) {
-                       vm_address_t addr = nextAltLoadAddress + regions[i].sfm_address - regions[0].sfm_address;
-                       vm_size_t size = regions[i].sfm_size ;
+                       vm_address_t addr = (vm_address_t)(nextAltLoadAddress + regions[i].sfm_address - regions[0].sfm_address);
+                       vm_size_t size = (vm_size_t)regions[i].sfm_size ;
                        r = vm_allocate(mach_task_self(), &addr, size, false /*only this range*/);
                        if ( 0 != r ) {
                                // no room here, deallocate what has succeeded so far
                                for(unsigned int j=0; j < i; ++j) {
                        r = vm_allocate(mach_task_self(), &addr, size, false /*only this range*/);
                        if ( 0 != r ) {
                                // no room here, deallocate what has succeeded so far
                                for(unsigned int j=0; j < i; ++j) {
-                                       addr = nextAltLoadAddress + regions[j].sfm_address - regions[0].sfm_address;
-                                       size = regions[j].sfm_size ;
+                                       addr = (vm_address_t)(nextAltLoadAddress + regions[j].sfm_address - regions[0].sfm_address);
+                                       size = (vm_size_t)(regions[j].sfm_size);
                                        (void)vm_deallocate(mach_task_self(), addr, size);
                                }
                                nextAltLoadAddress += 0x00100000;  // skip ahead 1MB and try again
                                        (void)vm_deallocate(mach_task_self(), addr, size);
                                }
                                nextAltLoadAddress += 0x00100000;  // skip ahead 1MB and try again
@@ -459,7 +459,7 @@ ImageLoaderMachOClassic::mapSplitSegDylibOutsideSharedRegion(int fd,
        }
        
        // map in each region
        }
        
        // map in each region
-       uintptr_t slide = nextAltLoadAddress - regions[0].sfm_address;
+       uintptr_t slide = (uintptr_t)(nextAltLoadAddress - regions[0].sfm_address);
        this->setSlide(slide);
        for(unsigned int i=0; i < regionCount; ++i) {
                if ( ((regions[i].sfm_init_prot & VM_PROT_ZF) != 0) || (regions[i].sfm_size == 0) ) {
        this->setSlide(slide);
        for(unsigned int i=0; i < regionCount; ++i) {
                if ( ((regions[i].sfm_init_prot & VM_PROT_ZF) != 0) || (regions[i].sfm_size == 0) ) {
@@ -467,7 +467,7 @@ ImageLoaderMachOClassic::mapSplitSegDylibOutsideSharedRegion(int fd,
                }
                else {
                        void* mmapAddress = (void*)(uintptr_t)(regions[i].sfm_address + slide);
                }
                else {
                        void* mmapAddress = (void*)(uintptr_t)(regions[i].sfm_address + slide);
-                       size_t size = regions[i].sfm_size;
+                       size_t size = (size_t)regions[i].sfm_size;
                        int protection = 0;
                        if ( regions[i].sfm_init_prot & VM_PROT_EXECUTE )
                                protection   |= PROT_EXEC;
                        int protection = 0;
                        if ( regions[i].sfm_init_prot & VM_PROT_EXECUTE )
                                protection   |= PROT_EXEC;
@@ -601,11 +601,13 @@ bool ImageLoaderMachOClassic::isSubframeworkOf(const LinkContext& context, const
                                                        return true;
                                                if ( context.imageSuffix != NULL ) {
                                                        // when DYLD_IMAGE_SUFFIX is used, lastSlash string needs imageSuffix removed from end
                                                        return true;
                                                if ( context.imageSuffix != NULL ) {
                                                        // when DYLD_IMAGE_SUFFIX is used, lastSlash string needs imageSuffix removed from end
-                                                       char reexportAndSuffix[strlen(context.imageSuffix)+strlen(exportThruName)+1];
-                                                       strcpy(reexportAndSuffix, exportThruName);
-                                                       strcat(reexportAndSuffix, context.imageSuffix);
-                                                       if ( strcmp(&lastSlash[1], reexportAndSuffix) == 0 )
-                                                               return true;
+                                                       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;
+                                                       }
                                                }
                                        }
                                }
                                                }
                                        }
                                }
@@ -647,11 +649,13 @@ bool ImageLoaderMachOClassic::hasSubLibrary(const LinkContext& context, const Im
                                                                        return true;
                                                                if ( context.imageSuffix != NULL ) {
                                                                        // when DYLD_IMAGE_SUFFIX is used, childLeafName string needs imageSuffix removed from end
                                                                        return true;
                                                                if ( context.imageSuffix != NULL ) {
                                                                        // when DYLD_IMAGE_SUFFIX is used, childLeafName string needs imageSuffix removed from end
-                                                                       char aSubLibNameAndSuffix[strlen(context.imageSuffix)+strlen(aSubLibName)+1];
-                                                                       strcpy(aSubLibNameAndSuffix, aSubLibName);
-                                                                       strcat(aSubLibNameAndSuffix, context.imageSuffix);
-                                                                       if ( strcmp(aSubLibNameAndSuffix, childLeafName) == 0 )
-                                                                               return true;
+                                                                       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;
+                                                                       }
                                                                }
                                                        }
                                                        break;
                                                                }
                                                        }
                                                        break;
@@ -680,11 +684,13 @@ bool ImageLoaderMachOClassic::hasSubLibrary(const LinkContext& context, const Im
                                                                        return true;
                                                                if ( context.imageSuffix != NULL ) {
                                                                        // when DYLD_IMAGE_SUFFIX is used, lastSlash string needs imageSuffix removed from end
                                                                        return true;
                                                                if ( context.imageSuffix != NULL ) {
                                                                        // when DYLD_IMAGE_SUFFIX is used, lastSlash string needs imageSuffix removed from end
-                                                                       char umbrellaAndSuffix[strlen(context.imageSuffix)+strlen(aSubUmbrellaName)+1];
-                                                                       strcpy(umbrellaAndSuffix, aSubUmbrellaName);
-                                                                       strcat(umbrellaAndSuffix, context.imageSuffix);
-                                                                       if ( strcmp(umbrellaAndSuffix, &lastSlash[1]) == 0 )
-                                                                               return true;
+                                                                       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;
+                                                                       }
                                                                }
                                                        }
                                                        break;
                                                                }
                                                        }
                                                        break;
@@ -728,7 +734,7 @@ void ImageLoaderMachOClassic::resetPreboundLazyPointers(const LinkContext& conte
 {
        // loop through all local (internal) relocation records looking for pre-bound-lazy-pointer values
        const uintptr_t relocBase = this->getRelocBase();
 {
        // loop through all local (internal) relocation records looking for pre-bound-lazy-pointer values
        const uintptr_t relocBase = this->getRelocBase();
-       register const uintptr_t slide = this->fSlide;
+    const uintptr_t slide = this->fSlide;
        const relocation_info* const relocsStart = (struct relocation_info*)(&fLinkEditBase[fDynamicInfo->locreloff]);
        const relocation_info* const relocsEnd = &relocsStart[fDynamicInfo->nlocrel];
        for (const relocation_info* reloc=relocsStart; reloc < relocsEnd; ++reloc) {
        const relocation_info* const relocsStart = (struct relocation_info*)(&fLinkEditBase[fDynamicInfo->locreloff]);
        const relocation_info* const relocsEnd = &relocsStart[fDynamicInfo->nlocrel];
        for (const relocation_info* reloc=relocsStart; reloc < relocsEnd; ++reloc) {
@@ -1083,7 +1089,7 @@ uintptr_t ImageLoaderMachOClassic::resolveUndefined(const LinkContext& context,
                // symbol requires searching images with coalesced symbols (not done during prebinding)
                if ( !context.prebinding && !dontCoalesce && (symbolIsWeakReference(undefinedSymbol) || symbolIsWeakDefinition(undefinedSymbol)) ) {
                        const Symbol* sym;
                // 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) ) {
+                       if ( context.coalescedExportFinder(symbolName, &sym, foundIn, nullptr) ) {
                                if ( *foundIn != this )
                                        context.addDynamicReference(this, const_cast<ImageLoader*>(*foundIn));
                                return (*foundIn)->getExportedSymbolAddress(sym, context, this);
                                if ( *foundIn != this )
                                        context.addDynamicReference(this, const_cast<ImageLoader*>(*foundIn));
                                return (*foundIn)->getExportedSymbolAddress(sym, context, this);
@@ -1643,7 +1649,7 @@ void ImageLoaderMachOClassic::updateUsesCoalIterator(CoalIterator& it, uintptr_t
                        if ( reloc->r_pcrel ) 
                                type = BIND_TYPE_TEXT_PCREL32;
                #endif
                        if ( reloc->r_pcrel ) 
                                type = BIND_TYPE_TEXT_PCREL32;
                #endif
-                       this->bindLocation(context, (uintptr_t)location, value, type, symbolName, addend, this->getPath(), targetImage ? targetImage->getPath() : NULL, "weak ");
+                       this->bindLocation(context, this->imageBaseAddress(), (uintptr_t)location, value, type, symbolName, addend, this->getPath(), targetImage ? targetImage->getPath() : NULL, "weak ", NULL, fSlide);
                        boundSomething = true;
                }
        }
                        boundSomething = true;
                }
        }