]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/interpose-weak.dtest/main.c
dyld-733.6.tar.gz
[apple/dyld.git] / testing / test-cases / interpose-weak.dtest / main.c
1 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib
2 // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/interpose-weak-present.exe
3 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/interpose-weak-present.exe
4 // BUILD: $CC interposer.c -dynamiclib $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/libinterposer.dylib -install_name libinterposer.dylib
5
6 // BUILD: $CC foo.c -dynamiclib -o $TEMP_DIR/libfoo2.dylib -install_name $RUN_DIR/libfoo2.dylib
7 // BUILD: $CC foo.c -DNO_FOO34 -dynamiclib -o $BUILD_DIR/libfoo2.dylib -install_name $RUN_DIR/libfoo2.dylib
8 // BUILD: $CC main.c -DNO_FOO34 $TEMP_DIR/libfoo2.dylib -o $BUILD_DIR/interpose-weak-missing.exe
9 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/interpose-weak-missing.exe
10 // BUILD: $CC interposer.c -dynamiclib $TEMP_DIR/libfoo2.dylib -o $BUILD_DIR/libinterposer2.dylib -install_name libinterposer.dylib
11
12
13 // RUN: DYLD_INSERT_LIBRARIES=libinterposer.dylib ./interpose-weak-present.exe
14 // RUN: DYLD_INSERT_LIBRARIES=libinterposer2.dylib ./interpose-weak-missing.exe
15
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22
23 extern int foo1();
24 extern int foo2();
25 extern int foo3() __attribute__((weak_import));
26 extern int foo4() __attribute__((weak_import));
27
28 #ifndef NO_FOO34
29 #define MODE "present"
30 #else
31 #define MODE "missing"
32 #endif
33
34 int main()
35 {
36 printf("[BEGIN] interpose-weak-" MODE "\n");
37
38 if ( foo1() != 1 ) {
39 printf("[FAIL] interpose-weak-" MODE ", foo1() != 1\n");
40 return 0;
41 }
42
43 if ( foo2() != 12 ) {
44 printf("[FAIL] interpose-weak-" MODE ", foo2() != 12\n");
45 return 0;
46 }
47
48 #ifndef NO_FOO34
49 if ( foo3() != 3 ) {
50 printf("[FAIL] interpose-weak-" MODE ", foo3() != 3\n");
51 return 0;
52 }
53
54 if ( foo4() != 14 ) {
55 printf("[FAIL] interpose-weak-" MODE ", foo4() != 14\n");
56 return 0;
57 }
58 #else
59 if ( &foo3 != NULL ) {
60 printf("[FAIL] interpose-weak-" MODE ", &foo3 != NULL\n");
61 return 0;
62 }
63
64 if ( &foo4 != NULL ) {
65 printf("[FAIL] interpose-weak-" MODE ", &foo4 != NULL\n");
66 return 0;
67 }
68 #endif
69
70 printf("[PASS] interpose-weak-" MODE "\n");
71 return 0;
72 }