diff options
| author | Khem Raj <raj.khem@gmail.com> | 2020-03-18 15:23:21 -0700 |
|---|---|---|
| committer | Khem Raj <raj.khem@gmail.com> | 2020-03-18 15:33:49 -0700 |
| commit | 42676e95014928a1c4a9a03866ddfbd84b73220f (patch) | |
| tree | 18df949b8546617b5c551502e1716ac81a7194ae | |
| parent | 6adacfcdbb29f3ed003307d1584167b7d2e92910 (diff) | |
| download | meta-openembedded-42676e95014928a1c4a9a03866ddfbd84b73220f.tar.gz | |
rocksdb: Fix build on platforms not having all atomic intrinsics
Signed-off-by: Khem Raj <raj.khem@gmail.com>
| -rw-r--r-- | meta-oe/recipes-dbs/rocksdb/files/0001-cmake-Add-check-for-atomic-support.patch | 115 | ||||
| -rw-r--r-- | meta-oe/recipes-dbs/rocksdb/rocksdb_git.bb | 1 |
2 files changed, 116 insertions, 0 deletions
diff --git a/meta-oe/recipes-dbs/rocksdb/files/0001-cmake-Add-check-for-atomic-support.patch b/meta-oe/recipes-dbs/rocksdb/files/0001-cmake-Add-check-for-atomic-support.patch new file mode 100644 index 0000000000..9bfb1f31d9 --- /dev/null +++ b/meta-oe/recipes-dbs/rocksdb/files/0001-cmake-Add-check-for-atomic-support.patch | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | From ba0a0e54d9544babbd3963891f4e3200dd5583f5 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Wed, 18 Mar 2020 15:10:37 -0700 | ||
| 4 | Subject: [PATCH] cmake: Add check for atomic support | ||
| 5 | |||
| 6 | Detect if libatomic should be linked in or compiler and platform can | ||
| 7 | provide the needed atomic instrinsics, this helps build on certain | ||
| 8 | platforms like mips or clang/i386 | ||
| 9 | |||
| 10 | Fixes | ||
| 11 | |||
| 12 | | /mnt/b/yoe/build/tmp/work/mips32r2-yoe-linux/rocksdb/6.6.4-r0/recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-ld: librocksdb.so.6.6.4: undefined reference to `__atomic_exchange_8' | ||
| 13 | | /mnt/b/yoe/build/tmp/work/mips32r2-yoe-linux/rocksdb/6.6.4-r0/recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-ld: librocksdb.so.6.6.4: undefined reference to `__atomic_fetch_or_8' | ||
| 14 | | /mnt/b/yoe/build/tmp/work/mips32r2-yoe-linux/rocksdb/6.6.4-r0/recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-ld: librocksdb.so.6.6.4: undefined reference to `__atomic_compare_exchange_8' | ||
| 15 | | /mnt/b/yoe/build/tmp/work/mips32r2-yoe-linux/rocksdb/6.6.4-r0/recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-ld: librocksdb.so.6.6.4: undefined reference to `__atomic_fetch_sub_8' | ||
| 16 | | /mnt/b/yoe/build/tmp/work/mips32r2-yoe-linux/rocksdb/6.6.4-r0/recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-ld: librocksdb.so.6.6.4: undefined reference to `__atomic_load_8' | ||
| 17 | | /mnt/b/yoe/build/tmp/work/mips32r2-yoe-linux/rocksdb/6.6.4-r0/recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-ld: librocksdb.so.6.6.4: undefined reference to `__atomic_store_8' | ||
| 18 | | /mnt/b/yoe/build/tmp/work/mips32r2-yoe-linux/rocksdb/6.6.4-r0/recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-ld: librocksdb.so.6.6.4: undefined reference to `__atomic_fetch_add_8' | ||
| 19 | |||
| 20 | Upstream-Status: Submitted [https://github.com/facebook/rocksdb/pull/6555] | ||
| 21 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 22 | --- | ||
| 23 | CMakeLists.txt | 6 +++ | ||
| 24 | cmake/modules/CheckAtomic.cmake | 69 +++++++++++++++++++++++++++++++++ | ||
| 25 | 2 files changed, 75 insertions(+) | ||
| 26 | create mode 100644 cmake/modules/CheckAtomic.cmake | ||
| 27 | |||
| 28 | --- a/CMakeLists.txt | ||
| 29 | +++ b/CMakeLists.txt | ||
| 30 | @@ -780,7 +780,13 @@ if(WIN32) | ||
| 31 | set(SYSTEM_LIBS ${SYSTEM_LIBS} shlwapi.lib rpcrt4.lib) | ||
| 32 | set(LIBS ${ROCKSDB_STATIC_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) | ||
| 33 | else() | ||
| 34 | + # check if linking against libatomic is necessary | ||
| 35 | + include(CheckAtomic) | ||
| 36 | + | ||
| 37 | set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT}) | ||
| 38 | + if(HAVE_CXX_ATOMIC_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) | ||
| 39 | + set(SYSTEM_LIBS ${SYSTEM_LIBS} atomic) | ||
| 40 | + endif() | ||
| 41 | set(LIBS ${ROCKSDB_SHARED_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) | ||
| 42 | |||
| 43 | add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES}) | ||
| 44 | --- /dev/null | ||
| 45 | +++ b/cmake/modules/CheckAtomic.cmake | ||
| 46 | @@ -0,0 +1,69 @@ | ||
| 47 | +# Checks if atomic operations are supported natively or if linking against | ||
| 48 | +# libatomic is needed. | ||
| 49 | + | ||
| 50 | +# Check inspired by LLVMs cmake/modules/CheckAtomic.cmake | ||
| 51 | + | ||
| 52 | +INCLUDE(CheckCXXSourceCompiles) | ||
| 53 | +INCLUDE(CheckLibraryExists) | ||
| 54 | + | ||
| 55 | +function(check_working_cxx_atomics varname) | ||
| 56 | + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) | ||
| 57 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") | ||
| 58 | + CHECK_CXX_SOURCE_COMPILES(" | ||
| 59 | +#include <atomic> | ||
| 60 | +std::atomic<int> x; | ||
| 61 | +int main() { | ||
| 62 | + return x; | ||
| 63 | +} | ||
| 64 | +" ${varname}) | ||
| 65 | + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) | ||
| 66 | +endfunction(check_working_cxx_atomics) | ||
| 67 | + | ||
| 68 | +function(check_working_cxx_atomics64 varname) | ||
| 69 | + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) | ||
| 70 | + set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") | ||
| 71 | + CHECK_CXX_SOURCE_COMPILES(" | ||
| 72 | +#include <atomic> | ||
| 73 | +#include <cstdint> | ||
| 74 | +std::atomic<uint64_t> x (0); | ||
| 75 | +std::atomic<double> y (0); | ||
| 76 | +int main() { | ||
| 77 | + uint64_t i = x.load(std::memory_order_relaxed); | ||
| 78 | + return int(y); | ||
| 79 | +} | ||
| 80 | +" ${varname}) | ||
| 81 | + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) | ||
| 82 | +endfunction(check_working_cxx_atomics64) | ||
| 83 | + | ||
| 84 | +# Check if atomics work without libatomic | ||
| 85 | +check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) | ||
| 86 | + | ||
| 87 | +if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) | ||
| 88 | + check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) | ||
| 89 | + if( HAVE_LIBATOMIC ) | ||
| 90 | + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") | ||
| 91 | + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) | ||
| 92 | + if (NOT HAVE_CXX_ATOMICS_WITH_LIB) | ||
| 93 | + message(FATAL_ERROR "Host compiler must support std::atomic!") | ||
| 94 | + endif() | ||
| 95 | + else() | ||
| 96 | + message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.") | ||
| 97 | + endif() | ||
| 98 | +endif() | ||
| 99 | + | ||
| 100 | +# Check if 64bit atomics work without libatomic | ||
| 101 | +check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) | ||
| 102 | + | ||
| 103 | +if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) | ||
| 104 | + check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) | ||
| 105 | + if(HAVE_CXX_LIBATOMICS64) | ||
| 106 | + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") | ||
| 107 | + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) | ||
| 108 | + if (NOT HAVE_CXX_ATOMICS64_WITH_LIB) | ||
| 109 | + message(FATAL_ERROR "Host compiler must support std::atomic!") | ||
| 110 | + endif() | ||
| 111 | + else() | ||
| 112 | + message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.") | ||
| 113 | + endif() | ||
| 114 | +endif() | ||
| 115 | + | ||
diff --git a/meta-oe/recipes-dbs/rocksdb/rocksdb_git.bb b/meta-oe/recipes-dbs/rocksdb/rocksdb_git.bb index e82b77e147..addf9552b5 100644 --- a/meta-oe/recipes-dbs/rocksdb/rocksdb_git.bb +++ b/meta-oe/recipes-dbs/rocksdb/rocksdb_git.bb | |||
| @@ -12,6 +12,7 @@ PV = "6.6.4" | |||
| 12 | 12 | ||
| 13 | SRC_URI = "git://github.com/facebook/${BPN}.git;branch=${SRCBRANCH} \ | 13 | SRC_URI = "git://github.com/facebook/${BPN}.git;branch=${SRCBRANCH} \ |
| 14 | file://0001-db-write_thread.cc-Initialize-state.patch \ | 14 | file://0001-db-write_thread.cc-Initialize-state.patch \ |
| 15 | file://0001-cmake-Add-check-for-atomic-support.patch \ | ||
| 15 | " | 16 | " |
| 16 | 17 | ||
| 17 | S = "${WORKDIR}/git" | 18 | S = "${WORKDIR}/git" |
