Source: opendht
Version: 2.1.9.5-1
Severity: normal
Tags: ftbfs patch upstream
User: debian-ri...@lists.debian.org
Usertags: riscv64

Hi,

opendht fails to build on riscv64 with the following failure:
| /usr/bin/c++ -g -O2 -fdebug-prefix-map=/<<PKGBUILDDIR>>=. 
-fstack-protector-strong -Wformat -Werror=format-security -Wdate-time 
-D_FORTIFY_SOURCE=2 -Wno-return-type -Wall -Wextra -Wnon-virtual-dtor 
-pedantic-errors -fvisibility=hidden -DMSGPACK_DISABLE_LEGACY_NIL 
-DMSGPACK_DISABLE_LEGACY_CONVERT -Wl,-z,relro -Wl,-z,now -rdynamic 
CMakeFiles/durl.dir/durl.cpp.o -o durl  -lreadline -lncurses ../libopendht.a 
-largon2 -lrt -ldl -lpthread -lgnutls -lnettle -ljsoncpp -Wl,-Bstatic -lfmt 
-Wl,-Bdynamic -lhttp_parser -lssl -lcrypto -ldl -lpthread -lgnutls -lnettle 
-ljsoncpp -Wl,-Bstatic -lfmt -Wl,-Bdynamic -lhttp_parser -lssl -lcrypto 
| /usr/bin/ld: ../libopendht.a(http.cpp.o): in function `.L0 ':
| /usr/include/asio/detail/completion_handler.hpp:72: undefined reference to 
`__atomic_exchange_1'
| /usr/bin/ld: ../libopendht.a(network_utils.cpp.o): in function 
`dht::net::UdpSocket::stop()':
| ./obj-riscv64-linux-gnu/./src/network_utils.cpp:350: undefined reference to 
`__atomic_exchange_1'
| /usr/bin/ld: ../libopendht.a(dht_proxy_client.cpp.o): in function 
`__gnu_cxx::__exchange_and_add_single(int*, int)':
| /usr/include/c++/10/ext/atomicity.h:69: undefined reference to 
`__atomic_exchange_1'
| collect2: error: ld returned 1 exit status

The full build log is available there:
https://buildd.debian.org/status/fetch.php?pkg=opendht&arch=riscv64&ver=2.1.9.5-1&stamp=1607520181&raw=0

The problem is that the linking is not done correctly, it uses -lpthread
meaning linking with the pthread library, instead of -pthread which
means enable thread support, and which brings libatomic.so on riscv64.
This can be fixed by using the THREADS_PREFER_PTHREAD_FLAG option, which
is "highly recommended" according to the documentation, but
unfortunately not the default.

This is what the attached patch does, could you please include it in the
next upload?

Thanks,
Aurelien
--- opendht-2.1.9.5/debian/patches/link-pthread.patch   1970-01-01 
00:00:00.000000000 +0000
+++ opendht-2.1.9.5/debian/patches/link-pthread.patch   2020-12-28 
10:55:59.000000000 +0000
@@ -0,0 +1,18 @@
+Description: Link with -pthread instead of -lpthread
+ The canonical way to link with the thread library is to use -pthread, which
+ brings in additional libraries like libatomic.so on riscv64. However cmake
+ defaults to link with -lpthread which only bring the libpthread.so library.
+ Fortunately it has the option THREADS_PREFER_PTHREAD_FLAG for that, which is
+ "highly recommended" but not the default.
+Author: Aurelien Jarno <aure...@debian.org>
+
+--- opendht-2.1.9.5.orig/CMakeLists.txt
++++ opendht-2.1.9.5/CMakeLists.txt
+@@ -42,6 +42,7 @@ option (OPENDHT_DOCUMENTATION "Create an
+ # Dependencies
+ list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
+ if (NOT MSVC)
++    set (THREADS_PREFER_PTHREAD_FLAG TRUE)
+     find_package (Threads)
+     find_package (PkgConfig REQUIRED)
+     find_package (GnuTLS 3.3 REQUIRED)
--- opendht-2.1.9.5/debian/patches/series       2020-12-08 22:56:05.000000000 
+0000
+++ opendht-2.1.9.5/debian/patches/series       2020-12-28 10:55:59.000000000 
+0000
@@ -1 +1,2 @@
 pkgconfig-static.patch
+link-pthread.patch

Reply via email to