From dd1e3476105179eb3efd5ebd2af97f6de91170b3 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 2 Apr 2020 16:52:21 +0000 Subject: [PATCH] dyld-733.8.tar.gz --- dyld3/Closure.cpp | 5 ++ dyld3/Closure.h | 4 +- dyld3/ClosureBuilder.cpp | 14 ++-- dyld3/ClosureBuilder.h | 3 + dyld3/ClosureWriter.cpp | 5 ++ dyld3/ClosureWriter.h | 1 + src/ImageLoader.h | 1 + src/dyld2.cpp | 57 +++++++++++--- testing/include/test_support.h | 74 ++++++++++++++++++ .../test-cases/amfi-interpose.dtest/interposer.c | 21 ++++++ testing/test-cases/amfi-interpose.dtest/main.c | 48 ++++++++++++ .../env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest}/foo.c | 0 .../env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/main.c | 65 ++++++++++++++++ .../env-DYLD_VERSIONED_LIBRARY_PATH.dtest}/foo.c | 0 .../env-DYLD_VERSIONED_LIBRARY_PATH.dtest/main.c | 87 ++++++++++++++++++++++ .../DYLD_VERSIONED_FRAMEWORK_PATH-basic/Makefile | 64 ---------------- .../DYLD_VERSIONED_FRAMEWORK_PATH-basic/bar.c | 5 -- .../DYLD_VERSIONED_FRAMEWORK_PATH-basic/foo.c | 5 -- .../DYLD_VERSIONED_FRAMEWORK_PATH-basic/main.c | 63 ---------------- .../DYLD_VERSIONED_LIBRARY_PATH-basic/Makefile | 61 --------------- .../DYLD_VERSIONED_LIBRARY_PATH-basic/bar.c | 5 -- .../DYLD_VERSIONED_LIBRARY_PATH-basic/foo.c | 5 -- .../DYLD_VERSIONED_LIBRARY_PATH-basic/main.c | 47 ------------ .../Makefile | 58 --------------- .../main.c | 47 ------------ .../DYLD_VERSIONED_LIBRARY_PATH-dyld_env/Makefile | 61 --------------- .../DYLD_VERSIONED_LIBRARY_PATH-dyld_env/main.c | 47 ------------ 27 files changed, 367 insertions(+), 486 deletions(-) create mode 100644 testing/include/test_support.h create mode 100644 testing/test-cases/amfi-interpose.dtest/interposer.c create mode 100644 testing/test-cases/amfi-interpose.dtest/main.c rename {unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env => testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest}/foo.c (100%) create mode 100644 testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/main.c rename {unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict => testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest}/foo.c (100%) create mode 100644 testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/main.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/Makefile delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/bar.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/foo.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/main.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/Makefile delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/bar.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/foo.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/main.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/Makefile delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/main.c delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/Makefile delete mode 100644 unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/main.c diff --git a/dyld3/Closure.cpp b/dyld3/Closure.cpp index 3e9c9f8..21b0c2e 100644 --- a/dyld3/Closure.cpp +++ b/dyld3/Closure.cpp @@ -1155,6 +1155,11 @@ bool LaunchClosure::hasInsertedLibraries() const return getFlags().hasInsertedLibraries; } +bool LaunchClosure::usedInterposing() const +{ + return getFlags().usedInterposing; +} + bool LaunchClosure::hasInterposings() const { __block bool result = false; diff --git a/dyld3/Closure.h b/dyld3/Closure.h index 4b4eb39..ab1a15f 100644 --- a/dyld3/Closure.h +++ b/dyld3/Closure.h @@ -709,6 +709,7 @@ struct VIS_HIDDEN LaunchClosure : public Closure void forEachInterposingTuple(void (^handler)(const InterposingTuple& tuple, bool& stop)) const; bool usedAtPaths() const; bool usedFallbackPaths() const; + bool usedInterposing() const; bool selectorHashTable(Array& imageNums, const ObjCSelectorOpt*& hashTable) const; bool classAndProtocolHashTables(Array& imageNums, @@ -730,7 +731,8 @@ private: usedFallbackPaths : 1, initImageCount : 16, hasInsertedLibraries : 1, - padding : 13; + usedInterposing : 1, + padding : 12; }; const Flags& getFlags() const; }; diff --git a/dyld3/ClosureBuilder.cpp b/dyld3/ClosureBuilder.cpp index daef752..10da1bf 100644 --- a/dyld3/ClosureBuilder.cpp +++ b/dyld3/ClosureBuilder.cpp @@ -1133,6 +1133,7 @@ void ClosureBuilder::addInterposingTuples(LaunchClosureWriter& writer, const Ima goodTuples.push_back(resolvedTuples[i]); } writer.addInterposingTuples(goodTuples); + _interposingTuplesUsed = !goodTuples.empty(); // if the target of the interposing is in the dyld shared cache, add a PatchEntry so the cache is fixed up at launch STACK_ALLOC_ARRAY(Closure::PatchEntry, patches, goodTuples.count()); @@ -3173,16 +3174,19 @@ const LaunchClosure* ClosureBuilder::makeLaunchClosure(const LoadedFileInfo& fil closureWriter.setBootUUID(bootSessionUUID); #endif - // record any interposing info - imageArray->forEachImage(^(const Image* image, bool &stop) { - if ( !image->inDyldCache() ) - addInterposingTuples(closureWriter, image, findLoadedImage(image->imageNum()).loadAddress()); - }); + // record any interposing info + if ( !_interposingDisabled ) { + imageArray->forEachImage(^(const Image* image, bool &stop) { + if ( !image->inDyldCache() ) + addInterposingTuples(closureWriter, image, findLoadedImage(image->imageNum()).loadAddress()); + }); + } // modify fixups in contained Images by applying interposing tuples closureWriter.applyInterposing((const LaunchClosure*)closureWriter.currentTypedBytes()); // set flags + closureWriter.setUsedInterposing(_interposingTuplesUsed); closureWriter.setUsedAtPaths(_atPathUsed); closureWriter.setUsedFallbackPaths(_fallbackPathUsed); closureWriter.setHasInsertedLibraries(_mainProgLoadIndex > 0); diff --git a/dyld3/ClosureBuilder.h b/dyld3/ClosureBuilder.h index ddc5d90..14554ba 100644 --- a/dyld3/ClosureBuilder.h +++ b/dyld3/ClosureBuilder.h @@ -104,6 +104,7 @@ public: ImageNum nextFreeImageNum() const { return _startImageNum + _nextIndex; } void setDyldCacheInvalidFormatVersion(); + void disableInterposing() { _interposingDisabled = true; } struct PatchableExport @@ -344,12 +345,14 @@ private: bool _makingCustomerCache = false; bool _allowRelativePaths = false; bool _atPathUsed = false; + bool _interposingTuplesUsed = false; bool _fallbackPathUsed = false; bool _allowMissingLazies = false; bool _dyldCacheInvalidFormatVersion = false; bool _foundNonCachedImage = false; // true means we have one or more images from disk we need to build closure(s) for bool _foundDyldCacheRoots = false; // true if one or more images are roots of the shared cache bool _foundMissingLazyBinds = false; // true if one or more images having missing lazy binds + bool _interposingDisabled = false; ImageNum _libDyldImageNum = 0; ImageNum _libSystemImageNum = 0; }; diff --git a/dyld3/ClosureWriter.cpp b/dyld3/ClosureWriter.cpp index 7347506..f4911bc 100644 --- a/dyld3/ClosureWriter.cpp +++ b/dyld3/ClosureWriter.cpp @@ -521,6 +521,11 @@ void LaunchClosureWriter::setUsedAtPaths(bool value) getFlags().usedAtPaths = value; } +void LaunchClosureWriter::setUsedInterposing(bool value) +{ + getFlags().usedInterposing = value; +} + void LaunchClosureWriter::setHasInsertedLibraries(bool value) { getFlags().hasInsertedLibraries = value; diff --git a/dyld3/ClosureWriter.h b/dyld3/ClosureWriter.h index 1ec0fed..2774318 100644 --- a/dyld3/ClosureWriter.h +++ b/dyld3/ClosureWriter.h @@ -154,6 +154,7 @@ public: void setStartEntry(Image::ResolvedSymbolTarget start); void setUsedFallbackPaths(bool); void setUsedAtPaths(bool); + void setUsedInterposing(bool); void setHasInsertedLibraries(bool); void setMustBeMissingFiles(const Array& paths); void setMustExistFiles(const Array& files); diff --git a/src/ImageLoader.h b/src/ImageLoader.h index 1a3d415..df2f44b 100644 --- a/src/ImageLoader.h +++ b/src/ImageLoader.h @@ -313,6 +313,7 @@ public: bool allowEnvVarsSharedCache; bool allowClassicFallbackPaths; bool allowInsertFailures; + bool allowInterposing; bool mainExecutableCodeSigned; bool prebinding; bool bindFlat; diff --git a/src/dyld2.cpp b/src/dyld2.cpp index 8a438af..40fbd5b 100644 --- a/src/dyld2.cpp +++ b/src/dyld2.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #if TARGET_OS_SIMULATOR enum { @@ -74,11 +75,13 @@ AMFI_DYLD_OUTPUT_ALLOW_FALLBACK_PATHS = (1 << 3), AMFI_DYLD_OUTPUT_ALLOW_PRINT_VARS = (1 << 4), AMFI_DYLD_OUTPUT_ALLOW_FAILED_LIBRARY_INSERTION = (1 << 5), + AMFI_DYLD_OUTPUT_ALLOW_LIBRARY_INTERPOSING = (1 << 6), }; extern "C" int amfi_check_dyld_policy_self(uint64_t input_flags, uint64_t* output_flags); #else #include #endif + #include #include #if __has_feature(ptrauth_calls) @@ -3813,6 +3816,16 @@ static ImageLoader* loadPhase1(const char* path, const char* orgPath, const Load return image; } +#if SUPPORT_VERSIONED_PATHS + // DYLD_VERSIONED_FRAMEWORK_PATH fails to load a framework if it does not also exist at the system install path + // Scan to see if the dylib appears in a versioned path. Don't worry if we find the newest, that will handled later + if ( !context.dontLoad && (exceptions != NULL) && ((sEnv.DYLD_VERSIONED_FRAMEWORK_PATH != NULL) || (sEnv.DYLD_VERSIONED_LIBRARY_PATH != NULL)) ) { + image = loadPhase2(path, orgPath, context, sEnv.DYLD_VERSIONED_FRAMEWORK_PATH, sEnv.DYLD_VERSIONED_LIBRARY_PATH, cacheIndex, exceptions); + if ( image != NULL ) + return image; + } +#endif + return NULL; } @@ -5083,6 +5096,11 @@ static void configureProcessRestrictions(const macho_header* mainExecutableMH, c gLinkContext.allowEnvVarsSharedCache = (amfiOutputFlags & AMFI_DYLD_OUTPUT_ALLOW_CUSTOM_SHARED_CACHE); gLinkContext.allowClassicFallbackPaths = (amfiOutputFlags & AMFI_DYLD_OUTPUT_ALLOW_FALLBACK_PATHS); gLinkContext.allowInsertFailures = (amfiOutputFlags & AMFI_DYLD_OUTPUT_ALLOW_FAILED_LIBRARY_INSERTION); +#ifdef AMFI_RETURNS_INTERPOSING_FLAG + gLinkContext.allowInterposing = (amfiOutputFlags & AMFI_DYLD_OUTPUT_ALLOW_LIBRARY_INTERPOSING); +#else + gLinkContext.allowInterposing = true; +#endif } else { #if __MAC_OS_X_VERSION_MIN_REQUIRED @@ -5112,6 +5130,7 @@ static void configureProcessRestrictions(const macho_header* mainExecutableMH, c gLinkContext.allowEnvVarsSharedCache = !libraryValidation || !usingSIP; gLinkContext.allowClassicFallbackPaths = !isRestricted; gLinkContext.allowInsertFailures = false; + gLinkContext.allowInterposing = true; #else halt("amfi_check_dyld_policy_self() failed\n"); #endif @@ -5793,7 +5812,11 @@ static bool closureValid(const dyld3::closure::LaunchClosure* mainClosure, const dyld::log("dyld: closure %p not used because is used default fallback paths, but process does not allow that\n", mainClosure); return false; } - + if ( mainClosure->usedInterposing() && !gLinkContext.allowInterposing ) { + if ( gLinkContext.verboseWarnings ) + dyld::log("dyld: closure %p not used because is uses interposing, but process does not allow that\n", mainClosure); + return false; + } return !foundFileThatInvalidatesClosure; } @@ -6009,6 +6032,8 @@ static const dyld3::closure::LaunchClosure* buildLaunchClosure(const uint8_t* ma archs, pathOverrides, atPathHanding, gLinkContext.allowEnvVarsPath, errorInfo); if (sForceInvalidSharedCacheClosureFormat) builder.setDyldCacheInvalidFormatVersion(); + if ( !gLinkContext.allowInterposing ) + builder.disableInterposing(); const dyld3::closure::LaunchClosure* result = builder.makeLaunchClosure(mainFileInfo, gLinkContext.allowInsertFailures); if ( builder.diagnostics().hasError() ) { const char* errMsg = builder.diagnostics().errorMessage(); @@ -6057,7 +6082,11 @@ static const dyld3::closure::LaunchClosure* buildLaunchClosure(const uint8_t* ma putHexByte(mypid, s); *s = '\0'; strlcat(closurePathTemp, pidBuf, PATH_MAX); +#if __MAC_OS_X_VERSION_MIN_REQUIRED int fd = ::open(closurePathTemp, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); +#else + int fd = ::open_dprotected_np(closurePathTemp, O_WRONLY|O_CREAT, PROTECTION_CLASS_D, 0, S_IRUSR|S_IWUSR); +#endif if ( fd != -1 ) { ::ftruncate(fd, result->size()); ::write(fd, result, result->size()); @@ -6613,20 +6642,24 @@ reloadAllImages: link(image, sEnv.DYLD_BIND_AT_LAUNCH, true, ImageLoader::RPathChain(NULL, NULL), -1); image->setNeverUnloadRecursive(); } - // only INSERTED libraries can interpose - // register interposing info after all inserted libraries are bound so chaining works - for(unsigned int i=0; i < sInsertedDylibCount; ++i) { - ImageLoader* image = sAllImages[i+1]; - image->registerInterposing(gLinkContext); + if ( gLinkContext.allowInterposing ) { + // only INSERTED libraries can interpose + // register interposing info after all inserted libraries are bound so chaining works + for(unsigned int i=0; i < sInsertedDylibCount; ++i) { + ImageLoader* image = sAllImages[i+1]; + image->registerInterposing(gLinkContext); + } } } - // dyld should support interposition even without DYLD_INSERT_LIBRARIES - for (long i=sInsertedDylibCount+1; i < sAllImages.size(); ++i) { - ImageLoader* image = sAllImages[i]; - if ( image->inSharedCache() ) - continue; - image->registerInterposing(gLinkContext); + if ( gLinkContext.allowInterposing ) { + // dyld should support interposition even without DYLD_INSERT_LIBRARIES + for (long i=sInsertedDylibCount+1; i < sAllImages.size(); ++i) { + ImageLoader* image = sAllImages[i]; + if ( image->inSharedCache() ) + continue; + image->registerInterposing(gLinkContext); + } } #if SUPPORT_ACCELERATE_TABLES if ( (sAllCacheImagesProxy != NULL) && ImageLoader::haveInterposingTuples() ) { diff --git a/testing/include/test_support.h b/testing/include/test_support.h new file mode 100644 index 0000000..5f3fc83 --- /dev/null +++ b/testing/include/test_support.h @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include + +#if __LP64__ +extern struct mach_header_64 __dso_handle; +#else +extern struct mach_header __dso_handle; +#endif + +static bool sIsATTY = false; +static const char * sTestName = NULL; +static uint64_t sTestCount = 0; + +__attribute__((constructor)) +static +void BEGIN(int argc, const char* argv[], const char* envp[]) { + // Set up values we need to print in PASS() and FAIL() + sIsATTY = isatty(fileno(stdout)); + sTestName = argv[0]; + // Early returnif this not the main executbale, we only need to print the [BEGIN] line once + if (__dso_handle.filetype != MH_EXECUTE) { + return; + } + printf("[BEGIN]"); + for (uint32_t i = 0; envp[i] != NULL; ++i) { + if (strncmp("DYLD_", envp[i], 5) == 0) { + printf(" %s", envp[i]); + } + } + char buffer[MAXPATHLEN]; + uint32_t bufsize = MAXPATHLEN; + if (_NSGetExecutablePath(buffer, &bufsize) == 0) { + printf(" %s", buffer); + } else { + printf(" %s", argv[0]); + } + for (uint32_t i = 1; i < argc; ++i) { + printf (" %s", argv[i]); + } + printf("\n"); +} + +__attribute__((format(printf, 1, 2))) +static +void PASS(const char *format, ...) { + if (sIsATTY) { + printf("[\033[0;32mPASS\033[0m] %s (%llu): ", sTestName, sTestCount++); + } else { + printf("[PASS] %s (%llu): ", sTestName, sTestCount++); + } + va_list args; + va_start (args, format); + vprintf (format, args); + va_end (args); + printf("\n"); +} + +__attribute__((format(printf, 1, 2))) +static +void FAIL(const char *format, ...) { + if (sIsATTY) { + printf("[\033[0;31mFAIL\033[0m] %s (%llu): ", sTestName, sTestCount++); + } else { + printf("[FAIL] %s (%llu): ", sTestName, sTestCount++); + } + va_list args; + va_start (args, format); + vprintf (format, args); + va_end (args); + printf("\n"); +} diff --git a/testing/test-cases/amfi-interpose.dtest/interposer.c b/testing/test-cases/amfi-interpose.dtest/interposer.c new file mode 100644 index 0000000..a9e5c36 --- /dev/null +++ b/testing/test-cases/amfi-interpose.dtest/interposer.c @@ -0,0 +1,21 @@ +#include +#include +#include + + + +void* mymalloc(size_t size) +{ + // bump ptr allocate twice the size and fills with '#' + char* result = malloc(size*2); + memset(result, '#', size*2); + return result; +} + +void myfree(void* p) +{ + free(p); +} + +DYLD_INTERPOSE(mymalloc, malloc) +DYLD_INTERPOSE(myfree, free) diff --git a/testing/test-cases/amfi-interpose.dtest/main.c b/testing/test-cases/amfi-interpose.dtest/main.c new file mode 100644 index 0000000..d35a65e --- /dev/null +++ b/testing/test-cases/amfi-interpose.dtest/main.c @@ -0,0 +1,48 @@ +// BOOT_ARGS: dyld_flags=2 + +// BUILD: $CC interposer.c -dynamiclib -o $BUILD_DIR/libmyalloc.dylib -install_name $RUN_DIR/libmyalloc.dylib +// BUILD: $CC main.c $BUILD_DIR/libmyalloc.dylib -o $BUILD_DIR/amfi-interpose.exe +// BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/amfi-interpose.exe + +// RUN: DYLD_AMFI_FAKE=0x7F ./amfi-interpose.exe +// RUN: DYLD_AMFI_FAKE=0x3F ./amfi-interpose.exe + +// +// Tests that AMFI_DYLD_OUTPUT_ALLOW_LIBRARY_INTERPOSING bit from AMFI blocks interposing +// + +#include +#include +#include +#include + +#include + +int main() +{ + printf("[BEGIN] amfi-interpose\n"); + + // interposed malloc() doubles alloction size and prefills allocation with '#' + char* p1 = malloc(10); + bool interposed = (strncmp(p1, "####################", 20) == 0); + + const char* amfiBits = getenv("DYLD_AMFI_FAKE"); + if ( amfiBits == NULL ) { + printf("[FAIL] amfi-interpose: DYLD_AMFI_FAKE not setn\n"); + return 0; + } +#ifdef AMFI_RETURNS_INTERPOSING_FLAG + bool allowInterposing = (strcmp(amfiBits, "0x7F") == 0); +#else + bool allowInterposing = true; +#endif + + if ( interposed == allowInterposing ) + printf("[PASS] amfi-interpose\n"); + else if ( interposed ) + printf("[FAIL] amfi-interpose: malloc interposed, but amfi said to block it\n"); + else + printf("[FAIL] amfi-interpose: malloc not interposed, but amfi said to allow it\n"); + + return 0; +} diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/foo.c b/testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/foo.c similarity index 100% rename from unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/foo.c rename to testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/foo.c diff --git a/testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/main.c b/testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/main.c new file mode 100644 index 0000000..2fbce3a --- /dev/null +++ b/testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/main.c @@ -0,0 +1,65 @@ + +// BUILD_ONLY: MacOSX +// BUILD: mkdir -p $BUILD_DIR/Foo.framework $BUILD_DIR/alt11/Foo.framework/Versions/A $BUILD_DIR/alt9/Foo.framework +// BUILD: mkdir -p $BUILD_DIR/alt12/Foo.framework $BUILD_DIR/Bar.framework $BUILD_DIR/alt11/Bar.framework/Versions/A +// BUILD: mkdir -p $BUILD_DIR/Foo2.framework $BUILD_DIR/alt12/Foo2.framework +// BUILD: $CC foo.c -dynamiclib -DRESULT=9 -current_version 9 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/alt9/Foo.framework/Foo +// BUILD: $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/Foo.framework/Foo +// BUILD: $CC foo.c -dynamiclib -DRESULT=11 -current_version 11 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/alt11/Foo.framework/Versions/A/Foo +// BUILD: $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/alt12/Foo.framework/Foo + +// BUILD: $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/Foo2.framework/Foo2 -o $BUILD_DIR/Foo2.framework/Foo2 +// BUILD: $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/Foo2.framework/Foo2 -o $BUILD_DIR/alt12/Foo2.framework/Foo2 + +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_FRAMEWORK_PATH.exe $BUILD_DIR/Foo.framework/Foo +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_FRAMEWORK_PATH-missing.exe -Wl,-dyld_env,DYLD_VERSIONED_FRAMEWORK_PATH=@loader_path/alt12 $BUILD_DIR/Foo2.framework/Foo2 + +// BUILD: cd $BUILD_DIR/alt11/Foo.framework && ln -sf Versions/A/Foo +// BUILD: rm -rf $BUILD_DIR/Foo2.framework +// BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_FRAMEWORK_PATH.exe + +// RUN: ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 10 +// RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt11 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 11 "alt11/Foo.framework/Versions/A/Foo" +// RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 10 +// RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt9:$RUN_DIR/alt11 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 11 +// RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt11:$RUN_DIR/alt12 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 12 +// FIXME: Forcibly disable testing with closures since macOS does not use them and they are currently broken +// RUN: DYLD_USE_CLOSURES=0 ./env-DYLD_VERSIONED_FRAMEWORK_PATH-missing.exe 12 + +#include // fprintf(), NULL +#include // exit(), EXIT_SUCCESS +#include +#include +#include // for atoi() + +#include "test_support.h" + +extern int foo(); + +int main(int argc, const char* argv[]) +{ + if ( argc > 2 ) { + bool found = false; + uint32_t count = _dyld_image_count(); + for(uint32_t i=0; i < count; ++i) { + const char* name = _dyld_get_image_name(i); + if ( strstr(name, argv[2]) != NULL ) { + found = true; + } + } + if ( !found ) { + FAIL("Dylib has wrong path"); + return EXIT_SUCCESS; + } + } + + int expectedResult = atoi(argv[1]); + int actualResult = foo(); + if ( actualResult != expectedResult ) { + FAIL("Using wrong dylib. foo() returned %d, expected %d", actualResult, expectedResult); + } else { + PASS("Success"); + } + return 0; +} + diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/foo.c b/testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/foo.c similarity index 100% rename from unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/foo.c rename to testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/foo.c diff --git a/testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/main.c b/testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/main.c new file mode 100644 index 0000000..b0a7e64 --- /dev/null +++ b/testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/main.c @@ -0,0 +1,87 @@ +// BUILD_ONLY: MacOSX +// BUILD: mkdir -p $BUILD_DIR/alt11 $BUILD_DIR/alt9 $BUILD_DIR/alt12 +// BUILD: $CC foo.c -dynamiclib -DRESULT=9 -current_version 9 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/alt9/libfoo.dylib +// BUILD: $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib +// BUILD: $CC foo.c -dynamiclib -DRESULT=11 -current_version 11 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/alt11/libfoo.dylib +// BUILD: $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/alt12/libfoo.dylib + +// BUILD: $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/libfoo2.dylib -o $BUILD_DIR/libfoo2.dylib +// BUILD: $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/libfoo2.dylib -o $BUILD_DIR/alt12/libfoo2.dylib + +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH.exe $BUILD_DIR/libfoo.dylib +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-10.exe $BUILD_DIR/libfoo.dylib +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-11.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-911.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-911b.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9:@loader_path/alt11 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-911c.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@executable_path/alt9:@executable_path/alt11 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1112.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1112b.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11:@loader_path/alt12 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1211.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1211b.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12:@loader_path/alt11 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing.exe $BUILD_DIR/libfoo2.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe -DUSE_DLOPEN -DRUN_DIR="$RUN_DIR" -DDYLIB_NAME="libfoo.dylib" +// BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing-dlopen.exe -DUSE_DLOPEN -DRUN_DIR="$RUN_DIR" -DDYLIB_NAME="libfoo2.dylib" + +// BUILD: rm -rf $BUILD_DIR/libfoo2.dylib + +// BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH.exe +// BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-11.exe + +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 10 +// RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt11 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 11 +// RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 10 +// RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9:$RUN_DIR/alt11 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 11 +// RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt11:$RUN_DIR/alt12 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 12 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-10.exe 10 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-11.exe 11 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-911.exe 11 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-911b.exe 11 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-911c.exe 11 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1112.exe 12 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1112b.exe 12 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1211.exe 12 +// RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1211b.exe 12 +// RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_LIBRARY_PATH-11.exe 11 +// RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt12 ./env-DYLD_VERSIONED_LIBRARY_PATH-11.exe 12 +// FIXME: Forcibly disable testing with closures since macOS does not use them and they are currently broken +// RUN: DYLD_USE_CLOSURES=0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing.exe 12 + +// RUN: DYLD_USE_CLOSURES=0 ./env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe 10 +// RUN: DYLD_USE_CLOSURES=0 DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt11 ./env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe 11 +// RUN: DYLD_USE_CLOSURES=0 DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe 10 +// RUN: DYLD_USE_CLOSURES=0 DYLD_VERSIONED_LIBRARY_PATH="/AppleInternal/CoreOS/tests/dyld/env-DYLD_VERSIONED_LIBRARY_PATH/alt12" ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dlopen.exe 12 + +#include // fprintf(), NULL +#include // exit(), EXIT_SUCCESS +#include +#include // for atoi() + +#include "test_support.h" + +#if USE_DLOPEN +#include +#else +extern int foo(); +#endif + +int main(int argc, const char* argv[]) +{ + int expectedResult = atoi(argv[1]); +#if USE_DLOPEN + void * handle = dlopen(RUN_DIR "/" DYLIB_NAME, RTLD_LAZY); + if (!handle) { + FAIL("dlopen(\"%s\") failed with error \"%s\"", RUN_DIR "/" DYLIB_NAME, dlerror()); + } + int (*foo)() = dlsym(handle, "foo"); + if (!foo) { + FAIL("dlsym(\"foo\") failed with error \"%s\"", dlerror()); + } +#endif + int actualResult = foo(); + if ( actualResult != expectedResult ) { + FAIL("Using wrong dylib. foo() returned %d, expected %d", actualResult, expectedResult); + } else { + PASS("Success"); + } + return 0; +} diff --git a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/Makefile b/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/Makefile deleted file mode 100644 index 67ef91c..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/Makefile +++ /dev/null @@ -1,64 +0,0 @@ -## -# Copyright (c) 2010 Apple 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 - -PWD = $(shell pwd) - -ifeq "$(OS_NAME)" "iPhoneOS" - CHECK = check-ios -else - CHECK = check-macosx -endif - - -all-check: all $(CHECK) - -check: $(CHECK) - -check-ios: - ./main 10 - -check-macosx: - ./main 10 - export DYLD_VERSIONED_FRAMEWORK_PATH="${PWD}/alt11" && ./main 11 "alt11/Foo.framework/Versions/A/Foo" - export DYLD_VERSIONED_FRAMEWORK_PATH="${PWD}/alt9" && ./main 10 - export DYLD_VERSIONED_FRAMEWORK_PATH="${PWD}/alt9:${PWD}/alt11" && ./main 11 - export DYLD_VERSIONED_FRAMEWORK_PATH="${PWD}/alt11:${PWD}/alt12" && ./main 12 - -all: - mkdir -p Foo.framework alt11/Foo.framework/Versions/A alt9/Foo.framework alt12/Foo.framework Bar.framework alt11/Bar.framework/Versions/A/ - ${CC} ${CCFLAGS} -dynamiclib bar.c -DRESULT=10 -current_version 10 -install_name "${PWD}/Bar.framework/Bar" -o Bar.framework/Bar - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=10 -current_version 10 -install_name "${PWD}/Foo.framework/Foo" -o Foo.framework/Foo - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c Bar.framework/Bar Foo.framework/Foo - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=11 -current_version 11 -install_name "${PWD}/Foo.framework/Foo" -o alt11/Foo.framework/Versions/A/Foo - ${CC} ${CCFLAGS} -dynamiclib bar.c -DRESULT=11 -current_version 11 -install_name "${PWD}/Bar.framework/Foo" -o alt11/Bar.framework/Versions/A/Bar - cd alt11/Foo.framework && ln -sf Versions/A/Foo - cd alt11/Bar.framework && ln -sf Versions/A/Bar - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=9 -current_version 9 -install_name "${PWD}/Foo.framework/Foo" -o alt9/Foo.framework/Foo - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=12 -current_version 12 -install_name "${PWD}/Foo.framework/Foo" -o alt12/Foo.framework/Foo - - -clean: - ${RM} -rf main Foo.framework Bar.framework alt9 alt11 alt12 - diff --git a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/bar.c b/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/bar.c deleted file mode 100644 index 4684921..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/bar.c +++ /dev/null @@ -1,5 +0,0 @@ - -int bar() -{ - return 0; -} diff --git a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/foo.c b/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/foo.c deleted file mode 100644 index 01c576d..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/foo.c +++ /dev/null @@ -1,5 +0,0 @@ - -int foo() -{ - return RESULT; -} diff --git a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/main.c b/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/main.c deleted file mode 100644 index 26a1e09..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_FRAMEWORK_PATH-basic/main.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2010 Apple 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 // for atoi() -#include - -#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() - - - -extern int foo(); - -int main(int argc, const char* argv[]) -{ - if ( argc > 2 ) { - bool found = false; - uint32_t count = _dyld_image_count(); - for(uint32_t i=0; i < count; ++i) { - const char* name = _dyld_get_image_name(i); - if ( strstr(name, argv[2]) != NULL ) - found = true; - //fprintf(stderr, "image[%d]=%s\n", i, name); - } - if ( !found ) { - FAIL("DYLD_VERSIONED_FRAMEWORK_PATH-basic dylib has wrong path"); - return EXIT_SUCCESS; - } - } - - int expectedResult = atoi(argv[1]); - int actualResult = foo(); - //fprintf(stderr, "foo() returned %d, expected %d\n", actualResult, expectedResult); - if ( actualResult != expectedResult ) - FAIL("DYLD_VERSIONED_FRAMEWORK_PATH-basic using wrong dylib. foo() returned %d, expected %d", actualResult, expectedResult); - else - PASS("DYLD_VERSIONED_FRAMEWORK_PATH-basic"); - - return EXIT_SUCCESS; -} - diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/Makefile b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/Makefile deleted file mode 100644 index 4206cb7..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/Makefile +++ /dev/null @@ -1,61 +0,0 @@ -## -# Copyright (c) 2010 Apple 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 - -PWD = $(shell pwd) - -ifeq "$(OS_NAME)" "iPhoneOS" - CHECK = check-ios -else - CHECK = check-macosx -endif - -all-check: all check - -check: $(CHECK) - -check-ios: - ./main 10 - -check-macosx: - ./main 10 - export DYLD_VERSIONED_LIBRARY_PATH="${PWD}/alt11" && ./main 11 - export DYLD_VERSIONED_LIBRARY_PATH="${PWD}/alt9" && ./main 10 - export DYLD_VERSIONED_LIBRARY_PATH="${PWD}/alt9:${PWD}/alt11" && ./main 11 - export DYLD_VERSIONED_LIBRARY_PATH="${PWD}/alt11:${PWD}/alt12" && ./main 12 - -all: - mkdir -p alt11 alt9 alt12 - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=10 -current_version 10 -o "${PWD}/libfoo.dylib" - ${CC} ${CCFLAGS} -dynamiclib bar.c -DRESULT=10 -current_version 10 -o "${PWD}/libbar.dylib" - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libbar.dylib libfoo.dylib - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=11 -current_version 11 -install_name "${PWD}/libfoo.dylib" -o alt11/libfoo.dylib - ${CC} ${CCFLAGS} -dynamiclib bar.c -DRESULT=11 -current_version 11 -install_name "${PWD}/libbar.dylib" -o alt11/libbar.dylib - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=9 -current_version 9 -install_name "${PWD}/libfoo.dylib" -o alt9/libfoo.dylib - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=12 -current_version 12 -install_name "${PWD}/libfoo.dylib" -o alt12/libfoo.dylib - - -clean: - ${RM} -rf main libfoo.dylib libbar.dylib alt9 alt11 alt12 - diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/bar.c b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/bar.c deleted file mode 100644 index c57608f..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/bar.c +++ /dev/null @@ -1,5 +0,0 @@ - -int bar() -{ - return RESULT; -} diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/foo.c b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/foo.c deleted file mode 100644 index 01c576d..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/foo.c +++ /dev/null @@ -1,5 +0,0 @@ - -int foo() -{ - return RESULT; -} diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/main.c b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/main.c deleted file mode 100644 index a903b04..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-basic/main.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2010 Apple 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 // for atoi() - -#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() - - - -extern int foo(); - -int main(int argc, const char* argv[]) -{ - int expectedResult = atoi(argv[1]); - int actualResult = foo(); - //fprintf(stderr, "foo() returned %d, expected %d\n", actualResult, expectedResult); - if ( actualResult != expectedResult ) - FAIL("DYLD_VERSIONED_LIBRARY_PATH-basic using wrong dylib. foo() returned %d, expected %d", actualResult, expectedResult); - else - PASS("DYLD_VERSIONED_LIBRARY_PATH-basic"); - - return EXIT_SUCCESS; -} - diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/Makefile b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/Makefile deleted file mode 100644 index eeaef6e..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/Makefile +++ /dev/null @@ -1,58 +0,0 @@ -## -# Copyright (c) 2010 Apple 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 - -PWD = $(shell pwd) - -all-check: all check - -check: - ./main10 10 - ./main11 11 - ./main911 11 - ./main911b 11 - ./main1112 12 - ./main1112b 12 - ./main1211 12 - ./main1211b 12 - -all: - mkdir -p alt11 alt9 alt12 - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=10 -current_version 10 -o "${PWD}/libfoo.dylib" - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=11 -current_version 11 -install_name "${PWD}/libfoo.dylib" -o alt11/libfoo.dylib - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=9 -current_version 9 -install_name "${PWD}/libfoo.dylib" -o alt9/libfoo.dylib - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=12 -current_version 12 -install_name "${PWD}/libfoo.dylib" -o alt12/libfoo.dylib - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main10 main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main11 main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main911 main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main911b main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9:@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1112 main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1112b main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11:@loader_path/alt12 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1211 main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1211b main.c libfoo.dylib -Wl,-sectcreate,__RESTRICT,__restrict,/dev/null -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12:@loader_path/alt11 - - -clean: - ${RM} -rf libfoo.dylib alt9 alt11 alt12 main10 main11 main9 main911 main911b main1112 main1112b main1211 main1211b - diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/main.c b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/main.c deleted file mode 100644 index a903b04..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env-restrict/main.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2010 Apple 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 // for atoi() - -#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() - - - -extern int foo(); - -int main(int argc, const char* argv[]) -{ - int expectedResult = atoi(argv[1]); - int actualResult = foo(); - //fprintf(stderr, "foo() returned %d, expected %d\n", actualResult, expectedResult); - if ( actualResult != expectedResult ) - FAIL("DYLD_VERSIONED_LIBRARY_PATH-basic using wrong dylib. foo() returned %d, expected %d", actualResult, expectedResult); - else - PASS("DYLD_VERSIONED_LIBRARY_PATH-basic"); - - return EXIT_SUCCESS; -} - diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/Makefile b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/Makefile deleted file mode 100644 index 357a34e..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/Makefile +++ /dev/null @@ -1,61 +0,0 @@ -## -# Copyright (c) 2010 Apple 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 - -PWD = $(shell pwd) - -all-check: all check - -check: - ./main10 10 - ./main11 11 - ./main911 11 - ./main911b 11 - ./main911c 11 - ./main1112 12 - ./main1112b 12 - ./main1211 12 - ./main1211b 12 - export DYLD_LIBRARY_PATH=./alt9 && ./main11 9 - -all: - mkdir -p alt11 alt9 alt12 - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=10 -current_version 10 -o "${PWD}/libfoo.dylib" - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=11 -current_version 11 -install_name "${PWD}/libfoo.dylib" -o alt11/libfoo.dylib - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=9 -current_version 9 -install_name "${PWD}/libfoo.dylib" -o alt9/libfoo.dylib - ${CC} ${CCFLAGS} -dynamiclib foo.c -DRESULT=12 -current_version 12 -install_name "${PWD}/libfoo.dylib" -o alt12/libfoo.dylib - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main10 main.c libfoo.dylib - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main11 main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main911 main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main911b main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9:@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main911c main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@executable_path/alt9:@executable_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1112 main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1112b main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11:@loader_path/alt12 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1211 main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 - ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main1211b main.c libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12:@loader_path/alt11 - - -clean: - ${RM} -rf libfoo.dylib alt9 alt11 alt12 main10 main11 main9 main911 main911b main911c main1112 main1112b main1211 main1211b - diff --git a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/main.c b/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/main.c deleted file mode 100644 index a903b04..0000000 --- a/unit-tests/test-cases/DYLD_VERSIONED_LIBRARY_PATH-dyld_env/main.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2010 Apple 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 // for atoi() - -#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() - - - -extern int foo(); - -int main(int argc, const char* argv[]) -{ - int expectedResult = atoi(argv[1]); - int actualResult = foo(); - //fprintf(stderr, "foo() returned %d, expected %d\n", actualResult, expectedResult); - if ( actualResult != expectedResult ) - FAIL("DYLD_VERSIONED_LIBRARY_PATH-basic using wrong dylib. foo() returned %d, expected %d", actualResult, expectedResult); - else - PASS("DYLD_VERSIONED_LIBRARY_PATH-basic"); - - return EXIT_SUCCESS; -} - -- 2.7.4