]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dladdr-dylib.dtest/foo.c
dyld-519.2.2.tar.gz
[apple/dyld.git] / testing / test-cases / dladdr-dylib.dtest / foo.c
1
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <dlfcn.h>
7 #include <mach-o/dyld_priv.h>
8
9 extern void* __dso_handle;
10
11 int dylib_bar()
12 {
13 return 2;
14 }
15
16 static int dylib_foo()
17 {
18 return 3;
19 }
20
21 __attribute__((visibility("hidden"))) int dylib_hide()
22 {
23 return 4;
24 }
25
26 // checks global symbol
27 static void verifybar()
28 {
29 Dl_info info;
30 if ( dladdr(&dylib_bar, &info) == 0 ) {
31 printf("[FAIL] dladdr(&dylib_bar, xx) failed\n");
32 exit(0);
33 }
34 if ( strcmp(info.dli_sname, "dylib_bar") != 0 ) {
35 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"dylib_bar\"\n", info.dli_sname);
36 exit(0);
37 }
38 if ( info.dli_saddr != &dylib_bar) {
39 printf("[FAIL] dladdr()->dli_saddr is not &dylib_bar\n");
40 exit(0);
41 }
42 if ( info.dli_fbase != &__dso_handle ) {
43 printf("[FAIL] dladdr()->dli_fbase is not image that contains &dylib_bar\n");
44 exit(0);
45 }
46 }
47
48 // checks local symbol
49 static void verifyfoo()
50 {
51 Dl_info info;
52 if ( dladdr(&dylib_foo, &info) == 0 ) {
53 printf("[FAIL] dladdr(&dylib_foo, xx) failed\n");
54 exit(0);
55 }
56 if ( strcmp(info.dli_sname, "dylib_foo") != 0 ) {
57 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"dylib_foo\"\n", info.dli_sname);
58 exit(0);
59 }
60 if ( info.dli_saddr != &dylib_foo) {
61 printf("[FAIL] dladdr()->dli_saddr is not &dylib_foo\n");
62 exit(0);
63 }
64 if ( info.dli_fbase != &__dso_handle ) {
65 printf("[FAIL] dladdr()->dli_fbase is not image that contains &dylib_foo\n");
66 exit(0);
67 }
68 }
69
70 // checks hidden symbol
71 static void verifyhide()
72 {
73 Dl_info info;
74 if ( dladdr(&dylib_hide, &info) == 0 ) {
75 printf("[FAIL] dladdr(&dylib_hide, xx) failed\n");
76 exit(0);
77 }
78 if ( strcmp(info.dli_sname, "dylib_hide") != 0 ) {
79 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"dylib_hide\"\n", info.dli_sname);
80 exit(0);
81 }
82 if ( info.dli_saddr != &dylib_hide) {
83 printf("[FAIL] dladdr()->dli_saddr is not &dylib_hide\n");
84 exit(0);
85 }
86 if ( info.dli_fbase != &__dso_handle ) {
87 printf("[FAIL] dladdr()->dli_fbase is not image that contains &dylib_hide\n");
88 exit(0);
89 }
90 }
91
92
93 void verifyDylib()
94 {
95 verifybar();
96 verifyfoo();
97 verifyhide();
98 }
99