Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build faild in Gentoo RISCV: undefined reference to `__atomic_compare_exchange_1' #17449

Closed
liangyongxiang opened this issue Dec 29, 2021 · 11 comments
Labels

Comments

@liangyongxiang
Copy link

Steps to reproduce

  1. Based on qemu-user or riscv hardware, using the system gentoo riscv stage3
  2. ekeyword riscv for gentoo:
ekeyword ~riscv /var/db/repo/gentoo/dev-cpp/ms-gsl/ms-gsl-3.1.0.ebuild
ekeyword ~riscv /var/db/repo/gentoo/ev-cpp/range-v3/range-v3-0.11.0.ebuild
ekeyword ~riscv /var/db/repo/gentoo/edia-libs/libtgvoip/libtgvoip-2.4.4_p20211129.ebuild
ekeyword ~riscv /var/db/repo/gentoo/edia-libs/rnnoise/rnnoise-0.4.1_p20210122.ebuild
ekeyword ~riscv /var/db/repo/gentoo/edia-libs/tg_owt/tg_owt-0_pre20211207.ebuild
ekeyword ~riscv /var/db/repo/gentoo/et-im/telegram-desktop/telegram-desktop-3.3.0.ebuild
ekeyword ~riscv /var/db/repo/gentoo/et-libs/usrsctp/usrsctp-0.9.5.0.ebuild
  1. build tdesktop
emerge telegram-desktop

Expected behaviour

It can be compiled successfully without manually appending '-pthread' to LDFLAGS.

Actual behaviour

Build faild:

: && /usr/bin/riscv64-unknown-linux-gnu-g++ -O2 -pipe -ggdb -Wl,-O1 -Wl,--as-needed     -Wl,--as-needed Telegram/codegen/codegen/common/CMakeFiles/codegen_common.dir/basic_tokenized_file.cpp.o Telegram/codegen/codegen/common/CMakeFiles/codegen_common.dir/checked_utf8_string.cpp.o Telegram/codegen/codegen/common/CMakeFiles/codegen_common.dir/clean_file.cpp.o Telegram/codegen/codegen/common/CMakeFiles/codegen_common.dir/cpp_file.cpp.o Telegram/codegen/codegen/common/CMakeFiles/codegen_common.dir/logging.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/common/crl_common_fp_exceptions.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/common/crl_common_list.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/common/crl_common_on_main.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/common/crl_common_queue.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/dispatch/crl_dispatch_async.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/dispatch/crl_dispatch_queue.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/dispatch/crl_dispatch_semaphore.cpp.o
Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/linux/crl_linux_time.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/qt/crl_qt_async.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/qt/crl_qt_semaphore.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/winapi/crl_winapi_async.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/winapi/crl_winapi_fp_exceptions.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/winapi/crl_winapi_list.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/winapi/crl_winapi_semaphore.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/winapi/crl_winapi_time.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/crl_object_on_thread.cpp.o Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/crl_time.cpp.o Telegram/codegen/codegen/style/CMakeFiles/codegen_style.dir/generator.cpp.o Telegram/codegen/codegen/style/CMakeFiles/codegen_style.dir/main.cpp.o Telegram/codegen/codegen/style/CMakeFiles/codegen_style.dir/module.cpp.o Telegram/codegen/codegen/style/CMakeFiles/codegen_style.dir/options.cpp.o Telegram/codegen/codegen/style/CMakeFiles/codegen_style.dir/parsed_file.cpp.o Telegram/codegen/codegen/style/CMakeFiles/codegen_style.dir/processor.cpp.o Telegram/codegen/codegen/style/CMakeFiles/codegen_style.dir/structure_types.cpp.o -o Telegram/codegen/codegen/style/codegen_style  Telegram/lib_base/liblib_base.a  -lpthread  /usr/lib64/libQt5Network.so.5.15.2  /usr/lib64/libQt5Svg.so.5.15.2
/usr/lib64/libQt5Widgets.so.5.15.2  /usr/lib64/libQt5DBus.so.5.15.2  /usr/lib64/libQt5XkbCommonSupport.a  /usr/lib64//libQt5Gui.so  /usr/lib64//libQt5Core.so  /usr/lib64/lp64d/libxkbcommon.so  /usr/lib64/lp64d/libGL.so  /usr/lib64/libQt5WaylandClient.so.5.15.2  /usr/lib64/libQt5Gui.so.5.15.2  /usr/lib64/libQt5Core.so.5.15.2  /usr/lib64/libssl.so  /usr/lib64/libcrypto.so  /usr/lib64/libcrypto.so  /usr/lib64/libgiomm-2.4.so  /usr/lib64/libglibmm-2.4.so  /usr/lib64/libsigc-2.0.so  /usr/lib64/libgio-2.0.so  /usr/lib64/libgobject-2.0.so  /usr/lib64/libglib-2.0.so  /usr/lib64/libxcb-keysyms.so  /usr/lib64/libxcb-record.so  /usr/lib64/libxcb-screensaver.so  /usr/lib64/libxcb.so && :
/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/../../../../riscv64-unknown-linux-gnu/bin/ld: Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/common/crl_common_queue.cpp.o: in function `std::__atomic_base<bool>::compare_exchange_strong(bool&, bool, std::memory_order, std::memory_order)':
/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/include/g++-v11/bits/atomic_base.h:571: undefined reference to `__atomic_compare_exchange_1'
/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/../../../../riscv64-unknown-linux-gnu/bin/ld: Telegram/lib_crl/CMakeFiles/lib_crl.dir/crl/crl_object_on_thread.cpp.o: in function
`std::unique_lock<std::mutex>::unlock()':
/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/include/g++-v11/bits/unique_lock.h:193: undefined reference to `__atomic_compare_exchange_1'
collect2: error: ld returned 1 exit status

And if I append '-pthread' to LDFLAGS manually, it compiles successfully and works fine

Operating system

Gentoo RISCV

Version of Telegram Desktop

3.3.0

Installation source

Other (unofficial) source

Logs

The full log is too long, so I put it in gists: https://gist.github.com/bc3a35f7a5a0c829b8c6bf188eb4b696
@ilya-fedin
Copy link
Contributor

Well, no one here has RISC-V hardware, maybe you can propose fix on your own with a PR?

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Dec 29, 2021

Hmm, looking at the log, you need to link with libatomic, tdesktop's build system tries to link with it if it can find libatomic, maybe it's in some directory that cmake is not aware of, you can set the path to libatomic directory with -DCMAKE_LIBRARY_PATH and it should build just fine

@liangyongxiang
Copy link
Author

Hmm, looking at the log, you need to link with libatomic, tdesktop's build system tries to link with it if it can find libatomic, maybe it's in some directory that cmake is not aware of, you can set the path to libatomic directory with -DCMAKE_LIBRARY_PATH and it should build just fine

I tried just adding "-latomic" and the result is the same as before: https://gist.github.com/liangyongxiang/2230c6e76df4c0adc7d2f05d8725e035#file-homeyongxiangriscv-workbtrfs-imagesriscv-systemd-2021-12-23rootbuild-append-log-L408

I'll try -DCMAKE_LIBRARY_PATH later

@ilya-fedin
Copy link
Contributor

It won't help apparently, then

@liangyongxiang
Copy link
Author

In my environment libatomic is here.

find /usr/|grep libatomic.so

/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/libatomic.so
/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/libatomic.so.1
/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/libatomic.so.1.2.0

What should -DCMAKE_LIBRARY_PATH be?

It won't help apparently, then

@ilya-fedin
Copy link
Contributor

/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1

@liangyongxiang
Copy link
Author

/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1

Yes. It worked.
But I don't know if there is a more perfect solution, so I also report to https://bugs.gentoo.org/830286.

@Aokromes
Copy link
Collaborator

so, 3rd party bug?

@ilya-fedin
Copy link
Contributor

Not a bug, just libatomic is not in standard directories on his system

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Jan 5, 2022

I reworked libdl/libpthread handling, now (on dev branch) -pthread is used instead of -lpthread and manual atomic linking is removed

@mid-kid
Copy link
Contributor

mid-kid commented Jan 6, 2022

Thanks, was about to comment this, -pthread should be used when threading is required.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants