]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dladdr-dylib.dtest/foo.c
7 #include <mach-o/dyld_priv.h>
8 #if __has_feature(ptrauth_calls)
12 #include "test_support.h"
14 extern void* __dso_handle
;
17 static const void* stripPointer(const void* ptr
)
19 #if __has_feature(ptrauth_calls)
20 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
32 static int dylib_foo()
37 __attribute__((visibility("hidden"))) int dylib_hide()
42 // checks global symbol
43 static void verifybar()
46 if ( dladdr(&dylib_bar
, &info
) == 0 ) {
47 FAIL("dladdr(&dylib_bar, xx) failed");
49 if ( strcmp(info
.dli_sname
, "dylib_bar") != 0 ) {
50 FAIL("dladdr()->dli_sname is \"%s\" instead of \"dylib_bar\"", info
.dli_sname
);
52 if ( info
.dli_saddr
!= stripPointer(&dylib_bar
) ) {
53 FAIL("dladdr()->dli_saddr is not &dylib_bar");
55 if ( info
.dli_fbase
!= &__dso_handle
) {
56 FAIL("dladdr()->dli_fbase is not image that contains &dylib_bar");
60 // checks local symbol
61 static void verifyfoo()
64 if ( dladdr(&dylib_foo
, &info
) == 0 ) {
65 FAIL("dladdr(&dylib_foo, xx) failed");
67 if ( strcmp(info
.dli_sname
, "dylib_foo") != 0 ) {
68 FAIL("dladdr()->dli_sname is \"%s\" instead of \"dylib_foo\"", info
.dli_sname
);
70 if ( info
.dli_saddr
!= stripPointer(&dylib_foo
) ) {
71 FAIL("dladdr()->dli_saddr is not &dylib_foo");
73 if ( info
.dli_fbase
!= &__dso_handle
) {
74 FAIL("dladdr()->dli_fbase is not image that contains &dylib_foo");
78 // checks hidden symbol
79 static void verifyhide()
82 if ( dladdr(&dylib_hide
, &info
) == 0 ) {
83 FAIL("dladdr(&dylib_hide, xx) failed");
85 if ( strcmp(info
.dli_sname
, "dylib_hide") != 0 ) {
86 FAIL("dladdr()->dli_sname is \"%s\" instead of \"dylib_hide\"", info
.dli_sname
);
88 if ( info
.dli_saddr
!= stripPointer(&dylib_hide
) ) {
89 FAIL("dladdr()->dli_saddr is not &dylib_hide");
91 if ( info
.dli_fbase
!= &__dso_handle
) {
92 FAIL("dladdr()->dli_fbase is not image that contains &dylib_hide");
97 static void verifyDSOHandle()
100 if ( dladdr(&__dso_handle
, &info
) == 0 ) {
101 FAIL("dladdr(&__dso_handle, xx) failed");
103 if ( strcmp(info
.dli_sname
, "__dso_handle") != 0 ) {
104 FAIL("dladdr()->dli_sname is \"%s\" instead of \"__dso_handle\"", info
.dli_sname
);
106 if ( info
.dli_saddr
!= stripPointer(&__dso_handle
) ) {
107 FAIL("dladdr()->dli_saddr is not &__dso_handle");
109 if ( info
.dli_fbase
!= &__dso_handle
) {
110 FAIL("dladdr()->dli_fbase is not image that contains &__dso_handle");