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
6 // RUN: ./NSCreateObjectFileImageFromFile-basic.exe $RUN_DIR/foo.bundle
12 #include <mach-o/dyld.h>
15 int main(int argc
, const char* argv
[])
17 printf("[BEGIN] NSCreateObjectFileImageFromFile-basic\n");
19 const char* path
= argv
[1];
21 NSObjectFileImage ofi
;
22 if ( NSCreateObjectFileImageFromFile(path
, &ofi
) != NSObjectFileImageSuccess
) {
23 printf("[FAIL] NSCreateObjectFileImageFromFile failed\n");
27 NSModule mod
= NSLinkModule(ofi
, path
, NSLINKMODULE_OPTION_NONE
);
29 printf("[FAIL] NSLinkModule failed\n");
33 NSSymbol sym
= NSLookupSymbolInModule(mod
, "_fooInBundle");
35 printf("[FAIL] NSLookupSymbolInModule failed\n");
39 void* func
= NSAddressOfSymbol(sym
);
41 printf("[FAIL] NSAddressOfSymbol failed\n");
46 if ( dladdr(func
, &info
) == 0 ) {
47 printf("[FAIL] dladdr(&p, xx) failed");
50 //printf("_fooInBundle found in %s\n", info.dli_fname);
52 if ( !NSUnLinkModule(mod
, NSUNLINKMODULE_OPTION_NONE
) ) {
53 printf("[FAIL] NSUnLinkModule failed\n");
57 if ( dladdr(func
, &info
) != 0 ) {
58 printf("[FAIL] dladdr(&p, xx) found but should not have\n");
62 if ( !NSDestroyObjectFileImage(ofi
) ) {
63 printf("[FAIL] NSDestroyObjectFileImage failed\n");
67 printf("[PASS] NSCreateObjectFileImageFromFile-basic\n");