]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-in-init2.dtest/main.c
454802dc071e09ee5f9ad3140455035b28904fa3
[apple/dyld.git] / testing / test-cases / dlopen-in-init2.dtest / main.c
1
2
3 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/libbar.dylib -install_name $RUN_DIR/libbar.dylib
4 // BUILD: $CC baz.c -dynamiclib -o $BUILD_DIR/libbaz.dylib -install_name $RUN_DIR/libbaz.dylib
5 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib $BUILD_DIR/libbaz.dylib -DRUN_DIR="$RUN_DIR"
6 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-in-init2.exe $BUILD_DIR/libfoo.dylib $BUILD_DIR/libbar.dylib
7
8 // RUN: ./dlopen-in-init2.exe
9
10 // This test uses dlopen to jump ahead in the initializer graph
11 // The static linkages here should result in initializers being run in the order libbaz, libfoo, libbar
12 // However, a dlopen of libbar inside libfoo's static initializer means we need to skip ahead and initialize libbar to satisfy that dlopen
13 // This means that the closure needs to have "initializer-order" on libfoo and not just the top level executable image.
14 // It also means that dlopen needs to check we have actually initialized libbar instead of just bumping its ref-count.
15
16 #include <stdio.h>
17 #include <dlfcn.h>
18 #include <stdlib.h>
19
20
21 extern int foo();
22 extern int bar();
23
24 int main() {
25 printf("[BEGIN] dlopen-in-init2\n");
26 if ( foo() != 0 )
27 return 0;
28 if ( bar() != 0 )
29 return 0;
30 printf("[PASS] dlopen-in-init2\n");
31 return 0;
32 }
33