]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/weak-coalesce-unload.dtest/main.c
2 // BUILD: $CC foo1.c -dynamiclib -install_name $RUN_DIR/libfoo1.dylib -o $BUILD_DIR/libfoo1.dylib
3 // BUILD: $CC foo2.c -dynamiclib -install_name $RUN_DIR/libfoo2.dylib -o $BUILD_DIR/libfoo2.dylib
4 // BUILD: $CC foo3.c -dynamiclib -install_name $RUN_DIR/libfoo3.dylib -o $BUILD_DIR/libfoo3.dylib
5 // BUILD: $CC main.c -o $BUILD_DIR/weak-coalesce-unload.exe -DRUN_DIR="$RUN_DIR"
7 // RUN: ./weak-coalesce-unload.exe
15 extern void* fooPtr();
19 printf("[BEGIN] weak-coalesce-unload\n");
21 // dlopen foo1 which defines "foo"
22 void* handle1
= dlopen(RUN_DIR
"/libfoo1.dylib", RTLD_FIRST
);
23 if ( handle1
== NULL
) {
24 printf("[FAIL] dlopen(\"%s\") failed with: %s\n", RUN_DIR
"/libfoo1.dylib", dlerror());
28 const void* symFoo1
= dlsym(handle1
, "foo");
29 if ( symFoo1
== NULL
) {
30 printf("[FAIL] dlsym(handle1, foo) failed\n");
34 const void* symFooPtr1
= dlsym(handle1
, "fooPtr");
35 if ( symFooPtr1
== NULL
) {
36 printf("[FAIL] dlsym(handle1, fooPtr) failed\n");
39 void* fooptr1
= ((__typeof(&fooPtr
))symFooPtr1
)();
41 int close1
= dlclose(handle1
);
43 printf("[FAIL] dlclose(handle1) failed with: %s\n", dlerror());
47 // Now dlopen foo2 and get the value it finds for foo
48 void* handle2
= dlopen(RUN_DIR
"/libfoo2.dylib", RTLD_FIRST
);
49 if ( handle2
== NULL
) {
50 printf("[FAIL] dlopen(\"%s\") failed with: %s\n", RUN_DIR
"/libfoo2.dylib", dlerror());
54 const void* symFoo2
= dlsym(handle2
, "foo");
55 if ( symFoo2
== NULL
) {
56 printf("[FAIL] dlsym(handle2, foo) failed\n");
60 const void* symFooPtr2
= dlsym(handle2
, "fooPtr");
61 if ( symFooPtr2
== NULL
) {
62 printf("[FAIL] dlsym(handle2, fooPtr) failed\n");
65 void* fooptr2
= ((__typeof(&fooPtr
))symFooPtr2
)();
67 // Don't close foo2, but instead open foo3
68 void* handle3
= dlopen(RUN_DIR
"/libfoo3.dylib", RTLD_FIRST
);
69 if ( handle3
== NULL
) {
70 printf("[FAIL] dlopen(\"%s\") failed with: %s\n", RUN_DIR
"/libfoo3.dylib", dlerror());
74 const void* symFoo3
= dlsym(handle3
, "foo");
75 if ( symFoo3
== NULL
) {
76 printf("[FAIL] dlsym(handle3, foo) failed\n");
80 const void* symFooPtr3
= dlsym(handle3
, "fooPtr");
81 if ( symFooPtr3
== NULL
) {
82 printf("[FAIL] dlsym(handle3, fooPtr) failed\n");
85 void* fooptr3
= ((__typeof(&fooPtr
))symFooPtr3
)();
87 // No-one should point to libfoo1.dylib
88 if ( symFoo1
== symFoo2
) {
89 printf("[FAIL] foo1 == foo2\n");
92 if ( symFoo1
== symFoo3
) {
93 printf("[FAIL] foo1 == foo3\n");
97 // foo2 and foo3 should be different
98 if ( symFoo2
== symFoo3
) {
99 printf("[FAIL] foo2 != foo3\n");
103 // But their coalesced values should be the same
104 if ( fooptr1
== fooptr2
) {
105 printf("[FAIL] fooptr1 == fooptr2\n");
108 if ( fooptr2
!= fooptr3
) {
109 printf("[FAIL] fooptr2 != fooptr3\n");
113 // foo should return the value from foo2, not the value from foo3
114 // Also calling this would explode if we somehow pointed at foo1
115 if ( ((__typeof(&foo
))fooptr2
)() != 2 ) {
116 printf("[FAIL] foo2 != 2\n");
119 if ( ((__typeof(&foo
))fooptr3
)() != 2 ) {
120 printf("[FAIL] foo3 != 2\n");
124 printf("[PASS] weak-coalesce-unload\n");