]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen_from-basic.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen_from-basic.dtest / main.c
1
2 // BUILD: $CC bar.c -dynamiclib -install_name @rpath/libbar.dylib -o $BUILD_DIR/dir/libbar.dylib
3 // BUILD: $CC bar.c -dynamiclib -install_name @rpath/libbaz.dylib -o $BUILD_DIR/dir/libbaz.dylib
4 // BUILD: $CC test.c -dynamiclib -install_name $RUN_DIR/test/libtest.dylib -o $BUILD_DIR/test/libtest.dylib -rpath @loader_path/../dir
5 // BUILD: $CC main.c -o $BUILD_DIR/dlopen_from-basic.exe $BUILD_DIR/test/libtest.dylib
6
7 // RUN: ./dlopen_from-basic.exe
8
9 #include <stdio.h>
10 #include <dlfcn_private.h>
11 #include <stdbool.h>
12
13 #include "test_support.h"
14
15 /// test dlopen_from() works for both @rpath and @loader_path
16
17 extern void test();
18
19 int main(int argc, const char* argv[], const char* envp[], const char* apple[])
20 {
21 // verify the straight dlopen fails because libtest.dylib sets up the LC_RPATH
22 void* handle = dlopen("@rpath/libbar.dylib", RTLD_LAZY);
23 if ( handle != NULL ) {
24 FAIL("dlopen(\"@rpath/libbar.dylib\") should not have succeeded");
25 }
26 // verify dlopen_from() works becuase libtest.dylib sets up an LC_RPATH
27 handle = dlopen_from("@rpath/libbar.dylib", RTLD_LAZY, &test);
28 if ( handle == NULL ) {
29 FAIL("dlopen_from(\"@rpath/libbar.dylib\", &test) failed: %s", dlerror());
30 }
31
32 // verify the straight dlopen fails because main executables @loader_path is used
33 handle = dlopen("@loader_path/../dir/libbaz.dylib", RTLD_LAZY);
34 if ( handle != NULL ) {
35 FAIL("dlopen(\"@loader_path/../dir/libbaz.dylib\") should not have succeeded");
36 }
37 // verify dlopen_from() works with @loader_path resolving to where libtest.dylib is
38 handle = dlopen_from("@loader_path/../dir/libbaz.dylib", RTLD_LAZY, &test);
39 if ( handle == NULL ) {
40 FAIL("dlopen_from(\"@loader_path/../dir/libbaz.dylib\", &test) failed: %s", dlerror());
41 }
42
43 PASS("dlopen_from");
44 }
45