]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.dtest/main.c
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.dtest / main.c
1 // This tests DYLD_VERSIONED_LIBRARY_PATH where the library we are doing a versioned check against is only in the shared
2 // cache and not on disk. This is the case when macOS moves to MRM.
3
4 // libz.1.dylib was chosen as (on 10.15) it had a current version of 1.2.11 so we can write test dylibs with higer/lower versions
5
6 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT="1.0.0" -current_version 1.0.0 -install_name /usr/lib/libz.1.dylib -o $BUILD_DIR/alt-1.0.0/libz.1.dylib
7 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT="2000.0.0" -current_version 2000.0.0 -install_name /usr/lib/libz.1.dylib -o $BUILD_DIR/alt-2000.0.0/libz.1.dylib
8
9 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.exe -lz
10 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1.0.0.exe -lz -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt-1.0.0
11 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-2000.0.0.exe -lz -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt-2000.0.0
12 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs-dlopen.exe -DUSE_DLOPEN
13
14 // BUILD(macos): $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.exe
15 // BUILD(macos): $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs-dlopen.exe
16
17 // BUILD(ios,tvos,watchos,bridgeos):
18
19 // Use the host when we have no ENV variable, or we check against the 1.0.0 test dylib which is lower than the host
20 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.exe "host"
21 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-1.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.exe "host"
22 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1.0.0.exe "host"
23 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs-dlopen.exe "host"
24 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-1.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs-dlopen.exe "host"
25
26 // Use the 2000.0.0 dylib when its present
27 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-2000.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.exe "2000.0.0"
28 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-2000.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-1.0.0.exe "2000.0.0"
29 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-2000.0.0.exe "2000.0.0"
30 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-2000.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs-dlopen.exe "2000.0.0"
31
32 // 2000.0.0 should also override the 1.0.0 version if we specify both (in either order)
33 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-1.0.0:$RUN_DIR/alt-2000.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.exe "2000.0.0"
34 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-2000.0.0:$RUN_DIR/alt-1.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs.exe "2000.0.0"
35 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-1.0.0:$RUN_DIR/alt-2000.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs-dlopen.exe "2000.0.0"
36 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt-2000.0.0:$RUN_DIR/alt-1.0.0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dylibs-dlopen.exe "2000.0.0"
37
38 #include <stdio.h> // fprintf(), NULL
39 #include <stdlib.h> // exit(), EXIT_SUCCESS
40 #include <string.h>
41 #include <stdlib.h> // for atoi()
42
43 #include "test_support.h"
44
45 #if USE_DLOPEN
46 #include <dlfcn.h>
47 #else
48 extern const char* zlibVersion(); // returns "1.2.11" on the host dylib
49 #endif
50
51 int main(int argc, const char* argv[])
52 {
53 const char* expectedResult = argv[1];
54
55 #if USE_DLOPEN
56 void * handle = dlopen("/usr/lib/libz.1.dylib", RTLD_LAZY);
57 if (!handle) {
58 FAIL("dlopen(\"%s\") failed with error \"%s\"", "/usr/lib/libz.1.dylib", dlerror());
59 }
60 const char* (*zlibVersion)() = dlsym(handle, "zlibVersion");
61 if (!zlibVersion) {
62 FAIL("dlsym(\"zlibVersion\") failed with error \"%s\"", dlerror());
63 }
64 #endif
65
66 const char* actualResult = zlibVersion();
67 if ( !strcmp(expectedResult, "host") ) {
68 // We don't know what the host version is, but we know we wanted it instead of the test dylibs
69 if ( !strcmp(actualResult, "1.0.0") ) {
70 FAIL("Using wrong dylib. zlibVersion() returned %s, expected host version", actualResult);
71 } else {
72 PASS("Success");
73 }
74 } else {
75 if ( strcmp(actualResult, expectedResult) ) {
76 FAIL("Using wrong dylib. zlibVersion() returned %s, expected %s", actualResult, expectedResult);
77 } else {
78 PASS("Success");
79 }
80 }
81 return 0;
82 }
83