]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlsym-RTLD_DEFAULT.dtest/main.c
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo-static.dylib -o $BUILD_DIR/libfoo-static.dylib
3 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo-dynamic.dylib -o $BUILD_DIR/libfoo-dynamic.dylib -DDYN
4 // BUILD: $CC main.c $BUILD_DIR/libfoo-static.dylib -o $BUILD_DIR/dlsym-RTLD_DEFAULT.exe -DRUN_DIR="$RUN_DIR"
6 // RUN: ./dlsym-RTLD_DEFAULT.exe
11 #include <mach-o/dyld_priv.h>
14 // verify RTLD_DEFAULT search order
19 // my local implemention of free
20 void free(void* p
) { }
23 static bool symbolInImage(const char* symName
, const char* image
)
25 void* sym
= dlsym(RTLD_DEFAULT
, symName
);
28 const char* imagePath
= dyld_image_path_containing_address(sym
);
29 if ( imagePath
== NULL
)
31 return (strstr(imagePath
, image
) != NULL
);
39 printf("[BEGIN] dlsym-RTLD_DEFAULT\n");
41 // verify mainSymbol is found in main executable
42 if ( !symbolInImage("mainSymbol", "dlsym-RTLD_DEFAULT") ) {
43 printf("[FAIL] dlsym-RTLD_DEFAULT: mainSymbol\n");
47 // verify free is found in main executable, overrideing one in OS
48 if ( !symbolInImage("free", "dlsym-RTLD_DEFAULT") ) {
49 printf("[FAIL] dlsym-RTLD_DEFAULT: free\n");
53 // verify foo is found in libfoo-static.dylib
54 if ( !symbolInImage("foo", "libfoo-static.dylib") ) {
55 printf("[FAIL] dlsym-RTLD_DEFAULT: foo not in libfoo-static.dylib\n");
59 void* handle
= dlopen(RUN_DIR
"/libfoo-dynamic.dylib", RTLD_LAZY
);
60 if ( handle
== NULL
) {
61 printf("[FAIL] dlsym-RTLD_DEFAULT: libfoo-dynamic.dylib could not be loaded\n");
65 // verify foo is still found in statically linked lib
66 if ( !symbolInImage("foo", "libfoo-static.dylib") ) {
67 printf("[FAIL] dlsym-RTLD_DEFAULT: foo not in libfoo-static.dylib\n");
71 // verify foo2 is found in libfoo-dynamic.dylib"
72 if ( !symbolInImage("foo2", "libfoo-dynamic.dylib") ) {
73 printf("[FAIL] dlsym-RTLD_DEFAULT: foo2 not in libfoo-dynamic.dylib\n");
77 // renamed and re-exported symbols work
78 if ( dlsym(RTLD_DEFAULT
, "strcmp") == NULL
) {
79 printf("[FAIL] dlsym-RTLD_DEFAULT: strcmp not found\n");
83 printf("[PASS] dlsym-RTLD_DEFAULT\n");