]>
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>
23 __attribute__((visibility("hidden"))) int hide()
28 // checks global symbol
29 static void verifybar()
32 if ( dladdr(&bar
, &info
) == 0 ) {
33 printf("[FAIL] dladdr(&bar, xx) failed");
36 if ( strcmp(info
.dli_sname
, "bar") != 0 ) {
37 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"bar\"", info
.dli_sname
);
40 if ( info
.dli_saddr
!= &bar
) {
41 printf("[FAIL] dladdr()->dli_saddr is not &bar");
44 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&bar
) ) {
45 printf("[FAIL] dladdr()->dli_fbase is not image that contains &bar");
50 // checks local symbol
51 static void verifyfoo()
54 if ( dladdr(&foo
, &info
) == 0 ) {
55 printf("[FAIL] dladdr(&foo, xx) failed");
58 if ( strcmp(info
.dli_sname
, "foo") != 0 ) {
59 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"foo\"", info
.dli_sname
);
62 if ( info
.dli_saddr
!= &foo
) {
63 printf("[FAIL] dladdr()->dli_saddr is not &foo");
66 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&foo
) ) {
67 printf("[FAIL] dladdr()->dli_fbase is not image that contains &foo");
72 // checks hidden symbol
73 static void verifyhide()
76 if ( dladdr(&hide
, &info
) == 0 ) {
77 printf("[FAIL] dladdr(&hide, xx) failed");
80 if ( strcmp(info
.dli_sname
, "hide") != 0 ) {
81 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"hide\"", info
.dli_sname
);
84 if ( info
.dli_saddr
!= &hide
) {
85 printf("[FAIL] dladdr()->dli_saddr is not &hide");
88 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&hide
) ) {
89 printf("[FAIL] dladdr()->dli_fbase is not image that contains &hide");
94 // checks dylib symbol
95 static void verifymalloc()
98 if ( dladdr(&malloc
, &info
) == 0 ) {
99 printf("[FAIL] dladdr(&malloc, xx) failed");
102 if ( strcmp(info
.dli_sname
, "malloc") != 0 ) {
103 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"malloc\"", info
.dli_sname
);
106 if ( info
.dli_saddr
!= &malloc
) {
107 printf("[FAIL] dladdr()->dli_saddr is not &malloc");
110 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&malloc
) ) {
111 printf("[FAIL] dladdr()->dli_fbase is not image that contains &malloc");
119 printf("[BEGIN] dladdr-basic\n");
126 printf("[PASS] dladdr-basic\n");