From 8bc9f0afa7d820677f5d190a59ca900972f9aa5e Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 6 Oct 2006 08:02:12 +0000 Subject: [PATCH] dyld-46.9.tar.gz --- dyld.xcodeproj/project.pbxproj | 19 +- src/ImageLoaderMachO.cpp | 134 ++- src/ImageLoaderMachO.h | 1 + src/dyld.cpp | 44 +- src/dyldAPIs.cpp | 12 +- src/dyldInitialization.cpp | 18 + src/dyldStartup.s | 43 + src/stub_binding_helper.s | 82 ++ unit-tests/run-all-unit-tests | 16 +- unit-tests/test-cases/big-jump-table/Makefile | 60 ++ unit-tests/test-cases/big-jump-table/foo.c | 827 +++++++++++++++++ unit-tests/test-cases/big-jump-table/foo.h | 825 +++++++++++++++++ unit-tests/test-cases/big-jump-table/funcs.c | 853 ++++++++++++++++++ .../bar.c => big-jump-table/main.c} | 14 +- .../test-cases/big-jump-table/pointers.c | 23 + .../test-cases/bundle-memory-load-fat/main.c | 2 +- unit-tests/test-cases/bundle-reload/Makefile | 2 +- .../test-cases/dlclose-dylib-unload/Makefile | 44 - .../test-cases/dlclose-dylib-unload/main.c | 162 ---- unit-tests/test-cases/dlerror-clear/Makefile | 38 - unit-tests/test-cases/dlerror-clear/main.c | 61 -- unit-tests/test-cases/dlerror/main.c | 93 -- .../lazy-binding-reg-params/Makefile | 8 + .../test-cases/lazy-binding-reg-params/foo.h | 2 +- .../test-cases/lazy-binding-reg-params/main.c | 2 +- .../Makefile | 22 +- .../test-cases/prebased-performance/foo.c | 76 ++ .../foo.c => prebased-performance/main.c} | 16 +- 28 files changed, 3033 insertions(+), 466 deletions(-) create mode 100644 unit-tests/test-cases/big-jump-table/Makefile create mode 100644 unit-tests/test-cases/big-jump-table/foo.c create mode 100644 unit-tests/test-cases/big-jump-table/foo.h create mode 100644 unit-tests/test-cases/big-jump-table/funcs.c rename unit-tests/test-cases/{dlclose-dylib-unload/bar.c => big-jump-table/main.c} (77%) create mode 100644 unit-tests/test-cases/big-jump-table/pointers.c delete mode 100644 unit-tests/test-cases/dlclose-dylib-unload/Makefile delete mode 100644 unit-tests/test-cases/dlclose-dylib-unload/main.c delete mode 100644 unit-tests/test-cases/dlerror-clear/Makefile delete mode 100644 unit-tests/test-cases/dlerror-clear/main.c delete mode 100644 unit-tests/test-cases/dlerror/main.c rename unit-tests/test-cases/{dlerror => prebased-performance}/Makefile (66%) create mode 100644 unit-tests/test-cases/prebased-performance/foo.c rename unit-tests/test-cases/{dlclose-dylib-unload/foo.c => prebased-performance/main.c} (69%) diff --git a/dyld.xcodeproj/project.pbxproj b/dyld.xcodeproj/project.pbxproj index 8d37830..a10989e 100644 --- a/dyld.xcodeproj/project.pbxproj +++ b/dyld.xcodeproj/project.pbxproj @@ -433,7 +433,7 @@ PRODUCT_NAME = dyld; STRIPFLAGS = "-S"; UNSTRIPPED_PRODUCT = NO; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; VERSIONING_SYSTEM = "apple-generic"; WARNING_CFLAGS = ( "-Wmost", @@ -477,7 +477,7 @@ OTHER_REZFLAGS = ""; PRODUCT_NAME = dyldapis; SECTORDER_FLAGS = ""; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; WARNING_CFLAGS = ( "-Wmost", "-Wno-four-char-constants", @@ -597,6 +597,7 @@ OTHER_LDFLAGS_i386 = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_LDFLAGS_ppc = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_LDFLAGS_ppc64 = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld64.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; + OTHER_LDFLAGS_x86_64 = "-lstdc++-static -seg1addr 0x7fff5fc00000 -exported_symbols_list src/dyld64.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_REZFLAGS = ""; PER_ARCH_CFLAGS_ppc = ""; PER_ARCH_CFLAGS_ppc64 = "-msoft-float"; @@ -604,7 +605,7 @@ PRODUCT_NAME = dyld; STRIPFLAGS = "-S"; UNSTRIPPED_PRODUCT = NO; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; VERSIONING_SYSTEM = "apple-generic"; WARNING_CFLAGS = ( "-Wmost", @@ -635,6 +636,7 @@ OTHER_LDFLAGS_i386 = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_LDFLAGS_ppc = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_LDFLAGS_ppc64 = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld64.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; + OTHER_LDFLAGS_x86_64 = "-lstdc++-static -seg1addr 0x7fff5fc00000 -exported_symbols_list src/dyld64.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_REZFLAGS = ""; PER_ARCH_CFLAGS_ppc = ""; PER_ARCH_CFLAGS_ppc64 = "-msoft-float"; @@ -642,7 +644,7 @@ PRODUCT_NAME = dyld; STRIPFLAGS = "-S"; UNSTRIPPED_PRODUCT = NO; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; VERSIONING_SYSTEM = "apple-generic"; WARNING_CFLAGS = ( "-Wmost", @@ -672,6 +674,7 @@ OTHER_LDFLAGS_i386 = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_LDFLAGS_ppc = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_LDFLAGS_ppc64 = "-lstdc++-static -seg1addr 8fe00000 -exported_symbols_list src/dyld64.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; + OTHER_LDFLAGS_x86_64 = "-lstdc++-static -seg1addr 0x7fff5fc00000 -exported_symbols_list src/dyld64.exp -nostdlib /usr/local/lib/system/libc.a -lgcc_eh -lgcc -Wl,-e,__dyld_start -Wl,-dylinker -Wl,-dylinker_install_name,/usr/lib/dyld"; OTHER_REZFLAGS = ""; PER_ARCH_CFLAGS_ppc = ""; PER_ARCH_CFLAGS_ppc64 = "-msoft-float"; @@ -679,7 +682,7 @@ PRODUCT_NAME = dyld; STRIPFLAGS = "-S"; UNSTRIPPED_PRODUCT = NO; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; VERSIONING_SYSTEM = "apple-generic"; WARNING_CFLAGS = ( "-Wmost", @@ -705,7 +708,7 @@ OTHER_REZFLAGS = ""; PRODUCT_NAME = dyldapis; SECTORDER_FLAGS = ""; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; WARNING_CFLAGS = ( "-Wmost", "-Wno-four-char-constants", @@ -729,7 +732,7 @@ OTHER_REZFLAGS = ""; PRODUCT_NAME = dyldapis; SECTORDER_FLAGS = ""; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; WARNING_CFLAGS = ( "-Wmost", "-Wno-four-char-constants", @@ -751,7 +754,7 @@ OTHER_REZFLAGS = ""; PRODUCT_NAME = dyldapis; SECTORDER_FLAGS = ""; - VALID_ARCHS = "ppc ppc64 i386"; + VALID_ARCHS = "ppc ppc64 i386 x86_64"; WARNING_CFLAGS = ( "-Wmost", "-Wno-four-char-constants", diff --git a/src/ImageLoaderMachO.cpp b/src/ImageLoaderMachO.cpp index d57bbd4..ed7c645 100644 --- a/src/ImageLoaderMachO.cpp +++ b/src/ImageLoaderMachO.cpp @@ -34,9 +34,13 @@ #include #include #include +#include #if __ppc__ || __ppc64__ #include #endif +#if __x86_64__ + #include +#endif #ifndef S_ATTR_SELF_MODIFYING_CODE #define S_ATTR_SELF_MODIFYING_CODE 0x04000000 @@ -76,7 +80,11 @@ extern "C" void sys_icache_invalidate(void *, size_t); struct macho_routines_command : public routines_command {}; #endif +#if __x86_64__ + #define POINTER_RELOC X86_64_RELOC_UNSIGNED +#else #define POINTER_RELOC GENERIC_RELOC_VANILLA +#endif uint32_t ImageLoaderMachO::fgHintedBinaryTreeSearchs = 0; uint32_t ImageLoaderMachO::fgUnhintedBinaryTreeSearchs = 0; @@ -1120,6 +1128,9 @@ void* ImageLoaderMachO::getMain() const #elif __i386__ const i386_thread_state_t* registers = (i386_thread_state_t*)(((char*)cmd) + 16); return (void*)registers->eip; + #elif __x86_64__ + const x86_thread_state64_t* registers = (x86_thread_state64_t*)(((char*)cmd) + 16); + return (void*)registers->rip; #else #warning need processor specific code #endif @@ -1208,6 +1219,10 @@ uintptr_t ImageLoaderMachO::getFirstWritableSegmentAddress() uintptr_t ImageLoaderMachO::getRelocBase() { +#if __x86_64__ + // r_address is offset from first writable segment + return getFirstWritableSegmentAddress(); +#endif #if __ppc__ || __i386__ if ( fIsSplitSeg ) { // in split segment libraries r_address is offset from first writable segment @@ -1246,14 +1261,40 @@ static inline void otherRelocsPPC(uintptr_t* locationToFix, uint8_t relocationTy } #endif +#if __ppc__ || __i386__ +void ImageLoaderMachO::resetPreboundLazyPointers(const LinkContext& context, uintptr_t relocBase) +{ + // loop through all local (internal) relocation records looking for pre-bound-lazy-pointer values + 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) { + if ( (reloc->r_address & R_SCATTERED) != 0 ) { + const struct scattered_relocation_info* sreloc = (struct scattered_relocation_info*)reloc; + 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; + break; + #endif + } + } + } + } +} +#endif + void ImageLoaderMachO::doRebase(const LinkContext& context) { // if prebound and loaded at prebound address, then no need to rebase - // Note: you might think that the check for allDependentLibrariesAsWhenPreBound() is not needed - // but it is. If a dependent library changed, this image's lazy pointers into that library - // need to be updated (reset back to lazy binding handler). That work is done most easily - // here because there is a PPC_RELOC_PB_LA_PTR reloc record for each lazy pointer. - if ( this->usablePrebinding(context) && this->usesTwoLevelNameSpace() ) { + if ( this->usablePrebinding(context) ) { // skip rebasing cause prebound and prebinding not disabled ++fgImagesWithUsedPrebinding; // bump totals for statistics return; @@ -1278,18 +1319,40 @@ void ImageLoaderMachO::doRebase(const LinkContext& context) } } + // cache values that are used in the following loop + const uintptr_t relocBase = this->getRelocBase(); + register const uintptr_t slide = this->fSlide; + +#if __ppc__ || __i386__ + // if prebound and we got here, then prebinding is not valid, so reset all lazy pointers + if ( this->isPrebindable() ) + this->resetPreboundLazyPointers(context, relocBase); +#endif + + // if loaded at preferred address, no rebasing necessary + if ( slide == 0 ) + return; + // if there are __TEXT fixups, temporarily make __TEXT writable if ( fTextSegmentWithFixups != NULL ) fTextSegmentWithFixups->tempWritable(); - // cache this value that is used in the following loop - register const uintptr_t slide = this->fSlide; - // loop through all local (internal) relocation records - const uintptr_t relocBase = this->getRelocBase(); 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) { + #if __x86_64__ + // only one kind of local relocation supported for x86_64 + if ( reloc->r_length != 3 ) + throw "bad local relocation length"; + if ( reloc->r_type != X86_64_RELOC_UNSIGNED ) + throw "unknown local relocation type"; + if ( reloc->r_pcrel != 0 ) + throw "bad local relocation pc_rel"; + if ( reloc->r_extern != 0 ) + throw "extern relocation found with local relocations"; + *((uintptr_t*)(reloc->r_address + relocBase)) += slide; + #endif #if __ppc__ || __ppc64__ || __i386__ if ( (reloc->r_address & R_SCATTERED) == 0 ) { if ( reloc->r_symbolnum == R_ABS ) { @@ -1325,12 +1388,6 @@ void ImageLoaderMachO::doRebase(const LinkContext& context) case GENERIC_RELOC_VANILLA: *locationToFix += slide; break; - #if __ppc__ || __ppc64__ - case PPC_RELOC_PB_LA_PTR: - // should only see these in prebound images, and we got here so prebinding is being ignored - *locationToFix = sreloc->r_value + slide; - break; - #endif #if __ppc__ case PPC_RELOC_HI16: case PPC_RELOC_LO16: @@ -1340,10 +1397,14 @@ void ImageLoaderMachO::doRebase(const LinkContext& context) otherRelocsPPC(locationToFix, sreloc->r_type, reloc->r_address, slide); break; #endif + #if __ppc__ || __ppc64__ + case PPC_RELOC_PB_LA_PTR: + // do nothing + break; + #endif #if __i386__ case GENERIC_RELOC_PB_LA_PTR: - // should only see these in prebound images, and we got here so prebinding is being ignored - *locationToFix = sreloc->r_value + slide; + // do nothing break; #endif default: @@ -1354,7 +1415,7 @@ void ImageLoaderMachO::doRebase(const LinkContext& context) throw "bad local scattered relocation length"; } } - #endif + #endif } // if there were __TEXT fixups, restore write protection @@ -1973,14 +2034,35 @@ uintptr_t ImageLoaderMachO::bindIndirectSymbol(uintptr_t* ptrToBind, const struc #if __i386__ // i386 has special self-modifying stubs that change from "CALL rel32" to "JMP rel32" if ( ((sect->flags & SECTION_TYPE) == S_SYMBOL_STUBS) && ((sect->flags & S_ATTR_SELF_MODIFYING_CODE) != 0) && (sect->reserved2 == 5) ) { - uint8_t* const jmpTableEntryToPatch = (uint8_t*)ptrToBind; uint32_t rel32 = targetAddr - (((uint32_t)ptrToBind)+5); - //fprintf(stderr, "rewriting stub at %p\n", jmpTableEntryToPatch); - jmpTableEntryToPatch[0] = 0xE9; // JMP rel32 - jmpTableEntryToPatch[1] = rel32 & 0xFF; - jmpTableEntryToPatch[2] = (rel32 >> 8) & 0xFF; - jmpTableEntryToPatch[3] = (rel32 >> 16) & 0xFF; - jmpTableEntryToPatch[4] = (rel32 >> 24) & 0xFF; + // re-write instruction in a thread-safe manner + // use 8-byte compare-and-swap to alter 5-byte jump table entries + // loop is required in case the extra three bytes that cover the next entry are altered by another thread + bool done = false; + while ( !done ) { + volatile int64_t* jumpPtr = (int64_t*)ptrToBind; + int pad = 0; + // By default the three extra bytes swapped follow the 5-byte JMP. + // But, if the 5-byte jump is up against the end of the __IMPORT segment + // We don't want to access bytes off the end of the segment, so we shift + // the extra bytes to precede the 5-byte JMP. + if ( (((uint32_t)ptrToBind + 8) & 0x00000FFC) == 0x00000000 ) { + jumpPtr = (int64_t*)((uint32_t)ptrToBind - 3); + pad = 3; + } + int64_t oldEntry = *jumpPtr; + union { + int64_t int64; + uint8_t bytes[8]; + } newEntry; + newEntry.int64 = oldEntry; + newEntry.bytes[pad+0] = 0xE9; // JMP rel32 + newEntry.bytes[pad+1] = rel32 & 0xFF; + newEntry.bytes[pad+2] = (rel32 >> 8) & 0xFF; + newEntry.bytes[pad+3] = (rel32 >> 16) & 0xFF; + newEntry.bytes[pad+4] = (rel32 >> 24) & 0xFF; + done = OSAtomicCompareAndSwap64Barrier(oldEntry, newEntry.int64, (int64_t*)jumpPtr); + } } else #endif @@ -2530,7 +2612,7 @@ void ImageLoaderMachO::applyPrebindingToLinkEdit(const LinkContext& context, uin switch(sreloc->r_type) { #if __ppc__ || __ppc64__ case PPC_RELOC_PB_LA_PTR: - #elif __i386__ + #elif __i386__ || __x86_64__ case GENERIC_RELOC_PB_LA_PTR: #else #error unknown architecture diff --git a/src/ImageLoaderMachO.h b/src/ImageLoaderMachO.h index 3c3fe1e..4e33955 100644 --- a/src/ImageLoaderMachO.h +++ b/src/ImageLoaderMachO.h @@ -113,6 +113,7 @@ private: uintptr_t resolveUndefined(const LinkContext& context, const struct macho_nlist* symbol, bool twoLevel, ImageLoader **foundIn); uintptr_t getRelocBase(); uintptr_t getFirstWritableSegmentAddress(); + void resetPreboundLazyPointers(const LinkContext& context, uintptr_t relocBase); void doImageInit(const LinkContext& context); void doModInitFunctions(const LinkContext& context); void setupLazyPointerHandler(const LinkContext& context); diff --git a/src/dyld.cpp b/src/dyld.cpp index 2f1be41..3fc6ac5 100644 --- a/src/dyld.cpp +++ b/src/dyld.cpp @@ -1054,6 +1054,15 @@ static bool fatFindRunsOnAllCPUs(cpu_type_t cpu, const fat_header* fh, uint64_t* return true; } break; +#ifdef CPU_TYPE_X86_64 + case CPU_TYPE_X86_64: + if ( (cpu_subtype_t)OSSwapBigToHostInt32(archs[i].cpusubtype) == CPU_SUBTYPE_X86_64_ALL ) { + *offset = OSSwapBigToHostInt32(archs[i].offset); + *len = OSSwapBigToHostInt32(archs[i].size); + return true; + } + break; +#endif } } } @@ -1133,6 +1142,12 @@ bool isCompatibleMachO(const uint8_t* firstPage) if ( mh->cpusubtype == CPU_SUBTYPE_I386_ALL ) return true; break; +#ifdef CPU_TYPE_X86_64 + case CPU_TYPE_X86_64: + if ( mh->cpusubtype == CPU_SUBTYPE_X86_64_ALL ) + return true; + break; +#endif } } } @@ -1694,7 +1709,7 @@ void halt(const char* message) #if __ppc__ || __ppc64__ __asm__ ("trap"); -#elif __i386__ +#elif __i386__ || __x86_64__ __asm__ ("int3"); #else #error unknown architecture @@ -1906,21 +1921,16 @@ static void setContext(int argc, const char* argv[], const char* envp[], const c gLinkContext.apple = apple; } -static bool checkEmulation() +static bool isRosetta() { -#if __i386__ int mib[] = { CTL_KERN, KERN_CLASSIC, getpid() }; int is_classic = 0; size_t len = sizeof(int); int ret = sysctl(mib, 3, &is_classic, &len, NULL, 0); if ((ret != -1) && is_classic) { - // When a 32-bit ppc program is run under emulation on an Intel processor, - // we want any i386 dylibs (e.g. the emulator) to not load in the shared region - // because the shared region is being used by ppc dylibs - gLinkContext.sharedRegionMode = ImageLoader::kDontUseSharedRegion; + // we're running under Rosetta return true; } -#endif return false; } @@ -1982,13 +1992,20 @@ _main(const struct mach_header* mainExecutableMH, int argc, const char* argv[], // set pthread keys to dyld range __pthread_tsd_first = 1; - bool isEmulated = checkEmulation(); // Pickup the pointer to the exec path. sExecPath = apple[0]; - if (isEmulated) { - // under Rosetta + bool ignoreEnvironmentVariables = false; +#if __i386__ + if ( isRosetta() ) { + // under Rosetta (x86 side) + // When a 32-bit ppc program is run under emulation on an Intel processor, + // we want any i386 dylibs (e.g. any used by Rosetta) to not load in the shared region + // because the shared region is being used by ppc dylibs + gLinkContext.sharedRegionMode = ImageLoader::kDontUseSharedRegion; sExecPath = strdup(apple[0] + strlen(apple[0]) + 1); + ignoreEnvironmentVariables = true; } +#endif if ( sExecPath[0] != '/' ) { // have relative path, use cwd to make absolute char cwdbuff[MAXPATHLEN]; @@ -2006,7 +2023,7 @@ _main(const struct mach_header* mainExecutableMH, int argc, const char* argv[], if ( issetugid() ) pruneEnvironmentVariables(envp, &apple); else - checkEnvironmentVariables(envp, isEmulated); + checkEnvironmentVariables(envp, ignoreEnvironmentVariables); if ( sEnv.DYLD_PRINT_OPTS ) printOptions(argv); if ( sEnv.DYLD_PRINT_ENV ) @@ -2064,8 +2081,9 @@ _main(const struct mach_header* mainExecutableMH, int argc, const char* argv[], fprintf(stderr, "dyld: launch failed\n"); } + // Link in any inserted libraries. - // Do this after link main executable so any extra libraries pulled in by inserted libraries are at end of flat namespace + // Do this after linking main executable so any extra libraries pulled in by inserted libraries are at end of flat namespace if ( insertLibrariesCount > 0 ) { for (int i=0; i < insertLibrariesCount; ++i) { try { diff --git a/src/dyldAPIs.cpp b/src/dyldAPIs.cpp index 584ca60..64cfb89 100644 --- a/src/dyldAPIs.cpp +++ b/src/dyldAPIs.cpp @@ -401,12 +401,11 @@ const struct mach_header* _dyld_get_image_header(uint32_t image_index) static __attribute__((noinline)) -const struct mach_header* addImage(const char* path, bool search, bool dontLoad, bool matchInstallName, bool abortOnError) +const struct mach_header* addImage(void* callerAddress, const char* path, bool search, bool dontLoad, bool matchInstallName, bool abortOnError) { ImageLoader* image = NULL; try { dyld::clearErrorMessage(); - void* callerAddress = __builtin_return_address(2); // note layers: 2: real client, 1: libSystem glue, 0: dyld API ImageLoader* callerImage = dyld::findImageContainingAddress(callerAddress); dyld::LoadContext context; context.useSearchPaths = search; @@ -448,21 +447,24 @@ const struct mach_header* NSAddImage(const char* path, uint32_t options) const bool search = ( (options & NSADDIMAGE_OPTION_WITH_SEARCHING) != 0 ); const bool matchInstallName = ( (options & NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME) != 0 ); const bool abortOnError = ( (options & NSADDIMAGE_OPTION_RETURN_ON_ERROR) == 0 ); - return addImage(path, search, dontLoad, matchInstallName, abortOnError); + void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue + return addImage(callerAddress, path, search, dontLoad, matchInstallName, abortOnError); } bool NSAddLibrary(const char* path) { if ( dyld::gLogAPIs ) fprintf(stderr, "%s(\"%s\")\n", __func__, path); - return (addImage(path, false, false, false, false) != NULL); + void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue + return (addImage(callerAddress, path, false, false, false, false) != NULL); } bool NSAddLibraryWithSearching(const char* path) { if ( dyld::gLogAPIs ) fprintf(stderr, "%s(\"%s\")\n", __func__, path); - return (addImage(path, true, false, false, false) != NULL); + void* callerAddress = __builtin_return_address(1); // note layers: 1: real client, 0: libSystem glue + return (addImage(callerAddress, path, true, false, false, false) != NULL); } diff --git a/src/dyldInitialization.cpp b/src/dyldInitialization.cpp index 88f5270..a4e8cc3 100644 --- a/src/dyldInitialization.cpp +++ b/src/dyldInitialization.cpp @@ -31,6 +31,9 @@ #if __ppc__ || __ppc64__ #include #endif +#if __x86_64__ + #include +#endif #include "dyld.h" #if __LP64__ @@ -47,7 +50,11 @@ #define RELOC_SIZE 2 #endif +#if __x86_64__ + #define POINTER_RELOC X86_64_RELOC_UNSIGNED +#else #define POINTER_RELOC GENERIC_RELOC_VANILLA +#endif // // Code to bootstrap dyld into a runnable state @@ -107,6 +114,9 @@ static void rebaseDyld(const struct macho_header* mh, intptr_t slide) const struct load_command* const cmds = (struct load_command*)(((char*)mh)+sizeof(macho_header)); const struct load_command* cmd = cmds; const struct macho_segment_command* linkEditSeg = NULL; +#if __x86_64__ + const struct macho_segment_command* firstWritableSeg = NULL; +#endif const struct dysymtab_command* dynamicSymbolTable = NULL; for (uint32_t i = 0; i < cmd_count; ++i) { switch (cmd->cmd) { @@ -128,6 +138,10 @@ static void rebaseDyld(const struct macho_header* mh, intptr_t slide) } } } +#if __x86_64__ + if ( (firstWritableSeg == NULL) && (seg->initprot & VM_PROT_WRITE) ) + firstWritableSeg = seg; +#endif } break; case LC_DYSYMTAB: @@ -138,7 +152,11 @@ static void rebaseDyld(const struct macho_header* mh, intptr_t slide) } // use reloc's to rebase all random data pointers +#if __x86_64__ + const uintptr_t relocBase = firstWritableSeg->vmaddr + slide; +#else const uintptr_t relocBase = (uintptr_t)mh; +#endif const relocation_info* const relocsStart = (struct relocation_info*)(linkEditSeg->vmaddr + slide + dynamicSymbolTable->locreloff - linkEditSeg->fileoff); const relocation_info* const relocsEnd = &relocsStart[dynamicSymbolTable->nlocrel]; for (const relocation_info* reloc=relocsStart; reloc < relocsEnd; ++reloc) { diff --git a/src/dyldStartup.s b/src/dyldStartup.s index 6496a68..6601cab 100644 --- a/src/dyldStartup.s +++ b/src/dyldStartup.s @@ -123,6 +123,49 @@ L_end: #endif /* __i386__ */ +#if __x86_64__ + .data + .align 3 +__dyld_start_static: + .quad __dyld_start + +# stable entry points into dyld + .text + .align 2 + .globl _stub_binding_helper +_stub_binding_helper: + jmp _stub_binding_helper_interface + nop + nop + nop + .globl _dyld_func_lookup +_dyld_func_lookup: + jmp __Z18lookupDyldFunctionPKcPm + + .text + .align 2,0x90 + .globl __dyld_start +__dyld_start: + pushq $0 # push a zero for debugger end of frames marker + movq %rsp,%rbp # pointer to base of kernel frame + andq $-16,%rsp # force SSE alignment + + # call dyldbootstrap::start(app_mh, argc, argv, slide) + movq 8(%rbp),%rdi # param1 = mh into %rdi + movl 16(%rbp),%esi # param2 = argc into %esi + leaq 24(%rbp),%rdx # param3 = &argv[0] into %rdx + movq __dyld_start_static(%rip), %r8 + leaq __dyld_start(%rip), %rcx + subq %r8, %rcx # param4 = slide into %rcx + call __ZN13dyldbootstrap5startEPK11mach_headeriPPKcl + + # clean up stack and jump to result + movq %rbp,%rsp # restore the unaligned stack pointer + addq $16,%rsp # remove the mh argument, and debugger end frame marker + movq $0,%rbp # restore ebp back to zero + jmp *%rax # jump to the entry point + +#endif /* __x86_64__ */ #if __ppc__ || __ppc64__ #include diff --git a/src/stub_binding_helper.s b/src/stub_binding_helper.s index 89ed0dc..4b13088 100644 --- a/src/stub_binding_helper.s +++ b/src/stub_binding_helper.s @@ -93,6 +93,88 @@ _stub_binding_helper_interface: +#if __x86_64__ +/* + * This is the interface for the stub_binding_helper for x86_64: + * The caller has pushed the address of the a lazy pointer to be filled in with + * the value for the defined symbol and pushed the address of the the mach + * header this pointer comes from. + * + * sp+4 address of lazy pointer + * sp+0 address of mach header + * + * All parameters registers must be preserved. + * + * After the symbol has been resolved and the pointer filled in this is to pop + * these arguments off the stack and jump to the address of the defined symbol. + */ +#define MH_PARAM_BP 8 +#define LP_PARAM_BP 16 + +#define RDI_SAVE 0 +#define RSI_SAVE 8 +#define RDX_SAVE 16 +#define RCX_SAVE 24 +#define R8_SAVE 32 +#define R9_SAVE 40 +#define RAX_SAVE 48 +#define XMMM0_SAVE 64 /* 16-byte align */ +#define XMMM1_SAVE 80 +#define XMMM2_SAVE 96 +#define XMMM3_SAVE 112 +#define XMMM4_SAVE 128 +#define XMMM5_SAVE 144 +#define XMMM6_SAVE 160 +#define XMMM7_SAVE 176 +#define STACK_SIZE 192 /* (XMMM7_SAVE+16) must be 16 byte aligned too */ + + .text + .align 2,0x90 + .globl _stub_binding_helper_interface +_stub_binding_helper_interface: + pushq %rbp + movq %rsp,%rbp + subq $STACK_SIZE,%rsp # at this point stack is 16-byte aligned because two meta-parameters where pushed + movq %rdi,RDI_SAVE(%rsp) # save registers that might be used as parameters + movq %rsi,RSI_SAVE(%rsp) + movq %rdx,RDX_SAVE(%rsp) + movq %rcx,RCX_SAVE(%rsp) + movq %r8,R8_SAVE(%rsp) + movq %r9,R9_SAVE(%rsp) + movq %rax,RAX_SAVE(%rsp) + movdqa %xmm0,XMMM0_SAVE(%rsp) + movdqa %xmm1,XMMM1_SAVE(%rsp) + movdqa %xmm2,XMMM2_SAVE(%rsp) + movdqa %xmm3,XMMM3_SAVE(%rsp) + movdqa %xmm4,XMMM4_SAVE(%rsp) + movdqa %xmm5,XMMM5_SAVE(%rsp) + movdqa %xmm6,XMMM6_SAVE(%rsp) + movdqa %xmm7,XMMM7_SAVE(%rsp) + movq MH_PARAM_BP(%rbp),%rdi # call dyld::bindLazySymbol(mh, lazy_ptr) + movq LP_PARAM_BP(%rbp),%rsi + call __ZN4dyld14bindLazySymbolEPK11mach_headerPm + movq %rax,%r11 # save target + movdqa XMMM0_SAVE(%rsp),%xmm0 # restore registers + movdqa XMMM1_SAVE(%rsp),%xmm1 + movdqa XMMM2_SAVE(%rsp),%xmm2 + movdqa XMMM3_SAVE(%rsp),%xmm3 + movdqa XMMM4_SAVE(%rsp),%xmm4 + movdqa XMMM5_SAVE(%rsp),%xmm5 + movdqa XMMM6_SAVE(%rsp),%xmm6 + movdqa XMMM7_SAVE(%rsp),%xmm7 + movq RDI_SAVE(%rsp),%rdi + movq RSI_SAVE(%rsp),%rsi + movq RDX_SAVE(%rsp),%rdx + movq RCX_SAVE(%rsp),%rcx + movq R8_SAVE(%rsp),%r8 + movq R9_SAVE(%rsp),%r9 + movq RAX_SAVE(%rsp),%rax + addq $STACK_SIZE,%rsp + popq %rbp + addq $16,%rsp # remove meta-parameters + jmp *%r11 # jmp to target + +#endif #if __ppc__ || __ppc64__ #include diff --git a/unit-tests/run-all-unit-tests b/unit-tests/run-all-unit-tests index 38f8960..ef857d1 100755 --- a/unit-tests/run-all-unit-tests +++ b/unit-tests/run-all-unit-tests @@ -26,7 +26,7 @@ then fi # if Intel, then also run all test cases under emulation -if [ `machine` = "pentium4" ] +if [ `sysctl -n hw.machine` = "i386" ] then echo "" echo " * * * Running all unit tests for emulated 32-bits * * *" @@ -34,7 +34,19 @@ then # make clean ../bin/make-recursive.pl clean > /dev/null - # build 64-bit architecture + # build ppc architecture ../bin/make-recursive.pl ARCH="-arch ppc" | ../bin/result-filter.pl fi +# if 64-bit capable Intel, then also run all test cases for 64-bits +if [ `sysctl -n hw.optional.x86_64` = "1" ] +then + echo "" + echo " * * * Running all unit tests for 64-bits * * *" + + # make clean + ../bin/make-recursive.pl clean > /dev/null + + # build x86_64 architecture + ../bin/make-recursive.pl ARCH="-arch x86_64" | ../bin/result-filter.pl +fi diff --git a/unit-tests/test-cases/big-jump-table/Makefile b/unit-tests/test-cases/big-jump-table/Makefile new file mode 100644 index 0000000..0fe015b --- /dev/null +++ b/unit-tests/test-cases/big-jump-table/Makefile @@ -0,0 +1,60 @@ +## +# Copyright (c) 2005 Apple Computer, Inc. All rights reserved. +# +# @APPLE_LICENSE_HEADER_START@ +# +# This file contains Original Code and/or Modifications of Original Code +# as defined in and that are subject to the Apple Public Source License +# Version 2.0 (the 'License'). You may not use this file except in +# compliance with the License. Please obtain a copy of the License at +# http://www.opensource.apple.com/apsl/ and read it before using this +# file. +# +# The Original Code and all software distributed under the License are +# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, +# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. +# Please see the License for the specific language governing rights and +# limitations under the License. +# +# @APPLE_LICENSE_HEADER_END@ +## +TESTROOT = ../.. +include ${TESTROOT}/include/common.makefile + +run: all + ./main + +all: main + +### +### The point of this test is to check an edge case for i386 architecture +### with "fast stubs". We want to verify that a fast stub that ends +### near the page boundary for the __IMPORT segment does not cause an +### accidental read beyou the __IMPORT segment +### rdar://problem/4653725 +### + +main: main.c libtest1.dylib libtest2.dylib libtest3.dylib libtest4.dylib + ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libtest1.dylib libtest2.dylib libtest3.dylib libtest4.dylib + +libtest1.dylib: pointers.c funcs.c libfoo.dylib + ${CC} ${CCFLAGS} -dynamiclib pointers.c funcs.c -DCASE=1 -o libtest1.dylib libfoo.dylib + +libtest2.dylib: pointers.c funcs.c libfoo.dylib + ${CC} ${CCFLAGS} -dynamiclib pointers.c funcs.c -DCASE=2 -o libtest2.dylib libfoo.dylib + +libtest3.dylib: pointers.c funcs.c libfoo.dylib + ${CC} ${CCFLAGS} -dynamiclib pointers.c funcs.c -DCASE=3 -o libtest3.dylib libfoo.dylib + +libtest4.dylib: pointers.c funcs.c libfoo.dylib + ${CC} ${CCFLAGS} -dynamiclib pointers.c funcs.c -DCASE=4 -o libtest4.dylib libfoo.dylib + +libfoo.dylib: foo.c + ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib + + +clean: + ${RM} ${RMFLAGS} *~ main libtest1.dylib libtest2.dylib libtest3.dylib libtest4.dylib libfoo.dylib + diff --git a/unit-tests/test-cases/big-jump-table/foo.c b/unit-tests/test-cases/big-jump-table/foo.c new file mode 100644 index 0000000..c1a6c6c --- /dev/null +++ b/unit-tests/test-cases/big-jump-table/foo.c @@ -0,0 +1,827 @@ +#include "foo.h" + +void foo000() {} +void foo001() {} +void foo002() {} +void foo003() {} +void foo004() {} +void foo005() {} +void foo006() {} +void foo007() {} +void foo008() {} +void foo009() {} +void foo010() {} +void foo011() {} +void foo012() {} +void foo013() {} +void foo014() {} +void foo015() {} +void foo016() {} +void foo017() {} +void foo018() {} +void foo019() {} +void foo020() {} +void foo021() {} +void foo022() {} +void foo023() {} +void foo024() {} +void foo025() {} +void foo026() {} +void foo027() {} +void foo028() {} +void foo029() {} +void foo030() {} +void foo031() {} +void foo032() {} +void foo033() {} +void foo034() {} +void foo035() {} +void foo036() {} +void foo037() {} +void foo038() {} +void foo039() {} +void foo040() {} +void foo041() {} +void foo042() {} +void foo043() {} +void foo044() {} +void foo045() {} +void foo046() {} +void foo047() {} +void foo048() {} +void foo049() {} +void foo050() {} +void foo051() {} +void foo052() {} +void foo053() {} +void foo054() {} +void foo055() {} +void foo056() {} +void foo057() {} +void foo058() {} +void foo059() {} +void foo060() {} +void foo061() {} +void foo062() {} +void foo063() {} +void foo064() {} +void foo065() {} +void foo066() {} +void foo067() {} +void foo068() {} +void foo069() {} +void foo070() {} +void foo071() {} +void foo072() {} +void foo073() {} +void foo074() {} +void foo075() {} +void foo076() {} +void foo077() {} +void foo078() {} +void foo079() {} +void foo080() {} +void foo081() {} +void foo082() {} +void foo083() {} +void foo084() {} +void foo085() {} +void foo086() {} +void foo087() {} +void foo088() {} +void foo089() {} +void foo090() {} +void foo091() {} +void foo092() {} +void foo093() {} +void foo094() {} +void foo095() {} +void foo096() {} +void foo097() {} +void foo098() {} +void foo099() {} +void foo100() {} +void foo101() {} +void foo102() {} +void foo103() {} +void foo104() {} +void foo105() {} +void foo106() {} +void foo107() {} +void foo108() {} +void foo109() {} +void foo110() {} +void foo111() {} +void foo112() {} +void foo113() {} +void foo114() {} +void foo115() {} +void foo116() {} +void foo117() {} +void foo118() {} +void foo119() {} +void foo120() {} +void foo121() {} +void foo122() {} +void foo123() {} +void foo124() {} +void foo125() {} +void foo126() {} +void foo127() {} +void foo128() {} +void foo129() {} +void foo130() {} +void foo131() {} +void foo132() {} +void foo133() {} +void foo134() {} +void foo135() {} +void foo136() {} +void foo137() {} +void foo138() {} +void foo139() {} +void foo140() {} +void foo141() {} +void foo142() {} +void foo143() {} +void foo144() {} +void foo145() {} +void foo146() {} +void foo147() {} +void foo148() {} +void foo149() {} +void foo150() {} +void foo151() {} +void foo152() {} +void foo153() {} +void foo154() {} +void foo155() {} +void foo156() {} +void foo157() {} +void foo158() {} +void foo159() {} +void foo160() {} +void foo161() {} +void foo162() {} +void foo163() {} +void foo164() {} +void foo165() {} +void foo166() {} +void foo167() {} +void foo168() {} +void foo169() {} +void foo170() {} +void foo171() {} +void foo172() {} +void foo173() {} +void foo174() {} +void foo175() {} +void foo176() {} +void foo177() {} +void foo178() {} +void foo179() {} +void foo180() {} +void foo181() {} +void foo182() {} +void foo183() {} +void foo184() {} +void foo185() {} +void foo186() {} +void foo187() {} +void foo188() {} +void foo189() {} +void foo190() {} +void foo191() {} +void foo192() {} +void foo193() {} +void foo194() {} +void foo195() {} +void foo196() {} +void foo197() {} +void foo198() {} +void foo199() {} +void foo200() {} +void foo201() {} +void foo202() {} +void foo203() {} +void foo204() {} +void foo205() {} +void foo206() {} +void foo207() {} +void foo208() {} +void foo209() {} +void foo210() {} +void foo211() {} +void foo212() {} +void foo213() {} +void foo214() {} +void foo215() {} +void foo216() {} +void foo217() {} +void foo218() {} +void foo219() {} +void foo220() {} +void foo221() {} +void foo222() {} +void foo223() {} +void foo224() {} +void foo225() {} +void foo226() {} +void foo227() {} +void foo228() {} +void foo229() {} +void foo230() {} +void foo231() {} +void foo232() {} +void foo233() {} +void foo234() {} +void foo235() {} +void foo236() {} +void foo237() {} +void foo238() {} +void foo239() {} +void foo240() {} +void foo241() {} +void foo242() {} +void foo243() {} +void foo244() {} +void foo245() {} +void foo246() {} +void foo247() {} +void foo248() {} +void foo249() {} +void foo250() {} +void foo251() {} +void foo252() {} +void foo253() {} +void foo254() {} +void foo255() {} +void foo256() {} +void foo257() {} +void foo258() {} +void foo259() {} +void foo260() {} +void foo261() {} +void foo262() {} +void foo263() {} +void foo264() {} +void foo265() {} +void foo266() {} +void foo267() {} +void foo268() {} +void foo269() {} +void foo270() {} +void foo271() {} +void foo272() {} +void foo273() {} +void foo274() {} +void foo275() {} +void foo276() {} +void foo277() {} +void foo278() {} +void foo279() {} +void foo280() {} +void foo281() {} +void foo282() {} +void foo283() {} +void foo284() {} +void foo285() {} +void foo286() {} +void foo287() {} +void foo288() {} +void foo289() {} +void foo290() {} +void foo291() {} +void foo292() {} +void foo293() {} +void foo294() {} +void foo295() {} +void foo296() {} +void foo297() {} +void foo298() {} +void foo299() {} +void foo300() {} +void foo301() {} +void foo302() {} +void foo303() {} +void foo304() {} +void foo305() {} +void foo306() {} +void foo307() {} +void foo308() {} +void foo309() {} +void foo310() {} +void foo311() {} +void foo312() {} +void foo313() {} +void foo314() {} +void foo315() {} +void foo316() {} +void foo317() {} +void foo318() {} +void foo319() {} +void foo320() {} +void foo321() {} +void foo322() {} +void foo323() {} +void foo324() {} +void foo325() {} +void foo326() {} +void foo327() {} +void foo328() {} +void foo329() {} +void foo330() {} +void foo331() {} +void foo332() {} +void foo333() {} +void foo334() {} +void foo335() {} +void foo336() {} +void foo337() {} +void foo338() {} +void foo339() {} +void foo340() {} +void foo341() {} +void foo342() {} +void foo343() {} +void foo344() {} +void foo345() {} +void foo346() {} +void foo347() {} +void foo348() {} +void foo349() {} +void foo350() {} +void foo351() {} +void foo352() {} +void foo353() {} +void foo354() {} +void foo355() {} +void foo356() {} +void foo357() {} +void foo358() {} +void foo359() {} +void foo360() {} +void foo361() {} +void foo362() {} +void foo363() {} +void foo364() {} +void foo365() {} +void foo366() {} +void foo367() {} +void foo368() {} +void foo369() {} +void foo370() {} +void foo371() {} +void foo372() {} +void foo373() {} +void foo374() {} +void foo375() {} +void foo376() {} +void foo377() {} +void foo378() {} +void foo379() {} +void foo380() {} +void foo381() {} +void foo382() {} +void foo383() {} +void foo384() {} +void foo385() {} +void foo386() {} +void foo387() {} +void foo388() {} +void foo389() {} +void foo390() {} +void foo391() {} +void foo392() {} +void foo393() {} +void foo394() {} +void foo395() {} +void foo396() {} +void foo397() {} +void foo398() {} +void foo399() {} +void foo400() {} +void foo401() {} +void foo402() {} +void foo403() {} +void foo404() {} +void foo405() {} +void foo406() {} +void foo407() {} +void foo408() {} +void foo409() {} +void foo410() {} +void foo411() {} +void foo412() {} +void foo413() {} +void foo414() {} +void foo415() {} +void foo416() {} +void foo417() {} +void foo418() {} +void foo419() {} +void foo420() {} +void foo421() {} +void foo422() {} +void foo423() {} +void foo424() {} +void foo425() {} +void foo426() {} +void foo427() {} +void foo428() {} +void foo429() {} +void foo430() {} +void foo431() {} +void foo432() {} +void foo433() {} +void foo434() {} +void foo435() {} +void foo436() {} +void foo437() {} +void foo438() {} +void foo439() {} +void foo440() {} +void foo441() {} +void foo442() {} +void foo443() {} +void foo444() {} +void foo445() {} +void foo446() {} +void foo447() {} +void foo448() {} +void foo449() {} +void foo450() {} +void foo451() {} +void foo452() {} +void foo453() {} +void foo454() {} +void foo455() {} +void foo456() {} +void foo457() {} +void foo458() {} +void foo459() {} +void foo460() {} +void foo461() {} +void foo462() {} +void foo463() {} +void foo464() {} +void foo465() {} +void foo466() {} +void foo467() {} +void foo468() {} +void foo469() {} +void foo470() {} +void foo471() {} +void foo472() {} +void foo473() {} +void foo474() {} +void foo475() {} +void foo476() {} +void foo477() {} +void foo478() {} +void foo479() {} +void foo480() {} +void foo481() {} +void foo482() {} +void foo483() {} +void foo484() {} +void foo485() {} +void foo486() {} +void foo487() {} +void foo488() {} +void foo489() {} +void foo490() {} +void foo491() {} +void foo492() {} +void foo493() {} +void foo494() {} +void foo495() {} +void foo496() {} +void foo497() {} +void foo498() {} +void foo499() {} +void foo500() {} +void foo501() {} +void foo502() {} +void foo503() {} +void foo504() {} +void foo505() {} +void foo506() {} +void foo507() {} +void foo508() {} +void foo509() {} +void foo510() {} +void foo511() {} +void foo512() {} +void foo513() {} +void foo514() {} +void foo515() {} +void foo516() {} +void foo517() {} +void foo518() {} +void foo519() {} +void foo520() {} +void foo521() {} +void foo522() {} +void foo523() {} +void foo524() {} +void foo525() {} +void foo526() {} +void foo527() {} +void foo528() {} +void foo529() {} +void foo530() {} +void foo531() {} +void foo532() {} +void foo533() {} +void foo534() {} +void foo535() {} +void foo536() {} +void foo537() {} +void foo538() {} +void foo539() {} +void foo540() {} +void foo541() {} +void foo542() {} +void foo543() {} +void foo544() {} +void foo545() {} +void foo546() {} +void foo547() {} +void foo548() {} +void foo549() {} +void foo550() {} +void foo551() {} +void foo552() {} +void foo553() {} +void foo554() {} +void foo555() {} +void foo556() {} +void foo557() {} +void foo558() {} +void foo559() {} +void foo560() {} +void foo561() {} +void foo562() {} +void foo563() {} +void foo564() {} +void foo565() {} +void foo566() {} +void foo567() {} +void foo568() {} +void foo569() {} +void foo570() {} +void foo571() {} +void foo572() {} +void foo573() {} +void foo574() {} +void foo575() {} +void foo576() {} +void foo577() {} +void foo578() {} +void foo579() {} +void foo580() {} +void foo581() {} +void foo582() {} +void foo583() {} +void foo584() {} +void foo585() {} +void foo586() {} +void foo587() {} +void foo588() {} +void foo589() {} +void foo590() {} +void foo591() {} +void foo592() {} +void foo593() {} +void foo594() {} +void foo595() {} +void foo596() {} +void foo597() {} +void foo598() {} +void foo599() {} +void foo600() {} +void foo601() {} +void foo602() {} +void foo603() {} +void foo604() {} +void foo605() {} +void foo606() {} +void foo607() {} +void foo608() {} +void foo609() {} +void foo610() {} +void foo611() {} +void foo612() {} +void foo613() {} +void foo614() {} +void foo615() {} +void foo616() {} +void foo617() {} +void foo618() {} +void foo619() {} +void foo620() {} +void foo621() {} +void foo622() {} +void foo623() {} +void foo624() {} +void foo625() {} +void foo626() {} +void foo627() {} +void foo628() {} +void foo629() {} +void foo630() {} +void foo631() {} +void foo632() {} +void foo633() {} +void foo634() {} +void foo635() {} +void foo636() {} +void foo637() {} +void foo638() {} +void foo639() {} +void foo640() {} +void foo641() {} +void foo642() {} +void foo643() {} +void foo644() {} +void foo645() {} +void foo646() {} +void foo647() {} +void foo648() {} +void foo649() {} +void foo650() {} +void foo651() {} +void foo652() {} +void foo653() {} +void foo654() {} +void foo655() {} +void foo656() {} +void foo657() {} +void foo658() {} +void foo659() {} +void foo660() {} +void foo661() {} +void foo662() {} +void foo663() {} +void foo664() {} +void foo665() {} +void foo666() {} +void foo667() {} +void foo668() {} +void foo669() {} +void foo670() {} +void foo671() {} +void foo672() {} +void foo673() {} +void foo674() {} +void foo675() {} +void foo676() {} +void foo677() {} +void foo678() {} +void foo679() {} +void foo680() {} +void foo681() {} +void foo682() {} +void foo683() {} +void foo684() {} +void foo685() {} +void foo686() {} +void foo687() {} +void foo688() {} +void foo689() {} +void foo690() {} +void foo691() {} +void foo692() {} +void foo693() {} +void foo694() {} +void foo695() {} +void foo696() {} +void foo697() {} +void foo698() {} +void foo699() {} +void foo700() {} +void foo701() {} +void foo702() {} +void foo703() {} +void foo704() {} +void foo705() {} +void foo706() {} +void foo707() {} +void foo708() {} +void foo709() {} +void foo710() {} +void foo711() {} +void foo712() {} +void foo713() {} +void foo714() {} +void foo715() {} +void foo716() {} +void foo717() {} +void foo718() {} +void foo719() {} +void foo720() {} +void foo721() {} +void foo722() {} +void foo723() {} +void foo724() {} +void foo725() {} +void foo726() {} +void foo727() {} +void foo728() {} +void foo729() {} +void foo730() {} +void foo731() {} +void foo732() {} +void foo733() {} +void foo734() {} +void foo735() {} +void foo736() {} +void foo737() {} +void foo738() {} +void foo739() {} +void foo740() {} +void foo741() {} +void foo742() {} +void foo743() {} +void foo744() {} +void foo745() {} +void foo746() {} +void foo747() {} +void foo748() {} +void foo749() {} +void foo750() {} +void foo751() {} +void foo752() {} +void foo753() {} +void foo754() {} +void foo755() {} +void foo756() {} +void foo757() {} +void foo758() {} +void foo759() {} +void foo760() {} +void foo761() {} +void foo762() {} +void foo763() {} +void foo764() {} +void foo765() {} +void foo766() {} +void foo767() {} +void foo768() {} +void foo769() {} +void foo770() {} +void foo771() {} +void foo772() {} +void foo773() {} +void foo774() {} +void foo775() {} +void foo776() {} +void foo777() {} +void foo778() {} +void foo779() {} +void foo780() {} +void foo781() {} +void foo782() {} +void foo783() {} +void foo784() {} +void foo785() {} +void foo786() {} +void foo787() {} +void foo788() {} +void foo789() {} +void foo790() {} +void foo791() {} +void foo792() {} +void foo793() {} +void foo794() {} +void foo795() {} +void foo796() {} +void foo797() {} +void foo798() {} +void foo799() {} +void foo800() {} +void foo801() {} +void foo802() {} +void foo803() {} +void foo804() {} +void foo805() {} +void foo806() {} +void foo807() {} +void foo808() {} +void foo809() {} +void foo810() {} +void foo811() {} +void foo812() {} +void foo813() {} +void foo814() {} +void foo815() {} +void foo816() {} +void foo817() {} +void foo818() {} +void foo819() {} +void foo820() {} +void foo821() {} +void foo822() {} +void foo823() {} +void foo824() {} diff --git a/unit-tests/test-cases/big-jump-table/foo.h b/unit-tests/test-cases/big-jump-table/foo.h new file mode 100644 index 0000000..e9b155b --- /dev/null +++ b/unit-tests/test-cases/big-jump-table/foo.h @@ -0,0 +1,825 @@ +extern void foo000(); +extern void foo001(); +extern void foo002(); +extern void foo003(); +extern void foo004(); +extern void foo005(); +extern void foo006(); +extern void foo007(); +extern void foo008(); +extern void foo009(); +extern void foo010(); +extern void foo011(); +extern void foo012(); +extern void foo013(); +extern void foo014(); +extern void foo015(); +extern void foo016(); +extern void foo017(); +extern void foo018(); +extern void foo019(); +extern void foo020(); +extern void foo021(); +extern void foo022(); +extern void foo023(); +extern void foo024(); +extern void foo025(); +extern void foo026(); +extern void foo027(); +extern void foo028(); +extern void foo029(); +extern void foo030(); +extern void foo031(); +extern void foo032(); +extern void foo033(); +extern void foo034(); +extern void foo035(); +extern void foo036(); +extern void foo037(); +extern void foo038(); +extern void foo039(); +extern void foo040(); +extern void foo041(); +extern void foo042(); +extern void foo043(); +extern void foo044(); +extern void foo045(); +extern void foo046(); +extern void foo047(); +extern void foo048(); +extern void foo049(); +extern void foo050(); +extern void foo051(); +extern void foo052(); +extern void foo053(); +extern void foo054(); +extern void foo055(); +extern void foo056(); +extern void foo057(); +extern void foo058(); +extern void foo059(); +extern void foo060(); +extern void foo061(); +extern void foo062(); +extern void foo063(); +extern void foo064(); +extern void foo065(); +extern void foo066(); +extern void foo067(); +extern void foo068(); +extern void foo069(); +extern void foo070(); +extern void foo071(); +extern void foo072(); +extern void foo073(); +extern void foo074(); +extern void foo075(); +extern void foo076(); +extern void foo077(); +extern void foo078(); +extern void foo079(); +extern void foo080(); +extern void foo081(); +extern void foo082(); +extern void foo083(); +extern void foo084(); +extern void foo085(); +extern void foo086(); +extern void foo087(); +extern void foo088(); +extern void foo089(); +extern void foo090(); +extern void foo091(); +extern void foo092(); +extern void foo093(); +extern void foo094(); +extern void foo095(); +extern void foo096(); +extern void foo097(); +extern void foo098(); +extern void foo099(); +extern void foo100(); +extern void foo101(); +extern void foo102(); +extern void foo103(); +extern void foo104(); +extern void foo105(); +extern void foo106(); +extern void foo107(); +extern void foo108(); +extern void foo109(); +extern void foo110(); +extern void foo111(); +extern void foo112(); +extern void foo113(); +extern void foo114(); +extern void foo115(); +extern void foo116(); +extern void foo117(); +extern void foo118(); +extern void foo119(); +extern void foo120(); +extern void foo121(); +extern void foo122(); +extern void foo123(); +extern void foo124(); +extern void foo125(); +extern void foo126(); +extern void foo127(); +extern void foo128(); +extern void foo129(); +extern void foo130(); +extern void foo131(); +extern void foo132(); +extern void foo133(); +extern void foo134(); +extern void foo135(); +extern void foo136(); +extern void foo137(); +extern void foo138(); +extern void foo139(); +extern void foo140(); +extern void foo141(); +extern void foo142(); +extern void foo143(); +extern void foo144(); +extern void foo145(); +extern void foo146(); +extern void foo147(); +extern void foo148(); +extern void foo149(); +extern void foo150(); +extern void foo151(); +extern void foo152(); +extern void foo153(); +extern void foo154(); +extern void foo155(); +extern void foo156(); +extern void foo157(); +extern void foo158(); +extern void foo159(); +extern void foo160(); +extern void foo161(); +extern void foo162(); +extern void foo163(); +extern void foo164(); +extern void foo165(); +extern void foo166(); +extern void foo167(); +extern void foo168(); +extern void foo169(); +extern void foo170(); +extern void foo171(); +extern void foo172(); +extern void foo173(); +extern void foo174(); +extern void foo175(); +extern void foo176(); +extern void foo177(); +extern void foo178(); +extern void foo179(); +extern void foo180(); +extern void foo181(); +extern void foo182(); +extern void foo183(); +extern void foo184(); +extern void foo185(); +extern void foo186(); +extern void foo187(); +extern void foo188(); +extern void foo189(); +extern void foo190(); +extern void foo191(); +extern void foo192(); +extern void foo193(); +extern void foo194(); +extern void foo195(); +extern void foo196(); +extern void foo197(); +extern void foo198(); +extern void foo199(); +extern void foo200(); +extern void foo201(); +extern void foo202(); +extern void foo203(); +extern void foo204(); +extern void foo205(); +extern void foo206(); +extern void foo207(); +extern void foo208(); +extern void foo209(); +extern void foo210(); +extern void foo211(); +extern void foo212(); +extern void foo213(); +extern void foo214(); +extern void foo215(); +extern void foo216(); +extern void foo217(); +extern void foo218(); +extern void foo219(); +extern void foo220(); +extern void foo221(); +extern void foo222(); +extern void foo223(); +extern void foo224(); +extern void foo225(); +extern void foo226(); +extern void foo227(); +extern void foo228(); +extern void foo229(); +extern void foo230(); +extern void foo231(); +extern void foo232(); +extern void foo233(); +extern void foo234(); +extern void foo235(); +extern void foo236(); +extern void foo237(); +extern void foo238(); +extern void foo239(); +extern void foo240(); +extern void foo241(); +extern void foo242(); +extern void foo243(); +extern void foo244(); +extern void foo245(); +extern void foo246(); +extern void foo247(); +extern void foo248(); +extern void foo249(); +extern void foo250(); +extern void foo251(); +extern void foo252(); +extern void foo253(); +extern void foo254(); +extern void foo255(); +extern void foo256(); +extern void foo257(); +extern void foo258(); +extern void foo259(); +extern void foo260(); +extern void foo261(); +extern void foo262(); +extern void foo263(); +extern void foo264(); +extern void foo265(); +extern void foo266(); +extern void foo267(); +extern void foo268(); +extern void foo269(); +extern void foo270(); +extern void foo271(); +extern void foo272(); +extern void foo273(); +extern void foo274(); +extern void foo275(); +extern void foo276(); +extern void foo277(); +extern void foo278(); +extern void foo279(); +extern void foo280(); +extern void foo281(); +extern void foo282(); +extern void foo283(); +extern void foo284(); +extern void foo285(); +extern void foo286(); +extern void foo287(); +extern void foo288(); +extern void foo289(); +extern void foo290(); +extern void foo291(); +extern void foo292(); +extern void foo293(); +extern void foo294(); +extern void foo295(); +extern void foo296(); +extern void foo297(); +extern void foo298(); +extern void foo299(); +extern void foo300(); +extern void foo301(); +extern void foo302(); +extern void foo303(); +extern void foo304(); +extern void foo305(); +extern void foo306(); +extern void foo307(); +extern void foo308(); +extern void foo309(); +extern void foo310(); +extern void foo311(); +extern void foo312(); +extern void foo313(); +extern void foo314(); +extern void foo315(); +extern void foo316(); +extern void foo317(); +extern void foo318(); +extern void foo319(); +extern void foo320(); +extern void foo321(); +extern void foo322(); +extern void foo323(); +extern void foo324(); +extern void foo325(); +extern void foo326(); +extern void foo327(); +extern void foo328(); +extern void foo329(); +extern void foo330(); +extern void foo331(); +extern void foo332(); +extern void foo333(); +extern void foo334(); +extern void foo335(); +extern void foo336(); +extern void foo337(); +extern void foo338(); +extern void foo339(); +extern void foo340(); +extern void foo341(); +extern void foo342(); +extern void foo343(); +extern void foo344(); +extern void foo345(); +extern void foo346(); +extern void foo347(); +extern void foo348(); +extern void foo349(); +extern void foo350(); +extern void foo351(); +extern void foo352(); +extern void foo353(); +extern void foo354(); +extern void foo355(); +extern void foo356(); +extern void foo357(); +extern void foo358(); +extern void foo359(); +extern void foo360(); +extern void foo361(); +extern void foo362(); +extern void foo363(); +extern void foo364(); +extern void foo365(); +extern void foo366(); +extern void foo367(); +extern void foo368(); +extern void foo369(); +extern void foo370(); +extern void foo371(); +extern void foo372(); +extern void foo373(); +extern void foo374(); +extern void foo375(); +extern void foo376(); +extern void foo377(); +extern void foo378(); +extern void foo379(); +extern void foo380(); +extern void foo381(); +extern void foo382(); +extern void foo383(); +extern void foo384(); +extern void foo385(); +extern void foo386(); +extern void foo387(); +extern void foo388(); +extern void foo389(); +extern void foo390(); +extern void foo391(); +extern void foo392(); +extern void foo393(); +extern void foo394(); +extern void foo395(); +extern void foo396(); +extern void foo397(); +extern void foo398(); +extern void foo399(); +extern void foo400(); +extern void foo401(); +extern void foo402(); +extern void foo403(); +extern void foo404(); +extern void foo405(); +extern void foo406(); +extern void foo407(); +extern void foo408(); +extern void foo409(); +extern void foo410(); +extern void foo411(); +extern void foo412(); +extern void foo413(); +extern void foo414(); +extern void foo415(); +extern void foo416(); +extern void foo417(); +extern void foo418(); +extern void foo419(); +extern void foo420(); +extern void foo421(); +extern void foo422(); +extern void foo423(); +extern void foo424(); +extern void foo425(); +extern void foo426(); +extern void foo427(); +extern void foo428(); +extern void foo429(); +extern void foo430(); +extern void foo431(); +extern void foo432(); +extern void foo433(); +extern void foo434(); +extern void foo435(); +extern void foo436(); +extern void foo437(); +extern void foo438(); +extern void foo439(); +extern void foo440(); +extern void foo441(); +extern void foo442(); +extern void foo443(); +extern void foo444(); +extern void foo445(); +extern void foo446(); +extern void foo447(); +extern void foo448(); +extern void foo449(); +extern void foo450(); +extern void foo451(); +extern void foo452(); +extern void foo453(); +extern void foo454(); +extern void foo455(); +extern void foo456(); +extern void foo457(); +extern void foo458(); +extern void foo459(); +extern void foo460(); +extern void foo461(); +extern void foo462(); +extern void foo463(); +extern void foo464(); +extern void foo465(); +extern void foo466(); +extern void foo467(); +extern void foo468(); +extern void foo469(); +extern void foo470(); +extern void foo471(); +extern void foo472(); +extern void foo473(); +extern void foo474(); +extern void foo475(); +extern void foo476(); +extern void foo477(); +extern void foo478(); +extern void foo479(); +extern void foo480(); +extern void foo481(); +extern void foo482(); +extern void foo483(); +extern void foo484(); +extern void foo485(); +extern void foo486(); +extern void foo487(); +extern void foo488(); +extern void foo489(); +extern void foo490(); +extern void foo491(); +extern void foo492(); +extern void foo493(); +extern void foo494(); +extern void foo495(); +extern void foo496(); +extern void foo497(); +extern void foo498(); +extern void foo499(); +extern void foo500(); +extern void foo501(); +extern void foo502(); +extern void foo503(); +extern void foo504(); +extern void foo505(); +extern void foo506(); +extern void foo507(); +extern void foo508(); +extern void foo509(); +extern void foo510(); +extern void foo511(); +extern void foo512(); +extern void foo513(); +extern void foo514(); +extern void foo515(); +extern void foo516(); +extern void foo517(); +extern void foo518(); +extern void foo519(); +extern void foo520(); +extern void foo521(); +extern void foo522(); +extern void foo523(); +extern void foo524(); +extern void foo525(); +extern void foo526(); +extern void foo527(); +extern void foo528(); +extern void foo529(); +extern void foo530(); +extern void foo531(); +extern void foo532(); +extern void foo533(); +extern void foo534(); +extern void foo535(); +extern void foo536(); +extern void foo537(); +extern void foo538(); +extern void foo539(); +extern void foo540(); +extern void foo541(); +extern void foo542(); +extern void foo543(); +extern void foo544(); +extern void foo545(); +extern void foo546(); +extern void foo547(); +extern void foo548(); +extern void foo549(); +extern void foo550(); +extern void foo551(); +extern void foo552(); +extern void foo553(); +extern void foo554(); +extern void foo555(); +extern void foo556(); +extern void foo557(); +extern void foo558(); +extern void foo559(); +extern void foo560(); +extern void foo561(); +extern void foo562(); +extern void foo563(); +extern void foo564(); +extern void foo565(); +extern void foo566(); +extern void foo567(); +extern void foo568(); +extern void foo569(); +extern void foo570(); +extern void foo571(); +extern void foo572(); +extern void foo573(); +extern void foo574(); +extern void foo575(); +extern void foo576(); +extern void foo577(); +extern void foo578(); +extern void foo579(); +extern void foo580(); +extern void foo581(); +extern void foo582(); +extern void foo583(); +extern void foo584(); +extern void foo585(); +extern void foo586(); +extern void foo587(); +extern void foo588(); +extern void foo589(); +extern void foo590(); +extern void foo591(); +extern void foo592(); +extern void foo593(); +extern void foo594(); +extern void foo595(); +extern void foo596(); +extern void foo597(); +extern void foo598(); +extern void foo599(); +extern void foo600(); +extern void foo601(); +extern void foo602(); +extern void foo603(); +extern void foo604(); +extern void foo605(); +extern void foo606(); +extern void foo607(); +extern void foo608(); +extern void foo609(); +extern void foo610(); +extern void foo611(); +extern void foo612(); +extern void foo613(); +extern void foo614(); +extern void foo615(); +extern void foo616(); +extern void foo617(); +extern void foo618(); +extern void foo619(); +extern void foo620(); +extern void foo621(); +extern void foo622(); +extern void foo623(); +extern void foo624(); +extern void foo625(); +extern void foo626(); +extern void foo627(); +extern void foo628(); +extern void foo629(); +extern void foo630(); +extern void foo631(); +extern void foo632(); +extern void foo633(); +extern void foo634(); +extern void foo635(); +extern void foo636(); +extern void foo637(); +extern void foo638(); +extern void foo639(); +extern void foo640(); +extern void foo641(); +extern void foo642(); +extern void foo643(); +extern void foo644(); +extern void foo645(); +extern void foo646(); +extern void foo647(); +extern void foo648(); +extern void foo649(); +extern void foo650(); +extern void foo651(); +extern void foo652(); +extern void foo653(); +extern void foo654(); +extern void foo655(); +extern void foo656(); +extern void foo657(); +extern void foo658(); +extern void foo659(); +extern void foo660(); +extern void foo661(); +extern void foo662(); +extern void foo663(); +extern void foo664(); +extern void foo665(); +extern void foo666(); +extern void foo667(); +extern void foo668(); +extern void foo669(); +extern void foo670(); +extern void foo671(); +extern void foo672(); +extern void foo673(); +extern void foo674(); +extern void foo675(); +extern void foo676(); +extern void foo677(); +extern void foo678(); +extern void foo679(); +extern void foo680(); +extern void foo681(); +extern void foo682(); +extern void foo683(); +extern void foo684(); +extern void foo685(); +extern void foo686(); +extern void foo687(); +extern void foo688(); +extern void foo689(); +extern void foo690(); +extern void foo691(); +extern void foo692(); +extern void foo693(); +extern void foo694(); +extern void foo695(); +extern void foo696(); +extern void foo697(); +extern void foo698(); +extern void foo699(); +extern void foo700(); +extern void foo701(); +extern void foo702(); +extern void foo703(); +extern void foo704(); +extern void foo705(); +extern void foo706(); +extern void foo707(); +extern void foo708(); +extern void foo709(); +extern void foo710(); +extern void foo711(); +extern void foo712(); +extern void foo713(); +extern void foo714(); +extern void foo715(); +extern void foo716(); +extern void foo717(); +extern void foo718(); +extern void foo719(); +extern void foo720(); +extern void foo721(); +extern void foo722(); +extern void foo723(); +extern void foo724(); +extern void foo725(); +extern void foo726(); +extern void foo727(); +extern void foo728(); +extern void foo729(); +extern void foo730(); +extern void foo731(); +extern void foo732(); +extern void foo733(); +extern void foo734(); +extern void foo735(); +extern void foo736(); +extern void foo737(); +extern void foo738(); +extern void foo739(); +extern void foo740(); +extern void foo741(); +extern void foo742(); +extern void foo743(); +extern void foo744(); +extern void foo745(); +extern void foo746(); +extern void foo747(); +extern void foo748(); +extern void foo749(); +extern void foo750(); +extern void foo751(); +extern void foo752(); +extern void foo753(); +extern void foo754(); +extern void foo755(); +extern void foo756(); +extern void foo757(); +extern void foo758(); +extern void foo759(); +extern void foo760(); +extern void foo761(); +extern void foo762(); +extern void foo763(); +extern void foo764(); +extern void foo765(); +extern void foo766(); +extern void foo767(); +extern void foo768(); +extern void foo769(); +extern void foo770(); +extern void foo771(); +extern void foo772(); +extern void foo773(); +extern void foo774(); +extern void foo775(); +extern void foo776(); +extern void foo777(); +extern void foo778(); +extern void foo779(); +extern void foo780(); +extern void foo781(); +extern void foo782(); +extern void foo783(); +extern void foo784(); +extern void foo785(); +extern void foo786(); +extern void foo787(); +extern void foo788(); +extern void foo789(); +extern void foo790(); +extern void foo791(); +extern void foo792(); +extern void foo793(); +extern void foo794(); +extern void foo795(); +extern void foo796(); +extern void foo797(); +extern void foo798(); +extern void foo799(); +extern void foo800(); +extern void foo801(); +extern void foo802(); +extern void foo803(); +extern void foo804(); +extern void foo805(); +extern void foo806(); +extern void foo807(); +extern void foo808(); +extern void foo809(); +extern void foo810(); +extern void foo811(); +extern void foo812(); +extern void foo813(); +extern void foo814(); +extern void foo815(); +extern void foo816(); +extern void foo817(); +extern void foo818(); +extern void foo819(); +extern void foo820(); +extern void foo821(); +extern void foo822(); +extern void foo823(); +extern void foo824(); diff --git a/unit-tests/test-cases/big-jump-table/funcs.c b/unit-tests/test-cases/big-jump-table/funcs.c new file mode 100644 index 0000000..16c40a2 --- /dev/null +++ b/unit-tests/test-cases/big-jump-table/funcs.c @@ -0,0 +1,853 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include "foo.h" + +static void __attribute__((constructor)) myinit() +{ + foo002(); + foo003(); + foo004(); + foo005(); + foo006(); + foo007(); + foo008(); + foo009(); + foo010(); + foo011(); + foo012(); + foo013(); + foo014(); + foo015(); + foo016(); + foo017(); + foo018(); + foo019(); + foo020(); + foo021(); + foo022(); + foo023(); + foo024(); + foo025(); + foo026(); + foo027(); + foo028(); + foo029(); + foo030(); + foo031(); + foo032(); + foo033(); + foo034(); + foo035(); + foo036(); + foo037(); + foo038(); + foo039(); + foo040(); + foo041(); + foo042(); + foo043(); + foo044(); + foo045(); + foo046(); + foo047(); + foo048(); + foo049(); + foo050(); + foo051(); + foo052(); + foo053(); + foo054(); + foo055(); + foo056(); + foo057(); + foo058(); + foo059(); + foo060(); + foo061(); + foo062(); + foo063(); + foo064(); + foo065(); + foo066(); + foo067(); + foo068(); + foo069(); + foo070(); + foo071(); + foo072(); + foo073(); + foo074(); + foo075(); + foo076(); + foo077(); + foo078(); + foo079(); + foo080(); + foo081(); + foo082(); + foo083(); + foo084(); + foo085(); + foo086(); + foo087(); + foo088(); + foo089(); + foo090(); + foo091(); + foo092(); + foo093(); + foo094(); + foo095(); + foo096(); + foo097(); + foo098(); + foo099(); + foo100(); + foo101(); + foo102(); + foo103(); + foo104(); + foo105(); + foo106(); + foo107(); + foo108(); + foo109(); + foo110(); + foo111(); + foo112(); + foo113(); + foo114(); + foo115(); + foo116(); + foo117(); + foo118(); + foo119(); + foo120(); + foo121(); + foo122(); + foo123(); + foo124(); + foo125(); + foo126(); + foo127(); + foo128(); + foo129(); + foo130(); + foo131(); + foo132(); + foo133(); + foo134(); + foo135(); + foo136(); + foo137(); + foo138(); + foo139(); + foo140(); + foo141(); + foo142(); + foo143(); + foo144(); + foo145(); + foo146(); + foo147(); + foo148(); + foo149(); + foo150(); + foo151(); + foo152(); + foo153(); + foo154(); + foo155(); + foo156(); + foo157(); + foo158(); + foo159(); + foo160(); + foo161(); + foo162(); + foo163(); + foo164(); + foo165(); + foo166(); + foo167(); + foo168(); + foo169(); + foo170(); + foo171(); + foo172(); + foo173(); + foo174(); + foo175(); + foo176(); + foo177(); + foo178(); + foo179(); + foo180(); + foo181(); + foo182(); + foo183(); + foo184(); + foo185(); + foo186(); + foo187(); + foo188(); + foo189(); + foo190(); + foo191(); + foo192(); + foo193(); + foo194(); + foo195(); + foo196(); + foo197(); + foo198(); + foo199(); + foo200(); + foo201(); + foo202(); + foo203(); + foo204(); + foo205(); + foo206(); + foo207(); + foo208(); + foo209(); + foo210(); + foo211(); + foo212(); + foo213(); + foo214(); + foo215(); + foo216(); + foo217(); + foo218(); + foo219(); + foo220(); + foo221(); + foo222(); + foo223(); + foo224(); + foo225(); + foo226(); + foo227(); + foo228(); + foo229(); + foo230(); + foo231(); + foo232(); + foo233(); + foo234(); + foo235(); + foo236(); + foo237(); + foo238(); + foo239(); + foo240(); + foo241(); + foo242(); + foo243(); + foo244(); + foo245(); + foo246(); + foo247(); + foo248(); + foo249(); + foo250(); + foo251(); + foo252(); + foo253(); + foo254(); + foo255(); + foo256(); + foo257(); + foo258(); + foo259(); + foo260(); + foo261(); + foo262(); + foo263(); + foo264(); + foo265(); + foo266(); + foo267(); + foo268(); + foo269(); + foo270(); + foo271(); + foo272(); + foo273(); + foo274(); + foo275(); + foo276(); + foo277(); + foo278(); + foo279(); + foo280(); + foo281(); + foo282(); + foo283(); + foo284(); + foo285(); + foo286(); + foo287(); + foo288(); + foo289(); + foo290(); + foo291(); + foo292(); + foo293(); + foo294(); + foo295(); + foo296(); + foo297(); + foo298(); + foo299(); + foo300(); + foo301(); + foo302(); + foo303(); + foo304(); + foo305(); + foo306(); + foo307(); + foo308(); + foo309(); + foo310(); + foo311(); + foo312(); + foo313(); + foo314(); + foo315(); + foo316(); + foo317(); + foo318(); + foo319(); + foo320(); + foo321(); + foo322(); + foo323(); + foo324(); + foo325(); + foo326(); + foo327(); + foo328(); + foo329(); + foo330(); + foo331(); + foo332(); + foo333(); + foo334(); + foo335(); + foo336(); + foo337(); + foo338(); + foo339(); + foo340(); + foo341(); + foo342(); + foo343(); + foo344(); + foo345(); + foo346(); + foo347(); + foo348(); + foo349(); + foo350(); + foo351(); + foo352(); + foo353(); + foo354(); + foo355(); + foo356(); + foo357(); + foo358(); + foo359(); + foo360(); + foo361(); + foo362(); + foo363(); + foo364(); + foo365(); + foo366(); + foo367(); + foo368(); + foo369(); + foo370(); + foo371(); + foo372(); + foo373(); + foo374(); + foo375(); + foo376(); + foo377(); + foo378(); + foo379(); + foo380(); + foo381(); + foo382(); + foo383(); + foo384(); + foo385(); + foo386(); + foo387(); + foo388(); + foo389(); + foo390(); + foo391(); + foo392(); + foo393(); + foo394(); + foo395(); + foo396(); + foo397(); + foo398(); + foo399(); + foo400(); + foo401(); + foo402(); + foo403(); + foo404(); + foo405(); + foo406(); + foo407(); + foo408(); + foo409(); + foo410(); + foo411(); + foo412(); + foo413(); + foo414(); + foo415(); + foo416(); + foo417(); + foo418(); + foo419(); + foo420(); + foo421(); + foo422(); + foo423(); + foo424(); + foo425(); + foo426(); + foo427(); + foo428(); + foo429(); + foo430(); + foo431(); + foo432(); + foo433(); + foo434(); + foo435(); + foo436(); + foo437(); + foo438(); + foo439(); + foo440(); + foo441(); + foo442(); + foo443(); + foo444(); + foo445(); + foo446(); + foo447(); + foo448(); + foo449(); + foo450(); + foo451(); + foo452(); + foo453(); + foo454(); + foo455(); + foo456(); + foo457(); + foo458(); + foo459(); + foo460(); + foo461(); + foo462(); + foo463(); + foo464(); + foo465(); + foo466(); + foo467(); + foo468(); + foo469(); + foo470(); + foo471(); + foo472(); + foo473(); + foo474(); + foo475(); + foo476(); + foo477(); + foo478(); + foo479(); + foo480(); + foo481(); + foo482(); + foo483(); + foo484(); + foo485(); + foo486(); + foo487(); + foo488(); + foo489(); + foo490(); + foo491(); + foo492(); + foo493(); + foo494(); + foo495(); + foo496(); + foo497(); + foo498(); + foo499(); + foo500(); + foo501(); + foo502(); + foo503(); + foo504(); + foo505(); + foo506(); + foo507(); + foo508(); + foo509(); + foo510(); + foo511(); + foo512(); + foo513(); + foo514(); + foo515(); + foo516(); + foo517(); + foo518(); + foo519(); + foo520(); + foo521(); + foo522(); + foo523(); + foo524(); + foo525(); + foo526(); + foo527(); + foo528(); + foo529(); + foo530(); + foo531(); + foo532(); + foo533(); + foo534(); + foo535(); + foo536(); + foo537(); + foo538(); + foo539(); + foo540(); + foo541(); + foo542(); + foo543(); + foo544(); + foo545(); + foo546(); + foo547(); + foo548(); + foo549(); + foo550(); + foo551(); + foo552(); + foo553(); + foo554(); + foo555(); + foo556(); + foo557(); + foo558(); + foo559(); + foo560(); + foo561(); + foo562(); + foo563(); + foo564(); + foo565(); + foo566(); + foo567(); + foo568(); + foo569(); + foo570(); + foo571(); + foo572(); + foo573(); + foo574(); + foo575(); + foo576(); + foo577(); + foo578(); + foo579(); + foo580(); + foo581(); + foo582(); + foo583(); + foo584(); + foo585(); + foo586(); + foo587(); + foo588(); + foo589(); + foo590(); + foo591(); + foo592(); + foo593(); + foo594(); + foo595(); + foo596(); + foo597(); + foo598(); + foo599(); + foo600(); + foo601(); + foo602(); + foo603(); + foo604(); + foo605(); + foo606(); + foo607(); + foo608(); + foo609(); + foo610(); + foo611(); + foo612(); + foo613(); + foo614(); + foo615(); + foo616(); + foo617(); + foo618(); + foo619(); + foo620(); + foo621(); + foo622(); + foo623(); + foo624(); + foo625(); + foo626(); + foo627(); + foo628(); + foo629(); + foo630(); + foo631(); + foo632(); + foo633(); + foo634(); + foo635(); + foo636(); + foo637(); + foo638(); + foo639(); + foo640(); + foo641(); + foo642(); + foo643(); + foo644(); + foo645(); + foo646(); + foo647(); + foo648(); + foo649(); + foo650(); + foo651(); + foo652(); + foo653(); + foo654(); + foo655(); + foo656(); + foo657(); + foo658(); + foo659(); + foo660(); + foo661(); + foo662(); + foo663(); + foo664(); + foo665(); + foo666(); + foo667(); + foo668(); + foo669(); + foo670(); + foo671(); + foo672(); + foo673(); + foo674(); + foo675(); + foo676(); + foo677(); + foo678(); + foo679(); + foo680(); + foo681(); + foo682(); + foo683(); + foo684(); + foo685(); + foo686(); + foo687(); + foo688(); + foo689(); + foo690(); + foo691(); + foo692(); + foo693(); + foo694(); + foo695(); + foo696(); + foo697(); + foo698(); + foo699(); + foo700(); + foo701(); + foo702(); + foo703(); + foo704(); + foo705(); + foo706(); + foo707(); + foo708(); + foo709(); + foo710(); + foo711(); + foo712(); + foo713(); + foo714(); + foo715(); + foo716(); + foo717(); + foo718(); + foo719(); + foo720(); + foo721(); + foo722(); + foo723(); + foo724(); + foo725(); + foo726(); + foo727(); + foo728(); + foo729(); + foo730(); + foo731(); + foo732(); + foo733(); + foo734(); + foo735(); + foo736(); + foo737(); + foo738(); + foo739(); + foo740(); + foo741(); + foo742(); + foo743(); + foo744(); + foo745(); + foo746(); + foo747(); + foo748(); + foo749(); + foo750(); + foo751(); + foo752(); + foo753(); + foo754(); + foo755(); + foo756(); + foo757(); + foo758(); + foo759(); + foo760(); + foo761(); + foo762(); + foo763(); + foo764(); + foo765(); + foo766(); + foo767(); + foo768(); + foo769(); + foo770(); + foo771(); + foo772(); + foo773(); + foo774(); + foo775(); + foo776(); + foo777(); + foo778(); + foo779(); + foo780(); + foo781(); + foo782(); + foo783(); + foo784(); + foo785(); + foo786(); + foo787(); + foo788(); + foo789(); + foo790(); + foo791(); + foo792(); + foo793(); + foo794(); + foo795(); + foo796(); + foo797(); + foo798(); + foo799(); + foo800(); + foo801(); + foo802(); + foo803(); + foo804(); + foo805(); + foo806(); + foo807(); + foo808(); + foo809(); + foo810(); + foo811(); + foo812(); + foo813(); +#if CASE <= 4 + foo814(); +#endif +#if CASE <= 3 + foo815(); +#endif +#if CASE <= 2 + foo816(); +#endif +#if CASE <= 1 + foo817(); +#endif +} + diff --git a/unit-tests/test-cases/dlclose-dylib-unload/bar.c b/unit-tests/test-cases/big-jump-table/main.c similarity index 77% rename from unit-tests/test-cases/dlclose-dylib-unload/bar.c rename to unit-tests/test-cases/big-jump-table/main.c index 817b8cd..6241ef4 100644 --- a/unit-tests/test-cases/dlclose-dylib-unload/bar.c +++ b/unit-tests/test-cases/big-jump-table/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -20,9 +20,17 @@ * * @APPLE_LICENSE_HEADER_END@ */ +#include // fprintf(), NULL +#include // exit(), EXIT_SUCCESS +#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() -int bar() + + +int main() { - return 10; + PASS("big-jump-table"); + return EXIT_SUCCESS; } + + diff --git a/unit-tests/test-cases/big-jump-table/pointers.c b/unit-tests/test-cases/big-jump-table/pointers.c new file mode 100644 index 0000000..5484be0 --- /dev/null +++ b/unit-tests/test-cases/big-jump-table/pointers.c @@ -0,0 +1,23 @@ + +#include "foo.h" + +long useNonLazy() +{ + long result = 0; + result += (long)&foo001; + result += (long)&foo002; + result += (long)&foo003; +#if CASE > 0 + result += (long)&foo818; +#endif +#if CASE > 1 + result += (long)&foo817; +#endif +#if CASE > 2 + result += (long)&foo816; +#endif +#if CASE > 3 + result += (long)&foo815; +#endif + return result; +} diff --git a/unit-tests/test-cases/bundle-memory-load-fat/main.c b/unit-tests/test-cases/bundle-memory-load-fat/main.c index 4d77c98..7169e32 100644 --- a/unit-tests/test-cases/bundle-memory-load-fat/main.c +++ b/unit-tests/test-cases/bundle-memory-load-fat/main.c @@ -74,7 +74,7 @@ int main() } CheckFunc func = NSAddressOfSymbol(sym); - if ( !func() ) { + if ( func == NULL ) { FAIL("NSAddressOfSymbol failed"); return 1; } diff --git a/unit-tests/test-cases/bundle-reload/Makefile b/unit-tests/test-cases/bundle-reload/Makefile index a32ecb5..194c744 100644 --- a/unit-tests/test-cases/bundle-reload/Makefile +++ b/unit-tests/test-cases/bundle-reload/Makefile @@ -38,7 +38,7 @@ main : main.c ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c test.bundle : bundle.cxx - ${CC} ${CXXFLAGS} -bundle -o test.bundle bundle.cxx + ${CXX} ${CXXFLAGS} -bundle -o test.bundle bundle.cxx clean: ${RM} ${RMFLAGS} *~ main test.bundle diff --git a/unit-tests/test-cases/dlclose-dylib-unload/Makefile b/unit-tests/test-cases/dlclose-dylib-unload/Makefile deleted file mode 100644 index 2597b53..0000000 --- a/unit-tests/test-cases/dlclose-dylib-unload/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -## -# Copyright (c) 2005 Apple Computer, Inc. All rights reserved. -# -# @APPLE_LICENSE_HEADER_START@ -# -# This file contains Original Code and/or Modifications of Original Code -# as defined in and that are subject to the Apple Public Source License -# Version 2.0 (the 'License'). You may not use this file except in -# compliance with the License. Please obtain a copy of the License at -# http://www.opensource.apple.com/apsl/ and read it before using this -# file. -# -# The Original Code and all software distributed under the License are -# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER -# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, -# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. -# Please see the License for the specific language governing rights and -# limitations under the License. -# -# @APPLE_LICENSE_HEADER_END@ -## -TESTROOT = ../.. -include ${TESTROOT}/include/common.makefile - -run: all - ./main - -all: main libfoo.dylib - -main : main.c libbar.dylib - ${CC} ${CCFLAGS} -I${TESTROOT}/include main.c libbar.dylib -o main - - -libfoo.dylib : foo.c - ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib - -libbar.dylib : bar.c - ${CC} ${CCFLAGS} -dynamiclib bar.c -o libbar.dylib - - -clean: - ${RM} ${RMFLAGS} *~ main libfoo.dylib libbar.dylib - diff --git a/unit-tests/test-cases/dlclose-dylib-unload/main.c b/unit-tests/test-cases/dlclose-dylib-unload/main.c deleted file mode 100644 index 5e48c00..0000000 --- a/unit-tests/test-cases/dlclose-dylib-unload/main.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#include // fprintf(), NULL -#include // exit(), EXIT_SUCCESS -#include - -#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() - - - - - -void verifyfoo() -{ - // open same dylib three times - void* handle1 = dlopen("libfoo.dylib", RTLD_LAZY); - if ( handle1 == NULL ) { - FAIL("dlclose-dylib-unload: dlopen(\"libfoo.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror()); - exit(0); - } - - void* handle2 = dlopen("libfoo.dylib", RTLD_LAZY); - if ( handle2 == NULL ) { - FAIL("dlclose-dylib-unload: dlopen(\"libfoo.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror()); - exit(0); - } - - void* handle3 = dlopen("libfoo.dylib", RTLD_LAZY); - if ( handle3 == NULL ) { - FAIL("dlclose-dylib-unload: dlopen(\"libfoo.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror()); - exit(0); - } - - // get symbol - void* sym = dlsym(handle1, "foo"); - if ( sym == NULL ) { - FAIL("dlclose-dylib-unload: dlsym(handle1, \"foo\") failed"); - exit(0); - } - - // close same bundle three times - if ( dlclose(handle3) != 0 ) { - FAIL("dlclose-dylib-unload: dlclose(handle3) != 0, dlerrr()=%s", dlerror()); - exit(0); - } - - if ( dlclose(handle2) != 0 ) { - FAIL("dlclose-dylib-unload: dlclose(handle2) != 0, dlerrr()=%s", dlerror()); - exit(0); - } - - if ( dlclose(handle1) != 0 ) { - FAIL("dlclose-dylib-unload: dlclose(handle1) != 0, dlerrr()=%s", dlerror()); - exit(0); - } - - // symbol foo should no longer be accessible via dladdr() - Dl_info info; - if ( dladdr(sym, &info) != 0 ) { - FAIL("dlclose-dylib-unload: dladdr(foo_sym) != 0, but should have failed"); - //exit(0); - } - - // extra close should fail - if ( dlclose(handle1) == 0 ) { - FAIL("dlclose-dylib-unload: dlclose(foo_handle4) == 0, but should have failed"); - //exit(0); - } - -} - - - -void verifybar() -{ - // open same dylib three times - void* handle1 = dlopen("libbar.dylib", RTLD_LAZY); - if ( handle1 == NULL ) { - FAIL("dlclose-dylib-unload: dlopen(\"libbar.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror()); - exit(0); - } - - void* handle2 = dlopen("libbar.dylib", RTLD_LAZY); - if ( handle2 == NULL ) { - FAIL("dlclose-dylib-unload: dlopen(\"libbar.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror()); - exit(0); - } - - void* handle3 = dlopen("libbar.dylib", RTLD_LAZY); - if ( handle3 == NULL ) { - FAIL("dlclose-dylib-unload: dlopen(\"libbar.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror()); - exit(0); - } - - // get symbol - void* sym = dlsym(handle1, "bar"); - if ( sym == NULL ) { - FAIL("dlclose-dylib-unload: dlsym(handle1, \"bar\") failed"); - exit(0); - } - - // close same bundle three times - if ( dlclose(handle3) != 0 ) { - FAIL("dlclose-dylib-unload: dlclose(handle3) != 0, dlerrr()=%s", dlerror()); - exit(0); - } - - if ( dlclose(handle2) != 0 ) { - FAIL("dlclose-dylib-unload: dlclose(handle2) != 0, dlerrr()=%s", dlerror()); - exit(0); - } - - if ( dlclose(handle1) != 0 ) { - FAIL("dlclose-dylib-unload: dlclose(handle1) != 0, dlerrr()=%s", dlerror()); - exit(0); - } - - // symbol bar should still longer be accessible via dladdr() because of external reference to libbar.dylib - Dl_info info; - if ( dladdr(sym, &info) == 0 ) { - FAIL("dlclose-dylib-unload: dladdr(bar_sym) == 0, but should have succeeded"); - exit(0); - } - - // extra close should fail - if ( dlclose(handle1) == 0 ) { - FAIL("dlclose-dylib-unload: dlclose(bar_handle4) == 0, but should have failed"); - exit(0); - } -} - - -// verify libbar.dylib can be loaded and unloaded -// verify libbar.dylib can be loaded, but cannot be unloaded (because main executable links against it) -int main() -{ - verifyfoo(); - verifybar(); - - PASS("dlclose-dylib-unload"); - return EXIT_SUCCESS; -} diff --git a/unit-tests/test-cases/dlerror-clear/Makefile b/unit-tests/test-cases/dlerror-clear/Makefile deleted file mode 100644 index 7337131..0000000 --- a/unit-tests/test-cases/dlerror-clear/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -## -# Copyright (c) 2005 Apple Computer, Inc. All rights reserved. -# -# @APPLE_LICENSE_HEADER_START@ -# -# This file contains Original Code and/or Modifications of Original Code -# as defined in and that are subject to the Apple Public Source License -# Version 2.0 (the 'License'). You may not use this file except in -# compliance with the License. Please obtain a copy of the License at -# http://www.opensource.apple.com/apsl/ and read it before using this -# file. -# -# The Original Code and all software distributed under the License are -# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER -# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, -# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. -# Please see the License for the specific language governing rights and -# limitations under the License. -# -# @APPLE_LICENSE_HEADER_END@ -## -TESTROOT = ../.. -include ${TESTROOT}/include/common.makefile - -run: all - ./main - -all: main - -main : main.c - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c - - - -clean: - ${RM} ${RMFLAGS} *~ main - diff --git a/unit-tests/test-cases/dlerror-clear/main.c b/unit-tests/test-cases/dlerror-clear/main.c deleted file mode 100644 index f70cc86..0000000 --- a/unit-tests/test-cases/dlerror-clear/main.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#include // fprintf(), NULL -#include // exit(), EXIT_SUCCESS -#include -#include -#include - -#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() - - -/// -/// This tests that the dlerror message is cleared when dlerror is called -/// - -int main() -{ - // try to non-existent library - void* handle1 = dlopen("frobulite", RTLD_LAZY); - if ( handle1 != NULL ) { - FAIL("dlerror-clear: dlopen(\"frobulite\", RTLD_LAZY) succeeded but should have failed"); - exit(0); - } - - // verify there is an error message - const char* msg = dlerror(); - if ( msg == NULL ) { - FAIL("dlerror-clear: dlerror() returned NULL but should have returned an error message"); - exit(0); - } - - // verify error message was cleared - const char* msg2 = dlerror(); - if ( msg2 != NULL ) { - FAIL("dlerror-clear: dlerror() returned message but should have returned NULL"); - exit(0); - } - - PASS("dlerror-clear"); - return 0; -} diff --git a/unit-tests/test-cases/dlerror/main.c b/unit-tests/test-cases/dlerror/main.c deleted file mode 100644 index 808dc56..0000000 --- a/unit-tests/test-cases/dlerror/main.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#include // fprintf(), NULL -#include // exit(), EXIT_SUCCESS -#include -#include -#include - -#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() - - -/// -/// This tests that the dlerror message is kept per thread -/// - -static void* work(void* arg) -{ - const char* str = (char*)arg; - for(int i=0; i < 1000; ++i) { - //fprintf(stderr, "dlopen(%s)\n", str); - void* handle = dlopen(str, RTLD_LAZY); - if ( handle != NULL ) { - FAIL("dlopen(%s) unexpectedly succeeded", str); - exit(0); - } - char* msg = dlerror(); - //fprintf(stderr, "dlopen(%s) => %s\n", str, msg); - if ( (msg == NULL) || (strstr(msg, str) == NULL) ) { - FAIL("dlerror() did not contain library name that could not be loaded", str); - exit(0); - } - - - } - return 0; -} - - - -int main() -{ - dlsym(RTLD_DEFAULT, "foobar"); - fprintf(stderr, "%s\n", dlerror()); - - pthread_t worker1; - if ( pthread_create(&worker1, NULL, work, "/frazzle/bar") != 0 ) { - FAIL("pthread_create failed"); - exit(0); - } - - pthread_t worker2; - if ( pthread_create(&worker2, NULL, work, "/frazzle/foo") != 0 ) { - FAIL("pthread_create failed"); - exit(0); - } - - pthread_t worker3; - if ( pthread_create(&worker3, NULL, work, "/frazzle/dazzle") != 0 ) { - FAIL("pthread_create failed"); - exit(0); - } - - void* result; - fprintf(stderr, "waiting for worker 1\n"); - pthread_join(worker1, &result); - fprintf(stderr, "waiting for worker 2\n"); - pthread_join(worker2, &result); - fprintf(stderr, "waiting for worker 3\n"); - pthread_join(worker3, &result); - - PASS("dlerror-thread-test"); - return 0; -} diff --git a/unit-tests/test-cases/lazy-binding-reg-params/Makefile b/unit-tests/test-cases/lazy-binding-reg-params/Makefile index 12eb337..f3037cd 100644 --- a/unit-tests/test-cases/lazy-binding-reg-params/Makefile +++ b/unit-tests/test-cases/lazy-binding-reg-params/Makefile @@ -23,6 +23,8 @@ TESTROOT = ../.. include ${TESTROOT}/include/common.makefile +MACHINE = $(shell machine) + ifeq "-arch ppc" "$(ARCH)" EXTRA_FLAG = -maltivec -force_cpusubtype_ALL else @@ -31,6 +33,12 @@ else else ifeq "-arch i386" "$(ARCH)" EXTRA_FLAG = "" + else + ifeq "" "$(ARCH)" + ifeq "ppc970" "$(MACHINE)" + EXTRA_FLAG = -maltivec -force_cpusubtype_ALL + endif + endif endif endif endif diff --git a/unit-tests/test-cases/lazy-binding-reg-params/foo.h b/unit-tests/test-cases/lazy-binding-reg-params/foo.h index 38f6da8..0072780 100644 --- a/unit-tests/test-cases/lazy-binding-reg-params/foo.h +++ b/unit-tests/test-cases/lazy-binding-reg-params/foo.h @@ -12,7 +12,7 @@ extern bool dofloattest(double,double,double,double,double,double,double,double, #endif -#if __i386__ +#if __i386__ || __x86_64__ typedef float vFloat __attribute__ ((__vector_size__ (16))); #elif __ppc__ || __ppc64__ typedef vector float vFloat; diff --git a/unit-tests/test-cases/lazy-binding-reg-params/main.c b/unit-tests/test-cases/lazy-binding-reg-params/main.c index 336d2ca..44c98b2 100644 --- a/unit-tests/test-cases/lazy-binding-reg-params/main.c +++ b/unit-tests/test-cases/lazy-binding-reg-params/main.c @@ -48,7 +48,7 @@ static bool floattest() { #if __ppc__ || __ppc64__ return dofloattest(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0); -#elif __i386__ +#elif __i386__ || __x86_64__ return true; #else #error unknown architecture diff --git a/unit-tests/test-cases/dlerror/Makefile b/unit-tests/test-cases/prebased-performance/Makefile similarity index 66% rename from unit-tests/test-cases/dlerror/Makefile rename to unit-tests/test-cases/prebased-performance/Makefile index 7337131..f895d90 100644 --- a/unit-tests/test-cases/dlerror/Makefile +++ b/unit-tests/test-cases/prebased-performance/Makefile @@ -1,5 +1,5 @@ ## -# Copyright (c) 2005 Apple Computer, Inc. All rights reserved. +# Copyright (c) 2006 Apple Computer, Inc. All rights reserved. # # @APPLE_LICENSE_HEADER_START@ # @@ -23,16 +23,30 @@ TESTROOT = ../.. include ${TESTROOT}/include/common.makefile +DYLIB_BASES_ADDRESS = 0x10000000 + +ifeq "-arch ppc64" "$(ARCH)" + DYLIB_BASES_ADDRESS = 0x300000000 +else + ifeq "-arch x86_64" "$(ARCH)" + DYLIB_BASES_ADDRESS = 0x300000000 + endif +endif + + + run: all ./main all: main -main : main.c - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c +main: main.c libfoo.dylib + ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libfoo.dylib +libfoo.dylib: foo.c + ${CC} ${CCFLAGS} -dynamiclib -o libfoo.dylib foo.c -seg1addr ${DYLIB_BASES_ADDRESS} -mmacosx-version-min=10.5 clean: - ${RM} ${RMFLAGS} *~ main + ${RM} ${RMFLAGS} *~ main libfoo.dylib diff --git a/unit-tests/test-cases/prebased-performance/foo.c b/unit-tests/test-cases/prebased-performance/foo.c new file mode 100644 index 0000000..0da036f --- /dev/null +++ b/unit-tests/test-cases/prebased-performance/foo.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include +#include +#include + +struct page +{ + struct page* other; + char pad[4096-sizeof(void*)]; +}; + + +struct page p1 = { &p1 }; +struct page p2 = { &p1 }; +struct page p3 = { &p1 }; +struct page p4 = { &p1 }; +struct page p5 = { &p1 }; +struct page p6 = { &p1 }; +struct page p7 = { &p1 }; +struct page p8 = { &p1 }; +struct page p9 = { &p1 }; +struct page p10 = { &p1 }; + +// +// This dylib has 10 pages of data and each page will be adjusted +// by dyld if this dylib is not loaded at its preferred address. +// +bool checkRebasing() +{ + int dirtyPageCount = 0; + vm_address_t start = (((uintptr_t)&p1) + 4095) & (-4096); + vm_address_t end = (((uintptr_t)&p10) + 4095) & (-4096); + task_port_t task; + task_for_pid(mach_task_self(), getpid(), &task); + + for (vm_address_t addr = start; addr < end; addr += 4096) { + integer_t disposition = 0; + integer_t ref_count = 0; + vm_map_page_query(task, start, &disposition, &ref_count); + if ( disposition & VM_PAGE_QUERY_PAGE_DIRTY ) + ++dirtyPageCount; + } + + // if there are too many dirty pages, then dyld is inefficient + return ( dirtyPageCount < 2 ); +} + + + + + diff --git a/unit-tests/test-cases/dlclose-dylib-unload/foo.c b/unit-tests/test-cases/prebased-performance/main.c similarity index 69% rename from unit-tests/test-cases/dlclose-dylib-unload/foo.c rename to unit-tests/test-cases/prebased-performance/main.c index 81f7dcf..98fe608 100644 --- a/unit-tests/test-cases/dlclose-dylib-unload/foo.c +++ b/unit-tests/test-cases/prebased-performance/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -20,9 +20,19 @@ * * @APPLE_LICENSE_HEADER_END@ */ +#include // fprintf(), NULL +#include // exit(), EXIT_SUCCESS +#include +#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() -int foo() +extern bool checkRebasing(); + +int main(int argc, const char* argv[]) { - return 10; + if ( checkRebasing() ) + PASS("prebased-performance"); + else + FAIL("prebased-performance"); + return EXIT_SUCCESS; } -- 2.45.2