From 89176e51cd4c9e26fbb8000a05e0494a3b1d3cfc Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 23 Apr 2017 06:37:03 -0400 Subject: [PATCH] Add safety for SSSE4.1 and SSE4.2 intructions They are giving ARIA and BLAKE2 trouble. It looks like SSE4 support appeared in the GCC compiler around 4.1 or 4.2. It looks like SHA support appeared in the GNU assembler around 2.18 --- CMakeLists.txt | 11 +++++++++++ GNUmakefile | 23 ++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f213131c..30c7071f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ endif() option(DISABLE_ASM "Disable ASM" OFF) option(DISABLE_SSSE3 "Disable SSSE3" OFF) +option(DISABLE_SSE4 "Disable SSE4" OFF) option(DISABLE_AESNI "Disable AES-NI" OFF) option(DISABLE_SHA "Disable SHA" OFF) option(DISABLE_NATIVE_ARCH "Disable the addition of -march=native" OFF) @@ -151,6 +152,15 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(DISABLE_NATIVE_ARCH 1) endif() + # OpenBSD, CentOS 5 needed this one due to ARIA and BLAKE2 + execute_process(COMMAND echo ${GAS_STRING} + COMMAND ${GREP_CMD} "GNU assembler version (2\\.1[8-9]|2\\.[2-9]|[3-9])" + OUTPUT_VARIABLE GAS218_OR_LATER) + if (GAS218_OR_LATER EQUAL 0) + add_definitions(-DCRYPTOPP_DISABLE_SSE4) + set(DISABLE_NATIVE_ARCH 1) + endif() + execute_process(COMMAND echo ${GAS_STRING} COMMAND ${GREP_CMD} "GNU assembler version (2\\.19|2\\.[2-9]|[3-9])" OUTPUT_VARIABLE GAS219_OR_LATER) @@ -159,6 +169,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(DISABLE_NATIVE_ARCH 1) endif() + # Ubuntu 10 and Ubuntu 12 needed this one execute_process(COMMAND echo ${GAS_STRING} COMMAND ${GREP_CMD} "GNU assembler version (2\\.2[3-9]|2\\.[3-9]|[3-9])" OUTPUT_VARIABLE GAS223_OR_LATER) diff --git a/GNUmakefile b/GNUmakefile index b0b57c2e..21d76e37 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -147,6 +147,7 @@ endif ifneq ($(HAVE_GAS),0) GAS210_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.[1-9][0-9]|[3-9])") GAS217_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.1[7-9]|2\.[2-9]|[3-9])") + GAS218_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.1[8-9]|2\.[2-9]|[3-9])") GAS219_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.19|2\.[2-9]|[3-9])") GAS223_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.2[3-9]|2\.[3-9]|[3-9])") endif @@ -163,13 +164,19 @@ endif # .intel_syntax wasn't supported until GNU assembler 2.10 # No DISABLE_NATIVE_ARCH with CRYPTOPP_DISABLE_ASM for now # See http://github.com/weidai11/cryptopp/issues/395 +ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) ifeq ($(HAVE_GAS)$(GAS210_OR_LATER),10) CXXFLAGS += -DCRYPTOPP_DISABLE_ASM +DISABLE_NATIVE_ARCH := 1 else ifeq ($(HAVE_GAS)$(GAS217_OR_LATER),10) CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3 DISABLE_NATIVE_ARCH := 1 else +ifeq ($(HAVE_GAS)$(GAS218_OR_LATER),10) +CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4 +DISABLE_NATIVE_ARCH := 1 +else ifeq ($(HAVE_GAS)$(GAS219_OR_LATER),10) CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI DISABLE_NATIVE_ARCH := 1 @@ -177,15 +184,17 @@ else ifeq ($(HAVE_GAS)$(GAS223_OR_LATER),10) CXXFLAGS += -DCRYPTOPP_DISABLE_SHA DISABLE_NATIVE_ARCH := 1 -endif -endif -endif -endif +endif # -DCRYPTOPP_DISABLE_SHA +endif # -DCRYPTOPP_DISABLE_AESNI +endif # -DCRYPTOPP_DISABLE_SSE4 +endif # -DCRYPTOPP_DISABLE_SSSE3 +endif # -DCRYPTOPP_DISABLE_ASM +endif # CXXFLAGS -# BEGIN NATIVE_ARCH +# BEGIN_NATIVE_ARCH # Guard use of -march=native (or -m{32|64} on some platforms) # Don't add anything if -march=XXX or -mtune=XXX is specified -ifneq ($(DISABLE_NATIVE_ARCH),1) +ifeq ($(DISABLE_NATIVE_ARCH),0) ifeq ($(findstring -march,$(CXXFLAGS)),) ifeq ($(findstring -mtune,$(CXXFLAGS)),) ifeq ($(GCC42_OR_LATER)$(IS_NETBSD),10) @@ -206,7 +215,7 @@ ifeq ($(findstring -mtune,$(CXXFLAGS)),) endif # -mtune endif # -march endif # DISABLE_NATIVE_ARCH -# END NATIVE_ARCH +# END_NATIVE_ARCH # Aligned access required for -O3 and above due to vectorization UNALIGNED_ACCESS := $(shell $(EGREP) -c "^[[:space:]]*//[[:space:]]*\#[[:space:]]*define[[:space:]]*CRYPTOPP_NO_UNALIGNED_DATA_ACCESS" config.h)