3 // BUILD: $CXX main.cpp -o $BUILD_DIR/NSCreateObjectFileImageFromFile-stress.exe -Wno-deprecated-declarations
4 // BUILD: $CC foo.c -o $BUILD_DIR/foo.bundle -bundle
6 // RUN: ./NSCreateObjectFileImageFromFile-stress.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 std::vector
<NSObjectFileImage
> ofis
;
22 for (unsigned i
= 0; i
!= 32; ++i
) {
23 NSObjectFileImage ofi
;
24 if ( NSCreateObjectFileImageFromFile(path
, &ofi
) != NSObjectFileImageSuccess
) {
25 printf("[FAIL] NSCreateObjectFileImageFromFile failed\n");
31 for (unsigned i
= 0; i
!= 32; ++i
) {
32 NSObjectFileImage ofi
= ofis
[i
];
33 NSModule mod
= NSLinkModule(ofi
, path
, NSLINKMODULE_OPTION_NONE
);
35 printf("[FAIL] NSLinkModule failed\n");
39 NSSymbol sym
= NSLookupSymbolInModule(mod
, "_fooInBundle");
41 printf("[FAIL] NSLookupSymbolInModule failed\n");
45 void* func
= NSAddressOfSymbol(sym
);
47 printf("[FAIL] NSAddressOfSymbol failed\n");
52 if ( dladdr(func
, &info
) == 0 ) {
53 printf("[FAIL] dladdr(&p, xx) failed");
56 //printf("_fooInBundle found in %s\n", info.dli_fname);
58 if ( !NSUnLinkModule(mod
, NSUNLINKMODULE_OPTION_NONE
) ) {
59 printf("[FAIL] NSUnLinkModule failed\n");
63 if ( dladdr(func
, &info
) != 0 ) {
64 printf("[FAIL] dladdr(&p, xx) found but should not have\n");
69 for (unsigned i
= 0; i
!= 32; ++i
) {
70 NSObjectFileImage ofi
= ofis
[i
];
71 if ( !NSDestroyObjectFileImage(ofi
) ) {
72 printf("[FAIL] NSDestroyObjectFileImage failed\n");
77 printf("[PASS] NSCreateObjectFileImageFromFile-basic\n");