dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / restrict-search.dtest / main.c
1 // BUILD_ONLY: MacOSX
2
3 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/lc/libfoo.dylib -install_name /blah/libfoo.dylib
4 // BUILD: $CC main.c $BUILD_DIR/lc/libfoo.dylib -o $BUILD_DIR/restrict-search-lc-find.exe -Wl,-dyld_env,DYLD_LIBRARY_PATH=@loader_path/lc -DMODE=lc-find -DSHOULD_BE_FOUND=1
5 // BUILD: $CC main.c $BUILD_DIR/lc/libfoo.dylib -o $BUILD_DIR/restrict-search-lc-no-find.exe -Wl,-dyld_env,DYLD_LIBRARY_PATH=@loader_path/lc -DMODE=lc-no-find -sectcreate __RESTRICT __restrict /dev/null
6 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/rpath/libfoo.dylib -install_name @rpath/libfoo.dylib
7 // BUILD: $CC main.c $BUILD_DIR/rpath/libfoo.dylib -o $BUILD_DIR/restrict-search-rpath-find.exe -Wl,-rpath,@loader_path/rpath/ -DMODE=rpath-find -DSHOULD_BE_FOUND=1
8 // BUILD: $CC main.c $BUILD_DIR/rpath/libfoo.dylib -o $BUILD_DIR/restrict-search-rpath-no-find.exe -Wl,-rpath,@loader_path/rpath/ -DMODE=rpath-no-find -sectcreate __RESTRICT __restrict /dev/null
9
10
11 // RUN: ./restrict-search-lc-find.exe
12 // RUN: ./restrict-search-lc-no-find.exe
13 // RUN: ./restrict-search-rpath-find.exe
14 // RUN: ./restrict-search-rpath-no-find.exe
15
16
17
18 #include <stdio.h>
19 #include <dlfcn.h>
20
21 #include "test_support.h"
22
23 // Two ways to find libfoo.dylb: @rpath or DYLD_LIBRARY_PATH (set via LC_DYLD_ENVIRONMENT)
24 // These should work for non-restrictured programs.
25 // These should fail for restricted programs.
26 // By weak linking we can test if libfoo.dylib was found or not.
27
28
29 extern int foo() __attribute__((weak_import));
30
31
32 #define STRINGIFY2( x) #x
33 #define STRINGIFY(x) STRINGIFY2(x)
34
35
36 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
37 #if SHOULD_BE_FOUND
38 if ( &foo == NULL )
39 FAIL("Incorrectly found %s", STRINGIFY(MODE));
40 else
41 PASS("Incorrectly did not find %s", STRINGIFY(MODE));
42 #else
43 // dylib won't be found at runtime, so &foo should be NULL
44 if ( &foo == NULL )
45 PASS("Found %s", STRINGIFY(MODE));
46 else
47 FAIL("Could not find %s", STRINGIFY(MODE));
48 #endif
49
50 return 0;
51 }
52