Fix compile on CentOS 6 with GCC 4.7

The system uses Glibc 2.12, which is below 2.16 required for getauxv
pull/507/head
Jeffrey Walton 2017-09-17 00:41:48 -04:00
parent 8f6afb3079
commit a835443b34
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 59 additions and 53 deletions

108
cpu.cpp
View File

@ -17,44 +17,16 @@
# include <sys/systemcfg.h> # include <sys/systemcfg.h>
#endif #endif
#if defined(__linux__) // Capability queries, requires Glibc 2.16, https://lwn.net/Articles/519085/
// CRYPTOPP_GLIBC_VERSION not used because config.h is missing <feature.h>
#if (((__GLIBC__ * 100) + __GLIBC_MINOR__) >= 216)
# define CRYPTOPP_GETAUXV_AVAILABLE 1
#endif
#if CRYPTOPP_GETAUXV_AVAILABLE
# include <sys/auxv.h> # include <sys/auxv.h>
# ifndef HWCAP_ASIMD #else
# define HWCAP_ASIMD (1 << 1) unsigned long int getauxval(unsigned long int) { return 0; }
# endif
# ifndef HWCAP_ARM_NEON
# define HWCAP_ARM_NEON 4096
# endif
# ifndef HWCAP_CRC32
# define HWCAP_CRC32 (1 << 7)
# endif
# ifndef HWCAP2_CRC32
# define HWCAP2_CRC32 (1 << 4)
# endif
# ifndef HWCAP_PMULL
# define HWCAP_PMULL (1 << 4)
# endif
# ifndef HWCAP2_PMULL
# define HWCAP2_PMULL (1 << 1)
# endif
# ifndef HWCAP_AES
# define HWCAP_AES (1 << 3)
# endif
# ifndef HWCAP2_AES
# define HWCAP2_AES (1 << 0)
# endif
# ifndef HWCAP_SHA1
# define HWCAP_SHA1 (1 << 5)
# endif
# ifndef HWCAP_SHA2
# define HWCAP_SHA2 (1 << 6)
# endif
# ifndef HWCAP2_SHA1
# define HWCAP2_SHA1 (1 << 2)
# endif
# ifndef HWCAP2_SHA2
# define HWCAP2_SHA2 (1 << 3)
# endif
#endif #endif
#if defined(__APPLE__) && defined(__aarch64__) #if defined(__APPLE__) && defined(__aarch64__)
@ -405,6 +377,43 @@ extern bool CPU_ProbeSHA1();
extern bool CPU_ProbeSHA2(); extern bool CPU_ProbeSHA2();
extern bool CPU_ProbePMULL(); extern bool CPU_ProbePMULL();
#ifndef HWCAP_ASIMD
# define HWCAP_ASIMD (1 << 1)
#endif
#ifndef HWCAP_ARM_NEON
# define HWCAP_ARM_NEON 4096
#endif
#ifndef HWCAP_CRC32
# define HWCAP_CRC32 (1 << 7)
#endif
#ifndef HWCAP2_CRC32
# define HWCAP2_CRC32 (1 << 4)
#endif
#ifndef HWCAP_PMULL
# define HWCAP_PMULL (1 << 4)
#endif
#ifndef HWCAP2_PMULL
# define HWCAP2_PMULL (1 << 1)
#endif
#ifndef HWCAP_AES
# define HWCAP_AES (1 << 3)
#endif
#ifndef HWCAP2_AES
# define HWCAP2_AES (1 << 0)
#endif
#ifndef HWCAP_SHA1
# define HWCAP_SHA1 (1 << 5)
#endif
#ifndef HWCAP_SHA2
# define HWCAP_SHA2 (1 << 6)
#endif
#ifndef HWCAP2_SHA1
# define HWCAP2_SHA1 (1 << 2)
#endif
#ifndef HWCAP2_SHA2
# define HWCAP2_SHA2 (1 << 3)
#endif
inline bool CPU_QueryNEON() inline bool CPU_QueryNEON()
{ {
#if defined(__ANDROID__) && defined(__aarch64__) #if defined(__ANDROID__) && defined(__aarch64__)
@ -600,8 +609,17 @@ void DetectArmFeatures()
#elif (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) #elif (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64)
#if defined(__linux__) bool CRYPTOPP_SECTION_INIT g_PowerpcDetectionDone = false;
# include <sys/auxv.h> bool CRYPTOPP_SECTION_INIT g_hasAltivec = false, CRYPTOPP_SECTION_INIT g_hasPower8 = false;
bool CRYPTOPP_SECTION_INIT g_hasAES = false, CRYPTOPP_SECTION_INIT g_hasSHA1 = false, CRYPTOPP_SECTION_INIT g_hasSHA2 = false;
word32 CRYPTOPP_SECTION_INIT g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
extern bool CPU_ProbeAltivec();
extern bool CPU_ProbePower8();
extern bool CPU_ProbeAES();
extern bool CPU_ProbeSHA1();
extern bool CPU_ProbeSHA2();
#ifndef PPC_FEATURE_HAS_ALTIVEC #ifndef PPC_FEATURE_HAS_ALTIVEC
# define PPC_FEATURE_HAS_ALTIVEC 0x10000000 # define PPC_FEATURE_HAS_ALTIVEC 0x10000000
#endif #endif
@ -614,18 +632,6 @@ void DetectArmFeatures()
#ifndef PPC_FEATURE2_VEC_CRYPTO #ifndef PPC_FEATURE2_VEC_CRYPTO
# define PPC_FEATURE2_VEC_CRYPTO 0x02000000 # define PPC_FEATURE2_VEC_CRYPTO 0x02000000
#endif #endif
#endif
bool CRYPTOPP_SECTION_INIT g_PowerpcDetectionDone = false;
bool CRYPTOPP_SECTION_INIT g_hasAltivec = false, CRYPTOPP_SECTION_INIT g_hasPower8 = false;
bool CRYPTOPP_SECTION_INIT g_hasAES = false, CRYPTOPP_SECTION_INIT g_hasSHA1 = false, CRYPTOPP_SECTION_INIT g_hasSHA2 = false;
word32 CRYPTOPP_SECTION_INIT g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
extern bool CPU_ProbeAltivec();
extern bool CPU_ProbePower8();
extern bool CPU_ProbeAES();
extern bool CPU_ProbeSHA1();
extern bool CPU_ProbeSHA2();
inline bool CPU_QueryAltivec() inline bool CPU_QueryAltivec()
{ {