]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlsym-RTLD_SELF.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_SELF.exe -DRUN_DIR="$RUN_DIR"
6 // RUN: ./dlsym-RTLD_SELF.exe
11 #include <mach-o/dyld_priv.h>
13 #include "test_support.h"
15 // verify RTLD_SELF search order
20 // my local implemention of free
21 void free(void* p
) { }
24 static bool symbolInImage(const char* symName
, const char* image
)
26 void* sym
= dlsym(RTLD_SELF
, symName
);
29 const char* imagePath
= dyld_image_path_containing_address(sym
);
30 if ( imagePath
== NULL
)
32 return (strstr(imagePath
, image
) != NULL
);
38 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
39 // verify mainSymbol is found
40 if ( dlsym(RTLD_SELF
, "mainSymbol") == NULL
) {
41 FAIL("mainSymbol should have been found");
44 // verify free is found in this program - not in OS
45 if ( !symbolInImage("free", "dlsym-RTLD_SELF") ) {
49 // verify foo is found in libfoo-static.dylib
50 if ( !symbolInImage("foo", "libfoo-static.dylib") ) {
51 FAIL("foo not in libfoo-static.dylib");
54 void* handle
= dlopen(RUN_DIR
"/libfoo-dynamic.dylib", RTLD_LAZY
);
55 if ( handle
== NULL
) {
56 FAIL("libfoo-dynamic.dylib could not be loaded");
59 // verify foo is still found in statically linked lib
60 if ( !symbolInImage("foo", "libfoo-static.dylib") ) {
61 FAIL("foo not in libfoo-static.dylib");
64 // verify foo2 is not found in libfoo-dynamic.dylib", because RTLD_SELF only searches thing this image would have seen
65 if ( symbolInImage("foo2", "libfoo-dynamic.dylib") ) {
66 FAIL("foo2 found but should not have been");