return getFlags().hasInsertedLibraries;
}
+bool LaunchClosure::usedInterposing() const
+{
+ return getFlags().usedInterposing;
+}
+
bool LaunchClosure::hasInterposings() const
{
__block bool result = false;
void forEachInterposingTuple(void (^handler)(const InterposingTuple& tuple, bool& stop)) const;
bool usedAtPaths() const;
bool usedFallbackPaths() const;
+ bool usedInterposing() const;
bool selectorHashTable(Array<Image::ObjCSelectorImage>& imageNums,
const ObjCSelectorOpt*& hashTable) const;
bool classAndProtocolHashTables(Array<Image::ObjCClassImage>& imageNums,
usedFallbackPaths : 1,
initImageCount : 16,
hasInsertedLibraries : 1,
- padding : 13;
+ usedInterposing : 1,
+ padding : 12;
};
const Flags& getFlags() const;
};
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());
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);
ImageNum nextFreeImageNum() const { return _startImageNum + _nextIndex; }
void setDyldCacheInvalidFormatVersion();
+ void disableInterposing() { _interposingDisabled = true; }
struct PatchableExport
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;
};
getFlags().usedAtPaths = value;
}
+void LaunchClosureWriter::setUsedInterposing(bool value)
+{
+ getFlags().usedInterposing = value;
+}
+
void LaunchClosureWriter::setHasInsertedLibraries(bool value)
{
getFlags().hasInsertedLibraries = value;
void setStartEntry(Image::ResolvedSymbolTarget start);
void setUsedFallbackPaths(bool);
void setUsedAtPaths(bool);
+ void setUsedInterposing(bool);
void setHasInsertedLibraries(bool);
void setMustBeMissingFiles(const Array<const char*>& paths);
void setMustExistFiles(const Array<LaunchClosure::SkippedFile>& files);
bool allowEnvVarsSharedCache;
bool allowClassicFallbackPaths;
bool allowInsertFailures;
+ bool allowInterposing;
bool mainExecutableCodeSigned;
bool prebinding;
bool bindFlat;
#include <kern/kcdata.h>
#include <sys/attr.h>
#include <sys/fsgetpath.h>
+#include <System/sys/content_protection.h>
#if TARGET_OS_SIMULATOR
enum {
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 <libamfi.h>
#endif
+
#include <sandbox.h>
#include <sandbox/private.h>
#if __has_feature(ptrauth_calls)
return image;
}
+#if SUPPORT_VERSIONED_PATHS
+ // <rdar://problem/53215116> 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;
}
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
gLinkContext.allowEnvVarsSharedCache = !libraryValidation || !usingSIP;
gLinkContext.allowClassicFallbackPaths = !isRestricted;
gLinkContext.allowInsertFailures = false;
+ gLinkContext.allowInterposing = true;
#else
halt("amfi_check_dyld_policy_self() failed\n");
#endif
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;
}
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();
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());
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);
+ }
}
}
- // <rdar://problem/19315404> 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 ) {
+ // <rdar://problem/19315404> 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() ) {
--- /dev/null
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <mach-o/dyld.h>
+#include <sys/param.h>
+
+#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");
+}
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <mach-o/dyld-interposing.h>
+
+
+
+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)
--- /dev/null
+// 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 <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libamfi.h>
+
+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;
+}
--- /dev/null
+
+int foo()
+{
+ return RESULT;
+}
--- /dev/null
+
+// 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 <stdio.h> // fprintf(), NULL
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+#include <dlfcn.h>
+#include <string.h>
+#include <stdlib.h> // 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;
+}
+
--- /dev/null
+
+int foo()
+{
+ return RESULT;
+}
--- /dev/null
+// 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 <stdio.h> // fprintf(), NULL
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+#include <string.h>
+#include <stdlib.h> // for atoi()
+
+#include "test_support.h"
+
+#if USE_DLOPEN
+#include <dlfcn.h>
+#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;
+}
+++ /dev/null
-##
-# 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
-
+++ /dev/null
-
-int bar()
-{
- return 0;
-}
+++ /dev/null
-
-int foo()
-{
- return RESULT;
-}
+++ /dev/null
-/*
- * 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 <stdio.h> // fprintf(), NULL
-#include <stdlib.h> // exit(), EXIT_SUCCESS
-#include <dlfcn.h>
-#include <string.h>
-#include <stdlib.h> // for atoi()
-#include <mach-o/dyld.h>
-
-#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;
-}
-
+++ /dev/null
-##
-# 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
-
+++ /dev/null
-
-int bar()
-{
- return RESULT;
-}
+++ /dev/null
-
-int foo()
-{
- return RESULT;
-}
+++ /dev/null
-/*
- * 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 <stdio.h> // fprintf(), NULL
-#include <stdlib.h> // exit(), EXIT_SUCCESS
-#include <dlfcn.h>
-#include <string.h>
-#include <stdlib.h> // 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;
-}
-
+++ /dev/null
-##
-# 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
-
+++ /dev/null
-
-int foo()
-{
- return RESULT;
-}
+++ /dev/null
-/*
- * 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 <stdio.h> // fprintf(), NULL
-#include <stdlib.h> // exit(), EXIT_SUCCESS
-#include <dlfcn.h>
-#include <string.h>
-#include <stdlib.h> // 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;
-}
-
+++ /dev/null
-##
-# 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
-
+++ /dev/null
-
-int foo()
-{
- return RESULT;
-}
+++ /dev/null
-/*
- * 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 <stdio.h> // fprintf(), NULL
-#include <stdlib.h> // exit(), EXIT_SUCCESS
-#include <dlfcn.h>
-#include <string.h>
-#include <stdlib.h> // 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;
-}
-