Index: trunk/i386/boot2/modules.c =================================================================== --- trunk/i386/boot2/modules.c (revision 926) +++ trunk/i386/boot2/modules.c (revision 927) @@ -22,8 +22,8 @@ #endif // NOTE: Global so that modules can link with this -unsigned long long textAddress = 0; -unsigned long long textSection = 0; +UInt64 textAddress = 0; +UInt64 textSection = 0; void* symbols_module_start = (void*)0xFFFFFFFF; // Global, value is populated by the makefile with actual address @@ -286,7 +286,7 @@ } #if CONFIG_MODULE_DEBUG - verbose("Unable to locate symbol %s\n", name); + printf("Unable to locate symbol %s\n", name); getchar(); #endif @@ -493,9 +493,9 @@ // Rebase the module before binding it. if(dyldInfoCommand->rebase_off) rebase_macho(binary, (char*)dyldInfoCommand->rebase_off, dyldInfoCommand->rebase_size); // Bind all symbols. - if(dyldInfoCommand->bind_off) bind_macho(binary, (char*)dyldInfoCommand->bind_off, dyldInfoCommand->bind_size); - if(dyldInfoCommand->weak_bind_off) bind_macho(binary, (char*)dyldInfoCommand->weak_bind_off, dyldInfoCommand->weak_bind_size); - if(dyldInfoCommand->lazy_bind_off) bind_macho(binary, (char*)dyldInfoCommand->lazy_bind_off, dyldInfoCommand->lazy_bind_size); + if(dyldInfoCommand->bind_off) bind_macho(binary, (UInt8*)dyldInfoCommand->bind_off, dyldInfoCommand->bind_size); + if(dyldInfoCommand->weak_bind_off) bind_macho(binary, (UInt8*)dyldInfoCommand->weak_bind_off, dyldInfoCommand->weak_bind_size); + if(dyldInfoCommand->lazy_bind_off) bind_macho(binary, (UInt8*)dyldInfoCommand->lazy_bind_off, dyldInfoCommand->lazy_bind_size); } return module_start; @@ -738,11 +738,33 @@ } +UInt32 read_uleb(UInt8* bind_stream, unsigned int* i) +{ + // Read in offset + UInt32 tmp = 0; + UInt8 bits = 0; + do + { + if(bits < sizeof(UInt32)*8) // hack + { + tmp |= (bind_stream[++(*i)] & 0x7f) << bits; + bits += 7; + } + else + { + ++(*i); + } + } + while(bind_stream[*i] & 0x80); + return tmp; +} + + // Based on code from dylibinfo.cpp and ImageLoaderMachOCompressed.cpp // NOTE: this uses 32bit values, and not 64bit values. // There is a possibility that this could cause issues, // however the modules are 32 bits, so it shouldn't matter too much -void bind_macho(void* base, char* bind_stream, UInt32 size) +void bind_macho(void* base, UInt8* bind_stream, UInt32 size) { bind_stream += (UInt32)base; @@ -762,7 +784,6 @@ UInt32 symbolAddr = 0xFFFFFFFF; // Temperary variables - UInt8 bits = 0; UInt32 tmp = 0; UInt32 tmp2 = 0; UInt32 index = 0; @@ -792,14 +813,7 @@ break; case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: - libraryOrdinal = 0; - bits = 0; - do - { - libraryOrdinal |= (bind_stream[++i] & 0x7f) << bits; - bits += 7; - } - while(bind_stream[i] & 0x80); + libraryOrdinal = read_uleb(bind_stream, &i); break; case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: @@ -819,15 +833,7 @@ break; case BIND_OPCODE_SET_ADDEND_SLEB: - addend = 0; - bits = 0; - do - { - addend |= (bind_stream[++i] & 0x7f) << bits; - bits += 7; - } - while(bind_stream[i] & 0x80); - + addend = read_uleb(bind_stream, &i); if(!(bind_stream[i-1] & 0x40)) addend *= -1; break; @@ -848,32 +854,12 @@ while(index <= immediate); segmentAddress = segCommand->fileoff; - - // Read in offset - tmp = 0; - bits = 0; - do - { - tmp |= (bind_stream[++i] & 0x7f) << bits; - bits += 7; - } - while(bind_stream[i] & 0x80); - - segmentAddress += tmp; + + segmentAddress += read_uleb(bind_stream, &i); break; case BIND_OPCODE_ADD_ADDR_ULEB: - // Read in offset - tmp = 0; - bits = 0; - do - { - tmp |= (bind_stream[++i] & 0x7f) << bits; - bits += 7; - } - while(bind_stream[i] & 0x80); - - segmentAddress += tmp; + segmentAddress += read_uleb(bind_stream, &i); break; case BIND_OPCODE_DO_BIND: @@ -894,14 +880,7 @@ case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: // Read in offset - tmp = 0; - bits = 0; - do - { - tmp |= (bind_stream[++i] & 0x7f) << bits; - bits += 7; - } - while(bind_stream[i] & 0x80); + tmp = read_uleb(bind_stream, &i); if(symbolAddr != 0xFFFFFFFF) { @@ -938,26 +917,10 @@ break; case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: - tmp = 0; - bits = 0; - do - { - tmp |= (bind_stream[++i] & 0x7f) << bits; - bits += 7; - } - while(bind_stream[i] & 0x80); + tmp = read_uleb(bind_stream, &i); + tmp2 = read_uleb(bind_stream, &i); - tmp2 = 0; - bits = 0; - do - { - tmp2 |= (bind_stream[++i] & 0x7f) << bits; - bits += 7; - } - while(bind_stream[i] & 0x80); - - if(symbolAddr != 0xFFFFFFFF) { for(index = 0; index < tmp; index++) @@ -978,6 +941,7 @@ i++; } } + inline void bind_location(UInt32* location, char* value, UInt32 addend, int type) { @@ -1140,10 +1104,11 @@ hooks = hooks->next; } } + #endif /********************************************************************************/ -/* dyld / Linker Interface */ +/* dyld / Linker Interface */ /********************************************************************************/ void dyld_stub_binder() Index: trunk/i386/boot2/modules.h =================================================================== --- trunk/i386/boot2/modules.h (revision 926) +++ trunk/i386/boot2/modules.h (revision 927) @@ -15,15 +15,15 @@ #define MODULE_PATH "/Extra/modules/" #define SYMBOLS_MODULE "Symbols.dylib" #define VOID_SYMBOL "dyld_void_start" -extern unsigned long long textAddress; -extern unsigned long long textSection; +extern UInt64 textAddress; +extern UInt64 textSection; typedef struct symbolList_t { char* symbol; - unsigned int addr; + UInt64 addr; struct symbolList_t* next; } symbolList_t; @@ -84,7 +84,7 @@ char is64); void rebase_macho(void* base, char* rebase_stream, UInt32 size); inline void rebase_location(UInt32* location, char* base, int type); -void bind_macho(void* base, char* bind_stream, UInt32 size); +void bind_macho(void* base, UInt8* bind_stream, UInt32 size); inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);