]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-flat.dtest/main.c
2 // BUILD: $CC foo.c -dynamiclib -Wl,-U,_gInitialisersCalled -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC bar.c -dynamiclib -Wl,-U,_gInitialisersCalled $BUILD_DIR/libfoo.dylib -flat_namespace -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib -Wl,-w
4 // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" -o $BUILD_DIR/dlopen-flat.exe
6 // RUN: ./dlopen-flat.exe
11 #include "test_support.h"
13 int gInitialisersCalled
= 0;
15 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
21 fooHandle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LAZY
);
23 FAIL("dlopen(\"" RUN_DIR
"/libfoo.dylib\") failed with error: %s", dlerror());
25 if (gInitialisersCalled
!= 1) {
26 FAIL("gInitialisersCalled != 1");
29 // Now unload foo which should do something.
30 result
= dlclose(fooHandle
);
32 FAIL("dlclose() returned %c", result
);
35 // Open foo again which should do something.
37 fooHandle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LAZY
);
39 FAIL("dlopen failed with error: %s", dlerror());
41 if (gInitialisersCalled
!= 2) {
42 FAIL("gInitialisersCalled != 2");
46 // Bar is going to resolve foo()
49 barHandle
= dlopen(RUN_DIR
"/libbar.dylib", RTLD_LAZY
);
51 FAIL("dlopen(\"" RUN_DIR
"/libbar.dylib\" failed with error: %s", dlerror());
53 if (gInitialisersCalled
!= 3) {
54 FAIL("gInitialisersCalled != 3");
57 // Now unload foo which shouldn't do anything.
58 result
= dlclose(fooHandle
);
60 FAIL("dlclose(\"" RUN_DIR
"/libfoo.dylib\") returned %c", result
);
63 // Open foo again which shouldn't do anything.
65 fooHandle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LAZY
);
67 FAIL("dlopen(\"" RUN_DIR
"/libfoo.dylib\" failed with error: %s", dlerror());
69 if (gInitialisersCalled
!= 3) {
70 FAIL("gInitialisersCalled != 3");