blob: 1c76ab3918154bbcb1f1e4ae25d3650f94220495 [file] [log] [blame]
From 976468458d53d8bb71acf48ddfc852a60557acb9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= <vicentiu@mariadb.org>
Date: Thu, 23 Jul 2020 00:02:21 -0700
Subject: [PATCH] Link with libatomic to enable C11 atomics support
Some architectures (mips) require libatomic to support proper
atomic operations. Check first if support is available without
linking, otherwise use the library.
Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
---
configure.cmake | 20 +++++++++++++++++++-
mysys/CMakeLists.txt | 4 ++++
sql/CMakeLists.txt | 4 ++++
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/configure.cmake b/configure.cmake
index 4fc324a9..23a2ea91 100644
--- a/configure.cmake
+++ b/configure.cmake
@@ -862,7 +862,25 @@ int main()
long long int *ptr= &var;
return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
}"
-HAVE_GCC_C11_ATOMICS)
+HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
+IF (HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
+ SET(HAVE_GCC_C11_ATOMICS True)
+ELSE()
+ SET(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ LIST(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
+ 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_WITH_LIBATOMIC)
+ IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
+ SET(HAVE_GCC_C11_ATOMICS True)
+ ENDIF()
+ SET(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
+ENDIF()
IF(WITH_VALGRIND)
SET(HAVE_valgrind 1)
diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt
index 6aab788f..91b9c393 100644
--- a/mysys/CMakeLists.txt
+++ b/mysys/CMakeLists.txt
@@ -154,6 +154,10 @@ TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY}
${LIBNSL} ${LIBM} ${LIBRT} ${CMAKE_DL_LIBS} ${LIBSOCKET} ${LIBEXECINFO})
DTRACE_INSTRUMENT(mysys)
+IF (HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
+ TARGET_LINK_LIBRARIES(mysys atomic)
+ENDIF()
+
IF(HAVE_BFD_H)
TARGET_LINK_LIBRARIES(mysys bfd)
ENDIF(HAVE_BFD_H)
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index b9cd418f..d42e5017 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -222,6 +222,10 @@ ELSE()
SET(MYSQLD_SOURCE main.cc ${DTRACE_PROBES_ALL})
ENDIF()
+IF (HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
+ TARGET_LINK_LIBRARIES(sql atomic)
+ENDIF()
+
IF(MSVC OR CMAKE_SYSTEM_NAME MATCHES AIX)
SET(libs_to_export_symbols sql mysys dbug strings)
# Create shared library of already compiled object
--
2.25.1