]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlsym-re-export.dtest/main.c
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / dlsym-re-export.dtest / main.c
1
2 // BUILD: $CC sub1.c -dynamiclib -install_name @rpath/libsub1.dylib -o $BUILD_DIR/sub1/libsub1.dylib
3 // BUILD: $CC sub2.c -dynamiclib -install_name @rpath/libsub2.dylib -o $BUILD_DIR/sub2/libsub2.dylib
4 // 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
5 // BUILD: $CC main.c -o $BUILD_DIR/dlsym-reexport.exe -DRUN_DIR="$RUN_DIR" -rpath @loader_path/sub2
6
7 // RUN: ./dlsym-reexport.exe
8
9 // rpath for sub1 is found in libfoo.dylib. rpath for sub2 is found in dlsym-reexport.exe
10
11 #include <stdio.h>
12 #include <dlfcn.h>
13
14 #include "test_support.h"
15
16 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
17 // RTLD_FIRST means dlsym() should only search libfoo.dylib (and any re-exports)
18 void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_FIRST);
19 if ( handle == NULL ) {
20 FAIL("dlerror(): %s", dlerror());
21 }
22
23 void* sym1 = dlsym(handle, "sub1");
24 if ( sym1 == NULL ) {
25 FAIL("dlerror(): %s", dlerror());
26 }
27
28 void* sym2 = dlsym(handle, "sub2");
29 if ( sym2 == NULL ) {
30 FAIL("dlerror(): %s", dlerror());
31 }
32
33 PASS("Success");
34 }
35