]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-in-init3.dtest/main.c
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-in-init3.dtest / main.c
1
2
3 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/libbar.dylib -install_name $RUN_DIR/libbar.dylib -DRUN_DIR="$RUN_DIR"
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/libbar.dylib $BUILD_DIR/libbaz.dylib
6 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-in-init3.exe -DRUN_DIR="$RUN_DIR"
7
8 // RUN: ./dlopen-in-init3.exe
9
10 // This test uses dlopen to jump ahead in the initializer graph
11 // main doesn't directly link any of the libraries here, but dlopen's libfoo which links libbar and libbaz.
12 // We should run initializers in the order libbar, libbaz, libfoo.
13 // However, libbar has a static init with a dlopen of libbaz and so libbaz needs to be initialized by libbar instead of by libfoo
14
15 #include <stdio.h>
16 #include <dlfcn.h>
17 #include <stdlib.h>
18
19 #include "test_support.h"
20
21 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
22 void* fooHandle = dlopen(RUN_DIR "/libfoo.dylib", 0);
23 if ( fooHandle == NULL ) {
24 FAIL("dlopen-in-init3, dlopen libfoo.dylib: %s", dlerror());
25 }
26 void* fooSymbol = dlsym(RTLD_DEFAULT, "foo");
27 if ( fooSymbol == NULL ) {
28 FAIL("dlsym libfoo.dylib");
29 }
30 if ( ((int(*)())fooSymbol)() != 0 ) {
31 FAIL("fooSymbol() should return 0");
32 }
33 PASS("Success");
34 }
35