]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/static-terminators.dtest/main.c
dyld-750.5.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 #include "test_support.h"
14
15 // verify all static terminators run in proper order
16
17
18 extern void mainTerminated();
19
20 static __attribute__((destructor))
21 void myTerm()
22 {
23 LOG("main's static terminator");
24 mainTerminated();
25 }
26
27
28 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
29 // load dylib
30 void* handle = dlopen(RUN_DIR "/libdynamic.dylib", RTLD_LAZY);
31 if ( handle == NULL ) {
32 FAIL("libdynamic.dylib could not be loaded, %s", dlerror());
33 }
34
35 // PASS is printed in libbase.dylib terminator
36 }
37