3 // BUILD: $CC main.c -o $BUILD_DIR/NSAddressOfSymbol-basic.exe -Wno-deprecated-declarations
5 // RUN: ./NSAddressOfSymbol-basic.exe
12 #include <mach-o/dyld.h>
14 extern struct mach_header __dso_handle
;
16 int main(int argc
, const char* argv
[])
18 printf("[BEGIN] NSAddressOfSymbol-basic\n");
20 NSSymbol sym
= NSLookupSymbolInImage(&__dso_handle
, "_main", NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
);
22 printf("[FAIL] NSAddressOfSymbol-basic can't find main\n");
25 void* mainAddr
= NSAddressOfSymbol(sym
);
26 if ( mainAddr
!= &main
) {
27 printf("[FAIL] NSAddressOfSymbol-basic address returned %p is not &main=%p\n", mainAddr
, &main
);
32 if ( NSAddressOfSymbol(NULL
) != NULL
) {
33 printf("[FAIL] NSAddressOfSymbol-basic NULL not handle\n");
37 printf("[PASS] NSAddressOfSymbol-basic\n");