Skip to content

Commit

Permalink
Merge pull request microsoft#8974 from valbendan/fix_libsodium
Browse files Browse the repository at this point in the history
[libsodium] Fix CPU feature not properly detected on Linux
  • Loading branch information
ras0219-msft authored Nov 22, 2019
2 parents 436d8a4 + 56b7f1c commit 329f9eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
42 changes: 22 additions & 20 deletions ports/libsodium/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.9)

include(CheckCSourceRuns)

file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/configure.ac config_ac_contents)

foreach (line ${config_ac_contents})
Expand Down Expand Up @@ -206,7 +208,7 @@ else ()
sodium_check_func(posix_memalign HAVE_POSIX_MEMALIGN)
sodium_check_func(getpid HAVE_GETPID)

check_c_source_compiles(
check_c_source_runs(
"
#pragma GCC target(\"mmx\")
#include <mmintrin.h>
Expand All @@ -223,7 +225,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -mmmx)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#pragma GCC target(\"sse2\")
#ifndef __SSE2__
Expand All @@ -244,7 +246,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -msse2)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#pragma GCC target(\"sse3\")
#include <pmmintrin.h>
Expand All @@ -260,7 +262,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -msse3)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#pragma GCC target(\"ssse3\")
#include <tmmintrin.h>
Expand All @@ -276,7 +278,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -mssse3)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#pragma GCC target(\"sse4.1\")
#include <smmintrin.h>
Expand All @@ -292,7 +294,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -msse4.1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#ifdef __native_client__
# error NativeClient detected - Avoiding AVX opcodes
Expand All @@ -311,7 +313,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -mavx)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#ifdef __native_client__
# error NativeClient detected - Avoiding AVX2 opcodes
Expand All @@ -331,7 +333,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_AVX2INTRIN_H=1)
target_compile_options(${PROJECT_NAME} PRIVATE -mavx2)

check_c_source_compiles(
check_c_source_runs(
"
#ifdef __native_client__
# error NativeClient detected - Avoiding AVX2 opcodes
Expand All @@ -353,7 +355,7 @@ else ()
endif ()
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#ifdef __native_client__
# error NativeClient detected - Avoiding AVX512F opcodes
Expand Down Expand Up @@ -388,7 +390,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -mno-avx512f)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#ifdef __native_client__
# error NativeClient detected - Avoiding AESNI opcodes
Expand All @@ -410,7 +412,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -maes -mpclmul)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#ifdef __native_client__
# error NativeClient detected - Avoiding RDRAND opcodes
Expand All @@ -431,7 +433,7 @@ else ()
target_compile_options(${PROJECT_NAME} PRIVATE -mrdrnd)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#include <intrin.h>
Expand All @@ -446,7 +448,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE__XGETBV=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
int main(void) {
int a = 42;
Expand All @@ -461,7 +463,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_INLINE_ASM=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
int main(void) {
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
Expand All @@ -488,7 +490,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_AMD64_ASM=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
int main(void) {
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
Expand All @@ -509,7 +511,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_AVX_ASM=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#if !defined(__clang__) && !defined(__GNUC__) && !defined(__SIZEOF_INT128__)
# error mode(TI) is a gcc extension, and __int128 is not available
Expand Down Expand Up @@ -547,7 +549,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_TI_MODE=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
int main(void) {
unsigned int cpu_info[4];
Expand All @@ -564,7 +566,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_CPUID=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#if !defined(__ELF__) && !defined(__APPLE_CC__)
# error Support for weak symbols may not be available
Expand All @@ -580,7 +582,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_WEAK_SYMBOLS=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
int main(void) {
static volatile int _sodium_lock;
Expand All @@ -595,7 +597,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_ATOMIC_OPS=1)
endif ()

check_c_source_compiles(
check_c_source_runs(
"
#include <limits.h>
#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion ports/libsodium/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source: libsodium
Version: 1.0.18-1
Version: 1.0.18-2
Description: A modern and easy-to-use crypto library
Homepage: https://github.com/jedisct1/libsodium

0 comments on commit 329f9eb

Please sign in to comment.