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 #include "test_support.h"
17 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
18 const char* path
= argv
[1];
20 std::vector
<NSObjectFileImage
> ofis
;
21 for (unsigned i
= 0; i
!= 32; ++i
) {
22 NSObjectFileImage ofi
;
23 if ( NSCreateObjectFileImageFromFile(path
, &ofi
) != NSObjectFileImageSuccess
) {
24 FAIL("NSCreateObjectFileImageFromFile failed");
29 for(unsigned i
= 0; i
!= 32; ++i
) {
30 NSObjectFileImage ofi
= ofis
[i
];
31 NSModule mod
= NSLinkModule(ofi
, path
, NSLINKMODULE_OPTION_NONE
);
33 FAIL("NSLinkModule failed");
36 NSSymbol sym
= NSLookupSymbolInModule(mod
, "_fooInBundle");
38 FAIL("NSLookupSymbolInModule failed");
41 void* func
= NSAddressOfSymbol(sym
);
43 FAIL("NSAddressOfSymbol failed");
47 if ( dladdr(func
, &info
) == 0 ) {
48 FAIL("dladdr(&p, xx) fail");
50 LOG("_fooInBundle found in %s", info
.dli_fname
);
52 if ( !NSUnLinkModule(mod
, NSUNLINKMODULE_OPTION_NONE
) ) {
53 FAIL("NSUnLinkModule failed");
56 if ( dladdr(func
, &info
) != 0 ) {
57 FAIL("dladdr(&p, xx) found but should not have");
61 for (unsigned i
= 0; i
!= 32; ++i
) {
62 NSObjectFileImage ofi
= ofis
[i
];
63 if ( !NSDestroyObjectFileImage(ofi
) ) {
64 FAIL("NSDestroyObjectFileImage failed");