]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlclose-static-terminator.dtest/main.c
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libterm.dylib -o $BUILD_DIR/libterm.dylib
3 // BUILD: $CC main.c -o $BUILD_DIR/dlclose-term.exe -DRUN_DIR="$RUN_DIR"
5 // RUN: ./dlclose-term.exe
10 #include <mach-o/dyld_priv.h>
13 // verify dlclose() runs static terminator
15 typedef void (*NotifyProc
)(void);
17 static bool termDidRun
= false;
19 static void termNotifyFunc()
26 printf("[BEGIN] dlclose-static-terminator\n");
29 void* handle
= dlopen(RUN_DIR
"/libterm.dylib", RTLD_LAZY
);
30 if ( handle
== NULL
) {
31 printf("[FAIL] dlclose-static-terminator: libterm.dylib could not be loaded, %s\n", dlerror());
35 // stuff pointer to my notifier
36 NotifyProc
* pointerAddress
= (NotifyProc
*)dlsym(handle
, "gNotifer");
37 if ( pointerAddress
== NULL
) {
38 printf("[FAIL] dlclose-static-terminator: gNotifer not found in libterm.dylib\n");
41 *pointerAddress
= &termNotifyFunc
;
47 printf("[PASS] dlclose-static-terminator\n");
49 printf("[FAIL] dlclose-static-terminator: terminator not run\n");