All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rocksdb: Fix build with gcc on rv32 and mips
@ 2021-06-19  0:03 Khem Raj
  0 siblings, 0 replies; only message in thread
From: Khem Raj @ 2021-06-19  0:03 UTC (permalink / raw)
  To: openembedded-devel; +Cc: Khem Raj

__sync_fetch_and_add (64bit) are not impelemented in gcc and clang
smartly converts them to __atomic_fetch_add() APIs, so do that
manually when using gcc for compiler

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 ...-with-new-atomic-builtin-equivalents.patch | 59 +++++++++++++++++++
 meta-oe/recipes-dbs/rocksdb/rocksdb_6.20.3.bb |  4 ++
 2 files changed, 63 insertions(+)
 create mode 100644 meta-oe/recipes-dbs/rocksdb/files/0001-replace-old-sync-with-new-atomic-builtin-equivalents.patch

diff --git a/meta-oe/recipes-dbs/rocksdb/files/0001-replace-old-sync-with-new-atomic-builtin-equivalents.patch b/meta-oe/recipes-dbs/rocksdb/files/0001-replace-old-sync-with-new-atomic-builtin-equivalents.patch
new file mode 100644
index 0000000000..4aa91d9b26
--- /dev/null
+++ b/meta-oe/recipes-dbs/rocksdb/files/0001-replace-old-sync-with-new-atomic-builtin-equivalents.patch
@@ -0,0 +1,59 @@
+From 114c42fba3fc86119710e8dd1bb2b7a9e39e3064 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Thu, 17 Jun 2021 19:35:01 -0700
+Subject: [PATCH] replace old sync with new atomic builtin equivalents
+
+Helps compiling with gcc on newer arches e.g. riscv32 where these
+__sync* builtins are not implemented atleast for 64bit values
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ .../range/range_tree/lib/portability/toku_atomic.h   | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+--- a/utilities/transactions/lock/range/range_tree/lib/portability/toku_atomic.h
++++ b/utilities/transactions/lock/range/range_tree/lib/portability/toku_atomic.h
+@@ -77,37 +77,37 @@ template <typename T, typename U>
+ __attribute__((always_inline)) static inline T toku_sync_fetch_and_add(T *addr,
+                                                                        U diff) {
+   paranoid_invariant(!crosses_boundary(addr, sizeof *addr));
+-  return __sync_fetch_and_add(addr, diff);
++  return __atomic_fetch_add(addr, diff, 5);
+ }
+ template <typename T, typename U>
+ __attribute__((always_inline)) static inline T toku_sync_add_and_fetch(T *addr,
+                                                                        U diff) {
+   paranoid_invariant(!crosses_boundary(addr, sizeof *addr));
+-  return __sync_add_and_fetch(addr, diff);
++  return __atomic_add_fetch(addr, diff, 5);
+ }
+ template <typename T, typename U>
+ __attribute__((always_inline)) static inline T toku_sync_fetch_and_sub(T *addr,
+                                                                        U diff) {
+   paranoid_invariant(!crosses_boundary(addr, sizeof *addr));
+-  return __sync_fetch_and_sub(addr, diff);
++  return __atomic_fetch_sub(addr, diff, 5);
+ }
+ template <typename T, typename U>
+ __attribute__((always_inline)) static inline T toku_sync_sub_and_fetch(T *addr,
+                                                                        U diff) {
+   paranoid_invariant(!crosses_boundary(addr, sizeof *addr));
+-  return __sync_sub_and_fetch(addr, diff);
++  return __atomic_sub_fetch(addr, diff, 5);
+ }
+ template <typename T, typename U, typename V>
+ __attribute__((always_inline)) static inline T toku_sync_val_compare_and_swap(
+     T *addr, U oldval, V newval) {
+   paranoid_invariant(!crosses_boundary(addr, sizeof *addr));
+-  return __sync_val_compare_and_swap(addr, oldval, newval);
++  return __atomic_compare_exchange(addr, oldval, newval);
+ }
+ template <typename T, typename U, typename V>
+ __attribute__((always_inline)) static inline bool
+ toku_sync_bool_compare_and_swap(T *addr, U oldval, V newval) {
+   paranoid_invariant(!crosses_boundary(addr, sizeof *addr));
+-  return __sync_bool_compare_and_swap(addr, oldval, newval);
++  return static_cast<bool>(__atomic_compare_exchange(addr, oldval, newval));
+ }
+ 
+ // in case you include this but not toku_portability.h
diff --git a/meta-oe/recipes-dbs/rocksdb/rocksdb_6.20.3.bb b/meta-oe/recipes-dbs/rocksdb/rocksdb_6.20.3.bb
index 99bfdd4264..c89d5d4313 100644
--- a/meta-oe/recipes-dbs/rocksdb/rocksdb_6.20.3.bb
+++ b/meta-oe/recipes-dbs/rocksdb/rocksdb_6.20.3.bb
@@ -20,6 +20,10 @@ SRC_URI = "git://github.com/facebook/${BPN}.git;branch=${SRCBRANCH} \
            file://arm.patch \
           "
 
+SRC_URI_append_riscv32 = " file://0001-replace-old-sync-with-new-atomic-builtin-equivalents.patch"
+SRC_URI_append_mips = " file://0001-replace-old-sync-with-new-atomic-builtin-equivalents.patch"
+SRC_URI_remove_toolchain-clang_riscv32 = "file://0001-replace-old-sync-with-new-atomic-builtin-equivalents.patch"
+
 S = "${WORKDIR}/git"
 
 inherit cmake
-- 
2.32.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-19  0:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-19  0:03 [PATCH] rocksdb: Fix build with gcc on rv32 and mips Khem Raj

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.