]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/NSCreateObjectFileImageFromFile-basic.dtest/main.c
49341b38fff70a4f9bd99014d4637ee1cea376c6
[apple/dyld.git] / testing / test-cases / NSCreateObjectFileImageFromFile-basic.dtest / main.c
1 // BUILD_ONLY: MacOSX
2
3 // BUILD: $CC main.c -o $BUILD_DIR/NSCreateObjectFileImageFromFile-basic.exe -Wno-deprecated-declarations
4 // BUILD: $CC foo.c -o $BUILD_DIR/foo.bundle -bundle
5
6 // RUN: ./NSCreateObjectFileImageFromFile-basic.exe $RUN_DIR/foo.bundle
7
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <dlfcn.h>
12 #include <mach-o/dyld.h>
13
14
15 int main(int argc, const char* argv[])
16 {
17 printf("[BEGIN] NSCreateObjectFileImageFromFile-basic\n");
18
19 const char* path = argv[1];
20
21 NSObjectFileImage ofi;
22 if ( NSCreateObjectFileImageFromFile(path, &ofi) != NSObjectFileImageSuccess ) {
23 printf("[FAIL] NSCreateObjectFileImageFromFile failed\n");
24 return 0;
25 }
26
27 NSModule mod = NSLinkModule(ofi, path, NSLINKMODULE_OPTION_NONE);
28 if ( mod == NULL ) {
29 printf("[FAIL] NSLinkModule failed\n");
30 return 0;
31 }
32
33 NSSymbol sym = NSLookupSymbolInModule(mod, "_fooInBundle");
34 if ( sym == NULL ) {
35 printf("[FAIL] NSLookupSymbolInModule failed\n");
36 return 0;
37 }
38
39 void* func = NSAddressOfSymbol(sym);
40 if ( func == NULL ) {
41 printf("[FAIL] NSAddressOfSymbol failed\n");
42 return 0;
43 }
44
45 Dl_info info;
46 if ( dladdr(func, &info) == 0 ) {
47 printf("[FAIL] dladdr(&p, xx) failed");
48 return 0;
49 }
50 //printf("_fooInBundle found in %s\n", info.dli_fname);
51
52 if ( !NSUnLinkModule(mod, NSUNLINKMODULE_OPTION_NONE) ) {
53 printf("[FAIL] NSUnLinkModule failed\n");
54 return 0;
55 }
56
57 if ( dladdr(func, &info) != 0 ) {
58 printf("[FAIL] dladdr(&p, xx) found but should not have\n");
59 return 0;
60 }
61
62 if ( !NSDestroyObjectFileImage(ofi) ) {
63 printf("[FAIL] NSDestroyObjectFileImage failed\n");
64 return 0;
65 }
66
67 printf("[PASS] NSCreateObjectFileImageFromFile-basic\n");
68 return 0;
69 }
70