]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dladdr-dylib.dtest/main.c
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/dladdr-basic.exe
5 // RUN: ./dladdr-basic.exe
11 #include <mach-o/dyld_priv.h>
13 extern void* __dso_handle
;
15 extern void verifyDylib();
27 __attribute__((visibility("hidden"))) int hide()
32 // checks global symbol
33 static void verifybar()
36 if ( dladdr(&bar
, &info
) == 0 ) {
37 printf("[FAIL] dladdr(&bar, xx) failed\n");
40 if ( strcmp(info
.dli_sname
, "bar") != 0 ) {
41 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"bar\"\n", info
.dli_sname
);
44 if ( info
.dli_saddr
!= &bar
) {
45 printf("[FAIL] dladdr()->dli_saddr is not &bar\n");
48 if ( info
.dli_fbase
!= &__dso_handle
) {
49 printf("[FAIL] dladdr()->dli_fbase is not image that contains &bar\n");
54 // checks local symbol
55 static void verifyfoo()
58 if ( dladdr(&foo
, &info
) == 0 ) {
59 printf("[FAIL] dladdr(&foo, xx) failed\n");
62 if ( strcmp(info
.dli_sname
, "foo") != 0 ) {
63 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"foo\"\n", info
.dli_sname
);
66 if ( info
.dli_saddr
!= &foo
) {
67 printf("[FAIL] dladdr()->dli_saddr is not &foo\n");
70 if ( info
.dli_fbase
!= &__dso_handle
) {
71 printf("[FAIL] dladdr()->dli_fbase is not image that contains &foo\n");
76 // checks hidden symbol
77 static void verifyhide()
80 if ( dladdr(&hide
, &info
) == 0 ) {
81 printf("[FAIL] dladdr(&hide, xx) failed\n");
84 if ( strcmp(info
.dli_sname
, "hide") != 0 ) {
85 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"hide\"\n", info
.dli_sname
);
88 if ( info
.dli_saddr
!= &hide
) {
89 printf("[FAIL] dladdr()->dli_saddr is not &hide\n");
92 if ( info
.dli_fbase
!= &__dso_handle
) {
93 printf("[FAIL] dladdr()->dli_fbase is not image that contains &hide\n");
98 // checks dylib symbol
99 static void verifymalloc()
102 if ( dladdr(&malloc
, &info
) == 0 ) {
103 printf("[FAIL] dladdr(&malloc, xx) failed\n");
106 if ( strcmp(info
.dli_sname
, "malloc") != 0 ) {
107 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"malloc\"\n", info
.dli_sname
);
110 if ( info
.dli_saddr
!= &malloc
) {
111 printf("[FAIL] dladdr()->dli_saddr is not &malloc\n");
114 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&malloc
) ) {
115 printf("[FAIL] dladdr()->dli_fbase is not image that contains &malloc\n");
123 printf("[BEGIN] dladdr-basic\n");
131 printf("[PASS] dladdr-basic\n");