]>
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
4 // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" -o $BUILD_DIR/dlopen-flat.exe
6 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR ./dlopen-flat.exe
11 int gInitialisersCalled
= 0;
14 printf("[BEGIN] dlopen-flat\n");
20 const char* path
= RUN_DIR
"/libfoo.dylib";
21 fooHandle
= dlopen(path
, RTLD_LAZY
);
23 printf("dlopen failed with error: %s\n", dlerror());
26 if (gInitialisersCalled
!= 1) {
27 printf("gInitialisersCalled != 1\n");
28 printf("[FAIL] dlopen-flat\n");
32 // Now unload foo which should do something.
33 result
= dlclose(fooHandle
);
35 printf("dlclose() returned %c\n", result
);
36 printf("[FAIL] dlopen-flat\n");
40 // Open foo again which should do something.
42 const char* path
= RUN_DIR
"/libfoo.dylib";
43 fooHandle
= dlopen(path
, RTLD_LAZY
);
45 printf("dlopen failed with error: %s\n", dlerror());
48 if (gInitialisersCalled
!= 2) {
49 printf("gInitialisersCalled != 2\n");
50 printf("[FAIL] dlopen-flat\n");
55 // Bar is going to resolve foo()
58 const char* path
= RUN_DIR
"/libbar.dylib";
59 barHandle
= dlopen(path
, RTLD_LAZY
);
61 printf("dlopen failed with error: %s\n", dlerror());
64 if (gInitialisersCalled
!= 3) {
65 printf("gInitialisersCalled != 3\n");
66 printf("[FAIL] dlopen-flat\n");
70 // Now unload foo which shouldn't do anything.
71 result
= dlclose(fooHandle
);
73 printf("dlclose() returned %c\n", result
);
74 printf("[FAIL] dlopen-flat\n");
78 // Open foo again which shouldn't do anything.
80 const char* path
= RUN_DIR
"/libfoo.dylib";
81 fooHandle
= dlopen(path
, RTLD_LAZY
);
83 printf("dlopen failed with error: %s\n", dlerror());
86 if (gInitialisersCalled
!= 3) {
87 printf("gInitialisersCalled != 3\n");
88 printf("[FAIL] dlopen-flat\n");
93 printf("[PASS] dlopen-flat\n");