]>
git.saurik.com Git - apple/dyld.git/blob - 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.
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
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
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
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
17 // BUILD(ios,tvos,watchos,bridgeos):
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"
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"
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"
38 #include <stdio.h> // fprintf(), NULL
39 #include <stdlib.h> // exit(), EXIT_SUCCESS
41 #include <stdlib.h> // for atoi()
43 #include "test_support.h"
48 extern const char* zlibVersion(); // returns "1.2.11" on the host dylib
51 int main(int argc
, const char* argv
[])
53 const char* expectedResult
= argv
[1];
56 void * handle
= dlopen("/usr/lib/libz.1.dylib", RTLD_LAZY
);
58 FAIL("dlopen(\"%s\") failed with error \"%s\"", "/usr/lib/libz.1.dylib", dlerror());
60 const char* (*zlibVersion
)() = dlsym(handle
, "zlibVersion");
62 FAIL("dlsym(\"zlibVersion\") failed with error \"%s\"", dlerror());
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
);
75 if ( strcmp(actualResult
, expectedResult
) ) {
76 FAIL("Using wrong dylib. zlibVersion() returned %s, expected %s", actualResult
, expectedResult
);