]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-in-init2.dtest/main.c
dyld-750.6.tar.gz
[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 #include "test_support.h"
21
22 extern void foo();
23 extern void bar();
24
25 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
26 foo();
27 bar();
28 PASS("Success");
29 }
30