]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlsym-handle.dtest/main.c
2 // BUILD: $CC base.c -dynamiclib -install_name $RUN_DIR/libbase.dylib -o $BUILD_DIR/libbase.dylib
3 // BUILD: $CC foo.c -dynamiclib $BUILD_DIR/libbase.dylib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
4 // BUILD: $CC bar.c -dynamiclib $BUILD_DIR/libbase.dylib -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib
5 // BUILD: $CC main.c -o $BUILD_DIR/dlsym-handle.exe -DRUN_DIR="$RUN_DIR"
7 // RUN: ./dlsym-handle.exe
12 #include <mach-o/dyld_priv.h>
15 // verify RTLD_DEFAULT search order
21 printf("[BEGIN] dlsym-handle\n");
23 void* fooHandle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LAZY
);
24 if ( fooHandle
== NULL
) {
25 printf("[FAIL] dlsym-handle: libfoo.dylib could not be loaded, %s\n", dlerror());
29 void* barHandle
= dlopen(RUN_DIR
"/libbar.dylib", RTLD_LAZY
);
30 if ( barHandle
== NULL
) {
31 printf("[FAIL] dlsym-handle: libbar.dylib could not be loaded, %s\n", dlerror());
35 // verify fooHandle does not find mainSymbol
36 if ( dlsym(fooHandle
, "mainSymbol") != NULL
) {
37 printf("[FAIL] dlsym-handle: mainSymbol was found with fooHandle\n");
41 // verify fooHandle can find foo
42 if ( dlsym(fooHandle
, "foo") == NULL
) {
43 printf("[FAIL] dlsym-handle: foo not found with fooHandle\n");
47 // verify fooHandle can find base
48 if ( dlsym(fooHandle
, "base") == NULL
) {
49 printf("[FAIL] dlsym-handle: base not found with fooHandle\n");
53 // verify fooHandle cannot find bar
54 if ( dlsym(fooHandle
, "bar") != NULL
) {
55 printf("[FAIL] dlsym-handle: bar found with fooHandle\n");
59 // verify barHandle can find bar
60 if ( dlsym(barHandle
, "bar") == NULL
) {
61 printf("[FAIL] dlsym-handle: bar not found with barHandle\n");
65 // verify barHandle can find base
66 if ( dlsym(barHandle
, "base") == NULL
) {
67 printf("[FAIL] dlsym-handle: base not found with barHandle\n");
71 // verify barHandle cannot find foo
72 if ( dlsym(barHandle
, "foo") != NULL
) {
73 printf("[FAIL] dlsym-handle: foo found with barHandle\n");
77 // verify renamed and re-exported symbols work
78 if ( dlsym(RTLD_DEFAULT
, "strcmp") == NULL
) {
79 printf("[FAIL] dlsym-handle: strcmp not found\n");
83 // verify bad handle errors
84 if ( dlsym((void*)0xdeadbeef, "malloc") != NULL
) {
85 printf("[FAIL] dlsym-handle: malloc found with bad handle\n");
89 const char* message
= dlerror();
90 if ( strstr(message
, "invalid") == NULL
) {
91 printf("[FAIL] dlsym-handle: invalid handle error message missing 'invalid'\n");
96 printf("[PASS] dlsym-handle\n");