]>
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>
14 #include "test_support.h"
16 // verify RTLD_DEFAULT search order
20 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
21 void* fooHandle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LAZY
);
22 if ( fooHandle
== NULL
) {
23 FAIL("libfoo.dylib could not be loaded, %s", dlerror());
26 void* barHandle
= dlopen(RUN_DIR
"/libbar.dylib", RTLD_LAZY
);
27 if ( barHandle
== NULL
) {
28 FAIL("libbar.dylib could not be loaded, %s", dlerror());
31 // verify fooHandle does not find mainSymbol
32 if ( dlsym(fooHandle
, "mainSymbol") != NULL
) {
33 FAIL("mainSymbol was found with fooHandle");
36 // verify fooHandle can find foo
37 if ( dlsym(fooHandle
, "foo") == NULL
) {
38 FAIL("foo not found with fooHandle");
41 // verify fooHandle can find base
42 if ( dlsym(fooHandle
, "base") == NULL
) {
43 FAIL("base not found with fooHandle");
46 // verify fooHandle cannot find bar
47 if ( dlsym(fooHandle
, "bar") != NULL
) {
48 FAIL("bar found with fooHandle");
51 // verify barHandle can find bar
52 if ( dlsym(barHandle
, "bar") == NULL
) {
53 FAIL("bar not found with barHandle");
56 // verify barHandle can find base
57 if ( dlsym(barHandle
, "base") == NULL
) {
58 FAIL("base not found with barHandle");
61 // verify barHandle cannot find foo
62 if ( dlsym(barHandle
, "foo") != NULL
) {
63 FAIL("foo found with barHandle");
66 // verify renamed and re-exported symbols work
67 if ( dlsym(RTLD_DEFAULT
, "strcmp") == NULL
) {
68 FAIL("strcmp not found");
71 // verify bad handle errors
72 if ( dlsym((void*)0xdeadbeef, "malloc") != NULL
) {
73 FAIL("malloc found with bad handle");
76 const char* message
= dlerror();
77 if ( strstr(message
, "invalid") == NULL
) {
78 FAIL(" invalid handle error message missing 'invalid'");