]>
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-dylib.exe
5 // RUN: ./dladdr-dylib.exe
11 #include <mach-o/dyld_priv.h>
12 #if __has_feature(ptrauth_calls)
16 #include "test_support.h"
18 extern void* __dso_handle
;
20 extern void verifyDylib();
23 static const void* stripPointer(const void* ptr
)
25 #if __has_feature(ptrauth_calls)
26 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
43 __attribute__((visibility("hidden"))) int hide()
48 // checks global symbol
49 static void verifybar()
52 if ( dladdr(&bar
, &info
) == 0 ) {
53 FAIL("dladdr(&bar, xx) failed");
55 if ( strcmp(info
.dli_sname
, "bar") != 0 ) {
56 FAIL("dladdr()->dli_sname is \"%s\" instead of \"bar\"", info
.dli_sname
);
58 if ( info
.dli_saddr
!= stripPointer(&bar
) ) {
59 FAIL("dladdr()->dli_saddr is not &bar");
61 if ( info
.dli_fbase
!= &__dso_handle
) {
62 FAIL("dladdr()->dli_fbase is not image that contains &bar");
66 // checks local symbol
67 static void verifyfoo()
70 if ( dladdr(&foo
, &info
) == 0 ) {
71 FAIL("dladdr(&foo, xx) failed");
73 if ( strcmp(info
.dli_sname
, "foo") != 0 ) {
74 FAIL("dladdr()->dli_sname is \"%s\" instead of \"foo\"", info
.dli_sname
);
76 if ( info
.dli_saddr
!= stripPointer(&foo
) ) {
77 FAIL("dladdr()->dli_saddr is not &foo");
79 if ( info
.dli_fbase
!= &__dso_handle
) {
80 FAIL("dladdr()->dli_fbase is not image that contains &foo");
84 // checks hidden symbol
85 static void verifyhide()
88 if ( dladdr(&hide
, &info
) == 0 ) {
89 FAIL("dladdr(&hide, xx) failed");
91 if ( strcmp(info
.dli_sname
, "hide") != 0 ) {
92 FAIL("dladdr()->dli_sname is \"%s\" instead of \"hide\"", info
.dli_sname
);
94 if ( info
.dli_saddr
!= stripPointer(&hide
) ) {
95 FAIL("dladdr()->dli_saddr is not &hide");
97 if ( info
.dli_fbase
!= &__dso_handle
) {
98 FAIL("dladdr()->dli_fbase is not image that contains &hide");
102 // checks dylib symbol
103 static void verifymalloc()
106 if ( dladdr(&malloc
, &info
) == 0 ) {
107 FAIL("dladdr(&malloc, xx) failed");
109 if ( strcmp(info
.dli_sname
, "malloc") != 0 ) {
110 FAIL("dladdr()->dli_sname is \"%s\" instead of \"malloc\"", info
.dli_sname
);
112 if ( info
.dli_saddr
!= stripPointer(&malloc
) ) {
113 FAIL("dladdr()->dli_saddr is not &malloc");
115 if ( info
.dli_fbase
!= dyld_image_header_containing_address(&malloc
) ) {
116 FAIL("dladdr()->dli_fbase is not image that contains &malloc");
121 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {