3 // BUILD: $CC a.c -dynamiclib -arch x86_64h -o $BUILD_DIR/libHaswellCheck.dylib -install_name $RUN_DIR/libHaswellCheck.dylib
4 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-haswell.exe -DRUN_DIR="$RUN_DIR"
6 // RUN: ./dlopen-haswell.exe
12 #include <mach/host_info.h>
13 #include <mach/mach.h>
14 #include <mach/mach_host.h>
16 #include "test_support.h"
18 typedef bool (*BoolFunc
)(void);
21 bool isHaswell_dynamic()
23 struct host_basic_info info
;
24 mach_msg_type_number_t count
= HOST_BASIC_INFO_COUNT
;
25 mach_port_t hostPort
= mach_host_self();
26 kern_return_t result
= host_info(hostPort
, HOST_BASIC_INFO
, (host_info_t
)&info
, &count
);
27 mach_port_deallocate(mach_task_self(), hostPort
);
28 if ( result
== KERN_SUCCESS
) {
29 return (info
.cpu_subtype
== CPU_SUBTYPE_X86_64_H
);
35 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
36 void* handle
= dlopen(RUN_DIR
"/libHaswellCheck.dylib", RTLD_LAZY
);
37 if ( handle
== NULL
) {
38 FAIL("dlopen(\"" RUN_DIR
"/libHaswellCheck.dylib\") error: %s", dlerror());
41 BoolFunc libFunc
= (BoolFunc
)dlsym(handle
, "isHaswell");
42 if ( libFunc
== NULL
) {
43 FAIL("dlsym(\"isHaswell\") error: %s", dlerror());
46 // check if haswell slice of libHaswellCheck.dylib was loaded on haswell machines
47 bool dylibIsHaswellSlice
= (*libFunc
)();
48 bool runtimeIsHaswell
= isHaswell_dynamic();
50 if ( dylibIsHaswellSlice
!= runtimeIsHaswell
)
51 FAIL("dlopen-haswell, dylibIsHaswellSlice=%d, runtimeIsHaswell=%d", dylibIsHaswellSlice
, runtimeIsHaswell
);