dyld-625.13.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-rpath-prev-override.dtest / main.c
1
2 // BUILD: mkdir -p $BUILD_DIR/dir $BUILD_DIR/good $BUILD_DIR/bad
3 // BUILD: $CC good.c -dynamiclib -install_name @rpath/libtest.dylib -o $BUILD_DIR/good/libtest.dylib
4 // BUILD: $CC bad.c -dynamiclib -install_name @rpath/libtest.dylib -o $BUILD_DIR/bad/libtest.dylib
5 // BUILD: $CC dyn.c -dynamiclib -install_name @rpath/libdynamic.dylib -o $BUILD_DIR/dir/libdynamic.dylib $BUILD_DIR/good/libtest.dylib -rpath @loader_path/../bad
6 // BUILD: $CC main.c $BUILD_DIR/good/libtest.dylib -DRUN_DIR="$RUN_DIR" -o $BUILD_DIR/dlopen-rpath-prev-override.exe -rpath @loader_path/good
7
8 // RUN: ./dlopen-rpath-prev-override.exe
9
10 // Processing of @rpath in dlopen()s always checks existing loaded images before using LC_RPATHs to find images on disk
11 //
12 // main links with @rpath/libtest.dylib found via -rpath @loader_path/good
13 // main dlopen()s libdynamic.dylib which links with @rpath/libtest.dylib and has LR_PATH to find it in bad/,
14 // but since it was already loaded from good/, that one should be re-used.
15
16 #include <stdio.h>
17 #include <dlfcn.h>
18
19 int main()
20 {
21 printf("[BEGIN] dlopen-rpath-prev-override\n");
22
23 void* handle = dlopen(RUN_DIR "/dir/libdynamic.dylib", RTLD_LAZY);
24 if ( handle == NULL ) {
25 printf("dlerror(): %s\n", dlerror());
26 printf("[FAIL] dlopen-rpath-prev-override\n");
27 return 0;
28 }
29
30 printf("[PASS] dlopen-rpath-prev-override\n");
31 return 0;
32 }
33