]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dladdr-dylib.dtest/foo.c
c62f8c639bf6bba6e3ce7983e4b2c7e94b751b0e
7 #include <mach-o/dyld_priv.h>
8 #if __has_feature(ptrauth_calls)
12 extern void* __dso_handle
;
15 static const void* stripPointer(const void* ptr
)
17 #if __has_feature(ptrauth_calls)
18 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
30 static int dylib_foo()
35 __attribute__((visibility("hidden"))) int dylib_hide()
40 // checks global symbol
41 static void verifybar()
44 if ( dladdr(&dylib_bar
, &info
) == 0 ) {
45 printf("[FAIL] dladdr(&dylib_bar, xx) failed\n");
48 if ( strcmp(info
.dli_sname
, "dylib_bar") != 0 ) {
49 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"dylib_bar\"\n", info
.dli_sname
);
52 if ( info
.dli_saddr
!= stripPointer(&dylib_bar
) ) {
53 printf("[FAIL] dladdr()->dli_saddr is not &dylib_bar\n");
56 if ( info
.dli_fbase
!= &__dso_handle
) {
57 printf("[FAIL] dladdr()->dli_fbase is not image that contains &dylib_bar\n");
62 // checks local symbol
63 static void verifyfoo()
66 if ( dladdr(&dylib_foo
, &info
) == 0 ) {
67 printf("[FAIL] dladdr(&dylib_foo, xx) failed\n");
70 if ( strcmp(info
.dli_sname
, "dylib_foo") != 0 ) {
71 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"dylib_foo\"\n", info
.dli_sname
);
74 if ( info
.dli_saddr
!= stripPointer(&dylib_foo
) ) {
75 printf("[FAIL] dladdr()->dli_saddr is not &dylib_foo\n");
78 if ( info
.dli_fbase
!= &__dso_handle
) {
79 printf("[FAIL] dladdr()->dli_fbase is not image that contains &dylib_foo\n");
84 // checks hidden symbol
85 static void verifyhide()
88 if ( dladdr(&dylib_hide
, &info
) == 0 ) {
89 printf("[FAIL] dladdr(&dylib_hide, xx) failed\n");
92 if ( strcmp(info
.dli_sname
, "dylib_hide") != 0 ) {
93 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"dylib_hide\"\n", info
.dli_sname
);
96 if ( info
.dli_saddr
!= stripPointer(&dylib_hide
) ) {
97 printf("[FAIL] dladdr()->dli_saddr is not &dylib_hide\n");
100 if ( info
.dli_fbase
!= &__dso_handle
) {
101 printf("[FAIL] dladdr()->dli_fbase is not image that contains &dylib_hide\n");
107 static void verifyDSOHandle()
110 if ( dladdr(&__dso_handle
, &info
) == 0 ) {
111 printf("[FAIL] dladdr(&__dso_handle, xx) failed\n");
114 if ( strcmp(info
.dli_sname
, "__dso_handle") != 0 ) {
115 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"__dso_handle\"\n", info
.dli_sname
);
118 if ( info
.dli_saddr
!= stripPointer(&__dso_handle
) ) {
119 printf("[FAIL] dladdr()->dli_saddr is not &__dso_handle\n");
122 if ( info
.dli_fbase
!= &__dso_handle
) {
123 printf("[FAIL] dladdr()->dli_fbase is not image that contains &__dso_handle\n");