Loading...
--- dyld/dyld-852/src/ImageLoaderMachOClassic.cpp
+++ dyld/dyld-132.13/src/ImageLoaderMachOClassic.cpp
@@ -1,6 +1,6 @@
/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
*
- * Copyright (c) 2004-2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
@@ -43,8 +43,10 @@
#include <sys/sysctl.h>
#include <libkern/OSAtomic.h>
#include <libkern/OSCacheControl.h>
-#include <mach-o/dyld_images.h>
-
+
+#if __ppc__ || __ppc64__
+ #include <mach-o/ppc/reloc.h>
+#endif
#if __x86_64__
#include <mach-o/x86_64/reloc.h>
#endif
@@ -53,9 +55,18 @@
#endif
#include "ImageLoaderMachOClassic.h"
+#include "mach-o/dyld_images.h"
+
+// optimize strcmp for ppc
+#if __ppc__
+ #include <ppc_intrinsics.h>
+#else
+ #define astrcmp(a,b) strcmp(a,b)
+#endif
+
// in dyldStartup.s
-extern "C" void stub_binding_helper_i386_old();
+extern "C" void fast_stub_binding_helper_interface();
#if __x86_64__
@@ -95,13 +106,11 @@
image->setSlide(slide);
// for PIE record end of program, to know where to start loading dylibs
- if ( slide != 0 )
+ if ( (mh->flags & MH_PIE) && !context.noPIE )
fgNextPIEDylibAddress = (uintptr_t)image->getEnd();
-
- image->disableCoverageCheck();
+
image->instantiateFinish(context);
- image->setMapped(context);
-
+
#if __i386__
// kernel may have mapped in __IMPORT segment read-only, we need it read/write to do binding
if ( image->fReadOnlyImportSegment ) {
@@ -127,47 +136,45 @@
}
// create image by mapping in a mach-o file
-ImageLoaderMachOClassic* ImageLoaderMachOClassic::instantiateFromFile(const char* path, int fd, const uint8_t* fileData, size_t lenFileData,
+ImageLoaderMachOClassic* ImageLoaderMachOClassic::instantiateFromFile(const char* path, int fd, const uint8_t* fileData,
uint64_t offsetInFat, uint64_t lenInFat, const struct stat& info,
- unsigned int segCount, unsigned int libCount,
- const struct linkedit_data_command* codeSigCmd, const LinkContext& context)
+ unsigned int segCount, unsigned int libCount, const LinkContext& context)
{
ImageLoaderMachOClassic* image = ImageLoaderMachOClassic::instantiateStart((macho_header*)fileData, path, segCount, libCount);
try {
// record info about file
image->setFileInfo(info.st_dev, info.st_ino, info.st_mtime);
- // if this image is code signed, let kernel validate signature before mapping any pages from image
- image->loadCodeSignature(codeSigCmd, fd, offsetInFat, context);
-
- // Validate that first data we read with pread actually matches with code signature
- image->validateFirstPages(codeSigCmd, fd, fileData, lenFileData, offsetInFat, context);
-
// mmap segments
image->mapSegmentsClassic(fd, offsetInFat, lenInFat, info.st_size, context);
- // finish up
- image->instantiateFinish(context);
-
+ #if CODESIGNING_SUPPORT
+ // if this code is signed, validate the signature before accessing any mapped pages
+ image->loadCodeSignature(fileData, fd, offsetInFat);
+ #endif
+
// if path happens to be same as in LC_DYLIB_ID load command use that, otherwise malloc a copy of the path
const char* installName = image->getInstallPath();
if ( (installName != NULL) && (strcmp(installName, path) == 0) && (path[0] == '/') )
image->setPathUnowned(installName);
- else if ( (path[0] != '/') || (strstr(path, "../") != NULL) ) {
- // rdar://problem/10733082 Fix up @path based paths during introspection
+ else if ( path[0] != '/' ) {
// rdar://problem/5135363 turn relative paths into absolute paths so gdb, Symbolication can later find them
char realPath[MAXPATHLEN];
- if ( fcntl(fd, F_GETPATH, realPath) == 0 )
- image->setPaths(path, realPath);
+ if ( realpath(path, realPath) != NULL )
+ image->setPath(realPath);
else
image->setPath(path);
}
else
image->setPath(path);
- // 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);
+
+ // finish up
+ image->instantiateFinish(context);
}
catch (...) {
// ImageLoader::setMapped() can throw an exception to block loading of image
@@ -180,7 +187,7 @@
}
// create image by using cached mach-o file
-ImageLoaderMachOClassic* ImageLoaderMachOClassic::instantiateFromCache(const macho_header* mh, const char* path, long slide, const struct stat& info,
+ImageLoaderMachOClassic* ImageLoaderMachOClassic::instantiateFromCache(const macho_header* mh, const char* path, const struct stat& info,
unsigned int segCount, unsigned int libCount, const LinkContext& context)
{
ImageLoaderMachOClassic* image = ImageLoaderMachOClassic::instantiateStart(mh, path, segCount, libCount);
@@ -191,7 +198,6 @@
// remember this is from shared cache and cannot be unloaded
image->fInSharedCache = true;
image->setNeverUnload();
- image->disableCoverageCheck();
// segments already mapped in cache
if ( context.verboseMapping ) {
@@ -202,7 +208,6 @@
}
image->instantiateFinish(context);
- image->setMapped(context);
}
catch (...) {
// ImageLoader::setMapped() can throw an exception to block loading of image
@@ -230,14 +235,11 @@
// for compatibility, never unload dylibs loaded from memory
image->setNeverUnload();
- image->disableCoverageCheck();
-
// bundle loads need path copied
if ( moduleName != NULL )
image->setPath(moduleName);
image->instantiateFinish(context);
- image->setMapped(context);
}
catch (...) {
// ImageLoader::setMapped() can throw an exception to block loading of image
@@ -275,7 +277,10 @@
void ImageLoaderMachOClassic::instantiateFinish(const LinkContext& context)
{
// now that segments are mapped in, get real fMachOData, fLinkEditBase, and fSlide
- this->parseLoadCmds(context);
+ this->parseLoadCmds();
+
+ // notify state change
+ this->setMapped(context);
}
ImageLoaderMachOClassic::~ImageLoaderMachOClassic()
@@ -293,8 +298,8 @@
ImageLoader* ImageLoaderMachOClassic::libImage(unsigned int libIndex) const
{
const uintptr_t* images = ((uintptr_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOClassic) + fSegmentsCount*sizeof(uint32_t)));
- // mask off low bits
- return (ImageLoader*)(images[libIndex] & (-4));
+ // mask off low bit
+ return (ImageLoader*)(images[libIndex] & (-2));
}
bool ImageLoaderMachOClassic::libReExported(unsigned int libIndex) const
@@ -304,22 +309,13 @@
return ((images[libIndex] & 1) != 0);
}
-bool ImageLoaderMachOClassic::libIsUpward(unsigned int libIndex) const
-{
- const uintptr_t* images = ((uintptr_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOClassic) + fSegmentsCount*sizeof(uint32_t)));
- // upward flag is second bit
- return ((images[libIndex] & 2) != 0);
-}
-
-
-void ImageLoaderMachOClassic::setLibImage(unsigned int libIndex, ImageLoader* image, bool reExported, bool upward)
+
+void ImageLoaderMachOClassic::setLibImage(unsigned int libIndex, ImageLoader* image, bool reExported)
{
uintptr_t* images = ((uintptr_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOClassic) + fSegmentsCount*sizeof(uint32_t)));
uintptr_t value = (uintptr_t)image;
if ( reExported )
value |= 1;
- if ( upward )
- value |= 2;
images[libIndex] = value;
}
@@ -331,6 +327,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 = start & (-4096);
+ end = (end + 4095) & (-4096);
+
+ // skip if there is only one page
+ if ( (end-start) > 4096 ) {
+ 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
@@ -396,14 +427,14 @@
while ( ! foundRoom ) {
foundRoom = true;
for(unsigned int i=0; i < regionCount; ++i) {
- 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 ;
+ vm_address_t addr = nextAltLoadAddress + regions[i].sfm_address - regions[0].sfm_address;
+ vm_size_t size = 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) {
- addr = (vm_address_t)(nextAltLoadAddress + regions[j].sfm_address - regions[0].sfm_address);
- size = (vm_size_t)(regions[j].sfm_size);
+ vm_address_t addr = nextAltLoadAddress + regions[j].sfm_address - regions[0].sfm_address;
+ vm_size_t size = regions[j].sfm_size ;
(void)vm_deallocate(mach_task_self(), addr, size);
}
nextAltLoadAddress += 0x00100000; // skip ahead 1MB and try again
@@ -419,7 +450,7 @@
}
// map in each region
- uintptr_t slide = (uintptr_t)(nextAltLoadAddress - regions[0].sfm_address);
+ uintptr_t slide = 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) ) {
@@ -427,7 +458,7 @@
}
else {
void* mmapAddress = (void*)(uintptr_t)(regions[i].sfm_address + slide);
- size_t size = (size_t)regions[i].sfm_size;
+ size_t size = regions[i].sfm_size;
int protection = 0;
if ( regions[i].sfm_init_prot & VM_PROT_EXECUTE )
protection |= PROT_EXEC;
@@ -475,12 +506,9 @@
return ImageLoaderMachO::mapSegments(fd, offsetInFat, lenInFat, fileLen, context);
#if SPLIT_SEG_SHARED_REGION_SUPPORT
- // don't map split-seg dylibs into shared region if shared cache is in use
- if ( ! context.dyldLoadedAtSameAddressNeededBySharedCache ) {
- // try to map into shared region at preferred address
- if ( mapSplitSegDylibInfoSharedRegion(fd, offsetInFat, lenInFat, fileLen, context) == 0)
- return;
- }
+ // try to map into shared region at preferred address
+ if ( mapSplitSegDylibInfoSharedRegion(fd, offsetInFat, lenInFat, fileLen, context) == 0)
+ return;
// if there is a problem, fall into case where we map file somewhere outside the shared region
#endif
@@ -561,13 +589,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;
}
}
}
@@ -588,7 +614,7 @@
const char* lastSlash = strrchr(childInstallPath, '/');
if ( lastSlash != NULL ) {
const char* firstDot = strchr(lastSlash, '.');
- size_t len;
+ int len;
if ( firstDot == NULL )
len = strlen(lastSlash);
else
@@ -609,13 +635,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 +668,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;
@@ -689,12 +711,39 @@
}
+#if __ppc__
+static inline void otherRelocsPPC(uintptr_t* locationToFix, uint8_t relocationType, uint16_t otherHalf, uintptr_t slide)
+{
+ // low 16 bits of 32-bit ppc instructions need fixing
+ struct ppcInstruction { uint16_t opcode; int16_t immediateValue; };
+ ppcInstruction* instruction = (ppcInstruction*)locationToFix;
+ //uint32_t before = *((uint32_t*)locationToFix);
+ switch ( relocationType )
+ {
+ case PPC_RELOC_LO16:
+ instruction->immediateValue = ((otherHalf << 16) | instruction->immediateValue) + slide;
+ break;
+ case PPC_RELOC_HI16:
+ instruction->immediateValue = ((((instruction->immediateValue << 16) | otherHalf) + slide) >> 16);
+ break;
+ case PPC_RELOC_HA16:
+ int16_t signedOtherHalf = (int16_t)(otherHalf & 0xffff);
+ uint32_t temp = (instruction->immediateValue << 16) + signedOtherHalf + slide;
+ if ( (temp & 0x00008000) != 0 )
+ temp += 0x00008000;
+ instruction->immediateValue = temp >> 16;
+ }
+ //uint32_t after = *((uint32_t*)locationToFix);
+ //dyld::log("dyld: ppc fixup %0p type %d from 0x%08X to 0x%08X\n", locationToFix, relocationType, before, after);
+}
+#endif
+
#if PREBOUND_IMAGE_SUPPORT
void ImageLoaderMachOClassic::resetPreboundLazyPointers(const LinkContext& context)
{
// loop through all local (internal) relocation records looking for pre-bound-lazy-pointer values
const uintptr_t relocBase = this->getRelocBase();
- const uintptr_t slide = this->fSlide;
+ register 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) {
@@ -703,6 +752,11 @@
if (sreloc->r_length == RELOC_SIZE) {
uintptr_t* locationToFix = (uintptr_t*)(sreloc->r_address + relocBase);
switch(sreloc->r_type) {
+ #if __ppc__
+ case PPC_RELOC_PB_LA_PTR:
+ *locationToFix = sreloc->r_value + slide;
+ break;
+ #endif
#if __i386__
case GENERIC_RELOC_PB_LA_PTR:
*locationToFix = sreloc->r_value + slide;
@@ -723,16 +777,19 @@
-void ImageLoaderMachOClassic::rebase(const LinkContext& context, uintptr_t slide)
-{
- CRSetCrashLogMessage2(this->getPath());
+void ImageLoaderMachOClassic::rebase(const LinkContext& context)
+{
+ register const uintptr_t slide = this->fSlide;
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];
for (const relocation_info* reloc=relocsStart; reloc < relocsEnd; ++reloc) {
- uintptr_t rebaseAddr;
try {
#if LINKEDIT_USAGE_DEBUG
noteAccessedLinkEditAddress(reloc);
@@ -747,12 +804,7 @@
throw "bad local relocation pc_rel";
if ( reloc->r_extern != 0 )
throw "extern relocation found with local relocations";
- rebaseAddr = reloc->r_address + relocBase;
- if ( ! this->containsAddress((void*)rebaseAddr) )
- dyld::throwf("local reloc %p not in mapped image\n", (void*)rebaseAddr);
- *((uintptr_t*)rebaseAddr) += slide;
- if ( context.verboseRebase )
- dyld::log("dyld: rebase: %s:*0x%08lX += 0x%08lX\n", this->getShortName(), rebaseAddr, slide);
+ *((uintptr_t*)(reloc->r_address + relocBase)) += slide;
#else
if ( (reloc->r_address & R_SCATTERED) == 0 ) {
if ( reloc->r_symbolnum == R_ABS ) {
@@ -761,13 +813,17 @@
else if (reloc->r_length == RELOC_SIZE) {
switch(reloc->r_type) {
case GENERIC_RELOC_VANILLA:
- rebaseAddr = reloc->r_address + relocBase;
- if ( ! this->containsAddress((void*)rebaseAddr) )
- dyld::throwf("local reloc %p not in mapped image\n", (void*)rebaseAddr);
- *((uintptr_t*)rebaseAddr) += slide;
- if ( context.verboseRebase )
- dyld::log("dyld: rebase: %s:*0x%08lX += 0x%08lX\n", this->getShortName(), rebaseAddr, slide);
+ *((uintptr_t*)(reloc->r_address + relocBase)) += slide;
break;
+ #if __ppc__
+ case PPC_RELOC_HI16:
+ case PPC_RELOC_LO16:
+ case PPC_RELOC_HA16:
+ // some tools leave object file relocations in linked images
+ otherRelocsPPC((uintptr_t*)(reloc->r_address + relocBase), reloc->r_type, reloc[1].r_address, slide);
+ ++reloc; // these relocations come in pairs, skip next
+ break;
+ #endif
default:
throw "unknown local relocation type";
}
@@ -782,13 +838,26 @@
uintptr_t* locationToFix = (uintptr_t*)(sreloc->r_address + relocBase);
switch(sreloc->r_type) {
case GENERIC_RELOC_VANILLA:
- if ( ! this->containsAddress((void*)locationToFix) )
- dyld::throwf("local scattered reloc %p not in mapped image\n", locationToFix);
*locationToFix += slide;
- if ( context.verboseRebase )
- dyld::log("dyld: rebase: %s:*0x%08lX += 0x%08lX\n", this->getShortName(), (uintptr_t)locationToFix, slide);
break;
- #if __i386__
+ #if __ppc__
+ case PPC_RELOC_HI16:
+ case PPC_RELOC_LO16:
+ case PPC_RELOC_HA16:
+ // Metrowerks compiler sometimes leaves object file relocations in linked images???
+ ++reloc; // these relocations come in pairs, get next one
+ otherRelocsPPC(locationToFix, sreloc->r_type, reloc->r_address, slide);
+ break;
+ case PPC_RELOC_PB_LA_PTR:
+ // do nothing
+ break;
+ #elif __ppc64__
+ case PPC_RELOC_PB_LA_PTR:
+ // needed for compatibility with ppc64 binaries built with the first ld64
+ // which used PPC_RELOC_PB_LA_PTR relocs instead of GENERIC_RELOC_VANILLA for lazy pointers
+ *locationToFix += slide;
+ break;
+ #elif __i386__
case GENERIC_RELOC_PB_LA_PTR:
// do nothing
break;
@@ -816,7 +885,6 @@
// update stats
fgTotalRebaseFixups += fDynamicInfo->nlocrel;
- CRSetCrashLogMessage2(NULL);
}
@@ -844,7 +912,7 @@
noteAccessedLinkEditAddress(pivot);
noteAccessedLinkEditAddress(pivotStr);
#endif
- int cmp = strcmp(key, pivotStr);
+ int cmp = astrcmp(key, pivotStr);
if ( cmp == 0 )
return pivot;
if ( cmp > 0 ) {
@@ -876,7 +944,7 @@
noteAccessedLinkEditAddress(pivot);
noteAccessedLinkEditAddress(pivotStr);
#endif
- int cmp = strcmp(key, pivotStr);
+ int cmp = astrcmp(key, pivotStr);
if ( cmp == 0 )
return pivot;
if ( cmp > 0 ) {
@@ -894,7 +962,7 @@
}
-const ImageLoader::Symbol* ImageLoaderMachOClassic::findShallowExportedSymbol(const char* name, const ImageLoader** foundIn) const
+const ImageLoader::Symbol* ImageLoaderMachOClassic::findExportedSymbol(const char* name, const ImageLoader** foundIn) const
{
const struct macho_nlist* sym = NULL;
if ( fDynamicInfo->tocoff == 0 )
@@ -918,7 +986,7 @@
}
-uintptr_t ImageLoaderMachOClassic::exportedSymbolAddress(const LinkContext& context, const Symbol* symbol, const ImageLoader* requestor, bool runResolver) const
+uintptr_t ImageLoaderMachOClassic::exportedSymbolAddress(const Symbol* symbol) const
{
const struct macho_nlist* sym = (macho_nlist*)symbol;
uintptr_t result = sym->n_value + fSlide;
@@ -998,13 +1066,13 @@
return false;
}
-uintptr_t ImageLoaderMachOClassic::getSymbolAddress(const macho_nlist* sym, const LinkContext& context, bool runResolver) const
-{
- return ImageLoaderMachO::getSymbolAddress((Symbol*)sym, this, context, runResolver);
+uintptr_t ImageLoaderMachOClassic::getSymbolAddress(const macho_nlist* sym, const LinkContext& context) const
+{
+ return ImageLoaderMachO::getSymbolAddress((Symbol*)sym, this, context);
}
uintptr_t ImageLoaderMachOClassic::resolveUndefined(const LinkContext& context, const struct macho_nlist* undefinedSymbol,
- bool twoLevel, bool dontCoalesce, bool runResolver, const ImageLoader** foundIn)
+ bool twoLevel, bool dontCoalesce, const ImageLoader** foundIn)
{
++fgTotalBindSymbolsResolved;
const char* symbolName = &fStrings[undefinedSymbol->n_un.n_strx];
@@ -1017,20 +1085,20 @@
// flat lookup
if ( ((undefinedSymbol->n_type & N_PEXT) != 0) && ((undefinedSymbol->n_type & N_TYPE) == N_SECT) ) {
// is a multi-module private_extern internal reference that the linker did not optimize away
- uintptr_t addr = this->getSymbolAddress(undefinedSymbol, context, false);
+ uintptr_t addr = this->getSymbolAddress(undefinedSymbol, context);
*foundIn = this;
return addr;
}
const Symbol* sym;
if ( context.flatExportFinder(symbolName, &sym, foundIn) ) {
- if ( *foundIn != this )
- context.addDynamicReference(this, const_cast<ImageLoader*>(*foundIn));
+ if ( (*foundIn != this) && !(*foundIn)->neverUnload() )
+ this->addDynamicReference(*foundIn);
return (*foundIn)->getExportedSymbolAddress(sym, context, this);
}
// if a bundle is loaded privately the above will not find its exports
if ( this->isBundle() && this->hasHiddenExports() ) {
// look in self for needed symbol
- sym = this->findShallowExportedSymbol(symbolName, foundIn);
+ sym = this->findExportedSymbol(symbolName, foundIn);
if ( sym != NULL )
return (*foundIn)->getExportedSymbolAddress(sym, context, this);
}
@@ -1039,25 +1107,25 @@
// if reference is weak_import, then it is ok, just return 0
return 0;
}
- throwSymbolNotFound(context, symbolName, this->getPath(), "", "flat namespace");
+ throwSymbolNotFound(symbolName, this->getPath(), "flat namespace");
}
else {
// 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 ( *foundIn != this )
- context.addDynamicReference(this, const_cast<ImageLoader*>(*foundIn));
+ if ( context.coalescedExportFinder(symbolName, &sym, foundIn) ) {
+ if ( (*foundIn != this) && !(*foundIn)->neverUnload() )
+ this->addDynamicReference(*foundIn);
return (*foundIn)->getExportedSymbolAddress(sym, context, this);
}
- //throwSymbolNotFound(context, symbolName, this->getPath(), "coalesced namespace");
+ //throwSymbolNotFound(symbolName, this->getPath(), "coalesced namespace");
//dyld::log("dyld: coalesced symbol %s not found in any coalesced image, falling back to two-level lookup", symbolName);
}
// if this is a real definition (not an undefined symbol) there is no ordinal
if ( (undefinedSymbol->n_type & N_TYPE) == N_SECT ) {
// static linker should never generate this case, but if it does, do something sane
- uintptr_t addr = this->getSymbolAddress(undefinedSymbol, context, false);
+ uintptr_t addr = this->getSymbolAddress(undefinedSymbol, context);
*foundIn = this;
return addr;
}
@@ -1084,7 +1152,7 @@
if ( context.flatExportFinder(symbolName, &sym, foundIn) )
return (*foundIn)->getExportedSymbolAddress(sym, context, this);
- throwSymbolNotFound(context, symbolName, this->getPath(), "", "dynamic lookup");
+ throwSymbolNotFound(symbolName, this->getPath(), "dynamic lookup");
}
else if ( ord <= libraryCount() ) {
target = libImage(ord-1);
@@ -1102,15 +1170,15 @@
//dyld::log("resolveUndefined(%s) in %s\n", symbolName, this->getPath());
throw "symbol not found";
}
-
- uintptr_t address;
- if ( target->findExportedSymbolAddress(context, symbolName, this, ord, runResolver, foundIn, &address) )
- return address;
-
- if ( (undefinedSymbol->n_type & N_PEXT) != 0 ) {
+
+ const Symbol* sym = target->findExportedSymbol(symbolName, true, foundIn);
+ if ( sym!= NULL ) {
+ return (*foundIn)->getExportedSymbolAddress(sym, context, this);
+ }
+ else if ( (undefinedSymbol->n_type & N_PEXT) != 0 ) {
// don't know why the static linker did not eliminate the internal reference to a private extern definition
*foundIn = this;
- return this->getSymbolAddress(undefinedSymbol, context, false);
+ return this->getSymbolAddress(undefinedSymbol, context);
}
else if ( (undefinedSymbol->n_desc & N_WEAK_REF) != 0 ) {
// if definition not found and reference is weak return 0
@@ -1118,7 +1186,7 @@
}
// nowhere to be found
- throwSymbolNotFound(context, symbolName, this->getPath(), "", target->getPath());
+ throwSymbolNotFound(symbolName, this->getPath(), target->getPath());
}
}
@@ -1178,8 +1246,6 @@
{
const struct macho_nlist* undefinedSymbol = &fSymbolTable[reloc->r_symbolnum];
uintptr_t* location = ((uintptr_t*)(reloc->r_address + relocBase));
- if ( ! this->containsAddress((void*)location) )
- dyld::throwf("external reloc %p not in mapped image %s\n", (void*)location, this->getPath());
uintptr_t value = *location;
bool symbolAddrCached = true;
#if __i386__
@@ -1230,11 +1296,11 @@
// range of global symbols. To handle that case we do the coalesing now.
dontCoalesce = false;
}
- symbolAddr = this->resolveUndefined(context, undefinedSymbol, twoLevel, dontCoalesce, false, &image);
+ symbolAddr = this->resolveUndefined(context, undefinedSymbol, twoLevel, dontCoalesce, &image);
lastUndefinedSymbol = undefinedSymbol;
symbolAddrCached = false;
}
- if ( context.verboseBind && (undefinedSymbol != NULL) ) {
+ if ( context.verboseBind ) {
const char *path = NULL;
if ( image != NULL ) {
path = image->getShortName();
@@ -1346,13 +1412,12 @@
return targetAddr;
}
-uintptr_t ImageLoaderMachOClassic::doBindFastLazySymbol(uint32_t lazyBindingInfoOffset, const LinkContext& context, void (*lock)(), void (*unlock)())
+uintptr_t ImageLoaderMachOClassic::doBindFastLazySymbol(uint32_t lazyBindingInfoOffset, const LinkContext& context)
{
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();
@@ -1371,11 +1436,11 @@
const uint8_t type = sect->flags & SECTION_TYPE;
uint32_t symbolIndex = INDIRECT_SYMBOL_LOCAL;
if ( type == S_LAZY_SYMBOL_POINTERS ) {
- const size_t pointerCount = sect->size / sizeof(uintptr_t);
+ const uint32_t pointerCount = sect->size / sizeof(uintptr_t);
uintptr_t* const symbolPointers = (uintptr_t*)(sect->addr + fSlide);
if ( (lazyPointer >= symbolPointers) && (lazyPointer < &symbolPointers[pointerCount]) ) {
const uint32_t indirectTableOffset = sect->reserved1;
- const size_t lazyIndex = lazyPointer - symbolPointers;
+ const uint32_t lazyIndex = lazyPointer - symbolPointers;
symbolIndex = indirectTable[indirectTableOffset + lazyIndex];
}
}
@@ -1397,7 +1462,7 @@
if ( symbolIndex != INDIRECT_SYMBOL_ABS && symbolIndex != INDIRECT_SYMBOL_LOCAL ) {
const char* symbolName = &fStrings[fSymbolTable[symbolIndex].n_un.n_strx];
const ImageLoader* image = NULL;
- uintptr_t symbolAddr = this->resolveUndefined(context, &fSymbolTable[symbolIndex], twoLevel, false, true, &image);
+ uintptr_t symbolAddr = this->resolveUndefined(context, &fSymbolTable[symbolIndex], twoLevel, false, &image);
symbolAddr = this->bindIndirectSymbol(lazyPointer, sect, symbolName, symbolAddr, image, context);
++fgTotalLazyBindFixups;
return symbolAddr;
@@ -1413,7 +1478,7 @@
-void ImageLoaderMachOClassic::initializeCoalIterator(CoalIterator& it, unsigned int loadOrder, unsigned)
+void ImageLoaderMachOClassic::initializeCoalIterator(CoalIterator& it, unsigned int loadOrder)
{
it.image = this;
it.symbolName = " ";
@@ -1488,23 +1553,15 @@
symbol_index = toc[it.curIndex-1].symbol_index;
}
else {
- symbol_index = fDynamicInfo->iextdefsym + (uint32_t)it.curIndex - 1;
+ symbol_index = fDynamicInfo->iextdefsym+it.curIndex-1;
}
const struct macho_nlist* sym = &fSymbolTable[symbol_index];
//dyld::log("getAddressCoalIterator() => 0x%llX, %s symbol_index=%d, in %s\n", (uint64_t)(sym->n_value + fSlide), &fStrings[sym->n_un.n_strx], symbol_index, this->getPath());
-#if __arm__
- // processor assumes code address with low bit set is thumb
- if (sym->n_desc & N_ARM_THUMB_DEF)
- return (sym->n_value | 1) + fSlide ;
- else
- return sym->n_value + fSlide;
-#else
return sym->n_value + fSlide;
-#endif
-}
-
-
-void ImageLoaderMachOClassic::updateUsesCoalIterator(CoalIterator& it, uintptr_t value, ImageLoader* targetImage, unsigned targetIndex, const LinkContext& context)
+}
+
+
+void ImageLoaderMachOClassic::updateUsesCoalIterator(CoalIterator& it, uintptr_t value, ImageLoader* targetImage, const LinkContext& context)
{
// flat_namespace images with classic LINKEDIT do not need late coalescing.
// They still need to be iterated becuase they may implement
@@ -1523,7 +1580,7 @@
symbol_index = toc[it.curIndex-1].symbol_index;
}
else {
- symbol_index = fDynamicInfo->iextdefsym + (uint32_t)it.curIndex - 1;
+ symbol_index = fDynamicInfo->iextdefsym+it.curIndex-1;
}
// if this image's copy of the symbol is not a weak definition nor a weak reference then nothing to coalesce here
@@ -1565,7 +1622,7 @@
#if __arm__
// if weak and thumb subtract off extra thumb bit
if ( (undefinedSymbol->n_desc & N_ARM_THUMB_DEF) != 0 )
- addend &= -2;
+ addend += 1;
#endif
}
}
@@ -1588,11 +1645,6 @@
// to be definition address plus addend
//dyld::log("weak def, initialValue=0x%lX, undefAddr=0x%lX\n", initialValue, undefinedSymbol->n_value+fSlide);
addend = initialValue - (undefinedSymbol->n_value + fSlide);
- #if __arm__
- // if weak and thumb subtract off extra thumb bit
- if ( (undefinedSymbol->n_desc & N_ARM_THUMB_DEF) != 0 )
- addend &= -2;
- #endif
}
else {
// nothing fixed up yet, addend is just initial value
@@ -1606,7 +1658,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, targetImage, type, symbolName, addend, "weak ");
boundSomething = true;
}
}
@@ -1629,16 +1681,15 @@
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:
{
- size_t elementCount = sect->size / elementSize;
+ uint32_t elementCount = sect->size / elementSize;
const uint32_t indirectTableOffset = sect->reserved1;
uint8_t* ptrToBind = (uint8_t*)(sect->addr + fSlide);
//dyld::log(" scanning section %s of %s starting at %p\n", sect->sectname, this->getShortName(), ptrToBind);
- for (size_t j=0; j < elementCount; ++j, ptrToBind += elementSize) {
+ for (uint32_t j=0; j < elementCount; ++j, ptrToBind += elementSize) {
if ( indirectTable[indirectTableOffset + j] == symbol_index ) {
//dyld::log(" found symbol index match at %d/%d, ptrToBind=%p\n", j, elementCount, ptrToBind);
// update pointer
@@ -1653,9 +1704,8 @@
}
cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
}
- if ( boundSomething && (targetImage != this) ) {
- context.addDynamicReference(this, targetImage);
- }
+ if ( boundSomething && (targetImage != this) && !targetImage->neverUnload() )
+ this->addDynamicReference(targetImage);
// mark that this symbol has already been bound, so we don't try to bind again
it.type = 1;
@@ -1681,7 +1731,7 @@
bool isLazySymbol = false;
const uint8_t type = sect->flags & SECTION_TYPE;
uint32_t elementSize = sizeof(uintptr_t);
- size_t elementCount = sect->size / elementSize;
+ uint32_t elementCount = sect->size / elementSize;
if ( type == S_NON_LAZY_SYMBOL_POINTERS ) {
if ( ! bindNonLazys )
continue;
@@ -1709,7 +1759,7 @@
}
const uint32_t indirectTableOffset = sect->reserved1;
uint8_t* ptrToBind = (uint8_t*)(sect->addr + fSlide);
- for (size_t j=0; j < elementCount; ++j, ptrToBind += elementSize) {
+ for (uint32_t j=0; j < elementCount; ++j, ptrToBind += elementSize) {
#if LINKEDIT_USAGE_DEBUG
noteAccessedLinkEditAddress(&indirectTable[indirectTableOffset + j]);
#endif
@@ -1761,9 +1811,9 @@
// range of global symbols. To handle that case we do the coalesing now.
dontCoalesce = false;
}
- uintptr_t symbolAddr = resolveUndefined(context, sym, twoLevel, dontCoalesce, false, &image);
+ uintptr_t symbolAddr = resolveUndefined(context, sym, twoLevel, dontCoalesce, &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;
}
@@ -1802,7 +1852,7 @@
const uint32_t* const indirectTable = (uint32_t*)&fLinkEditBase[fDynamicInfo->indirectsymoff];
uint8_t* start = (uint8_t*)(sect->addr + this->fSlide);
uint8_t* end = start + sect->size;
- uintptr_t dyldHandler = (uintptr_t)&stub_binding_helper_i386_old;
+ uintptr_t dyldHandler = (uintptr_t)&fast_stub_binding_helper_interface;
uint32_t entryIndex = 0;
for (uint8_t* entry = start; entry < end; entry += 5, ++entryIndex) {
bool installLazyHandler = true;
@@ -1816,7 +1866,7 @@
const char* symbolName = &fStrings[fSymbolTable[symbolIndex].n_un.n_strx];
const ImageLoader* image = NULL;
try {
- uintptr_t symbolAddr = this->resolveUndefined(context, &fSymbolTable[symbolIndex], this->usesTwoLevelNameSpace(), false, false, &image);
+ uintptr_t symbolAddr = this->resolveUndefined(context, &fSymbolTable[symbolIndex], this->usesTwoLevelNameSpace(), false, &image);
symbolAddr = this->bindIndirectSymbol((uintptr_t*)entry, sect, symbolName, symbolAddr, image, context);
++fgTotalBindFixups;
uint32_t rel32 = symbolAddr - (((uint32_t)entry)+5);
@@ -1853,9 +1903,8 @@
#endif // __i386__
-void ImageLoaderMachOClassic::doBind(const LinkContext& context, bool forceLazysBound, const ImageLoader* reExportParent)
-{
- CRSetCrashLogMessage2(this->getPath());
+void ImageLoaderMachOClassic::doBind(const LinkContext& context, bool forceLazysBound)
+{
#if __i386__
this->initializeLazyStubs(context);
#endif
@@ -1869,12 +1918,6 @@
// no valid prebinding, so bind symbols.
// values bound by name are stored two different ways in classic mach-o:
- #if TEXT_RELOC_SUPPORT
- // if there are __TEXT fixups, temporarily make __TEXT writable
- if ( fTextSegmentBinds )
- this->makeTextSegmentWritable(context, true);
- #endif
-
// 1) external relocations are used for data initialized to external symbols
this->doBindExternalRelocations(context);
@@ -1882,167 +1925,17 @@
// if this image is in the shared cache, there is no way to reset the lazy pointers, so bind them now
this->bindIndirectSymbolPointers(context, true, forceLazysBound || fInSharedCache);
- #if TEXT_RELOC_SUPPORT
- // if there were __TEXT fixups, restore write protection
- if ( fTextSegmentBinds )
- this->makeTextSegmentWritable(context, false);
- #endif
}
// set up dyld entry points in image
this->setupLazyPointerHandler(context);
-
- 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);
}
-
-void ImageLoaderMachOClassic::doInterpose(const LinkContext& context)
-{
- if ( context.verboseInterposing )
- dyld::log("dyld: interposing %lu tuples onto: %s\n", fgInterposingTuples.size(), this->getPath());
-
- // scan indirect symbols
- const uint32_t cmd_count = ((macho_header*)fMachOData)->ncmds;
- const struct load_command* const cmds = (struct load_command*)&fMachOData[sizeof(macho_header)];
- const struct load_command* cmd = cmds;
- for (uint32_t i = 0; i < cmd_count; ++i) {
- switch (cmd->cmd) {
- case LC_SEGMENT_COMMAND:
- {
- const struct macho_segment_command* seg = (struct macho_segment_command*)cmd;
- const struct macho_section* const sectionsStart = (struct macho_section*)((char*)seg + sizeof(struct macho_segment_command));
- const struct macho_section* const sectionsEnd = §ionsStart[seg->nsects];
- for (const struct macho_section* sect=sectionsStart; sect < sectionsEnd; ++sect) {
- const uint8_t type = sect->flags & SECTION_TYPE;
- if ( (type == S_NON_LAZY_SYMBOL_POINTERS) || (type == S_LAZY_SYMBOL_POINTERS) ) {
- const size_t pointerCount = sect->size / sizeof(uintptr_t);
- uintptr_t* const symbolPointers = (uintptr_t*)(sect->addr + fSlide);
- for (size_t pointerIndex=0; pointerIndex < pointerCount; ++pointerIndex) {
- uintptr_t newValue = interposedAddress(context, symbolPointers[pointerIndex], this);
- if ( newValue != symbolPointers[pointerIndex] )
- symbolPointers[pointerIndex] = newValue;
- }
- }
- #if __i386__
- // i386 has special self-modifying stubs that might be prebound to "JMP rel32" that need checking
- else if ( (type == S_SYMBOL_STUBS) && ((sect->flags & S_ATTR_SELF_MODIFYING_CODE) != 0) && (sect->reserved2 == 5) ) {
- // check each jmp entry in this section
- uint8_t* start = (uint8_t*)(sect->addr + this->fSlide);
- uint8_t* end = start + sect->size;
- for (uint8_t* entry = start; entry < end; entry += 5) {
- if ( entry[0] == 0xE9 ) { // 0xE9 == JMP
- uint32_t rel32 = *((uint32_t*)&entry[1]); // assume unaligned load of uint32_t is ok
- uint32_t target = (uint32_t)&entry[5] + rel32;
- uint32_t newTarget = interposedAddress(context, target, this);
- if ( newTarget != target ) {
- uint32_t newRel32 = newTarget - (uint32_t)&entry[5];
- *((uint32_t*)&entry[1]) = newRel32; // assume unaligned store of uint32_t is ok
- }
- }
- }
- }
- #endif
- }
- }
- break;
- }
- cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
- }
-
- // scan external relocations
- const uintptr_t relocBase = this->getRelocBase();
- const relocation_info* const relocsStart = (struct relocation_info*)(&fLinkEditBase[fDynamicInfo->extreloff]);
- const relocation_info* const relocsEnd = &relocsStart[fDynamicInfo->nextrel];
- for (const relocation_info* reloc=relocsStart; reloc < relocsEnd; ++reloc) {
- if (reloc->r_length == RELOC_SIZE) {
- switch(reloc->r_type) {
- case POINTER_RELOC:
- {
- uintptr_t* location = ((uintptr_t*)(reloc->r_address + relocBase));
- uintptr_t value = *location;
- uintptr_t newValue = interposedAddress(context, value, this);
- if ( newValue != value )
- *location = newValue;
- }
- break;
- }
- }
- }
-}
-
-void ImageLoaderMachOClassic::dynamicInterpose(const LinkContext& context)
-{
- if ( context.verboseInterposing )
- dyld::log("dyld: dynamic interposing %lu tuples onto image: %s\n", context.dynamicInterposeCount, this->getPath());
-
- // scan indirect symbols
- const uint32_t cmd_count = ((macho_header*)fMachOData)->ncmds;
- const struct load_command* const cmds = (struct load_command*)&fMachOData[sizeof(macho_header)];
- const struct load_command* cmd = cmds;
- for (uint32_t i = 0; i < cmd_count; ++i) {
- switch (cmd->cmd) {
- case LC_SEGMENT_COMMAND:
- {
- const struct macho_segment_command* seg = (struct macho_segment_command*)cmd;
- const struct macho_section* const sectionsStart = (struct macho_section*)((char*)seg + sizeof(struct macho_segment_command));
- const struct macho_section* const sectionsEnd = §ionsStart[seg->nsects];
- for (const struct macho_section* sect=sectionsStart; sect < sectionsEnd; ++sect) {
- const uint8_t type = sect->flags & SECTION_TYPE;
- if ( (type == S_NON_LAZY_SYMBOL_POINTERS) || (type == S_LAZY_SYMBOL_POINTERS) ) {
- const size_t pointerCount = sect->size / sizeof(uintptr_t);
- uintptr_t* const symbolPointers = (uintptr_t*)(sect->addr + fSlide);
- for (size_t pointerIndex=0; pointerIndex < pointerCount; ++pointerIndex) {
- for(size_t j=0; j < context.dynamicInterposeCount; ++j) {
- // replace all references to 'replacee' with 'replacement'
- if ( symbolPointers[pointerIndex] == (uintptr_t)context.dynamicInterposeArray[j].replacee ) {
- if ( context.verboseInterposing ) {
- dyld::log("dyld: dynamic interposing: at %p replace %p with %p in %s\n",
- &symbolPointers[pointerIndex], context.dynamicInterposeArray[j].replacee, context.dynamicInterposeArray[j].replacement, this->getPath());
- }
- symbolPointers[pointerIndex] = (uintptr_t)context.dynamicInterposeArray[j].replacement;
- }
- }
- }
- }
- }
- }
- break;
- }
- cmd = (const struct load_command*)(((char*)cmd)+cmd->cmdsize);
- }
-
- // scan external relocations
- const uintptr_t relocBase = this->getRelocBase();
- const relocation_info* const relocsStart = (struct relocation_info*)(&fLinkEditBase[fDynamicInfo->extreloff]);
- const relocation_info* const relocsEnd = &relocsStart[fDynamicInfo->nextrel];
- for (const relocation_info* reloc=relocsStart; reloc < relocsEnd; ++reloc) {
- if (reloc->r_length == RELOC_SIZE) {
- switch(reloc->r_type) {
- case POINTER_RELOC:
- {
- uintptr_t* location = ((uintptr_t*)(reloc->r_address + relocBase));
- for(size_t i=0; i < context.dynamicInterposeCount; ++i) {
- // replace all references to 'replacee' with 'replacement'
- if ( *location == (uintptr_t)context.dynamicInterposeArray[i].replacee ) {
- if ( context.verboseInterposing ) {
- dyld::log("dyld: dynamic interposing: at %p replace %p with %p in %s\n",
- location, context.dynamicInterposeArray[i].replacee, context.dynamicInterposeArray[i].replacement, this->getPath());
- }
- *location = (uintptr_t)context.dynamicInterposeArray[i].replacement;
- }
- }
- }
- break;
- }
- }
- }
-}
-
const char* ImageLoaderMachOClassic::findClosestSymbol(const void* addr, const void** closestAddr) const
{
@@ -2077,14 +1970,7 @@
}
}
if ( bestSymbol != NULL ) {
-#if __arm__
- if (bestSymbol->n_desc & N_ARM_THUMB_DEF)
- *closestAddr = (void*)((bestSymbol->n_value | 1) + fSlide);
- else
- *closestAddr = (void*)(bestSymbol->n_value + fSlide);
-#else
*closestAddr = (void*)(bestSymbol->n_value + fSlide);
-#endif
return &fStrings[bestSymbol->n_un.n_strx];
}
return NULL;