blob: 1c76ab3918154bbcb1f1e4ae25d3650f94220495 [file] [log] [blame]
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -05001From 976468458d53d8bb71acf48ddfc852a60557acb9 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= <vicentiu@mariadb.org>
3Date: Thu, 23 Jul 2020 00:02:21 -0700
4Subject: [PATCH] Link with libatomic to enable C11 atomics support
Brad Bishop19323692019-04-05 15:28:33 -04005
6 Some architectures (mips) require libatomic to support proper
7 atomic operations. Check first if support is available without
8 linking, otherwise use the library.
9
10Upstream-Status: Pending
11Signed-off-by: Khem Raj <raj.khem@gmail.com>
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050012Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
13---
14 configure.cmake | 20 +++++++++++++++++++-
15 mysys/CMakeLists.txt | 4 ++++
16 sql/CMakeLists.txt | 4 ++++
17 3 files changed, 27 insertions(+), 1 deletion(-)
Brad Bishop19323692019-04-05 15:28:33 -040018
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050019diff --git a/configure.cmake b/configure.cmake
Andrew Geisslere34f8962021-04-15 15:53:51 -050020index 4fc324a9..23a2ea91 100644
Brad Bishop19323692019-04-05 15:28:33 -040021--- a/configure.cmake
22+++ b/configure.cmake
Andrew Geisslere34f8962021-04-15 15:53:51 -050023@@ -862,7 +862,25 @@ int main()
Brad Bishop19323692019-04-05 15:28:33 -040024 long long int *ptr= &var;
25 return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
26 }"
27-HAVE_GCC_C11_ATOMICS)
28+HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
29+IF (HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
30+ SET(HAVE_GCC_C11_ATOMICS True)
31+ELSE()
32+ SET(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
33+ LIST(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
34+ CHECK_CXX_SOURCE_COMPILES("
35+ int main()
36+ {
37+ long long int var= 1;
38+ long long int *ptr= &var;
39+ return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
40+ }"
41+ HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
42+ IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
43+ SET(HAVE_GCC_C11_ATOMICS True)
44+ ENDIF()
45+ SET(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
46+ENDIF()
47
48 IF(WITH_VALGRIND)
49 SET(HAVE_valgrind 1)
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050050diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt
Andrew Geisslere34f8962021-04-15 15:53:51 -050051index 6aab788f..91b9c393 100644
Brad Bishop19323692019-04-05 15:28:33 -040052--- a/mysys/CMakeLists.txt
53+++ b/mysys/CMakeLists.txt
Andrew Geisslere34f8962021-04-15 15:53:51 -050054@@ -154,6 +154,10 @@ TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY}
Andrew Geisslereef63862021-01-29 15:58:13 -060055 ${LIBNSL} ${LIBM} ${LIBRT} ${CMAKE_DL_LIBS} ${LIBSOCKET} ${LIBEXECINFO})
Brad Bishop19323692019-04-05 15:28:33 -040056 DTRACE_INSTRUMENT(mysys)
57
58+IF (HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
59+ TARGET_LINK_LIBRARIES(mysys atomic)
60+ENDIF()
61+
62 IF(HAVE_BFD_H)
63 TARGET_LINK_LIBRARIES(mysys bfd)
64 ENDIF(HAVE_BFD_H)
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050065diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
Andrew Geisslere34f8962021-04-15 15:53:51 -050066index b9cd418f..d42e5017 100644
Brad Bishop19323692019-04-05 15:28:33 -040067--- a/sql/CMakeLists.txt
68+++ b/sql/CMakeLists.txt
Andrew Geisslere34f8962021-04-15 15:53:51 -050069@@ -222,6 +222,10 @@ ELSE()
Brad Bishop19323692019-04-05 15:28:33 -040070 SET(MYSQLD_SOURCE main.cc ${DTRACE_PROBES_ALL})
71 ENDIF()
72
73+IF (HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
74+ TARGET_LINK_LIBRARIES(sql atomic)
75+ENDIF()
76+
Andrew Geisslere34f8962021-04-15 15:53:51 -050077 IF(MSVC OR CMAKE_SYSTEM_NAME MATCHES AIX)
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050078 SET(libs_to_export_symbols sql mysys dbug strings)
79 # Create shared library of already compiled object
80--
Andrew Geisslere34f8962021-04-15 15:53:51 -0500812.25.1
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050082