]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dladdr-basic.dtest/main.c
5f2e67ce2d62292cedc37edbeb9b9ff0469e1ed3
2 // BUILD: $CC main.c -o $BUILD_DIR/dladdr-basic.exe
4 // RUN: ./dladdr-basic.exe
10 #include <mach-o/dyld_priv.h>
12 extern char** environ
;
14 #if __has_feature(ptrauth_calls)
30 __attribute__((visibility("hidden"))) int hide()
35 static const void *stripPointer(const void *ptr
) {
36 #if __has_feature(ptrauth_calls)
37 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
43 // checks global symbol
44 static void verifybar()
47 if ( dladdr(&bar
, &info
) == 0 ) {
48 printf("[FAIL] dladdr(&bar, xx) failed\n");
51 if ( strcmp(info
.dli_sname
, "bar") != 0 ) {
52 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"bar\"\n", info
.dli_sname
);
55 if ( info
.dli_saddr
!= stripPointer(&bar
) ) {
56 printf("[FAIL] dladdr()->dli_saddr is not &bar\n");
59 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&bar
) ) {
60 printf("[FAIL] dladdr()->dli_fbase is not image that contains &bar\n");
65 // checks local symbol
66 static void verifyfoo()
69 if ( dladdr(&foo
, &info
) == 0 ) {
70 printf("[FAIL] dladdr(&foo, xx) failed\n");
73 if ( strcmp(info
.dli_sname
, "foo") != 0 ) {
74 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"foo\"\n", info
.dli_sname
);
77 if ( info
.dli_saddr
!= stripPointer(&foo
) ) {
78 printf("[FAIL] dladdr()->dli_saddr is not &foo\n");
81 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&foo
) ) {
82 printf("[FAIL] dladdr()->dli_fbase is not image that contains &foo\n");
87 // checks hidden symbol
88 static void verifyhide()
91 if ( dladdr(&hide
, &info
) == 0 ) {
92 printf("[FAIL] dladdr(&hide, xx) failed\n");
95 if ( strcmp(info
.dli_sname
, "hide") != 0 ) {
96 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"hide\"\n", info
.dli_sname
);
99 if ( info
.dli_saddr
!= stripPointer(&hide
) ) {
100 printf("[FAIL] dladdr()->dli_saddr is not &hide\n");
103 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&hide
) ) {
104 printf("[FAIL] dladdr()->dli_fbase is not image that contains &hide\n");
109 // checks dylib symbol
110 static void verifymalloc()
113 if ( dladdr(&malloc
, &info
) == 0 ) {
114 printf("[FAIL] dladdr(&malloc, xx) failed\n");
117 if ( strcmp(info
.dli_sname
, "malloc") != 0 ) {
118 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"malloc\"\n", info
.dli_sname
);
121 if ( info
.dli_saddr
!= stripPointer(&malloc
) ) {
122 printf("[FAIL] dladdr()->dli_saddr is not &malloc\n");
125 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&malloc
) ) {
126 printf("[FAIL] dladdr()->dli_fbase is not image that contains &malloc\n");
131 // checks dylib data symbol
132 static void verifyenviron()
135 if ( dladdr(&environ
, &info
) == 0 ) {
136 printf("[FAIL] dladdr(&environ, xx) failed\n");
139 if ( strcmp(info
.dli_sname
, "environ") != 0 ) {
140 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"environ\"\n", info
.dli_sname
);
143 if ( info
.dli_saddr
!= &environ
) {
144 printf("[FAIL] dladdr()->dli_saddr is not &environ\n");
147 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&environ
) ) {
148 printf("[FAIL] dladdr()->dli_fbase is not image that contains &environ\n");
154 // checks data symbol in main executable
155 static void verifymydata()
158 if ( dladdr(&mydata
, &info
) == 0 ) {
159 printf("[FAIL] dladdr(&mydata, xx) failed\n");
162 if ( strcmp(info
.dli_sname
, "mydata") != 0 ) {
163 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"mydata\"\n", info
.dli_sname
);
166 if ( info
.dli_saddr
!= &mydata
) {
167 printf("[FAIL] dladdr()->dli_saddr is not &mydata\n");
170 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&mydata
) ) {
171 printf("[FAIL] dladdr()->dli_fbase is not image that contains &mydata\n");
177 // checks passing NULL for info parameter gracefully fails
178 static void verifyNULL()
181 if ( dladdr(&malloc
, NULL
) != 0 ) {
182 printf("[FAIL] dladdr(&malloc, NULL) did not fail\n");
185 if ( dladdr(NULL
, NULL
) != 0 ) {
186 printf("[FAIL] dladdr(NULL, NULL) did not fail\n");
193 printf("[BEGIN] dladdr-basic\n");
202 printf("[PASS] dladdr-basic\n");