]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dladdr-basic.dtest/main.c
2 // BUILD: $CC main.c -o $BUILD_DIR/dladdr-basic.exe
4 // RUN: ./dladdr-basic.exe
10 #include <mach-o/dyld_priv.h>
12 #include "test_support.h"
14 extern char** environ
;
16 #if __has_feature(ptrauth_calls)
32 __attribute__((visibility("hidden"))) int hide()
37 static const void *stripPointer(const void *ptr
) {
38 #if __has_feature(ptrauth_calls)
39 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
45 // checks global symbol
46 static void verifybar()
49 if ( dladdr(&bar
, &info
) == 0 ) {
50 FAIL("dladdr(&bar, xx) failed");
52 if ( strcmp(info
.dli_sname
, "bar") != 0 ) {
53 FAIL("dladdr()->dli_sname is \"%s\" instead of \"bar\"", info
.dli_sname
);
55 if ( info
.dli_saddr
!= stripPointer(&bar
) ) {
56 FAIL("dladdr()->dli_saddr is not &bar");
58 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&bar
) ) {
59 FAIL("dladdr()->dli_fbase is not image that contains &bar");
63 // checks local symbol
64 static void verifyfoo()
67 if ( dladdr(&foo
, &info
) == 0 ) {
68 FAIL("dladdr(&foo, xx) failed");
70 if ( strcmp(info
.dli_sname
, "foo") != 0 ) {
71 FAIL("dladdr()->dli_sname is \"%s\" instead of \"foo\"", info
.dli_sname
);
74 if ( info
.dli_saddr
!= stripPointer(&foo
) ) {
75 FAIL("dladdr()->dli_saddr is not &foo");
77 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&foo
) ) {
78 FAIL("dladdr()->dli_fbase is not image that contains &foo");
82 // checks hidden symbol
83 static void verifyhide()
86 if ( dladdr(&hide
, &info
) == 0 ) {
87 FAIL("dladdr(&hide, xx) failed");
89 if ( strcmp(info
.dli_sname
, "hide") != 0 ) {
90 FAIL("dladdr()->dli_sname is \"%s\" instead of \"hide\"", info
.dli_sname
);
92 if ( info
.dli_saddr
!= stripPointer(&hide
) ) {
93 FAIL("dladdr()->dli_saddr is not &hide");
95 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&hide
) ) {
96 FAIL("dladdr()->dli_fbase is not image that contains &hide");
100 // checks dylib symbol
101 static void verifymalloc()
104 if ( dladdr(&malloc
, &info
) == 0 ) {
105 FAIL("dladdr(&malloc, xx) failed");
107 if ( strcmp(info
.dli_sname
, "malloc") != 0 ) {
108 FAIL("dladdr()->dli_sname is \"%s\" instead of \"malloc\"", info
.dli_sname
);
111 if ( info
.dli_saddr
!= stripPointer(&malloc
) ) {
112 FAIL("dladdr()->dli_saddr is not &malloc");
114 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&malloc
) ) {
115 FAIL("dladdr()->dli_fbase is not image that contains &malloc");
119 // checks dylib data symbol
120 static void verifyenviron()
123 if ( dladdr(&environ
, &info
) == 0 ) {
124 FAIL("dladdr(&environ, xx) failed");
126 if ( strcmp(info
.dli_sname
, "environ") != 0 ) {
127 FAIL("dladdr()->dli_sname is \"%s\" instead of \"environ\"", info
.dli_sname
);
129 if ( info
.dli_saddr
!= &environ
) {
130 FAIL("dladdr()->dli_saddr is not &environ");
132 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&environ
) ) {
133 FAIL("dladdr()->dli_fbase is not image that contains &environ");
138 // checks data symbol in main executable
139 static void verifymydata()
142 if ( dladdr(&mydata
, &info
) == 0 ) {
143 FAIL("dladdr(&mydata, xx) failed");
145 if ( strcmp(info
.dli_sname
, "mydata") != 0 ) {
146 FAIL("dladdr()->dli_sname is \"%s\" instead of \"mydata\"", info
.dli_sname
);
148 if ( info
.dli_saddr
!= &mydata
) {
149 FAIL("dladdr()->dli_saddr is not &mydata");
151 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&mydata
) ) {
152 FAIL("dladdr()->dli_fbase is not image that contains &mydata");
157 // checks passing NULL for info parameter gracefully fails
158 static void verifyNULL()
161 if ( dladdr(&malloc
, NULL
) != 0 ) {
162 FAIL("dladdr(&malloc, NULL) did not fail");
164 if ( dladdr(NULL
, NULL
) != 0 ) {
165 FAIL("dladdr(NULL, NULL) did not fail");
169 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {