]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-atpath-restricted.dtest/main.c
bd55fb4d24cf59d3fd9365d2e914346932c464dd
[apple/dyld.git] / testing / test-cases / dlopen-atpath-restricted.dtest / main.c
1 // BUILD_ONLY: MacOSX
2
3 // BUILD: mkdir -p $BUILD_DIR/test1
4 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/test1/libtest1.dylib -install_name @rpath/libtest1.dylib
5 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/test1.bundle -Wl,-rpath,@loader_path/test1/ $BUILD_DIR/test1/libtest1.dylib
6
7 // BUILD: mkdir -p $BUILD_DIR/test2
8 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/test2/libtest2.dylib -install_name @loader_path/test2/libtest2.dylib
9 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/test2.bundle $BUILD_DIR/test2/libtest2.dylib
10
11 // BUILD: mkdir -p $BUILD_DIR/test3
12 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/test3/libtest3.dylib -install_name @rpath/libtest3.dylib
13 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/test3.bundle -Wl,-rpath,$RUN_DIR/test3 $BUILD_DIR/test3/libtest3.dylib
14
15 // BUILD: mkdir -p $BUILD_DIR/test4
16 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/test4/libtest4.dylib -install_name @rpath/libtest4.dylib
17 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/test4.bundle -Wl,-rpath,@executable_path/test4/ $BUILD_DIR/test4/libtest4.dylib
18
19 // BUILD: mkdir -p $BUILD_DIR/test5
20 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/test5/libtest5.dylib -install_name @executable_path/test5/libtest5.dylib
21 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/test5.bundle $BUILD_DIR/test5/libtest5.dylib
22
23
24
25 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-restricted.exe -DRUN_DIR="$RUN_DIR" -sectcreate __RESTRICT __restrict /dev/null
26
27 // RUN: ./dlopen-restricted.exe
28
29 #include <stdio.h>
30 #include <dlfcn.h>
31
32
33 int main(int argc, const char* argv[])
34 {
35 printf("[BEGIN] dlopen-restricted\n");
36
37 // test1: LC_RPATH not in main executable uses @loader_path
38 void* handle = dlopen(RUN_DIR "/test1.bundle", RTLD_LAZY);
39 if ( handle == NULL ) {
40 printf("dlerror(): %s\n", dlerror());
41 printf("[FAIL] dlopen-restricted test1.bundle\n");
42 return 0;
43 }
44
45 // test2: @loader_path not in main executable
46 handle = dlopen(RUN_DIR "/test2.bundle", RTLD_LAZY);
47 if ( handle == NULL ) {
48 printf("dlerror(): %s\n", dlerror());
49 printf("[FAIL] dlopen-restricted test2.bundle\n");
50 return 0;
51 }
52
53 // test3: LC_RPATH not in main executable uses absolute path
54 handle = dlopen(RUN_DIR "/test3.bundle", RTLD_LAZY);
55 if ( handle == NULL ) {
56 printf("dlerror(): %s\n", dlerror());
57 printf("[FAIL] dlopen-restricted test3.bundle\n");
58 return 0;
59 }
60
61 // test4: [SHOULD FAIL] LC_RPATH not in main executable uses @executable_path
62 handle = dlopen(RUN_DIR "/test4.bundle", RTLD_LAZY);
63 if ( handle != NULL ) {
64 printf("[FAIL] dlopen-restricted test4.bundle dlopen() should not work\n");
65 return 0;
66 }
67
68 // test5: [SHOULD FAIL] @executable_path in LC_LOAD_DYLIB
69 handle = dlopen(RUN_DIR "/test5.bundle", RTLD_LAZY);
70 if ( handle != NULL ) {
71 printf("[FAIL] dlopen-restricted test5.bundle dlopen() should not work\n");
72 return 0;
73 }
74
75
76
77 printf("[PASS] dlopen-restricted\n");
78 return 0;
79 }
80