dyld-832.7.1.tar.gz
[apple/dyld.git] / 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
7
8 // BUILD(ios,tvos,watchos,bridgeos):
9
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
14
15
16
17 #include <stdio.h>
18 #include <dlfcn.h>
19
20 #include "test_support.h"
21
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.
26
27
28 extern int foo() __attribute__((weak_import));
29
30
31 #define STRINGIFY2( x) #x
32 #define STRINGIFY(x) STRINGIFY2(x)
33
34
35 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
36 #if SHOULD_BE_FOUND
37 if ( &foo == NULL )
38 FAIL("Incorrectly found %s", STRINGIFY(MODE));
39 else
40 PASS("Incorrectly did not find %s", STRINGIFY(MODE));
41 #else
42 // dylib won't be found at runtime, so &foo should be NULL
43 if ( &foo == NULL )
44 PASS("Found %s", STRINGIFY(MODE));
45 else
46 FAIL("Could not find %s", STRINGIFY(MODE));
47 #endif
48
49 return 0;
50 }
51