Source: ceph
Version: 16.2.7+ds-4
Severity: important
Tags: ftbfs patch
Justification: fails to build from source (but built successfully in the past)
X-Debbugs-Cc: i...@hack3r.moe

Dear maintainers,

Ceph does not build on riscv64 due to not linking to libatomic: 

```
/usr/bin/ld: ../../lib/libos.a(MemStore.cc.o): in function 
`std::__atomic_base<unsigned short>::operator++()':
/usr/include/c++/12/bits/atomic_base.h:385: undefined reference to 
`__atomic_fetch_add_2'
/usr/bin/ld: ../../lib/libos.a(MemStore.cc.o): in function 
`std::__atomic_base<unsigned short>::operator--()':
/usr/include/c++/12/bits/atomic_base.h:393: undefined reference to 
`__atomic_fetch_sub_2'
/usr/bin/ld: ../../lib/libos.a(MemStore.cc.o): in function 
`std::__atomic_base<unsigned short>::operator++()':
/usr/include/c++/12/bits/atomic_base.h:385: undefined reference to 
`__atomic_fetch_add_2'
/usr/bin/ld: ../../lib/libos.a(MemStore.cc.o): in function 
`std::__atomic_base<unsigned short>::operator--()':
/usr/include/c++/12/bits/atomic_base.h:393: undefined reference to 
`__atomic_fetch_sub_2'
/usr/bin/ld: /usr/include/c++/12/bits/atomic_base.h:393: undefined reference to 
`__atomic_fetch_sub_2'
/usr/bin/ld: /usr/include/c++/12/bits/atomic_base.h:393: undefined reference to 
`__atomic_fetch_sub_2'
/usr/bin/ld: /usr/include/c++/12/bits/atomic_base.h:393: undefined reference to 
`__atomic_fetch_sub_2'
/usr/bin/ld: ../../lib/libblk.a(KernelDevice.cc.o): in function 
`std::__atomic_base<bool>::compare_exchange_strong(bool&, bool, 
std::memory_order, std::memory_order)':
/usr/include/c++/12/bits/atomic_base.h:560: undefined reference to 
`__atomic_compare_exchange_1'
/usr/bin/ld: ../rocksdb/librocksdb.a(memtable.cc.o): in function 
`rocksdb::MergeContext::GetOperandsDirectionBackward()':
/<<PKGBUILDDIR>>/src/rocksdb/db/merge_context.h:98: undefined reference to 
`__atomic_compare_exchange_1'
/usr/bin/ld: ../rocksdb/librocksdb.a(memtable.cc.o): in function 
`std::__atomic_base<bool>::compare_exchange_weak(bool&, bool, 
std::memory_order, std::memory_order)':
/usr/include/c++/12/bits/atomic_base.h:523: undefined reference to 
`__atomic_compare_exchange_1'
/usr/bin/ld: /usr/include/c++/12/bits/atomic_base.h:523: undefined reference to 
`__atomic_compare_exchange_1'
/usr/bin/ld: /usr/include/c++/12/bits/atomic_base.h:523: undefined reference to 
`__atomic_compare_exchange_1'
/usr/bin/ld: 
../rocksdb/librocksdb.a(memtable.cc.o):/usr/include/c++/12/bits/atomic_base.h:523:
 more undefined references to `__atomic_compare_exchange_1' follow
collect2: error: ld returned 1 exit status
make[3]: *** [src/os/CMakeFiles/ceph-bluestore-tool.dir/build.make:134: 
bin/ceph-bluestore-tool] Error 1
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-riscv64-linux-gnu'
make[2]: *** [CMakeFiles/Makefile2:4724: 
src/os/CMakeFiles/ceph-bluestore-tool.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
```

Full buildd log: 
https://buildd.debian.org/status/fetch.php?pkg=ceph&arch=riscv64&ver=16.2.10%2Bds-2%2Bb3&stamp=1661840444&raw=0

This is because riscv64 does not have full support for atomic primitives, yet
passes the test located at cmake/modules/CheckCxxAtomic.cmake. I've attached a
patch to fix the issue.

The patch is also submitted upstream: https://github.com/ceph/ceph/pull/47883

Please let me know if I missed anything.

Cheers,
Eric

-- System Information:
Debian Release: bookworm/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.18.0-4-amd64 (SMP w/8 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Description: Fix CheckCxxAtomic to detect more accurately
 Some platforms like riscv64 does not have full support for atomic primitives,
 yet passes the test. Adding operator++ fixes this issue.
Author: Eric Long <i...@hack3r.moe>
Last-Update: 2022-08-30
--- a/cmake/modules/CheckCxxAtomic.cmake
+++ b/cmake/modules/CheckCxxAtomic.cmake
@@ -32,7 +32,7 @@
   std::atomic<uint16_t> w2;
   std::atomic<uint32_t> w4;
   std::atomic<uint64_t> w8;
-  return w1 + w2 + w4 + w8;
+  return ++w1 + ++w2 + ++w4 + ++w8;
 }
 " ${var})
 endfunction(check_cxx_atomics)

Reply via email to