From 02f5422ba1908639b5949d5e228863a73e0c7520 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 18 Nov 2011 20:46:16 +0000 Subject: Call cpuid via inline asm on x86-64, so we can use it with Clang (no cpuid intrinsic) and older GCC (no cpuid.h before 4.3) --- src/utils/cpuid.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp index 917789f65..c5710d689 100644 --- a/src/utils/cpuid.cpp +++ b/src/utils/cpuid.cpp @@ -24,9 +24,9 @@ #elif defined(BOTAN_BUILD_COMPILER_IS_INTEL) #include - #define CALL_CPUID(type, out) do { __cpuid(out, type); } while(0); + #define CALL_CPUID(type, out) do { __cpuid(out, type); } while(0) -#elif (BOTAN_GCC_VERSION >= 430) +#elif defined(BOTAN_BUILD_COMPILER_IS_GCC) && (BOTAN_GCC_VERSION >= 430) // Only available starting in GCC 4.3 #include @@ -46,6 +46,20 @@ namespace { } +#elif defined(BOTAN_TARGET_ARCH_IS_X86_64) && \ + (defined(BOTAN_BUILD_COMPILER_IS_CLANG) || defined(BOTAN_BUILD_COMPILER_IS_GCC)) + + /* + * We can't safely use this on x86-32 as some 32-bit ABIs use ebx as + * a PIC register, and in theory there are some x86-32s still out + * there that don't support cpuid at all; it requires strange + * contortions to detect them. + */ + + #define CALL_CPUID(type, out) \ + asm("cpuid\n\t" : "=a" (out[0]), "=b" (out[1]), "=c" (out[2]), "=d" (out[3]) \ + : "0" (type)) + #else #warning "No method of calling CPUID for this compiler" #endif -- cgit v1.2.3 From 173a01fc66a9b7d76903e5134fc15d1bb3cb276c Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 28 Nov 2011 14:30:45 +0000 Subject: Add AltiVec detection on OpenBSD, contributed by Brad Smith in PR 162 --- doc/log.txt | 2 ++ src/utils/cpuid.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/doc/log.txt b/doc/log.txt index d82f47157..dfc49d90c 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -21,6 +21,8 @@ Version 1.10.2, Not Yet Released * Add AltiVec detection for IBM POWER7 processors. +* Add AltiVec detection for OpenBSD, contributed by Brad Smith (PR 162) + * Don't set a soname on OpenBSD, as it doesn't support it (PR 158) * Fix a configure.py incompatability with the subprocess module diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp index c5710d689..f6581f09c 100644 --- a/src/utils/cpuid.cpp +++ b/src/utils/cpuid.cpp @@ -10,10 +10,20 @@ #include #include +#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY) + #if defined(BOTAN_TARGET_OS_IS_DARWIN) #include #endif +#if defined(BOTAN_TARGET_OS_IS_OPENBSD) + #include + #include + #include +#endif + +#endif + #if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) #if defined(BOTAN_BUILD_COMPILER_IS_MSVC) @@ -106,10 +116,14 @@ u32bit get_x86_cache_line_size() bool altivec_check_sysctl() { -#if defined(BOTAN_TARGET_OS_IS_DARWIN) +#if defined(BOTAN_TARGET_OS_IS_DARWIN) || defined(BOTAN_TARGET_OS_IS_OPENBSD) +#if defined(BOTAN_TARGET_OS_IS_OPENBSD) + int sels[2] = { CTL_MACHDEP, CPU_ALTIVEC }; +#else // From Apple's docs int sels[2] = { CTL_HW, HW_VECTORUNIT }; +#endif int vector_type = 0; size_t length = sizeof(vector_type); int error = sysctl(sels, 2, &vector_type, &length, NULL, 0); -- cgit v1.2.3 From ef9a9e9022f5aba23fd4c0f4db0c07d02bf2ba38 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 2 Dec 2011 14:15:01 +0000 Subject: GCC doesn't like casting a function pointer to void* without an explicit cast. --- doc/log.txt | 2 ++ src/utils/dyn_load/dyn_load.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/doc/log.txt b/doc/log.txt index dfc49d90c..acce16410 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -23,6 +23,8 @@ Version 1.10.2, Not Yet Released * Add AltiVec detection for OpenBSD, contributed by Brad Smith (PR 162) +* Fixed a compilation problem of the dynamic loader hooks under MinGW GCC + * Don't set a soname on OpenBSD, as it doesn't support it (PR 158) * Fix a configure.py incompatability with the subprocess module diff --git a/src/utils/dyn_load/dyn_load.cpp b/src/utils/dyn_load/dyn_load.cpp index 4a8cb16fa..7f42218f9 100644 --- a/src/utils/dyn_load/dyn_load.cpp +++ b/src/utils/dyn_load/dyn_load.cpp @@ -65,7 +65,8 @@ void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol) #if defined(BOTAN_TARGET_OS_HAS_DLOPEN) addr = ::dlsym(lib, symbol.c_str()); #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY) - addr = ::GetProcAddress((HMODULE)lib, symbol.c_str()); + addr = reinterpret_cast(::GetProcAddress((HMODULE)lib, + symbol.c_str())); #endif if(!addr) -- cgit v1.2.3 From ca2d58210875a8ab1b52c07dc31401de6d89d110 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 13 Dec 2011 21:37:59 +0000 Subject: Use LoadLibraryA instead of bare LoadLibrary so things work if used in an amalgamation and the app is compiled in Unicode mode. --- src/utils/dyn_load/dyn_load.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/dyn_load/dyn_load.cpp b/src/utils/dyn_load/dyn_load.cpp index 7f42218f9..06b8c5df3 100644 --- a/src/utils/dyn_load/dyn_load.cpp +++ b/src/utils/dyn_load/dyn_load.cpp @@ -39,7 +39,7 @@ Dynamically_Loaded_Library::Dynamically_Loaded_Library( raise_runtime_loader_exception(lib_name, dlerror()); #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY) - lib = ::LoadLibrary(lib_name.c_str()); + lib = ::LoadLibraryA(lib_name.c_str()); if(!lib) raise_runtime_loader_exception(lib_name, "LoadLibrary failed"); -- cgit v1.2.3