]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dladdr-dylib.dtest/main.c
a4401abf3d38e306da8c2891f925a999a9d1c3ca
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-dylib.exe
5 // RUN: ./dladdr-dylib.exe
11 #include <mach-o/dyld_priv.h>
12 #if __has_feature(ptrauth_calls)
16 extern void* __dso_handle
;
18 extern void verifyDylib();
21 static const void* stripPointer(const void* ptr
)
23 #if __has_feature(ptrauth_calls)
24 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
41 __attribute__((visibility("hidden"))) int hide()
46 // checks global symbol
47 static void verifybar()
50 if ( dladdr(&bar
, &info
) == 0 ) {
51 printf("[FAIL] dladdr(&bar, xx) failed\n");
54 if ( strcmp(info
.dli_sname
, "bar") != 0 ) {
55 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"bar\"\n", info
.dli_sname
);
58 if ( info
.dli_saddr
!= stripPointer(&bar
) ) {
59 printf("[FAIL] dladdr()->dli_saddr is not &bar\n");
62 if ( info
.dli_fbase
!= &__dso_handle
) {
63 printf("[FAIL] dladdr()->dli_fbase is not image that contains &bar\n");
68 // checks local symbol
69 static void verifyfoo()
72 if ( dladdr(&foo
, &info
) == 0 ) {
73 printf("[FAIL] dladdr(&foo, xx) failed\n");
76 if ( strcmp(info
.dli_sname
, "foo") != 0 ) {
77 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"foo\"\n", info
.dli_sname
);
80 if ( info
.dli_saddr
!= stripPointer(&foo
) ) {
81 printf("[FAIL] dladdr()->dli_saddr is not &foo\n");
84 if ( info
.dli_fbase
!= &__dso_handle
) {
85 printf("[FAIL] dladdr()->dli_fbase is not image that contains &foo\n");
90 // checks hidden symbol
91 static void verifyhide()
94 if ( dladdr(&hide
, &info
) == 0 ) {
95 printf("[FAIL] dladdr(&hide, xx) failed\n");
98 if ( strcmp(info
.dli_sname
, "hide") != 0 ) {
99 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"hide\"\n", info
.dli_sname
);
102 if ( info
.dli_saddr
!= stripPointer(&hide
) ) {
103 printf("[FAIL] dladdr()->dli_saddr is not &hide\n");
106 if ( info
.dli_fbase
!= &__dso_handle
) {
107 printf("[FAIL] dladdr()->dli_fbase is not image that contains &hide\n");
112 // checks dylib symbol
113 static void verifymalloc()
116 if ( dladdr(&malloc
, &info
) == 0 ) {
117 printf("[FAIL] dladdr(&malloc, xx) failed\n");
120 if ( strcmp(info
.dli_sname
, "malloc") != 0 ) {
121 printf("[FAIL] dladdr()->dli_sname is \"%s\" instead of \"malloc\"\n", info
.dli_sname
);
124 if ( info
.dli_saddr
!= stripPointer(&malloc
) ) {
125 printf("[FAIL] dladdr()->dli_saddr is not &malloc\n");
128 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&malloc
) ) {
129 printf("[FAIL] dladdr()->dli_fbase is not image that contains &malloc\n");
137 printf("[BEGIN] dladdr-dylib\n");
145 printf("[PASS] dladdr-dylib\n");