]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/restrict-search.dtest/main.c
3 // BUILD: mkdir $BUILD_DIR/lc
4 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/lc/libfoo.dylib -install_name /blah/libfoo.dylib
5 // 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
6 // 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
7 // BUILD: mkdir $BUILD_DIR/rpath
8 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/rpath/libfoo.dylib -install_name @rpath/libfoo.dylib
9 // 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
10 // 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
13 // RUN: ./restrict-search-lc-find.exe
14 // RUN: ./restrict-search-lc-no-find.exe
15 // RUN: ./restrict-search-rpath-find.exe
16 // RUN: ./restrict-search-rpath-no-find.exe
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.
29 extern int foo() __attribute__((weak_import
));
32 #define STRINGIFY2( x) #x
33 #define STRINGIFY(x) STRINGIFY2(x)
36 int main(int argc
, const char* argv
[])
38 printf("[BEGIN] restrict-search %s\n", STRINGIFY(MODE
));
41 printf("[FAIL] restrict-search %s\n", STRINGIFY(MODE
));
43 printf("[PASS] restrict-search %s\n", STRINGIFY(MODE
));
45 // dylib won't be found at runtime, so &foo should be NULL
47 printf("[PASS] restrict-search %s\n", STRINGIFY(MODE
));
49 printf("[FAIL] restrict-search %s\n", STRINGIFY(MODE
));