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