1 // BUILD(macos):  $CC main.c  -o $BUILD_DIR/NSCreateObjectFileImageFromFile-basic.exe -Wno-deprecated-declarations 
   2 // BUILD(macos):  $CC foo.c   -o $BUILD_DIR/foo.bundle -bundle 
   4 // BUILD(ios,tvos,watchos,bridgeos): 
   6 // RUN:  ./NSCreateObjectFileImageFromFile-basic.exe $RUN_DIR/foo.bundle 
  12 #include <mach-o/dyld.h> 
  14 #include "test_support.h" 
  16 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) { 
  17     const char* path 
= argv
[1]; 
  19     NSObjectFileImage ofi
; 
  20     if ( NSCreateObjectFileImageFromFile(path
, &ofi
) != NSObjectFileImageSuccess 
) { 
  21         FAIL("NSCreateObjectFileImageFromFile failed"); 
  24     NSModule mod 
= NSLinkModule(ofi
, path
, NSLINKMODULE_OPTION_NONE
); 
  26         FAIL("NSLinkModule failed"); 
  29     NSSymbol sym 
= NSLookupSymbolInModule(mod
, "_fooInBundle"); 
  31         FAIL("NSLookupSymbolInModule failed"); 
  34     void* func 
= NSAddressOfSymbol(sym
); 
  36         FAIL("NSAddressOfSymbol failed"); 
  40     if ( dladdr(func
, &info
) == 0 ) { 
  41         FAIL("dladdr(&p, xx) fail"); 
  43     LOG("_fooInBundle found in %s", info
.dli_fname
); 
  45     if ( !NSUnLinkModule(mod
, NSUNLINKMODULE_OPTION_NONE
) ) { 
  46         FAIL("NSUnLinkModule failed"); 
  49     if ( dladdr(func
, &info
) != 0 ) { 
  50         FAIL("dladdr(&p, xx) found but should not have"); 
  53         if ( !NSDestroyObjectFileImage(ofi
) ) { 
  54         FAIL("NSDestroyObjectFileImage failed");