]>
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
13 #include "test_support.h"
15 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
17 /// This tests that RTLD_LOCAL prevents RTLD_DEFAULT from finding symbols, but can be found via handle
19 void* handle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LOCAL
);
20 if ( handle
== NULL
) {
21 FAIL("dlopen(\"libfoo.dylib\", RTLD_LOCAL) failed but it should have worked: %s", dlerror());
23 void* sym
= dlsym(handle
, "foo");
25 FAIL("dlsym(handle, \"foo\") failed but it should have worked: %s", dlerror());
27 void* sym2
= dlsym(RTLD_DEFAULT
, "foo");
29 FAIL("dlsym(RTLD_DEFAULT, \"foo\") succeeded but it should have failed");
33 /// This tests that RTLD_GLOBAL after RTLD_LOCAL allows RTLD_DEFAULT to find symbols
35 void* handle2
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_GLOBAL
);
36 if ( handle2
== NULL
) {
37 FAIL("dlopen(\"libfoo.dylib\", RTLD_GLOBAL) failed but it should have worked: %s", dlerror());
39 void* sym3
= dlsym(RTLD_DEFAULT
, "foo");
41 FAIL("dlsym(RTLD_DEFAULT, \"foo\") failed after upgrading to RTLD_GLOBAL");
45 /// This tests that RTLD_LOCAL after RTLD_GLOBAL does not block RTLD_DEFAULT from finding symbols
47 void* handle3
= dlopen(RUN_DIR
"/libbar.dylib", RTLD_GLOBAL
);
48 if ( handle3
== NULL
) {
49 FAIL("dlopen(\"libbar.dylib\", RTLD_GLOBAL) failed but it should have worked: %s", dlerror());
51 void* handle4
= dlopen(RUN_DIR
"/libbar.dylib", RTLD_LOCAL
);
52 if ( handle4
== NULL
) {
53 FAIL("dlopen(\"libbar.dylib\", RTLD_LOCAL) failed but it should have worked: %s", dlerror());
55 void* sym4
= dlsym(RTLD_DEFAULT
, "bar");
57 FAIL("dlsym(RTLD_DEFAULT, \"bar\") failed but it should have worked: %s", dlerror());