arvidn / libtorrent

an efficient feature complete C++ bittorrent implementation
http://libtorrent.org
Other
5.28k stars 997 forks source link

client_test build issue with Boost atomic library #4657

Closed jamesr42 closed 3 years ago

jamesr42 commented 4 years ago

libtorrent version (or branch): 1.2.6 platform/architecture: Raspberry Pi 3 ARM compiler and compiler version: gcc 8.3.0 Boost: 1.73, fresh build of b2

Awesome product, btw ... refreshing my coding and design skills using it. Python bindings make it possible to interactively do torrenting stuff as a learning/technical experience. A+!

libtorrent library shared and static build ok, but client_test does not, seems to be a problem with the Boost atomic library. Odd (in Boost) that it compiled, but could not find functions in library.

b2 release runtime-link=shared link=shared -j 2 client_test
../Jamroot.jam:1: syntax error at EOF
CXXFLAGS =
LDFLAGS =
OS = LINUX
building boost from source directory:  /home/pi/boost_1_73_0
Performing configuration checks

    - default address-model    : 32-bit (cached)
    - default architecture     : arm (cached)
...patience...
...patience...
...patience...
...found 3215 targets...
...updating 1 target...
gcc.link bin/gcc-8/release/threading-multi/client_test
/usr/bin/ld: ../bin/gcc-8/release/threading-multi/libtorrent.so.1.2.6: undefined reference to '__atomic_compare_exchange_8'
/usr/bin/ld: ../bin/gcc-8/release/threading-multi/libtorrent.so.1.2.6: undefined reference to '__atomic_load_8'
/usr/bin/ld: ../bin/gcc-8/release/threading-multi/libtorrent.so.1.2.6: undefined reference to '__atomic_store_8'
/usr/bin/ld: ../bin/gcc-8/release/threading-multi/libtorrent.so.1.2.6: undefined reference to '__atomic_fetch_add_8'
collect2: error: ld returned 1 exit status

    "g++"  -Wl,-rpath -Wl,"/home/pi/boost_1_73_0/bin.v2/libs/system/build/gcc-8/release/threading-multi/visibility-hidden" -Wl,-rpath -Wl,"/home/pi/libtorrent-rasterbar-1.2.6/bin/gcc-8/release/threading-multi" -Wl,-rpath-link -Wl,"/home/pi/boost_1_73_0/bin.v2/libs/system/build/gcc-8/release/threading-multi/visibility-hidden" -Wl,-rpath-link -Wl,"/home/pi/libtorrent-rasterbar-1.2.6/bin/gcc-8/release/threading-multi" -o "bin/gcc-8/release/threading-multi/client_test" -Wl,--start-group "bin/gcc-8/release/threading-multi/client_test.o" "bin/gcc-8/release/threading-multi/print.o" "bin/gcc-8/release/threading-multi/torrent_view.o" "bin/gcc-8/release/threading-multi/session_view.o" "../bin/gcc-8/release/threading-multi/libtorrent.so.1.2.6" "/home/pi/boost_1_73_0/bin.v2/libs/system/build/gcc-8/release/threading-multi/visibility-hidden/libboost_system.so.1.73.0"  -Wl,-Bstatic  -Wl,-Bdynamic -lrt -Wl,--end-group -fPIC -pthread

...failed gcc.link bin/gcc-8/release/threading-multi/client_test...
...failed updating 1 target...

b2 release -j 2 client_test
../Jamroot.jam:1: syntax error at EOF
CXXFLAGS =
LDFLAGS =
OS = LINUX
building boost from source directory:  /home/pi/boost_1_73_0
Performing configuration checks

    - default address-model    : 32-bit (cached)
    - default architecture     : arm (cached)
...patience...
...patience...
...patience...
...found 3220 targets...
...updating 1 target...
gcc.link bin/gcc-8/release/link-static/threading-multi/client_test
/usr/bin/ld: ../bin/gcc-8/release/link-static/threading-multi/libtorrent.a(performance_counters.o): in function 'libtorrent::counters::counters()':
performance_counters.cpp:(.text+0x30): undefined reference to '__atomic_store_8'
/usr/bin/ld: ../bin/gcc-8/release/link-static/threading-multi/libtorrent.a(performance_counters.o): in function 'libtorrent::counters::counters(libtorrent::counters const&)':
performance_counters.cpp:(.text+0x70): undefined reference to '__atomic_load_8'
/usr/bin/ld: performance_counters.cpp:(.text+0x88): undefined reference to '__atomic_store_8'
/usr/bin/ld: ../bin/gcc-8/release/link-static/threading-multi/libtorrent.a(performance_counters.o): in function 'libtorrent::counters::operator=(libtorrent::counters const&)':
performance_counters.cpp:(.text+0xd4): undefined reference to '__atomic_load_8'
/usr/bin/ld: performance_counters.cpp:(.text+0xec): undefined reference to '__atomic_store_8'
/usr/bin/ld: ../bin/gcc-8/release/link-static/threading-multi/libtorrent.a(performance_counters.o): in function 'libtorrent::counters::operator[](int) const':
performance_counters.cpp:(.text+0x110): undefined reference to '__atomic_load_8'
/usr/bin/ld: ../bin/gcc-8/release/link-static/threading-multi/libtorrent.a(performance_counters.o): in function 'libtorrent::counters::inc_stats_counter(int, long long)':
performance_counters.cpp:(.text+0x130): undefined reference to '__atomic_fetch_add_8'
/usr/bin/ld: ../bin/gcc-8/release/link-static/threading-multi/libtorrent.a(performance_counters.o): in function 'libtorrent::counters::blend_stats_counter(int, long long, int)':
performance_counters.cpp:(.text+0x164): undefined reference to '__atomic_load_8'
/usr/bin/ld: performance_counters.cpp:(.text+0x1d0): undefined reference to '__atomic_compare_exchange_8'
/usr/bin/ld: ../bin/gcc-8/release/link-static/threading-multi/libtorrent.a(performance_counters.o): in function 'libtorrent::counters::set_value(int, long long)':
performance_counters.cpp:(.text+0x230): undefined reference to '__atomic_store_8'
collect2: error: ld returned 1 exit status

    "g++"    -o "bin/gcc-8/release/link-static/threading-multi/client_test" -Wl,--start-group "bin/gcc-8/release/link-static/threading-multi/client_test.o" "bin/gcc-8/release/link-static/threading-multi/print.o" "bin/gcc-8/release/link-static/threading-multi/torrent_view.o" "bin/gcc-8/release/link-static/threading-multi/session_view.o" "../bin/gcc-8/release/link-static/threading-multi/libtorrent.a" "/home/pi/boost_1_73_0/bin.v2/libs/system/build/gcc-8/release/link-static/threading-multi/visibility-hidden/libboost_system.a"  -Wl,-Bstatic  -Wl,-Bdynamic -lrt -Wl,--end-group -pthread

...failed gcc.link bin/gcc-8/release/link-static/threading-multi/client_test...
...failed updating 1 target...
arvidn commented 4 years ago

I don't think those are boost.atomic symbols. Those look like runtime or libgcc symbols

arvidn commented 4 years ago

they seem to be part of libccc: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

jamesr42 commented 4 years ago

Apologies I am duh I did not even google that. May also be libatomic, although I Raspbian has that. Continuing to investigate.

jamesr42 commented 4 years ago

Yup it's libatomic; if I do this:

export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1

Then python3 imports libtorrent ok.

Would Boost be responsible for linking in libatomic? My theory is performance_counters -> atomic -> libatomic

arvidn commented 4 years ago

no, I just use the standard library. i.e. std::atomic

arvidn commented 4 years ago

"no" to it being a transitive dependency via boost. "yes" on the performance counters use atomic operations

jamesr42 commented 4 years ago

OK gotcha. Now to figure out why libatomic is not being linked in.

johang commented 4 years ago

They're hitting this problem for certain archs in Debian too:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=958958

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

micdonato commented 4 years ago

Wait, I am not sure how to solve this yet. I followed the tutorial on the deluge webpage, everything goes well until I try to import libtorrent from python and I get this error:

elusero:elcomputero~ $ python -c "import libtorrent; print (libtorrent.version)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: /usr/local/lib/libtorrent-rasterbar.so.10: undefined symbol: __atomic_fetch_add_8
arvidn commented 4 years ago

this might give some hints: https://stackoverflow.com/questions/42887975/how-to-link-against-the-libatomic-library-in-gcc

if you run ldd on the libtorrent module, do you see a dependency on libatomic?

micdonato commented 4 years ago

this might give some hints: https://stackoverflow.com/questions/42887975/how-to-link-against-the-libatomic-library-in-gcc

if you run ldd on the libtorrent module, do you see a dependency on libatomic?

Hmmm no, I do not see the dependency:

elusero:elcomputero:~ $ ldd /usr/local/lib/libtorrent-rasterbar.so.10
    linux-vdso.so.1 (0x7ec41000)
    /usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so (0x76c10000)
    libssl.so.1.1 => /usr/lib/arm-linux-gnueabihf/libssl.so.1.1 (0x76b91000)
    libcrypto.so.1.1 => /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.1 (0x76978000)
    libboost_system.so.1.67.0 => /usr/lib/arm-linux-gnueabihf/libboost_system.so.1.67.0 (0x76964000)
    libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0x7693a000)
    libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0x767f3000)
    libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x76771000)
    libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x76623000)
    /lib/ld-linux-armhf.so.3 (0x76f7c000)
    libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0x765f6000)
    libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0x765e3000)
    librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0x765ca000)
elusero:elcomputero:~ $ ldd /usr/local/lib/libtorrent-rasterbar.so.10 | grep ato
elusero:elcomputero:~ $ 

About the stackoverflow post, they suggest to look at the file /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libatomic.so. I did not have one there, and I thought it would be because of the different version of gcc (I have 8.3) so I checked /usr/lib/gcc/x86_64-redhat-linux/8/libatomic.so but it is not the "single line of text" described in the stackoverflow post, but it seems to be a binary file.

Maybe I should open a different issue?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

FranciscoPombal commented 3 years ago

I think this is basically a duplicate of https://github.com/arvidn/libtorrent/issues/5117 (or, rather, that new one is a duplicate of this one). I have worked on a suitable patch and will submit it soon.

FranciscoPombal commented 3 years ago

https://github.com/arvidn/libtorrent/pull/5748