]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/restrict-search.dtest/main.c
1 // BUILD(macos): $CC foo.c -dynamiclib -o $BUILD_DIR/lc/libfoo.dylib -install_name /blah/libfoo.dylib
2 // BUILD(macos): $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
3 // BUILD(macos): $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
4 // BUILD(macos): $CC foo.c -dynamiclib -o $BUILD_DIR/rpath/libfoo.dylib -install_name @rpath/libfoo.dylib
5 // BUILD(macos): $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
6 // BUILD(macos): $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
8 // BUILD(ios,tvos,watchos,bridgeos):
10 // RUN: ./restrict-search-lc-find.exe
11 // RUN: ./restrict-search-lc-no-find.exe
12 // RUN: ./restrict-search-rpath-find.exe
13 // RUN: ./restrict-search-rpath-no-find.exe
20 #include "test_support.h"
22 // Two ways to find libfoo.dylb: @rpath or DYLD_LIBRARY_PATH (set via LC_DYLD_ENVIRONMENT)
23 // These should work for non-restrictured programs.
24 // These should fail for restricted programs.
25 // By weak linking we can test if libfoo.dylib was found or not.
28 extern int foo() __attribute__((weak_import
));
31 #define STRINGIFY2( x) #x
32 #define STRINGIFY(x) STRINGIFY2(x)
35 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
38 FAIL("Incorrectly found %s", STRINGIFY(MODE
));
40 PASS("Incorrectly did not find %s", STRINGIFY(MODE
));
42 // dylib won't be found at runtime, so &foo should be NULL
44 PASS("Found %s", STRINGIFY(MODE
));
46 FAIL("Could not find %s", STRINGIFY(MODE
));