dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-atpath-restricted.dtest / main.c
1 // BUILD(macos): $CC bar.c -dynamiclib -o $BUILD_DIR/test1/libtest1.dylib -install_name @rpath/libtest1.dylib
2 // BUILD(macos): $CC foo.c -bundle -o $BUILD_DIR/test1.bundle -Wl,-rpath,@loader_path/test1/ $BUILD_DIR/test1/libtest1.dylib
3
4 // BUILD(macos): $CC bar.c -dynamiclib -o $BUILD_DIR/test2/libtest2.dylib -install_name @loader_path/test2/libtest2.dylib
5 // BUILD(macos): $CC foo.c -bundle -o $BUILD_DIR/test2.bundle $BUILD_DIR/test2/libtest2.dylib
6
7 // BUILD(macos): $CC bar.c -dynamiclib -o $BUILD_DIR/test3/libtest3.dylib -install_name @rpath/libtest3.dylib
8 // BUILD(macos): $CC foo.c -bundle -o $BUILD_DIR/test3.bundle -Wl,-rpath,$RUN_DIR/test3 $BUILD_DIR/test3/libtest3.dylib
9
10 // BUILD(macos): $CC bar.c -dynamiclib -o $BUILD_DIR/test4/libtest4.dylib -install_name @rpath/libtest4.dylib
11 // BUILD(macos): $CC foo.c -bundle -o $BUILD_DIR/test4.bundle -Wl,-rpath,@executable_path/test4/ $BUILD_DIR/test4/libtest4.dylib
12
13 // BUILD(macos): $CC bar.c -dynamiclib -o $BUILD_DIR/test5/libtest5.dylib -install_name @executable_path/test5/libtest5.dylib
14 // BUILD(macos): $CC foo.c -bundle -o $BUILD_DIR/test5.bundle $BUILD_DIR/test5/libtest5.dylib
15
16 // BUILD(macos): $CC main.c -o $BUILD_DIR/dlopen-restricted.exe -DRUN_DIR="$RUN_DIR" -sectcreate __RESTRICT __restrict /dev/null
17
18 // BUILD(ios,tvos,watchos,bridgeos):
19
20 // RUN: ./dlopen-restricted.exe
21
22 #include <stdio.h>
23 #include <dlfcn.h>
24
25 #include "test_support.h"
26
27 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
28
29 // test1: LC_RPATH not in main executable uses @loader_path
30 void* handle = dlopen(RUN_DIR "/test1.bundle", RTLD_LAZY);
31 if ( handle == NULL ) {
32 FAIL("test1.bundle dlerror(): %s", dlerror());
33 }
34
35 // test2: @loader_path not in main executable
36 handle = dlopen(RUN_DIR "/test2.bundle", RTLD_LAZY);
37 if ( handle == NULL ) {
38 FAIL("test2.bundle\n dlerror(): %s", dlerror());
39 }
40
41 // test3: LC_RPATH not in main executable uses absolute path
42 handle = dlopen(RUN_DIR "/test3.bundle", RTLD_LAZY);
43 if ( handle == NULL ) {
44 FAIL("test3.bundle dlerror(): %s", dlerror());
45 }
46
47 // test4: [SHOULD FAIL] LC_RPATH not in main executable uses @executable_path
48 handle = dlopen(RUN_DIR "/test4.bundle", RTLD_LAZY);
49 if ( handle != NULL ) {
50 FAIL("test4.bundle dlopen() should not work");
51 }
52
53 // test5: [SHOULD FAIL] @executable_path in LC_LOAD_DYLIB
54 handle = dlopen(RUN_DIR "/test5.bundle", RTLD_LAZY);
55 if ( handle != NULL ) {
56 FAIL("test5.bundle dlopen() should not work");
57 }
58
59 PASS("Success");
60 }
61