]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlsym-re-export.dtest/main.c
b1752d65a95f2913ed29b63f77c1e8461059a2aa
[apple/dyld.git] / testing / test-cases / dlsym-re-export.dtest / main.c
1
2 // BUILD: mkdir -p $BUILD_DIR/sub1 $BUILD_DIR/sub2
3 // BUILD: $CC sub1.c -dynamiclib -install_name @rpath/libsub1.dylib -o $BUILD_DIR/sub1/libsub1.dylib
4 // BUILD: $CC sub2.c -dynamiclib -install_name @rpath/libsub2.dylib -o $BUILD_DIR/sub2/libsub2.dylib
5 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib -rpath @loader_path/sub1 -Wl,-reexport_library,$BUILD_DIR/sub1/libsub1.dylib -Wl,-reexport_library,$BUILD_DIR/sub2/libsub2.dylib
6 // BUILD: $CC main.c -o $BUILD_DIR/dlsym-reexport.exe -DRUN_DIR="$RUN_DIR" -rpath @loader_path/sub2
7
8 // RUN: ./dlsym-reexport.exe
9
10 // rpath for sub1 is found in libfoo.dylib. rpath for sub2 is found in dlsym-reexport.exe
11
12 #include <stdio.h>
13 #include <dlfcn.h>
14
15 int main()
16 {
17 printf("[BEGIN] dlsym-re-export\n");
18 // RTLD_FIRST means dlsym() should only search libfoo.dylib (and any re-exports)
19 void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_FIRST);
20 if ( handle == NULL ) {
21 printf("dlerror(): %s\n", dlerror());
22 printf("[FAIL] dlsym-re-export\n");
23 return 0;
24 }
25
26 void* sym1 = dlsym(handle, "sub1");
27 if ( sym1 == NULL ) {
28 printf("dlerror(): %s\n", dlerror());
29 printf("[FAIL] dlsym-re-export\n");
30 return 0;
31 }
32
33 void* sym2 = dlsym(handle, "sub2");
34 if ( sym2 == NULL ) {
35 printf("dlerror(): %s\n", dlerror());
36 printf("[FAIL] dlsym-re-export\n");
37 return 0;
38 }
39
40 printf("[PASS] dlsym-re-export\n");
41 return 0;
42 }
43