]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/NSAddressOfSymbol-basic.dtest/main.c
dyld-519.2.2.tar.gz
[apple/dyld.git] / testing / test-cases / NSAddressOfSymbol-basic.dtest / main.c
1 // BUILD_ONLY: MacOSX
2
3 // BUILD: $CC main.c -o $BUILD_DIR/NSAddressOfSymbol-basic.exe -Wno-deprecated-declarations
4
5 // RUN: ./NSAddressOfSymbol-basic.exe
6
7
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <dlfcn.h>
12 #include <mach-o/dyld.h>
13
14 extern struct mach_header __dso_handle;
15
16 int main(int argc, const char* argv[])
17 {
18 printf("[BEGIN] NSAddressOfSymbol-basic\n");
19
20 NSSymbol sym = NSLookupSymbolInImage(&__dso_handle, "_main", NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
21 if ( sym == NULL ) {
22 printf("[FAIL] NSAddressOfSymbol-basic can't find main\n");
23 return 0;
24 }
25 void* mainAddr = NSAddressOfSymbol(sym);
26 if ( mainAddr != &main ) {
27 printf("[FAIL] NSAddressOfSymbol-basic address returned %p is not &main=%p\n", mainAddr, &main);
28 return 0;
29 }
30
31 // verify NULL works
32 if ( NSAddressOfSymbol(NULL) != NULL ) {
33 printf("[FAIL] NSAddressOfSymbol-basic NULL not handle\n");
34 return 0;
35 }
36
37 printf("[PASS] NSAddressOfSymbol-basic\n");
38 return 0;
39 }
40