diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -54,6 +54,13 @@ CMAKE_TOOLCHAIN_FILE[arm-linux-gnueabihf]=LinuxARM.cmake CMAKE_TOOLCHAIN_FILE[aarch64-linux-gnu]=LinuxAArch64.cmake + # Allow extra cmake option to be specified for each host + declare -A CMAKE_EXTRA_OPTIONS + CMAKE_EXTRA_OPTIONS[i686-pc-linux-gnu]="-DSECP256K1_USE_ASM=OFF" + CMAKE_EXTRA_OPTIONS[aarch64-linux-gnu]="-DSECP256K1_USE_ASM=OFF" + # ARM assembly is supported but experimental, disable it for the release + CMAKE_EXTRA_OPTIONS[arm-linux-gnueabihf]="-DSECP256K1_USE_ASM=OFF" + INSTALL_COMPONENTS="bitcoind bitcoin-qt bitcoin-seeder" FAKETIME_HOST_PROGS="" @@ -164,7 +171,8 @@ -DENABLE_GLIBC_BACK_COMPAT=ON \ -DCMAKE_INSTALL_PREFIX=${INSTALLPATH} \ -DCCACHE=OFF \ - -DUSE_LD_GOLD=OFF + -DUSE_LD_GOLD=OFF \ + ${CMAKE_EXTRA_OPTIONS[${i}]} ninja ninja security-check diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -164,7 +164,7 @@ # Allow extra cmake option to be specified for each host declare -A CMAKE_EXTRA_OPTIONS - CMAKE_EXTRA_OPTIONS[i686-w64-mingw32]="-DCPACK_PACKAGE_FILE_NAME=${DISTNAME}-win32-setup-unsigned" + CMAKE_EXTRA_OPTIONS[i686-w64-mingw32]="-DCPACK_PACKAGE_FILE_NAME=${DISTNAME}-win32-setup-unsigned -DSECP256K1_USE_ASM=OFF" CMAKE_EXTRA_OPTIONS[x86_64-w64-mingw32]="-DCPACK_PACKAGE_FILE_NAME=${DISTNAME}-win64-setup-unsigned" ORIGPATH="$PATH" diff --git a/src/secp256k1/CMakeLists.txt b/src/secp256k1/CMakeLists.txt --- a/src/secp256k1/CMakeLists.txt +++ b/src/secp256k1/CMakeLists.txt @@ -65,19 +65,42 @@ set(USE_SCALAR_INV_BUILTIN 1) endif() -# We check if amd64 asm is supported. option(SECP256K1_USE_ASM "Use assembly if available" ON) -if($SECP256K1_USE_ASM) - check_c_source_compiles(" - #include - int main() { - uint64_t a = 11, tmp; - __asm__ __volatile__(\"movq \$0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\"); - return 0; - } - " USE_ASM_X86_64) -else() - set(USE_ASM_X86_64 0) + +if(SECP256K1_USE_ASM) + macro(unsupported_asm_error) + message(FATAL_ERROR + "Assembly is not supported for your target architecture." + "Re-run cmake with -DSECP256k1_USE_ASM=OFF to disable ASM support" + ) + endmacro() + + # Guess the target architecture. + # First check if the CMAKE_C_COMPILER_TARGET is set (should be when + # cross compiling), then CMAKE_SYSTEM_PROCESSOR as a fallback if meaningful + # (this is not the case for ARM as the content is highly non standard). + if(CMAKE_C_COMPILER_TARGET MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + # We check if amd64 asm is supported. + check_c_source_compiles(" + #include + int main() { + uint64_t a = 11, tmp; + __asm__ __volatile__(\"movq \$0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\"); + return 0; + } + " USE_ASM_X86_64) + + if(NOT USE_ASM_X86_64) + unsupported_asm_error() + endif() + elseif(CMAKE_C_COMPILER_TARGET MATCHES "arm-linux-gnueabihf") + enable_language(ASM) + set(USE_EXTERNAL_ASM 1) + add_library(secp256k1_common src/asm/field_10x26_arm.s) + target_link_libraries(secp256k1 secp256k1_common) + else() + unsupported_asm_error() + endif() endif() # We make sure __int128 is defined diff --git a/src/secp256k1/src/libsecp256k1-config.h.cmake.in b/src/secp256k1/src/libsecp256k1-config.h.cmake.in --- a/src/secp256k1/src/libsecp256k1-config.h.cmake.in +++ b/src/secp256k1/src/libsecp256k1-config.h.cmake.in @@ -20,6 +20,7 @@ #cmakedefine USE_FIELD_10X26 #cmakedefine USE_ASM_X86_64 +#cmakedefine USE_EXTERNAL_ASM #cmakedefine USE_ENDOMORPHISM #cmakedefine USE_EXTERNAL_DEFAULT_CALLBACKS