]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/static-terminators.dtest/main.c
dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / static-terminators.dtest / main.c
1
2 // BUILD: $CC base.c -dynamiclib -install_name $RUN_DIR/libbase.dylib -o $BUILD_DIR/libbase.dylib
3 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libdynamic.dylib -o $BUILD_DIR/libdynamic.dylib $BUILD_DIR/libbase.dylib
4 // BUILD: $CC main.c -o $BUILD_DIR/static-terminators.exe -DRUN_DIR="$RUN_DIR" $BUILD_DIR/libbase.dylib
5
6 // RUN: ./static-terminators.exe
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <dlfcn.h>
11 #include <mach-o/dyld_priv.h>
12
13
14 // verify all static terminators run in proper order
15
16
17 extern void mainTerminated();
18
19 static __attribute__((destructor))
20 void myTerm()
21 {
22 //fprintf(stderr, "main's static terminator\n");
23 mainTerminated();
24 }
25
26
27 int main()
28 {
29 printf("[BEGIN] static-terminators\n");
30
31 // load dylib
32 void* handle = dlopen(RUN_DIR "/libdynamic.dylib", RTLD_LAZY);
33 if ( handle == NULL ) {
34 printf("[FAIL] dlclose-static-terminator: libdynamic.dylib could not be loaded, %s\n", dlerror());
35 return 0;
36 }
37
38 // PASS is printed in libbase.dylib terminator
39
40 return 0;
41 }
42