blob: 32c9818ab0c1f6cb1cbcfe78493deac4c6f838b5 [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 Geisslereef63862021-01-29 15:58:13 -060020index bb3ad43..2ff4f19 100644
Brad Bishop19323692019-04-05 15:28:33 -040021--- a/configure.cmake
22+++ b/configure.cmake
Andrew Geisslereef63862021-01-29 15:58:13 -060023@@ -861,7 +861,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 Geisslereef63862021-01-29 15:58:13 -060051index 6a3a1ef..e306ae7 100644
Brad Bishop19323692019-04-05 15:28:33 -040052--- a/mysys/CMakeLists.txt
53+++ b/mysys/CMakeLists.txt
Andrew Geisslereef63862021-01-29 15:58:13 -060054@@ -140,6 +140,10 @@ TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY}
55 ${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 Geisslereef63862021-01-29 15:58:13 -060066index 4978d01..883a930 100644
Brad Bishop19323692019-04-05 15:28:33 -040067--- a/sql/CMakeLists.txt
68+++ b/sql/CMakeLists.txt
Andrew Geisslereef63862021-01-29 15:58:13 -060069@@ -220,6 +220,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 Geisslerbffdb3e2020-08-21 16:13:29 -050077 IF(MSVC)
78 SET(libs_to_export_symbols sql mysys dbug strings)
79 # Create shared library of already compiled object
80--
812.17.1
82