Commit 66fd45af authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-7398 mysqld segfaults on FreeBSD 10.1 i386 when built with clang 3.4

in cmake tests let's treat clang like gcc (same options,
same builtins) in many cases.

* don't check the compiler when
  * testing for -fvisibility=hidden support
  * testing for HAVE_ABI_CXA_DEMANGLE
  * testing for HAVE_GCC_ATOMIC_BUILTINS
  * when removing options with string(replace)
  * when running ${CC} --version (ignore the error instead)
* run ABI checks for clang
* use "canonical" gcc flags for clang
* fix groonga too

Also:

* add cmake detection for gcc __atomic_* builtins. they might be
  supported (__ATOMIC_SEQ_CST is defined), but not for all operand
  sizes. In particular, 64-bit atomic load is problematic on i386
* cache check results for Windows
* remove the test for HAVE_CXXABI_H (HAVE_ABI_CXA_DEMANGLE is
  suffifient)
parent 7bfda275
......@@ -28,7 +28,7 @@ ELSE()
SET(RUN_ABI_CHECK 0)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCC AND RUN_ABI_CHECK)
IF(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" AND RUN_ABI_CHECK)
IF(CMAKE_C_COMPILER MATCHES "ccache$")
SET(COMPILER ${CMAKE_C_COMPILER_ARG1})
STRING(REGEX REPLACE "^ " "" COMPILER ${COMPILER})
......
......@@ -308,17 +308,15 @@ INCLUDE(CheckCCompilerFlag)
SET(VISIBILITY_HIDDEN_FLAG)
IF(CMAKE_COMPILER_IS_GNUCXX AND UNIX)
IF(CMAKE_C_COMPILER_ID MATCHES "SunPro")
SET(VISIBILITY_HIDDEN_FLAG "-xldscope=hidden")
ELSEIF(UNIX)
CHECK_C_COMPILER_FLAG("-fvisibility=hidden" HAVE_VISIBILITY_HIDDEN)
IF(HAVE_VISIBILITY_HIDDEN)
SET(VISIBILITY_HIDDEN_FLAG "-fvisibility=hidden")
ENDIF()
ENDIF()
IF(CMAKE_C_COMPILER_ID MATCHES "SunPro")
SET(VISIBILITY_HIDDEN_FLAG "-xldscope=hidden")
ENDIF()
# We try to hide the symbols in yassl/zlib to avoid name clashes with
# other libraries like openssl.
FUNCTION(RESTRICT_SYMBOL_EXPORTS target)
......
......@@ -41,11 +41,11 @@ IF(MYSQL_MAINTAINER_MODE MATCHES "ERR")
ENDIF()
# Set warning flags for GCC/Clang
IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
IF(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
SET(MY_MAINTAINER_C_WARNINGS "${MY_C_WARNING_FLAGS}")
ENDIF()
# Set warning flags for G++/Clang++
IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
SET(MY_MAINTAINER_CXX_WARNINGS "${MY_CXX_WARNING_FLAGS}")
ENDIF()
......
......@@ -351,7 +351,6 @@ SET(C_HAS___inline 1 CACHE INTERNAL "")
SET(FIONREAD_IN_SYS_IOCTL CACHE INTERNAL "")
SET(FIONREAD_IN_SYS_FILIO CACHE INTERNAL "")
SET(GWINSZ_IN_SYS_IOCTL CACHE INTERNAL "")
SET(HAVE_CXXABI_H CACHE INTERNAL "")
SET(HAVE_NDIR_H CACHE INTERNAL "")
SET(HAVE_SYS_NDIR_H CACHE INTERNAL "")
SET(HAVE_SYS_NDIR_H CACHE INTERNAL "")
......@@ -371,4 +370,8 @@ SET(HAVE_PTHREAD_ATTR_GETGUARDSIZE CACHE INTERNAL "")
SET(HAVE_UCONTEXT_H CACHE INTERNAL "")
SET(HAVE_SOCKPEERCRED CACHE INTERNAL "")
SET(HAVE_GGDB3 CACHE INTERNAL "")
SET(HAVE_ABI_CXA_DEMANGLE CACHE INTERNAL "")
SET(HAVE_GCC_ATOMIC_BUILTINS CACHE INTERNAL "")
SET(HAVE_GCC_C11_ATOMICS CACHE INTERNAL "")
SET(HAVE_VISIBILITY_HIDDEN CACHE INTERNAL "")
ENDIF(MSVC)
......@@ -27,7 +27,6 @@
#cmakedefine HAVE_BSEARCH 1
#cmakedefine HAVE_CRYPT_H 1
#cmakedefine HAVE_CURSES_H 1
#cmakedefine HAVE_CXXABI_H 1
#cmakedefine HAVE_BFD_H 1
#cmakedefine HAVE_NCURSES_H 1
#cmakedefine HAVE_NDIR_H 1
......@@ -471,6 +470,7 @@
#cmakedefine MY_ATOMIC_MODE_DUMMY 1
#cmakedefine MY_ATOMIC_MODE_RWLOCKS 1
#cmakedefine HAVE_GCC_ATOMIC_BUILTINS 1
#cmakedefine HAVE_GCC_C11_ATOMICS 1
#cmakedefine HAVE_SOLARIS_ATOMIC 1
#cmakedefine HAVE_DECL_SHM_HUGETLB 1
#cmakedefine HAVE_LARGE_PAGES 1
......
......@@ -52,7 +52,7 @@ IF(NOT SYSTEM_TYPE)
ENDIF()
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# MySQL "canonical" GCC flags. At least -fno-rtti flag affects
# ABI and cannot be simply removed.
SET(CMAKE_CXX_FLAGS
......@@ -175,7 +175,6 @@ CHECK_INCLUDE_FILES (alloca.h HAVE_ALLOCA_H)
CHECK_INCLUDE_FILES (aio.h HAVE_AIO_H)
CHECK_INCLUDE_FILES (arpa/inet.h HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILES (crypt.h HAVE_CRYPT_H)
CHECK_INCLUDE_FILE_CXX (cxxabi.h HAVE_CXXABI_H)
CHECK_INCLUDE_FILES (bfd.h BFD_H_EXISTS)
CHECK_INCLUDE_FILES (dirent.h HAVE_DIRENT_H)
CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H)
......@@ -874,7 +873,7 @@ ENDIF(NOT HAVE_POSIX_SIGNALS)
# Assume regular sprintf
SET(SPRINTFS_RETURNS_INT 1)
IF(CMAKE_COMPILER_IS_GNUCXX AND HAVE_CXXABI_H)
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
CHECK_CXX_SOURCE_COMPILES("
#include <cxxabi.h>
int main(int argc, char **argv)
......@@ -946,7 +945,6 @@ SET(SIGNAL_WITH_VIO_CLOSE 1)
MARK_AS_ADVANCED(NO_ALARM)
IF(CMAKE_COMPILER_IS_GNUCXX)
IF(WITH_ATOMIC_OPS STREQUAL "up")
SET(MY_ATOMIC_MODE_DUMMY 1 CACHE BOOL "Assume single-CPU mode, no concurrency")
ELSEIF(WITH_ATOMIC_OPS STREQUAL "rwlocks")
......@@ -977,10 +975,17 @@ ELSEIF(NOT WITH_ATOMIC_OPS)
return 0;
}"
HAVE_GCC_ATOMIC_BUILTINS)
CHECK_CXX_SOURCE_COMPILES("
int main()
{
long long int var= 1;
long long int *ptr= &var;
return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
}"
HAVE_GCC_C11_ATOMICS)
ELSE()
MESSAGE(FATAL_ERROR "${WITH_ATOMIC_OPS} is not a valid value for WITH_ATOMIC_OPS!")
ENDIF()
ENDIF()
SET(WITH_ATOMIC_OPS "${WITH_ATOMIC_OPS}" CACHE STRING
"Implement atomic operations using pthread rwlocks (rwlocks); or atomic CPU
......
......@@ -20,12 +20,9 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/extra/yassl/taocrypt/mySTL)
ADD_DEFINITIONS(${SSL_DEFINES})
IF(CMAKE_COMPILER_IS_GNUXX)
#Remove -fno-implicit-templates
#(yassl sources cannot be compiled with it)
STRING(REPLACE "-fno-implicit-templates" "" CMAKE_CXX_FLAGS
${CMAKE_CXX_FLAGS})
ENDIF()
#Remove -fno-implicit-templates
#(yassl sources cannot be compiled with it)
STRING(REPLACE "-fno-implicit-templates" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
SET(YASSL_SOURCES src/buffer.cpp src/cert_wrapper.cpp src/crypto_wrapper.cpp src/handshake.cpp src/lock.cpp
src/log.cpp src/socket_wrapper.cpp src/ssl.cpp src/timer.cpp src/yassl_error.cpp
src/yassl_imp.cpp src/yassl_int.cpp)
......
......@@ -31,8 +31,8 @@
#define make_atomic_store_body(S) *a= v
#define MY_ATOMIC_MODE "gcc-builtins-up"
#elif defined(__ATOMIC_SEQ_CST)
#define MY_ATOMIC_MODE "gcc-builtins-smp"
#elif defined(HAVE_GCC_C11_ATOMICS)
#define MY_ATOMIC_MODE "gcc-atomics-smp"
#define make_atomic_load_body(S) \
ret= __atomic_load_n(a, __ATOMIC_SEQ_CST)
#define make_atomic_store_body(S) \
......
......@@ -35,8 +35,7 @@
#define HAVE_WRITE_CORE
#if HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS && \
HAVE_CXXABI_H && HAVE_ABI_CXA_DEMANGLE && \
#if HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS && HAVE_ABI_CXA_DEMANGLE && \
HAVE_WEAK_SYMBOL
#define BACKTRACE_DEMANGLE 1
#endif
......
......@@ -6,9 +6,7 @@ IF(WIN32)
ENDIF()
#Remove -fno-implicit-templates from compiler flags(handlersocket would not work with it)
IF(CMAKE_COMPILER_IS_GNUCXX)
STRING(REPLACE "-fno-implicit-templates" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
ENDIF()
STRING(REPLACE "-fno-implicit-templates" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
INCLUDE_DIRECTORIES(libhsclient)
......
......@@ -147,22 +147,16 @@ SET(CONFIGURE_LINE "Built using CMake")
# Also required for mysqlbug, autoconf only supports --version so for now we
# just explicitly require GNU
IF(CMAKE_COMPILER_IS_GNUCC)
EXECUTE_PROCESS(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} --version
COMMAND sed 1q
OUTPUT_VARIABLE CC_VERSION)
ELSE()
SET(CC_VERSION "")
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
EXECUTE_PROCESS(
COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version
COMMAND sed 1q
OUTPUT_VARIABLE CXX_VERSION)
ELSE()
SET(CXX_VERSION "")
ENDIF()
EXECUTE_PROCESS(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} --version
COMMAND sed 1q
ERROR_QUIET
OUTPUT_VARIABLE CC_VERSION)
EXECUTE_PROCESS(
COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version
COMMAND sed 1q
ERROR_QUIET
OUTPUT_VARIABLE CXX_VERSION)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysqlbug.sh
${CMAKE_CURRENT_BINARY_DIR}/mysqlbug ESCAPE_QUOTES @ONLY)
......
......@@ -168,7 +168,7 @@ macro(check_build_flag flag)
check_cxxflag(${flag})
endmacro()
if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
check_build_flag("-Wall")
check_build_flag("-Wextra")
check_build_flag("-Wno-unused-but-set-variable")
......@@ -201,7 +201,7 @@ endif()
option(GRN_WITH_DEBUG "enable debug build." OFF)
if(GRN_WITH_DEBUG)
if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
set(GRN_C_COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS} -g3 -O0")
set(GRN_CXX_COMPILE_FLAGS "${GRN_CXX_COMPILE_FLAGS} -g3 -O0")
endif()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment