]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/weak-coalesce-dlopen.dtest/main.cpp
2 // BUILD: $CC foo.cpp -lc++ -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC main.cpp -lc++ -o $BUILD_DIR/weak-coalesce-dlopen.exe -DRUN_DIR="$RUN_DIR"
5 // RUN: ./weak-coalesce-dlopen.exe
13 #include "test_support.h"
17 void* lastAllocatedValue
= NULL
;
19 void* operator new(size_t size
) {
20 lastAllocatedValue
= malloc(size
);
21 return lastAllocatedValue
;
26 // The value we allocate should come from our new function
27 int* value1
= new int(1);
28 if ( value1
!= lastAllocatedValue
) {
29 FAIL("value1 (%p) != lastAllocatedValue (%p)", value1
, lastAllocatedValue
);
32 // dlopen foo which defines "foo"
33 // In dyld2, for chained fixups, this will run weakBindOld which patches the cache for
34 // weak defs. That patching will fail if the cache uses __DATA_CONST and was not marked as
35 // RW prior to patching
36 void* handle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_FIRST
);
37 if ( handle
== NULL
) {
38 FAIL("dlopen(\"%s\") failed with: %s", RUN_DIR
"/libfoo.dylib", dlerror());
41 const void* symFoo
= dlsym(handle
, "foo");
42 if ( symFoo
== NULL
) {
43 FAIL("dlsym(handle, foo) failed");
46 // The value foo allocates should come from our new function
47 void* value2
= ((__typeof(&foo
))symFoo
)();
48 if ( value2
!= lastAllocatedValue
) {
49 FAIL("value2 (%p) != lastAllocatedValue (%p)", value2
, lastAllocatedValue
);
52 PASS("weak-coalesce-dlopen");