]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-RTLD_LOCAL-hides.dtest/main.c
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC bar.c -dynamiclib -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib
4 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-RTLD_LOCAL-hides.exe -DRUN_DIR="$RUN_DIR"
6 // RUN: ./dlopen-RTLD_LOCAL-hides.exe
16 printf("[BEGIN] dlopen-RTLD_LOCAL-hides\n");
19 /// This tests that RTLD_LOCAL prevents RTLD_DEFAULT from finding symbols, but can be found via handle
21 void* handle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LOCAL
);
22 if ( handle
== NULL
) {
23 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlopen(libfoo.dylib, RTLD_LOCAL) failed but it should have worked: %s\n", dlerror());
26 void* sym
= dlsym(handle
, "foo");
28 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlsym(handle, \"foo\") failed but it should have worked: %s\n", dlerror());
31 void* sym2
= dlsym(RTLD_DEFAULT
, "foo");
33 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlsym(RTLD_DEFAULT, \"foo\") succeeded but it should have failed\n");
39 /// This tests that RTLD_GLOBAL after RTLD_LOCAL allows RTLD_DEFAULT to find symbols
41 void* handle2
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_GLOBAL
);
42 if ( handle2
== NULL
) {
43 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlopen(libfoo.dylib, RTLD_GLOBAL) failed but it should have worked: %s\n", dlerror());
46 void* sym3
= dlsym(RTLD_DEFAULT
, "foo");
48 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlsym(RTLD_DEFAULT, \"foo\") failed after upgrading to RTLD_GLOBAL\n");
54 /// This tests that RTLD_LOCAL after RTLD_GLOBAL does not block RTLD_DEFAULT from finding symbols
56 void* handle3
= dlopen(RUN_DIR
"/libbar.dylib", RTLD_GLOBAL
);
57 if ( handle3
== NULL
) {
58 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlopen(libbar.dylib, RTLD_GLOBAL) failed but it should have worked: %s\n", dlerror());
61 void* handle4
= dlopen(RUN_DIR
"/libbar.dylib", RTLD_LOCAL
);
62 if ( handle4
== NULL
) {
63 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlopen(libbar.dylib, RTLD_LOCAL) failed but it should have worked: %s\n", dlerror());
66 void* sym4
= dlsym(RTLD_DEFAULT
, "bar");
68 printf("[FAIL] dlopen-RTLD_LOCAL-hides: dlsym(RTLD_DEFAULT, \"bar\") failed but it should have worked: %s\n", dlerror());
72 printf("[PASS] dlopen-RTLD_LOCAL-hides\n");